mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-10 15:16:28 +00:00
bulk code format fix (#8707)
This commit is contained in:
@@ -44,12 +44,7 @@ fn create_serialized_example_with_generated_code(builder: &mut flatbuffers::Flat
|
||||
&[-0x8000000000000000, 0x7FFFFFFFFFFFFFFF],
|
||||
);
|
||||
// Test five makes sense when specified.
|
||||
let ss = ArrayTable::create(
|
||||
builder,
|
||||
&ArrayTableArgs {
|
||||
a: Some(&array_struct),
|
||||
},
|
||||
);
|
||||
let ss = ArrayTable::create(builder, &ArrayTableArgs { a: Some(&array_struct) });
|
||||
finish_array_table_buffer(builder, ss);
|
||||
}
|
||||
|
||||
@@ -102,10 +97,7 @@ fn serialized_example_is_accessible_and_correct(
|
||||
assert_eq!(nested_struct2.c().get(1), TestEnum::A);
|
||||
assert_eq!(nested_struct2.d().len(), 2);
|
||||
let arr: [i64; 2] = nested_struct2.d().into();
|
||||
assert_eq!(
|
||||
arr,
|
||||
[-0x1122334455667788, 0x1122334455667788]
|
||||
);
|
||||
assert_eq!(arr, [-0x1122334455667788, 0x1122334455667788]);
|
||||
|
||||
assert_eq!(array_struct.e(), 1);
|
||||
assert_eq!(array_struct.f().len(), 2);
|
||||
@@ -254,9 +246,11 @@ impl<T: Arbitrary + Debug + PartialEq, const N: usize> Arbitrary for FakeArray<T
|
||||
let x: [T; N] = array_init(|_| {
|
||||
loop {
|
||||
let generated_scalar = T::arbitrary(g);
|
||||
// Verify that generated scalar is not Nan, which is not equals to itself,
|
||||
// Verify that generated scalar is not Nan, which is not equals to itself,
|
||||
// therefore we can't use it to validate input == output
|
||||
if generated_scalar == generated_scalar { return generated_scalar; }
|
||||
if generated_scalar == generated_scalar {
|
||||
return generated_scalar;
|
||||
}
|
||||
}
|
||||
});
|
||||
FakeArray { 0: x }
|
||||
@@ -265,9 +259,9 @@ impl<T: Arbitrary + Debug + PartialEq, const N: usize> Arbitrary for FakeArray<T
|
||||
|
||||
#[cfg(test)]
|
||||
mod array_fuzz {
|
||||
#[cfg(not(miri))] // slow.
|
||||
extern crate quickcheck;
|
||||
extern crate flatbuffers;
|
||||
#[cfg(not(miri))] // slow.
|
||||
extern crate quickcheck;
|
||||
|
||||
use self::flatbuffers::{Follow, Push};
|
||||
use super::*;
|
||||
@@ -278,10 +272,10 @@ mod array_fuzz {
|
||||
// This uses a macro because lifetimes for the trait-bounded function get too
|
||||
// complicated.
|
||||
macro_rules! impl_prop {
|
||||
($test_name:ident, $fn_name:ident, $ty:ident) => (
|
||||
($test_name:ident, $fn_name:ident, $ty:ident) => {
|
||||
fn $fn_name(xs: FakeArray<$ty, ARRAY_SIZE>) {
|
||||
let mut test_buf = [0 as u8; 1024];
|
||||
let arr: flatbuffers::Array<$ty, ARRAY_SIZE> = unsafe {
|
||||
let arr: flatbuffers::Array<$ty, ARRAY_SIZE> = unsafe {
|
||||
flatbuffers::emplace_scalar_array(&mut test_buf, 0, &xs.0);
|
||||
flatbuffers::Array::follow(&test_buf, 0)
|
||||
};
|
||||
@@ -289,10 +283,12 @@ mod array_fuzz {
|
||||
assert_eq!(got, xs.0);
|
||||
}
|
||||
#[test]
|
||||
fn $test_name() {
|
||||
quickcheck::QuickCheck::new().max_tests(MAX_TESTS).quickcheck($fn_name as fn(FakeArray<$ty, ARRAY_SIZE>));
|
||||
fn $test_name() {
|
||||
quickcheck::QuickCheck::new()
|
||||
.max_tests(MAX_TESTS)
|
||||
.quickcheck($fn_name as fn(FakeArray<$ty, ARRAY_SIZE>));
|
||||
}
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
impl_prop!(test_bool, prop_bool, bool);
|
||||
@@ -322,19 +318,25 @@ mod array_fuzz {
|
||||
|
||||
fn prop_struct(xs: FakeArray<NestedStructWrapper, ARRAY_SIZE>) {
|
||||
let mut test_buf = [0 as u8; 1024];
|
||||
let native_struct_array: [&NestedStruct; ARRAY_SIZE] = array_init::from_iter(xs.0.iter().map(|x| &x.0)).unwrap();
|
||||
let native_struct_array: [&NestedStruct; ARRAY_SIZE] =
|
||||
array_init::from_iter(xs.0.iter().map(|x| &x.0)).unwrap();
|
||||
for i in 0..ARRAY_SIZE {
|
||||
let offset = i * NESTED_STRUCT_SIZE;
|
||||
unsafe { native_struct_array[i].push(&mut test_buf[offset..offset + NESTED_STRUCT_SIZE], 0) };
|
||||
unsafe {
|
||||
native_struct_array[i].push(&mut test_buf[offset..offset + NESTED_STRUCT_SIZE], 0)
|
||||
};
|
||||
}
|
||||
let arr: flatbuffers::Array<NestedStruct, ARRAY_SIZE> = unsafe { flatbuffers::Array::follow(&test_buf, 0) };
|
||||
let arr: flatbuffers::Array<NestedStruct, ARRAY_SIZE> =
|
||||
unsafe { flatbuffers::Array::follow(&test_buf, 0) };
|
||||
let got: [&NestedStruct; ARRAY_SIZE] = arr.into();
|
||||
assert_eq!(got, native_struct_array);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(miri))] // slow.
|
||||
#[cfg(not(miri))] // slow.
|
||||
fn test_struct() {
|
||||
quickcheck::QuickCheck::new().max_tests(MAX_TESTS).quickcheck(prop_struct as fn(FakeArray<NestedStructWrapper, ARRAY_SIZE>));
|
||||
quickcheck::QuickCheck::new()
|
||||
.max_tests(MAX_TESTS)
|
||||
.quickcheck(prop_struct as fn(FakeArray<NestedStructWrapper, ARRAY_SIZE>));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ fn store_vec_uint_16() {
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(not(miri))] // slow.
|
||||
#[cfg(not(miri))] // slow.
|
||||
quickcheck! {
|
||||
fn qc_f32(x: f32) -> bool {
|
||||
let fxb = singleton(x);
|
||||
|
||||
@@ -16,6 +16,6 @@ mod binary_format;
|
||||
#[cfg(not(feature = "no_std"))] // uses file I/O
|
||||
mod interop;
|
||||
mod other_api;
|
||||
#[cfg(not(miri))] // slow.
|
||||
#[cfg(not(miri))] // slow.
|
||||
mod qc_serious;
|
||||
mod rwyw;
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use flexbuffers::*;
|
||||
#[cfg(not(miri))] // slow.
|
||||
#[cfg(not(miri))] // slow.
|
||||
use quickcheck::QuickCheck;
|
||||
|
||||
#[test]
|
||||
#[cfg(not(miri))] // slow.
|
||||
#[cfg(not(miri))] // slow.
|
||||
fn qc_reader_no_crash() {
|
||||
fn no_crash(xs: Vec<u8>) -> bool {
|
||||
let r = Reader::get_root(xs.as_ref());
|
||||
@@ -165,12 +165,7 @@ fn get_root_deref_oob() {
|
||||
}
|
||||
#[test]
|
||||
fn get_root_deref_u64() {
|
||||
let s = &[
|
||||
0,
|
||||
0,
|
||||
(FlexBufferType::IndirectUInt as u8) << 2 | BitWidth::W64 as u8,
|
||||
1,
|
||||
];
|
||||
let s = &[0, 0, (FlexBufferType::IndirectUInt as u8) << 2 | BitWidth::W64 as u8, 1];
|
||||
// The risk of crashing is reading 8 bytes from index 0.
|
||||
assert_eq!(Reader::get_root(s.as_ref()).unwrap().as_u64(), 0);
|
||||
}
|
||||
|
||||
@@ -25,11 +25,7 @@ enum Enum {
|
||||
String(String),
|
||||
Strings(String, String),
|
||||
Everything(u8, u16, u32, u64, i8, i16, i32, i64, f32, f64, String),
|
||||
Arrays {
|
||||
a: Array3<u16>,
|
||||
b: Array4<i32>,
|
||||
c: Array2<f64>,
|
||||
},
|
||||
Arrays { a: Array3<u16>, b: Array4<i32>, c: Array2<f64> },
|
||||
Blobs(#[serde(with = "serde_bytes")] Vec<u8>),
|
||||
}
|
||||
|
||||
@@ -126,12 +122,7 @@ impl<A: Arbitrary> Arbitrary for Array3<A> {
|
||||
}
|
||||
impl<A: Arbitrary> Arbitrary for Array4<A> {
|
||||
fn arbitrary<G: Gen>(g: &mut G) -> Self {
|
||||
Array4([
|
||||
A::arbitrary(g),
|
||||
A::arbitrary(g),
|
||||
A::arbitrary(g),
|
||||
A::arbitrary(g),
|
||||
])
|
||||
Array4([A::arbitrary(g), A::arbitrary(g), A::arbitrary(g), A::arbitrary(g)])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use alloc::vec::Vec;
|
||||
|
||||
// Read what you wrote.
|
||||
use flexbuffers::*;
|
||||
#[cfg(not(miri))] // slow.
|
||||
#[cfg(not(miri))] // slow.
|
||||
use quickcheck;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -28,16 +28,12 @@ impl quickcheck::Arbitrary for NonNullString {
|
||||
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
|
||||
let size = core::cmp::min(1, usize::arbitrary(g));
|
||||
NonNullString(
|
||||
(0..)
|
||||
.map(|_| <char>::arbitrary(g))
|
||||
.filter(|&b| b != '\0')
|
||||
.take(size)
|
||||
.collect(),
|
||||
(0..).map(|_| <char>::arbitrary(g)).filter(|&b| b != '\0').take(size).collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(miri))] // slow.
|
||||
#[cfg(not(miri))] // slow.
|
||||
quickcheck! {
|
||||
fn qc_vec_bool(xs: Vec<bool>) -> bool {
|
||||
let mut builder = Builder::default();
|
||||
@@ -371,7 +367,7 @@ struct Foo {
|
||||
d: String,
|
||||
}
|
||||
|
||||
#[cfg(not(miri))] // slow.
|
||||
#[cfg(not(miri))] // slow.
|
||||
quickcheck! {
|
||||
fn serde_foo(a: i8,
|
||||
b: f64,
|
||||
@@ -415,22 +411,13 @@ fn serde_serious() {
|
||||
let data = MyTupleStruct(
|
||||
MyNewType,
|
||||
MyUnitStruct(vec!["Hello".to_string(), "World".to_string()]),
|
||||
MyStruct {
|
||||
a: 2,
|
||||
b: 4,
|
||||
c: 8,
|
||||
d: 16,
|
||||
},
|
||||
MyStruct { a: 2, b: 4, c: 8, d: 16 },
|
||||
vec![
|
||||
MyEnum::Unit,
|
||||
MyEnum::NewType([-1, 0, 1]),
|
||||
MyEnum::Unit,
|
||||
MyEnum::Tuple(3.14, 2.71),
|
||||
MyEnum::Struct {
|
||||
a: 32,
|
||||
b: 64,
|
||||
c: 128,
|
||||
},
|
||||
MyEnum::Struct { a: 32, b: 64, c: 128 },
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -59,41 +59,17 @@ make_test!(optional_i32, just_i32, default_i32, maybe_i32, 5, 0, 42);
|
||||
make_test!(optional_u32, just_u32, default_u32, maybe_u32, 5, 0, 42);
|
||||
make_test!(optional_i64, just_i64, default_i64, maybe_i64, 5, 0, 42);
|
||||
make_test!(optional_u64, just_u64, default_u64, maybe_u64, 5, 0, 42);
|
||||
make_test!(optional_f32, just_f32, default_f32, maybe_f32, 5.0, 0.0, 42.0);
|
||||
make_test!(optional_f64, just_f64, default_f64, maybe_f64, 5.0, 0.0, 42.0);
|
||||
make_test!(optional_bool, just_bool, default_bool, maybe_bool, true, false, true);
|
||||
make_test!(
|
||||
optional_f32,
|
||||
just_f32,
|
||||
default_f32,
|
||||
maybe_f32,
|
||||
5.0,
|
||||
0.0,
|
||||
42.0
|
||||
);
|
||||
make_test!(
|
||||
optional_f64,
|
||||
just_f64,
|
||||
default_f64,
|
||||
maybe_f64,
|
||||
5.0,
|
||||
0.0,
|
||||
42.0
|
||||
);
|
||||
make_test!(
|
||||
optional_bool,
|
||||
just_bool,
|
||||
default_bool,
|
||||
maybe_bool,
|
||||
true,
|
||||
false,
|
||||
true
|
||||
);
|
||||
make_test!(
|
||||
optional_enum,
|
||||
just_enum,
|
||||
default_enum,
|
||||
maybe_enum,
|
||||
OptionalByte::Two,
|
||||
OptionalByte::None,
|
||||
OptionalByte::One
|
||||
optional_enum,
|
||||
just_enum,
|
||||
default_enum,
|
||||
maybe_enum,
|
||||
OptionalByte::Two,
|
||||
OptionalByte::None,
|
||||
OptionalByte::One
|
||||
);
|
||||
|
||||
#[test]
|
||||
@@ -143,7 +119,6 @@ fn object_api_defaults() {
|
||||
just_enum: OptionalByte::None,
|
||||
maybe_enum: None,
|
||||
default_enum: OptionalByte::One,
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user