From f65fcce463f49c8935d65a3fd0573f6145e66a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dj8yf0=CE=BCl?= <26653921+dj8yfo@users.noreply.github.com> Date: Mon, 25 Mar 2024 20:24:22 +0200 Subject: [PATCH] test: reorg tests (#285) --- .github/test.sh | 42 +- README.md | 4 + borsh/Cargo.toml | 6 +- borsh/src/de/mod.rs | 9 +- borsh/src/lib.rs | 4 +- borsh/src/schema.rs | 421 ------------------ borsh/src/schema/container_ext/max_size.rs | 230 +--------- borsh/src/ser/mod.rs | 6 +- borsh/tests/common_macro.rs | 10 +- .../schema/test_generic_enums.rs | 35 ++ .../compile_derives/test_generic_enums.rs | 41 ++ .../compile_derives/test_generic_structs.rs | 98 ++++ .../test_macro_namespace_collisions.rs | 2 - .../compile_derives/test_recursive_structs.rs | 35 ++ .../{ => custom_reader}/test_custom_reader.rs | 5 - .../test_ascii_strings.rs | 28 ++ .../deserialization_errors/test_cells.rs | 13 + .../test_initial.rs} | 4 - ...test_init_in_deserialize__simple_enum.snap | 7 + ...t_init_in_deserialize__simple_struct.snap} | 2 +- .../test_init_in_deserialize.rs | 3 - ...ory__test_bson_object_ids__object_id.snap} | 2 +- ...ry__test_generic_enums__generic_enum.snap} | 2 +- ...ructs__generic_associated_type_field.snap} | 2 +- ...test_generic_structs__generic_struct.snap} | 2 +- ...eric_structs__generic_struct_hashmap.snap} | 2 +- ...test_recursive_enums__recursive_enum.snap} | 2 +- ..._recursive_structs__recursive_struct.snap} | 2 +- ...rde_with_third_party__overriden_enum.snap} | 2 +- ...e_with_third_party__overriden_struct.snap} | 2 +- ...gory__test_simple_enums__mixed_enum-2.snap | 7 + ...ory__test_simple_enums__mixed_enum-3.snap} | 2 +- ...gory__test_simple_enums__mixed_enum-4.snap | 7 + ...tegory__test_simple_enums__mixed_enum.snap | 9 + ...ed__ultimate_combined_all_features-2.snap} | 2 +- ...ined__ultimate_combined_all_features.snap} | 2 +- .../test_bson_object_ids.rs | 2 - .../test_enum_discriminants.rs | 116 ----- .../test_generic_enums.rs | 29 ++ .../test_generic_structs.rs | 109 +++++ .../test_recursive_enums.rs | 28 ++ .../test_recursive_structs.rs | 31 ++ .../test_serde_with_third_party.rs} | 9 - .../test_simple_enums.rs | 30 ++ .../test_ultimate_many_features_combined.rs} | 42 -- ...trip__test_arrays__array_array_u8-10.snap} | 2 +- ...dtrip__test_arrays__array_array_u8-2.snap} | 2 +- ...dtrip__test_arrays__array_array_u8-3.snap} | 2 +- ...dtrip__test_arrays__array_array_u8-4.snap} | 2 +- ...dtrip__test_arrays__array_array_u8-5.snap} | 2 +- ...dtrip__test_arrays__array_array_u8-6.snap} | 2 +- ...dtrip__test_arrays__array_array_u8-7.snap} | 2 +- ...dtrip__test_arrays__array_array_u8-8.snap} | 2 +- ...dtrip__test_arrays__array_array_u8-9.snap} | 2 +- ...oundtrip__test_arrays__array_array_u8.snap | 5 + ...roundtrip__test_arrays__array_f32-10.snap} | 2 +- ..._roundtrip__test_arrays__array_f32-2.snap} | 2 +- ..._roundtrip__test_arrays__array_f32-3.snap} | 2 +- ..._roundtrip__test_arrays__array_f32-4.snap} | 2 +- ..._roundtrip__test_arrays__array_f32-5.snap} | 2 +- ..._roundtrip__test_arrays__array_f32-6.snap} | 2 +- ..._roundtrip__test_arrays__array_f32-7.snap} | 2 +- ..._roundtrip__test_arrays__array_f32-8.snap} | 2 +- ..._roundtrip__test_arrays__array_f32-9.snap} | 2 +- ...ts__roundtrip__test_arrays__array_f32.snap | 5 + ..._roundtrip__test_arrays__array_i8-10.snap} | 2 +- ...s__roundtrip__test_arrays__array_i8-2.snap | 7 + ...__roundtrip__test_arrays__array_i8-3.snap} | 2 +- ...__roundtrip__test_arrays__array_i8-4.snap} | 2 +- ...__roundtrip__test_arrays__array_i8-5.snap} | 2 +- ...__roundtrip__test_arrays__array_i8-6.snap} | 2 +- ...__roundtrip__test_arrays__array_i8-7.snap} | 2 +- ...__roundtrip__test_arrays__array_i8-8.snap} | 2 +- ...__roundtrip__test_arrays__array_i8-9.snap} | 2 +- ...sts__roundtrip__test_arrays__array_i8.snap | 5 + ...oundtrip__test_arrays__array_u128-10.snap} | 2 +- ...roundtrip__test_arrays__array_u128-2.snap} | 2 +- ...roundtrip__test_arrays__array_u128-3.snap} | 2 +- ...roundtrip__test_arrays__array_u128-4.snap} | 2 +- ...roundtrip__test_arrays__array_u128-5.snap} | 2 +- ...roundtrip__test_arrays__array_u128-6.snap} | 2 +- ...roundtrip__test_arrays__array_u128-7.snap} | 2 +- ...roundtrip__test_arrays__array_u128-8.snap} | 2 +- ...roundtrip__test_arrays__array_u128-9.snap} | 2 +- ...s__roundtrip__test_arrays__array_u128.snap | 5 + ...roundtrip__test_arrays__array_u32-10.snap} | 2 +- ..._roundtrip__test_arrays__array_u32-2.snap} | 2 +- ..._roundtrip__test_arrays__array_u32-3.snap} | 2 +- ..._roundtrip__test_arrays__array_u32-4.snap} | 2 +- ..._roundtrip__test_arrays__array_u32-5.snap} | 2 +- ..._roundtrip__test_arrays__array_u32-6.snap} | 2 +- ..._roundtrip__test_arrays__array_u32-7.snap} | 2 +- ..._roundtrip__test_arrays__array_u32-8.snap} | 2 +- ..._roundtrip__test_arrays__array_u32-9.snap} | 2 +- ...ts__roundtrip__test_arrays__array_u32.snap | 5 + ...roundtrip__test_arrays__array_u64-10.snap} | 2 +- ..._roundtrip__test_arrays__array_u64-2.snap} | 2 +- ..._roundtrip__test_arrays__array_u64-3.snap} | 2 +- ..._roundtrip__test_arrays__array_u64-4.snap} | 2 +- ..._roundtrip__test_arrays__array_u64-5.snap} | 2 +- ..._roundtrip__test_arrays__array_u64-6.snap} | 2 +- ..._roundtrip__test_arrays__array_u64-7.snap} | 2 +- ..._roundtrip__test_arrays__array_u64-8.snap} | 2 +- ..._roundtrip__test_arrays__array_u64-9.snap} | 2 +- ...ts__roundtrip__test_arrays__array_u64.snap | 5 + ..._roundtrip__test_arrays__array_u8-10.snap} | 2 +- ...s__roundtrip__test_arrays__array_u8-2.snap | 7 + ...__roundtrip__test_arrays__array_u8-3.snap} | 2 +- ...__roundtrip__test_arrays__array_u8-4.snap} | 2 +- ...__roundtrip__test_arrays__array_u8-5.snap} | 2 +- ...__roundtrip__test_arrays__array_u8-6.snap} | 2 +- ...__roundtrip__test_arrays__array_u8-7.snap} | 2 +- ...__roundtrip__test_arrays__array_u8-8.snap} | 2 +- ...s__roundtrip__test_arrays__array_u8-9.snap | 70 +++ ...sts__roundtrip__test_arrays__array_u8.snap | 5 + ..._roundtrip__test_arrays__array_zst-10.snap | 5 + ...__roundtrip__test_arrays__array_zst-2.snap | 5 + ...__roundtrip__test_arrays__array_zst-3.snap | 5 + ...__roundtrip__test_arrays__array_zst-4.snap | 5 + ...__roundtrip__test_arrays__array_zst-5.snap | 5 + ...__roundtrip__test_arrays__array_zst-6.snap | 5 + ...__roundtrip__test_arrays__array_zst-7.snap | 5 + ...__roundtrip__test_arrays__array_zst-8.snap | 5 + ...__roundtrip__test_arrays__array_zst-9.snap | 5 + ...ts__roundtrip__test_arrays__array_zst.snap | 5 + ...ip__test_arrays__custom_struct_array.snap} | 2 +- ...roundtrip__test_arrays__string_array.snap} | 2 +- ...sts__roundtrip__test_ascii_strings__a.snap | 11 + ...rip__test_ascii_strings__empty_string.snap | 10 + ...ndtrip__test_ascii_strings__hello_10.snap} | 4 +- ...rip__test_ascii_strings__hello_world.snap} | 4 +- ...oundtrip__test_ascii_strings__x_1024.snap} | 4 +- ...__test_btree_map__1_element_btreemap.snap} | 2 +- ...__test_btree_map__1_element_btreeset.snap} | 2 +- ...__test_btree_map__2_element_btreeset.snap} | 2 +- ...__test_btree_map__8_element_btreemap.snap} | 2 +- ...ip__test_btree_map__default_btreemap.snap} | 2 +- ...ip__test_btree_map__default_btreeset.snap} | 2 +- ...dtrip__test_btree_map__empty_btreemap.snap | 10 + ...dtrip__test_btree_map__empty_btreeset.snap | 10 + ..._roundtrip__test_cow__cow_byte_slice.snap} | 2 +- ...trip__test_cow__cow_slice_of_cow_str.snap} | 2 +- .../tests__roundtrip__test_cow__cow_str.snap} | 2 +- ..._hash_map__1_element_generic_hashmap.snap} | 2 +- ..._hash_map__1_element_generic_hashset.snap} | 2 +- ...ip__test_hash_map__1_element_hashmap.snap} | 2 +- ...ip__test_hash_map__1_element_hashset.snap} | 2 +- ..._hash_map__2_element_generic_hashset.snap} | 2 +- ...ip__test_hash_map__2_element_hashset.snap} | 2 +- ..._hash_map__8_element_generic_hashmap.snap} | 2 +- ...ip__test_hash_map__8_element_hashmap.snap} | 2 +- ...trip__test_hash_map__default_hashmap.snap} | 2 +- ...trip__test_hash_map__default_hashset.snap} | 2 +- ...test_hash_map__empty_generic_hashmap.snap} | 2 +- ...test_hash_map__empty_generic_hashset.snap} | 2 +- ...ndtrip__test_hash_map__empty_hashmap.snap} | 2 +- ...ndtrip__test_hash_map__empty_hashset.snap} | 2 +- ..._test_hash_map__generic_hash_hashmap.snap} | 2 +- ...trip__test_hash_map__generic_hashset.snap} | 2 +- ...oundtrip__test_primitives__isize_max.snap} | 2 +- ...oundtrip__test_primitives__isize_min.snap} | 2 +- ...oundtrip__test_primitives__isize_neg.snap} | 2 +- ...oundtrip__test_primitives__isize_pos.snap} | 2 +- ...s__roundtrip__test_primitives__usize.snap} | 2 +- ...oundtrip__test_primitives__usize_max.snap} | 2 +- ...oundtrip__test_primitives__usize_min.snap} | 2 +- ...tests__roundtrip__test_range__ranges.snap} | 2 +- .../tests__roundtrip__test_strings__a.snap | 11 + ...roundtrip__test_strings__empty_string.snap | 10 + ...s__roundtrip__test_strings__hello_10.snap} | 4 +- ...roundtrip__test_strings__hello_world.snap} | 4 +- ...__roundtrip__test_strings__non_ascii.snap} | 4 +- ...sts__roundtrip__test_strings__x_1024.snap} | 4 +- ...s__roundtrip__test_tuple__unary_tuple.snap | 7 + ...sts__roundtrip__test_vecs__vec_f32-2.snap} | 2 +- ...sts__roundtrip__test_vecs__vec_f32-3.snap} | 2 +- ...sts__roundtrip__test_vecs__vec_f32-4.snap} | 2 +- ...tests__roundtrip__test_vecs__vec_f32.snap} | 2 +- ...ests__roundtrip__test_vecs__vec_i8-2.snap} | 2 +- ...ests__roundtrip__test_vecs__vec_i8-3.snap} | 2 +- ...ests__roundtrip__test_vecs__vec_i8-4.snap} | 2 +- .../tests__roundtrip__test_vecs__vec_i8.snap} | 2 +- ...__roundtrip__test_vecs__vec_string-2.snap} | 2 +- ...__roundtrip__test_vecs__vec_string-3.snap} | 2 +- ...__roundtrip__test_vecs__vec_string-4.snap} | 2 +- ...ts__roundtrip__test_vecs__vec_string.snap} | 2 +- ...sts__roundtrip__test_vecs__vec_u32-2.snap} | 2 +- ...sts__roundtrip__test_vecs__vec_u32-3.snap} | 2 +- ...sts__roundtrip__test_vecs__vec_u32-4.snap} | 2 +- ...tests__roundtrip__test_vecs__vec_u32.snap} | 2 +- ...ests__roundtrip__test_vecs__vec_u8-2.snap} | 2 +- ...ests__roundtrip__test_vecs__vec_u8-3.snap} | 2 +- ...ests__roundtrip__test_vecs__vec_u8-4.snap} | 2 +- .../tests__roundtrip__test_vecs__vec_u8.snap | 10 + ..._roundtrip__test_vecs__vec_vec_u32-2.snap} | 2 +- ..._roundtrip__test_vecs__vec_vec_u32-3.snap} | 2 +- ..._roundtrip__test_vecs__vec_vec_u32-4.snap} | 2 +- ...ts__roundtrip__test_vecs__vec_vec_u32.snap | 10 + ...__roundtrip__test_vecs__vec_vec_u8-2.snap} | 2 +- ...__roundtrip__test_vecs__vec_vec_u8-3.snap} | 2 +- ...__roundtrip__test_vecs__vec_vec_u8-4.snap} | 2 +- ...sts__roundtrip__test_vecs__vec_vec_u8.snap | 10 + borsh/tests/{ => roundtrip}/test_arrays.rs | 4 - borsh/tests/roundtrip/test_ascii_strings.rs | 53 +++ borsh/tests/{ => roundtrip}/test_btree_map.rs | 10 - borsh/tests/roundtrip/test_cells.rs | 23 + borsh/tests/roundtrip/test_cow.rs | 71 +++ borsh/tests/{ => roundtrip}/test_hash_map.rs | 9 - .../{ => roundtrip}/test_nonzero_integers.rs | 1 - .../tests/{ => roundtrip}/test_primitives.rs | 1 - borsh/tests/{ => roundtrip}/test_range.rs | 2 - borsh/tests/roundtrip/test_rc.rs | 37 ++ borsh/tests/{ => roundtrip}/test_strings.rs | 4 - borsh/tests/{ => roundtrip}/test_tuple.rs | 1 - borsh/tests/{ => roundtrip}/test_vecs.rs | 4 - .../container_extension/test_max_size.rs | 216 +++++++++ .../test_schema_validate.rs | 17 +- .../schema_conflict}/test_schema_conflict.rs | 13 +- ...mple_enums__complex_enum_with_schema.snap} | 2 +- borsh/tests/schema/test_arrays.rs | 48 ++ borsh/tests/schema/test_ascii_strings.rs | 32 ++ borsh/tests/schema/test_box.rs | 9 + borsh/tests/schema/test_btree_map.rs | 53 +++ borsh/tests/schema/test_cells.rs | 40 ++ borsh/tests/schema/test_cow.rs | 68 +++ borsh/tests/schema/test_enum_discriminants.rs | 102 +++++ .../test_generic_enums.rs} | 307 +++++-------- .../test_generic_structs.rs} | 161 +------ borsh/tests/schema/test_hash_map.rs | 59 +++ borsh/tests/schema/test_option.rs | 52 +++ borsh/tests/schema/test_phantom_data.rs | 47 ++ .../test_primitives.rs} | 8 +- borsh/tests/schema/test_range.rs | 49 ++ borsh/tests/schema/test_rc.rs | 53 +++ .../test_recursive_enums.rs} | 52 +-- borsh/tests/schema/test_recursive_structs.rs | 47 ++ .../test_schema_with_third_party.rs} | 9 +- borsh/tests/schema/test_simple_enums.rs | 160 +++++++ borsh/tests/schema/test_simple_structs.rs | 112 +++++ borsh/tests/schema/test_strings.rs | 36 ++ borsh/tests/schema/test_tuple.rs | 70 +++ borsh/tests/schema/test_vecs.rs | 86 ++++ .../test_arrays__array_array_u8.snap | 5 - .../snapshots/test_arrays__array_f32.snap | 5 - .../snapshots/test_arrays__array_i8-2.snap | 7 - .../snapshots/test_arrays__array_i8.snap | 5 - .../snapshots/test_arrays__array_u128.snap | 5 - .../snapshots/test_arrays__array_u32.snap | 5 - .../snapshots/test_arrays__array_u64.snap | 5 - .../snapshots/test_arrays__array_u8-2.snap | 7 - .../snapshots/test_arrays__array_u8-9.snap | 70 --- .../snapshots/test_arrays__array_u8.snap | 5 - .../snapshots/test_arrays__array_zst-10.snap | 5 - .../snapshots/test_arrays__array_zst-2.snap | 5 - .../snapshots/test_arrays__array_zst-3.snap | 5 - .../snapshots/test_arrays__array_zst-4.snap | 5 - .../snapshots/test_arrays__array_zst-5.snap | 5 - .../snapshots/test_arrays__array_zst-6.snap | 5 - .../snapshots/test_arrays__array_zst-7.snap | 5 - .../snapshots/test_arrays__array_zst-8.snap | 5 - .../snapshots/test_arrays__array_zst-9.snap | 5 - .../snapshots/test_arrays__array_zst.snap | 5 - .../snapshots/test_ascii_strings__a.snap | 11 - .../test_hash_map__empty_hashmap.snap | 10 - .../test_hash_map__empty_hashset.snap | 10 - ...test_init_in_deserialize__simple_enum.snap | 7 - .../test_simple_structs__mixed_enum-2.snap | 7 - .../test_simple_structs__mixed_enum-4.snap | 7 - .../test_simple_structs__mixed_enum.snap | 9 - borsh/tests/snapshots/test_strings__a.snap | 11 - .../snapshots/test_tuple__unary_tuple.snap | 7 - .../snapshots/test_vecs__vec_string.snap | 10 - borsh/tests/snapshots/test_vecs__vec_u32.snap | 10 - borsh/tests/snapshots/test_vecs__vec_u8.snap | 10 - .../snapshots/test_vecs__vec_vec_u32.snap | 10 - .../snapshots/test_vecs__vec_vec_u8.snap | 10 - borsh/tests/test_ascii_strings.rs | 124 ------ borsh/tests/test_cells.rs | 92 ---- borsh/tests/test_cow.rs | 157 ------- borsh/tests/test_generic_struct.rs | 238 ---------- borsh/tests/test_rc.rs | 105 ----- borsh/tests/test_recursive_structs.rs | 89 ---- borsh/tests/test_schema_nested.rs | 110 ----- borsh/tests/test_schema_tuple.rs | 20 - borsh/tests/test_schema_vec.rs | 49 -- borsh/tests/tests.rs | 129 ++++++ .../test_zero_sized_types_forbidden.rs} | 12 +- 287 files changed, 2760 insertions(+), 2775 deletions(-) create mode 100644 borsh/tests/compile_derives/schema/test_generic_enums.rs create mode 100644 borsh/tests/compile_derives/test_generic_enums.rs create mode 100644 borsh/tests/compile_derives/test_generic_structs.rs rename borsh/tests/{ => compile_derives}/test_macro_namespace_collisions.rs (79%) create mode 100644 borsh/tests/compile_derives/test_recursive_structs.rs rename borsh/tests/{ => custom_reader}/test_custom_reader.rs (96%) create mode 100644 borsh/tests/deserialization_errors/test_ascii_strings.rs create mode 100644 borsh/tests/deserialization_errors/test_cells.rs rename borsh/tests/{test_de_errors.rs => deserialization_errors/test_initial.rs} (97%) create mode 100644 borsh/tests/init_in_deserialize/snapshots/tests__init_in_deserialize__test_init_in_deserialize__simple_enum.snap rename borsh/tests/{snapshots/test_init_in_deserialize__simple_struct.snap => init_in_deserialize/snapshots/tests__init_in_deserialize__test_init_in_deserialize__simple_struct.snap} (58%) rename borsh/tests/{ => init_in_deserialize}/test_init_in_deserialize.rs (94%) rename borsh/tests/{snapshots/test_bson_object_ids__object_id.snap => roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_bson_object_ids__object_id.snap} (66%) rename borsh/tests/{snapshots/test_generic_struct__generic_enum.snap => roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_enums__generic_enum.snap} (81%) rename borsh/tests/{snapshots/test_generic_struct__generic_associated_type_field.snap => roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_structs__generic_associated_type_field.snap} (68%) rename borsh/tests/{snapshots/test_generic_struct__generic_struct.snap => roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_structs__generic_struct.snap} (90%) rename borsh/tests/{snapshots/test_generic_struct__generic_struct_hashmap.snap => roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_structs__generic_struct_hashmap.snap} (81%) rename borsh/tests/{snapshots/test_recursive_structs__recursive_enum.snap => roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_recursive_enums__recursive_enum.snap} (72%) rename borsh/tests/{snapshots/test_recursive_structs__recursive_struct.snap => roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_recursive_structs__recursive_struct.snap} (78%) rename borsh/tests/{snapshots/test_ser_de_with__overriden_enum.snap => roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_serde_with_third_party__overriden_enum.snap} (84%) rename borsh/tests/{snapshots/test_ser_de_with__overriden_struct.snap => roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_serde_with_third_party__overriden_struct.snap} (84%) create mode 100644 borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum-2.snap rename borsh/tests/{snapshots/test_simple_structs__mixed_enum-3.snap => roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum-3.snap} (58%) create mode 100644 borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum-4.snap create mode 100644 borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum.snap rename borsh/tests/{snapshots/test_simple_structs__ultimate_combined_all_features-2.snap => roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_ultimate_many_features_combined__ultimate_combined_all_features-2.snap} (97%) rename borsh/tests/{snapshots/test_simple_structs__ultimate_combined_all_features.snap => roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_ultimate_many_features_combined__ultimate_combined_all_features.snap} (95%) rename borsh/tests/{ => roundtrip/requires_derive_category}/test_bson_object_ids.rs (89%) rename borsh/tests/{ => roundtrip/requires_derive_category}/test_enum_discriminants.rs (51%) create mode 100644 borsh/tests/roundtrip/requires_derive_category/test_generic_enums.rs create mode 100644 borsh/tests/roundtrip/requires_derive_category/test_generic_structs.rs create mode 100644 borsh/tests/roundtrip/requires_derive_category/test_recursive_enums.rs create mode 100644 borsh/tests/roundtrip/requires_derive_category/test_recursive_structs.rs rename borsh/tests/{test_ser_de_with.rs => roundtrip/requires_derive_category/test_serde_with_third_party.rs} (93%) create mode 100644 borsh/tests/roundtrip/requires_derive_category/test_simple_enums.rs rename borsh/tests/{test_simple_structs.rs => roundtrip/requires_derive_category/test_ultimate_many_features_combined.rs} (85%) rename borsh/tests/{snapshots/test_arrays__array_array_u8-10.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-10.snap} (99%) rename borsh/tests/{snapshots/test_arrays__array_u8-8.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-2.snap} (87%) rename borsh/tests/{snapshots/test_arrays__array_i8-9.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-3.snap} (93%) rename borsh/tests/{snapshots/test_arrays__array_array_u8-4.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-4.snap} (95%) rename borsh/tests/{snapshots/test_arrays__array_array_u8-5.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-5.snap} (96%) rename borsh/tests/{snapshots/test_arrays__array_array_u8-6.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-6.snap} (98%) rename borsh/tests/{snapshots/test_arrays__array_array_u8-7.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-7.snap} (99%) rename borsh/tests/{snapshots/test_arrays__array_array_u8-8.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-8.snap} (99%) rename borsh/tests/{snapshots/test_arrays__array_array_u8-9.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-9.snap} (99%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8.snap rename borsh/tests/{snapshots/test_arrays__array_f32-10.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-10.snap} (98%) rename borsh/tests/{snapshots/test_arrays__array_f32-2.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-2.snap} (57%) rename borsh/tests/{snapshots/test_arrays__array_f32-3.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-3.snap} (68%) rename borsh/tests/{snapshots/test_arrays__array_f32-4.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-4.snap} (74%) rename borsh/tests/{snapshots/test_arrays__array_f32-5.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-5.snap} (78%) rename borsh/tests/{snapshots/test_arrays__array_f32-6.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-6.snap} (86%) rename borsh/tests/{snapshots/test_arrays__array_f32-7.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-7.snap} (92%) rename borsh/tests/{snapshots/test_arrays__array_f32-8.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-8.snap} (96%) rename borsh/tests/{snapshots/test_arrays__array_f32-9.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-9.snap} (97%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32.snap rename borsh/tests/{snapshots/test_arrays__array_i8-10.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-10.snap} (93%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-2.snap rename borsh/tests/{snapshots/test_arrays__array_i8-3.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-3.snap} (50%) rename borsh/tests/{snapshots/test_arrays__array_u8-4.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-4.snap} (55%) rename borsh/tests/{snapshots/test_arrays__array_i8-5.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-5.snap} (58%) rename borsh/tests/{snapshots/test_arrays__array_u8-6.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-6.snap} (68%) rename borsh/tests/{snapshots/test_arrays__array_u8-7.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-7.snap} (79%) rename borsh/tests/{snapshots/test_arrays__array_array_u8-2.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-8.snap} (87%) rename borsh/tests/{snapshots/test_arrays__array_array_u8-3.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-9.snap} (93%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8.snap rename borsh/tests/{snapshots/test_arrays__array_u128-10.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-10.snap} (99%) rename borsh/tests/{snapshots/test_arrays__array_u128-2.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-2.snap} (77%) rename borsh/tests/{snapshots/test_arrays__array_u128-3.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-3.snap} (86%) rename borsh/tests/{snapshots/test_arrays__array_u128-4.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-4.snap} (90%) rename borsh/tests/{snapshots/test_arrays__array_u128-5.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-5.snap} (92%) rename borsh/tests/{snapshots/test_arrays__array_u128-6.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-6.snap} (95%) rename borsh/tests/{snapshots/test_arrays__array_u128-7.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-7.snap} (97%) rename borsh/tests/{snapshots/test_arrays__array_u128-8.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-8.snap} (98%) rename borsh/tests/{snapshots/test_arrays__array_u128-9.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-9.snap} (99%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128.snap rename borsh/tests/{snapshots/test_arrays__array_u32-10.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-10.snap} (97%) rename borsh/tests/{snapshots/test_arrays__array_u32-2.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-2.snap} (57%) rename borsh/tests/{snapshots/test_arrays__array_u32-3.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-3.snap} (67%) rename borsh/tests/{snapshots/test_arrays__array_u32-4.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-4.snap} (73%) rename borsh/tests/{snapshots/test_arrays__array_u32-5.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-5.snap} (78%) rename borsh/tests/{snapshots/test_arrays__array_u32-6.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-6.snap} (86%) rename borsh/tests/{snapshots/test_arrays__array_u32-7.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-7.snap} (92%) rename borsh/tests/{snapshots/test_arrays__array_u32-8.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-8.snap} (96%) rename borsh/tests/{snapshots/test_arrays__array_u32-9.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-9.snap} (97%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32.snap rename borsh/tests/{snapshots/test_arrays__array_u64-10.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-10.snap} (98%) rename borsh/tests/{snapshots/test_arrays__array_u64-2.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-2.snap} (67%) rename borsh/tests/{snapshots/test_arrays__array_u64-3.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-3.snap} (78%) rename borsh/tests/{snapshots/test_arrays__array_u64-4.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-4.snap} (83%) rename borsh/tests/{snapshots/test_arrays__array_u64-5.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-5.snap} (86%) rename borsh/tests/{snapshots/test_arrays__array_u64-6.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-6.snap} (92%) rename borsh/tests/{snapshots/test_arrays__array_u64-7.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-7.snap} (96%) rename borsh/tests/{snapshots/test_arrays__array_u64-8.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-8.snap} (97%) rename borsh/tests/{snapshots/test_arrays__array_u64-9.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-9.snap} (98%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64.snap rename borsh/tests/{snapshots/test_arrays__array_u8-10.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-10.snap} (93%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-2.snap rename borsh/tests/{snapshots/test_arrays__array_u8-3.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-3.snap} (50%) rename borsh/tests/{snapshots/test_arrays__array_i8-4.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-4.snap} (55%) rename borsh/tests/{snapshots/test_arrays__array_u8-5.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-5.snap} (58%) rename borsh/tests/{snapshots/test_arrays__array_i8-6.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-6.snap} (68%) rename borsh/tests/{snapshots/test_arrays__array_i8-7.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-7.snap} (79%) rename borsh/tests/{snapshots/test_arrays__array_i8-8.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-8.snap} (87%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-9.snap create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8.snap create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-10.snap create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-2.snap create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-3.snap create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-4.snap create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-5.snap create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-6.snap create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-7.snap create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-8.snap create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-9.snap create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst.snap rename borsh/tests/{snapshots/test_arrays__custom_struct_array.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__custom_struct_array.snap} (55%) rename borsh/tests/{snapshots/test_arrays__string_array.snap => roundtrip/snapshots/tests__roundtrip__test_arrays__string_array.snap} (76%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__a.snap create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__empty_string.snap rename borsh/tests/{snapshots/test_strings__hello_10.snap => roundtrip/snapshots/tests__roundtrip__test_ascii_strings__hello_10.snap} (97%) rename borsh/tests/{snapshots/test_ascii_strings__hello_world.snap => roundtrip/snapshots/tests__roundtrip__test_ascii_strings__hello_world.snap} (66%) rename borsh/tests/{snapshots/test_strings__x_1024.snap => roundtrip/snapshots/tests__roundtrip__test_ascii_strings__x_1024.snap} (99%) rename borsh/tests/{snapshots/test_hash_map__1_element_hashmap.snap => roundtrip/snapshots/tests__roundtrip__test_btree_map__1_element_btreemap.snap} (80%) rename borsh/tests/{snapshots/test_hash_map__1_element_generic_hashset.snap => roundtrip/snapshots/tests__roundtrip__test_btree_map__1_element_btreeset.snap} (70%) rename borsh/tests/{snapshots/test_hash_map__2_element_hashset.snap => roundtrip/snapshots/tests__roundtrip__test_btree_map__2_element_btreeset.snap} (82%) rename borsh/tests/{snapshots/test_hash_map__8_element_hashmap.snap => roundtrip/snapshots/tests__roundtrip__test_btree_map__8_element_btreemap.snap} (96%) rename borsh/tests/{snapshots/test_btree_map__default_btreemap.snap => roundtrip/snapshots/tests__roundtrip__test_btree_map__default_btreemap.snap} (85%) rename borsh/tests/{snapshots/test_hash_map__generic_hashset.snap => roundtrip/snapshots/tests__roundtrip__test_btree_map__default_btreeset.snap} (91%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__empty_btreemap.snap create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__empty_btreeset.snap rename borsh/tests/{snapshots/test_cow__cow_byte_slice.snap => roundtrip/snapshots/tests__roundtrip__test_cow__cow_byte_slice.snap} (75%) rename borsh/tests/{snapshots/test_cow__cow_slice_of_cow_str.snap => roundtrip/snapshots/tests__roundtrip__test_cow__cow_slice_of_cow_str.snap} (91%) rename borsh/tests/{snapshots/test_cow__cow_str.snap => roundtrip/snapshots/tests__roundtrip__test_cow__cow_str.snap} (79%) rename borsh/tests/{snapshots/test_btree_map__1_element_btreemap.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_generic_hashmap.snap} (81%) rename borsh/tests/{snapshots/test_hash_map__1_element_hashset.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_generic_hashset.snap} (70%) rename borsh/tests/{snapshots/test_hash_map__1_element_generic_hashmap.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_hashmap.snap} (81%) rename borsh/tests/{snapshots/test_btree_map__1_element_btreeset.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_hashset.snap} (70%) rename borsh/tests/{snapshots/test_btree_map__2_element_btreeset.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__2_element_generic_hashset.snap} (82%) rename borsh/tests/{snapshots/test_hash_map__2_element_generic_hashset.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__2_element_hashset.snap} (82%) rename borsh/tests/{snapshots/test_hash_map__8_element_generic_hashmap.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__8_element_generic_hashmap.snap} (96%) rename borsh/tests/{snapshots/test_btree_map__8_element_btreemap.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__8_element_hashmap.snap} (96%) rename borsh/tests/{snapshots/test_hash_map__generic_hash_hashmap.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__default_hashmap.snap} (85%) rename borsh/tests/{snapshots/test_hash_map__default_hashset.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__default_hashset.snap} (91%) rename borsh/tests/{snapshots/test_hash_map__empty_generic_hashmap.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_generic_hashmap.snap} (54%) rename borsh/tests/{snapshots/test_hash_map__empty_generic_hashset.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_generic_hashset.snap} (54%) rename borsh/tests/{snapshots/test_btree_map__empty_btreemap.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_hashmap.snap} (54%) rename borsh/tests/{snapshots/test_btree_map__empty_btreeset.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_hashset.snap} (54%) rename borsh/tests/{snapshots/test_hash_map__default_hashmap.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__generic_hash_hashmap.snap} (85%) rename borsh/tests/{snapshots/test_btree_map__default_btreeset.snap => roundtrip/snapshots/tests__roundtrip__test_hash_map__generic_hashset.snap} (91%) rename borsh/tests/{snapshots/test_primitives__isize_max.snap => roundtrip/snapshots/tests__roundtrip__test_primitives__isize_max.snap} (67%) rename borsh/tests/{snapshots/test_primitives__isize_min.snap => roundtrip/snapshots/tests__roundtrip__test_primitives__isize_min.snap} (63%) rename borsh/tests/{snapshots/test_primitives__isize_neg.snap => roundtrip/snapshots/tests__roundtrip__test_primitives__isize_neg.snap} (67%) rename borsh/tests/{snapshots/test_primitives__usize.snap => roundtrip/snapshots/tests__roundtrip__test_primitives__isize_pos.snap} (63%) rename borsh/tests/{snapshots/test_primitives__isize_pos.snap => roundtrip/snapshots/tests__roundtrip__test_primitives__usize.snap} (63%) rename borsh/tests/{snapshots/test_primitives__usize_max.snap => roundtrip/snapshots/tests__roundtrip__test_primitives__usize_max.snap} (67%) rename borsh/tests/{snapshots/test_primitives__usize_min.snap => roundtrip/snapshots/tests__roundtrip__test_primitives__usize_min.snap} (63%) rename borsh/tests/{snapshots/test_range__ranges.snap => roundtrip/snapshots/tests__roundtrip__test_range__ranges.snap} (83%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__a.snap create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__empty_string.snap rename borsh/tests/{snapshots/test_ascii_strings__hello_10.snap => roundtrip/snapshots/tests__roundtrip__test_strings__hello_10.snap} (98%) rename borsh/tests/{snapshots/test_strings__hello_world.snap => roundtrip/snapshots/tests__roundtrip__test_strings__hello_world.snap} (68%) rename borsh/tests/{snapshots/test_strings__non_ascii.snap => roundtrip/snapshots/tests__roundtrip__test_strings__non_ascii.snap} (54%) rename borsh/tests/{snapshots/test_ascii_strings__x_1024.snap => roundtrip/snapshots/tests__roundtrip__test_strings__x_1024.snap} (99%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_tuple__unary_tuple.snap rename borsh/tests/{snapshots/test_vecs__vec_f32-2.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32-2.snap} (67%) rename borsh/tests/{snapshots/test_vecs__vec_f32-3.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32-3.snap} (90%) rename borsh/tests/{snapshots/test_vecs__vec_f32-4.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32-4.snap} (98%) rename borsh/tests/{snapshots/test_ascii_strings__empty_string.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32.snap} (56%) rename borsh/tests/{snapshots/test_vecs__vec_i8-2.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8-2.snap} (60%) rename borsh/tests/{snapshots/test_vecs__vec_i8-3.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8-3.snap} (77%) rename borsh/tests/{snapshots/test_vecs__vec_i8-4.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8-4.snap} (95%) rename borsh/tests/{snapshots/test_strings__empty_string.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8.snap} (56%) rename borsh/tests/{snapshots/test_vecs__vec_string-2.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string-2.snap} (68%) rename borsh/tests/{snapshots/test_vecs__vec_string-3.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string-3.snap} (90%) rename borsh/tests/{snapshots/test_vecs__vec_string-4.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string-4.snap} (98%) rename borsh/tests/{snapshots/test_vecs__vec_i8.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string.snap} (56%) rename borsh/tests/{snapshots/test_vecs__vec_u32-2.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32-2.snap} (67%) rename borsh/tests/{snapshots/test_vecs__vec_u32-3.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32-3.snap} (90%) rename borsh/tests/{snapshots/test_vecs__vec_u32-4.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32-4.snap} (98%) rename borsh/tests/{snapshots/test_vecs__vec_f32.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32.snap} (56%) rename borsh/tests/{snapshots/test_vecs__vec_u8-2.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8-2.snap} (60%) rename borsh/tests/{snapshots/test_vecs__vec_u8-3.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8-3.snap} (77%) rename borsh/tests/{snapshots/test_vecs__vec_u8-4.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8-4.snap} (95%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8.snap rename borsh/tests/{snapshots/test_vecs__vec_vec_u32-2.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32-2.snap} (89%) rename borsh/tests/{snapshots/test_vecs__vec_vec_u32-3.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32-3.snap} (98%) rename borsh/tests/{snapshots/test_vecs__vec_vec_u32-4.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32-4.snap} (99%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32.snap rename borsh/tests/{snapshots/test_vecs__vec_vec_u8-2.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8-2.snap} (80%) rename borsh/tests/{snapshots/test_vecs__vec_vec_u8-3.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8-3.snap} (96%) rename borsh/tests/{snapshots/test_vecs__vec_vec_u8-4.snap => roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8-4.snap} (99%) create mode 100644 borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8.snap rename borsh/tests/{ => roundtrip}/test_arrays.rs (95%) create mode 100644 borsh/tests/roundtrip/test_ascii_strings.rs rename borsh/tests/{ => roundtrip}/test_btree_map.rs (91%) create mode 100644 borsh/tests/roundtrip/test_cells.rs create mode 100644 borsh/tests/roundtrip/test_cow.rs rename borsh/tests/{ => roundtrip}/test_hash_map.rs (96%) rename borsh/tests/{ => roundtrip}/test_nonzero_integers.rs (94%) rename borsh/tests/{ => roundtrip}/test_primitives.rs (95%) rename borsh/tests/{ => roundtrip}/test_range.rs (86%) create mode 100644 borsh/tests/roundtrip/test_rc.rs rename borsh/tests/{ => roundtrip}/test_strings.rs (95%) rename borsh/tests/{ => roundtrip}/test_tuple.rs (88%) rename borsh/tests/{ => roundtrip}/test_vecs.rs (91%) create mode 100644 borsh/tests/schema/container_extension/test_max_size.rs rename borsh/tests/{ => schema/container_extension}/test_schema_validate.rs (89%) rename borsh/tests/{ => schema/schema_conflict}/test_schema_conflict.rs (94%) rename borsh/tests/{snapshots/test_schema_enums__complex_enum_with_schema.snap => schema/snapshots/tests__schema__test_simple_enums__complex_enum_with_schema.snap} (98%) create mode 100644 borsh/tests/schema/test_arrays.rs create mode 100644 borsh/tests/schema/test_ascii_strings.rs create mode 100644 borsh/tests/schema/test_box.rs create mode 100644 borsh/tests/schema/test_btree_map.rs create mode 100644 borsh/tests/schema/test_cells.rs create mode 100644 borsh/tests/schema/test_cow.rs create mode 100644 borsh/tests/schema/test_enum_discriminants.rs rename borsh/tests/{test_schema_enums.rs => schema/test_generic_enums.rs} (56%) rename borsh/tests/{test_schema_structs.rs => schema/test_generic_structs.rs} (57%) create mode 100644 borsh/tests/schema/test_hash_map.rs create mode 100644 borsh/tests/schema/test_option.rs create mode 100644 borsh/tests/schema/test_phantom_data.rs rename borsh/tests/{test_schema_primitives.rs => schema/test_primitives.rs} (76%) create mode 100644 borsh/tests/schema/test_range.rs create mode 100644 borsh/tests/schema/test_rc.rs rename borsh/tests/{test_schema_recursive.rs => schema/test_recursive_enums.rs} (51%) create mode 100644 borsh/tests/schema/test_recursive_structs.rs rename borsh/tests/{test_schema_with.rs => schema/test_schema_with_third_party.rs} (96%) create mode 100644 borsh/tests/schema/test_simple_enums.rs create mode 100644 borsh/tests/schema/test_simple_structs.rs create mode 100644 borsh/tests/schema/test_strings.rs create mode 100644 borsh/tests/schema/test_tuple.rs create mode 100644 borsh/tests/schema/test_vecs.rs delete mode 100644 borsh/tests/snapshots/test_arrays__array_array_u8.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_f32.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_i8-2.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_i8.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_u128.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_u32.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_u64.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_u8-2.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_u8-9.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_u8.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_zst-10.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_zst-2.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_zst-3.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_zst-4.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_zst-5.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_zst-6.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_zst-7.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_zst-8.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_zst-9.snap delete mode 100644 borsh/tests/snapshots/test_arrays__array_zst.snap delete mode 100644 borsh/tests/snapshots/test_ascii_strings__a.snap delete mode 100644 borsh/tests/snapshots/test_hash_map__empty_hashmap.snap delete mode 100644 borsh/tests/snapshots/test_hash_map__empty_hashset.snap delete mode 100644 borsh/tests/snapshots/test_init_in_deserialize__simple_enum.snap delete mode 100644 borsh/tests/snapshots/test_simple_structs__mixed_enum-2.snap delete mode 100644 borsh/tests/snapshots/test_simple_structs__mixed_enum-4.snap delete mode 100644 borsh/tests/snapshots/test_simple_structs__mixed_enum.snap delete mode 100644 borsh/tests/snapshots/test_strings__a.snap delete mode 100644 borsh/tests/snapshots/test_tuple__unary_tuple.snap delete mode 100644 borsh/tests/snapshots/test_vecs__vec_string.snap delete mode 100644 borsh/tests/snapshots/test_vecs__vec_u32.snap delete mode 100644 borsh/tests/snapshots/test_vecs__vec_u8.snap delete mode 100644 borsh/tests/snapshots/test_vecs__vec_vec_u32.snap delete mode 100644 borsh/tests/snapshots/test_vecs__vec_vec_u8.snap delete mode 100644 borsh/tests/test_ascii_strings.rs delete mode 100644 borsh/tests/test_cells.rs delete mode 100644 borsh/tests/test_cow.rs delete mode 100644 borsh/tests/test_generic_struct.rs delete mode 100644 borsh/tests/test_rc.rs delete mode 100644 borsh/tests/test_recursive_structs.rs delete mode 100644 borsh/tests/test_schema_nested.rs delete mode 100644 borsh/tests/test_schema_tuple.rs delete mode 100644 borsh/tests/test_schema_vec.rs create mode 100644 borsh/tests/tests.rs rename borsh/tests/{test_zero_sized_types.rs => zero_sized_types/test_zero_sized_types_forbidden.rs} (93%) diff --git a/.github/test.sh b/.github/test.sh index 0d935f1ae..2fdbf58b9 100755 --- a/.github/test.sh +++ b/.github/test.sh @@ -1,22 +1,54 @@ #!/usr/bin/env bash + +# NOTE: `cargo test [TESTNAME]` is used to filter only the submodule with tests to test a +# specific feature or features' combination +# e.g. `cargo test --features rc,unstable__schema 'schema::test_rc'` is used to test `BorshSchema` +# implementation of `std::rc::Rc` and `std::sync::Arc`, +# where `[TESTNAME]` argument is set to `schema::test_rc`, which includes tests from `schema::test_rc` +# submodule of `borsh/tests/tests.rs` to be run. set -e set -x export INSTA_UPDATE=no pushd borsh +############################ borsh `default-features = true` group ######################### +########## general group cargo test --no-run cargo test -cargo test --features unstable__schema,ascii --test test_ascii_strings cargo test --features derive cargo test --features unstable__schema -cargo test --test test_rc --features unstable__schema,rc -cargo test --test test_hash_map --test test_btree_map --features de_strict_order +########## features = ["ascii"] group +cargo test --features ascii 'roundtrip::test_ascii_strings' +cargo test --features ascii 'deserialization_errors::test_ascii_strings' +cargo test --features ascii,unstable__schema 'schema::test_ascii_strings' +########## features = ["rc"] group +cargo test --features rc 'roundtrip::test_rc' +cargo test --features rc,unstable__schema 'schema::test_rc' +########## features = ["de_strict_order"] group +cargo test --features de_strict_order 'roundtrip::test_hash_map' +cargo test --features de_strict_order 'roundtrip::test_btree_map' +########## features = ["bson"] group +cargo test --features bson,derive 'roundtrip::requires_derive_category::test_bson_object_ids' +########## features = ["bytes"] group +cargo test --features bytes,derive 'roundtrip::requires_derive_category::test_ultimate_many_features_combined' + +############################ borsh `default-features = false` group ######################### +########## general group cargo test --no-default-features -cargo test --no-default-features --features unstable__schema,ascii --test test_ascii_strings cargo test --no-default-features --features derive cargo test --no-default-features --features unstable__schema -cargo test --no-default-features --test test_rc --features unstable__schema,rc +########## features = ["ascii"] group +cargo test --no-default-features --features ascii 'roundtrip::test_ascii_strings' +cargo test --no-default-features --features ascii 'deserialization_errors::test_ascii_strings' +cargo test --no-default-features --features ascii,unstable__schema 'schema::test_ascii_strings' +########## features = ["rc"] group +cargo test --no-default-features --features rc 'roundtrip::test_rc' +cargo test --no-default-features --features rc,unstable__schema 'schema::test_rc' +########## features = ["hashbrown"] group cargo test --no-default-features --features hashbrown +cargo test --no-default-features --features hashbrown,derive +cargo test --no-default-features --features hashbrown,unstable__schema popd pushd borsh-derive +############################ borsh-derive group ######################### cargo test --features schema diff --git a/README.md b/README.md index bb04fd5a1..f2dfb0b77 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,10 @@ enum A { } ``` +## Testing + +Integration tests should generally be preferred to unit ones. Root module of integration tests of `borsh` crate is [linked](./borsh/tests/tests.rs) here. + ## Releasing The versions of all public crates in this repository are collectively managed by a single version in the [workspace manifest](https://github.com/near/borsh-rs/blob/master/Cargo.toml). diff --git a/borsh/Cargo.toml b/borsh/Cargo.toml index 7ccf3941f..7bde589a5 100644 --- a/borsh/Cargo.toml +++ b/borsh/Cargo.toml @@ -12,7 +12,7 @@ homepage = "https://borsh.io" description = """ Binary Object Representation Serializer for Hashing """ -exclude = ["tests/snapshots"] +exclude = ["*.snap"] [lib] name = "borsh" @@ -38,10 +38,6 @@ bytes = { version = "1", optional = true } bson = { version = "2", optional = true } [dev-dependencies] -bytes = "1" -bson = "2" -# Enable the "bytes" and "bson" features in integ tests: https://github.com/rust-lang/cargo/issues/2911#issuecomment-1464060655 -borsh = { path = ".", default_features = false, features = ["bytes", "bson"] } insta = "1.29.0" [package.metadata.docs.rs] diff --git a/borsh/src/de/mod.rs b/borsh/src/de/mod.rs index d9e667046..19279cc72 100644 --- a/borsh/src/de/mod.rs +++ b/borsh/src/de/mod.rs @@ -5,7 +5,7 @@ use core::{ mem::size_of, }; -#[cfg(any(test, feature = "bytes"))] +#[cfg(feature = "bytes")] use bytes::{BufMut, BytesMut}; use crate::__private::maybestd::{ @@ -421,7 +421,7 @@ where } } -#[cfg(any(test, feature = "bytes"))] +#[cfg(feature = "bytes")] impl BorshDeserialize for bytes::Bytes { #[inline] fn deserialize_reader(reader: &mut R) -> Result { @@ -430,7 +430,7 @@ impl BorshDeserialize for bytes::Bytes { } } -#[cfg(any(test, feature = "bytes"))] +#[cfg(feature = "bytes")] impl BorshDeserialize for bytes::BytesMut { #[inline] fn deserialize_reader(reader: &mut R) -> Result { @@ -443,7 +443,7 @@ impl BorshDeserialize for bytes::BytesMut { } } -#[cfg(any(test, feature = "bson"))] +#[cfg(feature = "bson")] impl BorshDeserialize for bson::oid::ObjectId { #[inline] fn deserialize_reader(reader: &mut R) -> Result { @@ -779,6 +779,7 @@ fn array_deserialization_doesnt_leak() { static DESERIALIZE_COUNT: AtomicUsize = AtomicUsize::new(0); static DROP_COUNT: AtomicUsize = AtomicUsize::new(0); + #[allow(unused)] struct MyType(u8); impl BorshDeserialize for MyType { fn deserialize_reader(reader: &mut R) -> Result { diff --git a/borsh/src/lib.rs b/borsh/src/lib.rs index c163751fc..eafad58a4 100644 --- a/borsh/src/lib.rs +++ b/borsh/src/lib.rs @@ -43,10 +43,10 @@ This feature is set to be mutually exclusive with **std** feature. * **bytes** - Gates implementation of [BorshSerialize] and [BorshDeserialize] - for [Bytes](bytes::Bytes) and [BytesMut](bytes::BytesMut). + for [Bytes](https://docs.rs/bytes/1.5.0/bytes/struct.Bytes.html) and [BytesMut](https://docs.rs/bytes/1.5.0/bytes/struct.BytesMut.html). * **bson** - Gates implementation of [BorshSerialize] and [BorshDeserialize] - for [ObjectId](bson::oid::ObjectId). + for [ObjectId](https://docs.rs/bson/2.9.0/bson/oid/struct.ObjectId.html). * **ascii** - Gates implementation of [BorshSerialize], [BorshDeserialize], [BorshSchema] for types from [ascii](https://docs.rs/ascii/1.1.0/ascii/) crate. diff --git a/borsh/src/schema.rs b/borsh/src/schema.rs index 07cbc0abd..7c5587065 100644 --- a/borsh/src/schema.rs +++ b/borsh/src/schema.rs @@ -831,424 +831,3 @@ impl_tuple!( impl_tuple!( T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20 ); - -#[cfg(test)] -mod tests { - use super::*; - #[cfg(hash_collections)] - use crate::__private::maybestd::collections::{HashMap, HashSet}; - - macro_rules! map( - () => { BTreeMap::new() }; - { $($key:expr => $value:expr),+ } => { - { - let mut m = BTreeMap::new(); - $( - m.insert($key.to_string(), $value); - )+ - m - } - }; - ); - - #[test] - fn simple_option() { - let actual_name = Option::::declaration(); - let mut actual_defs = map!(); - Option::::add_definitions_recursively(&mut actual_defs); - assert_eq!("Option", actual_name); - assert_eq!( - map! { - "Option" => Definition::Enum { - tag_width: 1, - variants: vec![ - (0, "None".to_string(), "()".to_string()), - (1, "Some".to_string(), "u64".to_string()), - ] - }, - "u64" => Definition::Primitive(8), - "()" => Definition::Primitive(0) - }, - actual_defs - ); - } - - #[test] - fn nested_option() { - let actual_name = Option::>::declaration(); - let mut actual_defs = map!(); - Option::>::add_definitions_recursively(&mut actual_defs); - assert_eq!("Option>", actual_name); - assert_eq!( - map! { - "Option" => Definition::Enum { - tag_width: 1, - variants: vec![ - (0, "None".to_string(), "()".to_string()), - (1, "Some".to_string(), "u64".to_string()), - ] - }, - "Option>" => Definition::Enum { - tag_width: 1, - variants: vec![ - (0, "None".to_string(), "()".to_string()), - (1, "Some".to_string(), "Option".to_string()), - ] - }, - "u64" => Definition::Primitive(8), - "()" => Definition::Primitive(0) - }, - actual_defs - ); - } - - #[test] - fn simple_vec() { - let actual_name = Vec::::declaration(); - let mut actual_defs = map!(); - Vec::::add_definitions_recursively(&mut actual_defs); - assert_eq!("Vec", actual_name); - assert_eq!( - map! { - "Vec" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u64".to_string(), - }, - "u64" => Definition::Primitive(8) - }, - actual_defs - ); - } - - #[test] - fn nested_vec() { - let actual_name = Vec::>::declaration(); - let mut actual_defs = map!(); - Vec::>::add_definitions_recursively(&mut actual_defs); - assert_eq!("Vec>", actual_name); - assert_eq!( - map! { - "Vec" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u64".to_string(), - }, - "Vec>" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "Vec".to_string(), - }, - "u64" => Definition::Primitive(8) - }, - actual_defs - ); - } - - #[test] - fn simple_tuple() { - let actual_name = <(u64, core::num::NonZeroU16, String)>::declaration(); - let mut actual_defs = map!(); - <(u64, core::num::NonZeroU16, String)>::add_definitions_recursively(&mut actual_defs); - assert_eq!("(u64, NonZeroU16, String)", actual_name); - assert_eq!( - map! { - "(u64, NonZeroU16, String)" => Definition::Tuple { - elements: vec![ - "u64".to_string(), - "NonZeroU16".to_string(), - "String".to_string() - ] - }, - "u64" => Definition::Primitive(8), - "NonZeroU16" => Definition::Primitive(2), - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - }, - "u8" => Definition::Primitive(1) - }, - actual_defs - ); - } - - #[test] - fn nested_tuple() { - let actual_name = <(u64, (u8, bool), String)>::declaration(); - let mut actual_defs = map!(); - <(u64, (u8, bool), String)>::add_definitions_recursively(&mut actual_defs); - assert_eq!("(u64, (u8, bool), String)", actual_name); - assert_eq!( - map! { - "(u64, (u8, bool), String)" => Definition::Tuple { elements: vec![ - "u64".to_string(), - "(u8, bool)".to_string(), - "String".to_string(), - ]}, - "(u8, bool)" => Definition::Tuple { elements: vec![ "u8".to_string(), "bool".to_string()]}, - "u64" => Definition::Primitive(8), - "u8" => Definition::Primitive(1), - "bool" => Definition::Primitive(1), - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - } - }, - actual_defs - ); - } - - #[cfg(hash_collections)] - #[test] - fn simple_map() { - let actual_name = HashMap::::declaration(); - let mut actual_defs = map!(); - HashMap::::add_definitions_recursively(&mut actual_defs); - assert_eq!("HashMap", actual_name); - assert_eq!( - map! { - "HashMap" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "(u64, String)".to_string(), - } , - "(u64, String)" => Definition::Tuple { - elements: vec![ "u64".to_string(), "String".to_string()], - }, - "u64" => Definition::Primitive(8), - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - }, - "u8" => Definition::Primitive(1) - - }, - actual_defs - ); - } - - #[cfg(hash_collections)] - #[test] - fn simple_set() { - let actual_name = HashSet::::declaration(); - let mut actual_defs = map!(); - HashSet::::add_definitions_recursively(&mut actual_defs); - assert_eq!("HashSet", actual_name); - assert_eq!( - map! { - "HashSet" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "String".to_string(), - }, - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - }, - "u8" => Definition::Primitive(1) - }, - actual_defs - ); - } - - #[test] - fn b_tree_map() { - let actual_name = BTreeMap::::declaration(); - let mut actual_defs = map!(); - BTreeMap::::add_definitions_recursively(&mut actual_defs); - assert_eq!("BTreeMap", actual_name); - assert_eq!( - map! { - "BTreeMap" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "(u64, String)".to_string(), - } , - "(u64, String)" => Definition::Tuple { elements: vec![ "u64".to_string(), "String".to_string()]}, - "u64" => Definition::Primitive(8), - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - }, - "u8" => Definition::Primitive(1) - }, - actual_defs - ); - } - - #[test] - fn b_tree_set() { - let actual_name = BTreeSet::::declaration(); - let mut actual_defs = map!(); - BTreeSet::::add_definitions_recursively(&mut actual_defs); - assert_eq!("BTreeSet", actual_name); - assert_eq!( - map! { - "BTreeSet" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "String".to_string(), - }, - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - }, - "u8" => Definition::Primitive(1) - }, - actual_defs - ); - } - - #[test] - fn simple_array() { - let actual_name = <[u64; 32]>::declaration(); - let mut actual_defs = map!(); - <[u64; 32]>::add_definitions_recursively(&mut actual_defs); - assert_eq!("[u64; 32]", actual_name); - assert_eq!( - map! { - "[u64; 32]" => Definition::Sequence { - length_width: Definition::ARRAY_LENGTH_WIDTH, - length_range: 32..=32, - elements: "u64".to_string() - }, - "u64" => Definition::Primitive(8) - }, - actual_defs - ); - } - - #[test] - fn nested_array() { - let actual_name = <[[[u64; 9]; 10]; 32]>::declaration(); - let mut actual_defs = map!(); - <[[[u64; 9]; 10]; 32]>::add_definitions_recursively(&mut actual_defs); - assert_eq!("[[[u64; 9]; 10]; 32]", actual_name); - assert_eq!( - map! { - "[u64; 9]" => Definition::Sequence { - length_width: Definition::ARRAY_LENGTH_WIDTH, - length_range: 9..=9, - elements: "u64".to_string() - }, - "[[u64; 9]; 10]" => Definition::Sequence { - length_width: Definition::ARRAY_LENGTH_WIDTH, - length_range: 10..=10, - elements: "[u64; 9]".to_string() - }, - "[[[u64; 9]; 10]; 32]" => Definition::Sequence { - length_width: Definition::ARRAY_LENGTH_WIDTH, - length_range: 32..=32, - elements: "[[u64; 9]; 10]".to_string() - }, - "u64" => Definition::Primitive(8) - }, - actual_defs - ); - } - - #[test] - fn string() { - let actual_name = str::declaration(); - assert_eq!("String", actual_name); - let actual_name = String::declaration(); - assert_eq!("String", actual_name); - let mut actual_defs = map!(); - String::add_definitions_recursively(&mut actual_defs); - assert_eq!( - map! { - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - }, - "u8" => Definition::Primitive(1) - }, - actual_defs - ); - - let mut actual_defs = map!(); - str::add_definitions_recursively(&mut actual_defs); - assert_eq!( - map! { - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - }, - "u8" => Definition::Primitive(1) - }, - actual_defs - ); - } - - #[test] - fn boxed_schema() { - let boxed_declaration = Box::::declaration(); - assert_eq!("String", boxed_declaration); - let boxed_declaration = Box::<[u8]>::declaration(); - assert_eq!("Vec", boxed_declaration); - } - - #[test] - fn phantom_data_schema() { - let phantom_declaration = PhantomData::::declaration(); - assert_eq!("()", phantom_declaration); - let phantom_declaration = PhantomData::>::declaration(); - assert_eq!("()", phantom_declaration); - } - - #[test] - fn range() { - assert_eq!("RangeFull", ::declaration()); - let mut actual_defs = map!(); - ::add_definitions_recursively(&mut actual_defs); - assert_eq!( - map! { - "RangeFull" => Definition::Struct { - fields: Fields::Empty - } - }, - actual_defs - ); - - let actual_name = >::declaration(); - let mut actual_defs = map!(); - >::add_definitions_recursively(&mut actual_defs); - assert_eq!("Range", actual_name); - assert_eq!( - map! { - "Range" => Definition::Struct { - fields: Fields::NamedFields(vec![ - ("start".into(), "u64".into()), - ("end".into(), "u64".into()), - ]) - }, - "u64" => Definition::Primitive(8) - }, - actual_defs - ); - - let actual_name = >::declaration(); - let mut actual_defs = map!(); - >::add_definitions_recursively(&mut actual_defs); - assert_eq!("RangeTo", actual_name); - assert_eq!( - map! { - "RangeTo" => Definition::Struct { - fields: Fields::NamedFields(vec![ - ("end".into(), "u64".into()), - ]) - }, - "u64" => Definition::Primitive(8) - }, - actual_defs - ); - } -} diff --git a/borsh/src/schema/container_ext/max_size.rs b/borsh/src/schema/container_ext/max_size.rs index a6bebb793..193f3be1e 100644 --- a/borsh/src/schema/container_ext/max_size.rs +++ b/borsh/src/schema/container_ext/max_size.rs @@ -266,34 +266,7 @@ mod tests { // this is not integration test module, so can use __private for ease of imports; // it cannot be made integration, as it tests `is_zero_size` function, chosen to be non-pub - use crate::{ - BorshSchema, - __private::maybestd::{ - boxed::Box, - collections::BTreeMap, - format, - string::{String, ToString}, - vec, - }, - }; - - #[track_caller] - fn test_ok(want: usize) { - let schema = BorshSchemaContainer::for_type::(); - assert_eq!(Ok(want), schema.max_serialized_size()); - assert_eq!( - want == 0, - is_zero_size(schema.declaration(), &schema).unwrap() - ); - } - - #[track_caller] - fn test_err(err: Error) { - let schema = BorshSchemaContainer::for_type::(); - assert_eq!(Err(err), schema.max_serialized_size()); - } - - const MAX_LEN: usize = u32::MAX as usize; + use crate::__private::maybestd::{boxed::Box, string::ToString}; #[test] fn test_is_zero_size_recursive_check_bypassed() { @@ -319,205 +292,4 @@ mod tests { is_zero_size(schema.declaration(), &schema) ); } - - #[test] - fn max_serialized_size_primitives() { - test_ok::<()>(0); - test_ok::(1); - - test_ok::(4); - test_ok::(8); - - test_ok::(1); - test_ok::(2); - test_ok::(4); - test_ok::(8); - test_ok::(16); - - test_ok::(1); - test_ok::(2); - test_ok::(4); - test_ok::(8); - test_ok::(16); - - test_ok::(1); - test_ok::(2); - test_ok::(4); - test_ok::(8); - test_ok::(16); - - test_ok::(1); - test_ok::(2); - test_ok::(4); - test_ok::(8); - test_ok::(16); - - test_ok::(8); - test_ok::(8); - test_ok::(8); - } - - #[test] - fn max_serialized_size_built_in_types() { - test_ok::(0); - test_ok::>(2); - test_ok::>(8); - - test_ok::>(1); - test_ok::>(2); - test_ok::>(9); - test_ok::>>(1 + 4 + MAX_LEN); - - test_ok::<()>(0); - test_ok::<(u8,)>(1); - test_ok::<(u8, u32)>(5); - - test_ok::<[u8; 0]>(0); - test_ok::<[u8; 16]>(16); - test_ok::<[[u8; 4]; 4]>(16); - - test_ok::<[u16; 0]>(0); - test_ok::<[u16; 16]>(32); - test_ok::<[[u16; 4]; 4]>(32); - - test_ok::>(4 + MAX_LEN); - test_ok::(4 + MAX_LEN); - - test_err::>>(Error::Overflow); - test_ok::>>(4 + MAX_LEN * 4); - test_ok::<[[[(); MAX_LEN]; MAX_LEN]; MAX_LEN]>(0); - } - - #[test] - fn max_serialized_size_derived_types() { - use crate as borsh; - - #[derive(::borsh_derive::BorshSchema)] - pub struct Empty; - - #[derive(::borsh_derive::BorshSchema)] - pub struct Named { - _foo: usize, - _bar: [u8; 15], - } - - #[derive(::borsh_derive::BorshSchema)] - pub struct Unnamed(usize, [u8; 15]); - - #[derive(::borsh_derive::BorshSchema)] - struct Multiple { - _usz0: usize, - _usz1: usize, - _usz2: usize, - _vec0: Vec, - _vec1: Vec, - } - - #[derive(::borsh_derive::BorshSchema)] - struct Recursive(Option>); - - test_ok::(0); - test_ok::(23); - test_ok::(23); - test_ok::(3 * 8 + 2 * (4 + MAX_LEN * 8)); - test_err::(Error::Overflow); - test_err::(Error::Recursive); - } - - #[test] - fn max_serialized_size_custom_enum() { - #[allow(dead_code)] - enum Maybe { - Just(T), - Nothing, - } - - impl BorshSchema for Maybe { - fn declaration() -> Declaration { - let res = format!(r#"Maybe<{}, {}>"#, N, T::declaration()); - res - } - fn add_definitions_recursively(definitions: &mut BTreeMap) { - let definition = Definition::Enum { - tag_width: N, - variants: vec![ - (0, "Just".into(), T::declaration()), - (1, "Nothing".into(), <()>::declaration()), - ], - }; - crate::schema::add_definition(Self::declaration(), definition, definitions); - T::add_definitions_recursively(definitions); - <()>::add_definitions_recursively(definitions); - } - } - - test_ok::>(0); - test_ok::>(2); - test_ok::>(8); - - test_ok::>(1); - test_ok::>(3); - test_ok::>(9); - - test_ok::>(4); - test_ok::>(6); - test_ok::>(12); - } - - #[test] - fn max_serialized_size_bound_vec() { - #[allow(dead_code)] - struct BoundVec; - - impl BorshSchema for BoundVec { - fn declaration() -> Declaration { - format!("BoundVec<{}, {}>", W, N) - } - fn add_definitions_recursively(definitions: &mut BTreeMap) { - let definition = Definition::Sequence { - length_width: W, - length_range: 0..=N, - elements: "u8".to_string(), - }; - crate::schema::add_definition(Self::declaration(), definition, definitions); - u8::add_definitions_recursively(definitions); - } - } - - test_ok::>(4); - test_ok::>(4 + u16::MAX as usize); - test_ok::>(24); - - test_ok::>(1); - test_ok::>(1 + u16::MAX as usize); - test_ok::>(21); - - test_ok::>(0); - test_ok::>(u16::MAX as usize); - test_ok::>(20); - } - - #[test] - fn max_serialized_size_small_vec() { - #[allow(dead_code)] - struct SmallVec(core::marker::PhantomData); - - impl BorshSchema for SmallVec { - fn declaration() -> Declaration { - format!(r#"SmallVec<{}>"#, T::declaration()) - } - fn add_definitions_recursively(definitions: &mut BTreeMap) { - let definition = Definition::Sequence { - length_width: 1, - length_range: 0..=u8::MAX as u64, - elements: T::declaration(), - }; - crate::schema::add_definition(Self::declaration(), definition, definitions); - T::add_definitions_recursively(definitions); - } - } - - test_ok::>(u8::MAX as usize + 1); - test_ok::>(u8::MAX as usize * 2 + 1); - } } diff --git a/borsh/src/ser/mod.rs b/borsh/src/ser/mod.rs index ec399eab5..e14b6dcfb 100644 --- a/borsh/src/ser/mod.rs +++ b/borsh/src/ser/mod.rs @@ -293,7 +293,7 @@ where } } -#[cfg(any(test, feature = "bytes"))] +#[cfg(feature = "bytes")] impl BorshSerialize for bytes::Bytes { #[inline] fn serialize(&self, writer: &mut W) -> Result<()> { @@ -301,7 +301,7 @@ impl BorshSerialize for bytes::Bytes { } } -#[cfg(any(test, feature = "bytes"))] +#[cfg(feature = "bytes")] impl BorshSerialize for bytes::BytesMut { #[inline] fn serialize(&self, writer: &mut W) -> Result<()> { @@ -309,7 +309,7 @@ impl BorshSerialize for bytes::BytesMut { } } -#[cfg(any(test, feature = "bson"))] +#[cfg(feature = "bson")] impl BorshSerialize for bson::oid::ObjectId { #[inline] fn serialize(&self, writer: &mut W) -> Result<()> { diff --git a/borsh/tests/common_macro.rs b/borsh/tests/common_macro.rs index a3cf9b86e..bc5503ffb 100644 --- a/borsh/tests/common_macro.rs +++ b/borsh/tests/common_macro.rs @@ -127,12 +127,7 @@ macro_rules! schema_map( #[allow(unused)] #[cfg(feature = "unstable__schema")] pub mod schema_imports { - #[cfg(feature = "std")] - pub use std::collections::BTreeMap; - - #[cfg(not(feature = "std"))] extern crate alloc; - #[cfg(not(feature = "std"))] pub use alloc::{ boxed::Box, collections::BTreeMap, @@ -142,6 +137,9 @@ pub mod schema_imports { vec::Vec, }; - pub use borsh::schema::{BorshSchemaContainer, Definition, Fields}; + pub use borsh::schema::{ + add_definition, BorshSchemaContainer, Declaration, Definition, Fields, + SchemaContainerValidateError, SchemaMaxSerializedSizeError, + }; pub use borsh::{schema_container_of, BorshSchema}; } diff --git a/borsh/tests/compile_derives/schema/test_generic_enums.rs b/borsh/tests/compile_derives/schema/test_generic_enums.rs new file mode 100644 index 000000000..08957c6f8 --- /dev/null +++ b/borsh/tests/compile_derives/schema/test_generic_enums.rs @@ -0,0 +1,35 @@ +#![allow(unused)] +use crate::common_macro::schema_imports::*; + +use core::fmt::{Debug, Display}; + +/// test: Sausage wasn't populated with param Sausage +#[derive(borsh::BorshSchema, Debug)] +enum AWithSkip { + Bacon, + Eggs, + Salad(u32, C, u32), + Sausage { + #[borsh(skip)] + wrapper: W, + filling: u32, + }, +} + +/// test: inner structs in BorshSchema derive don't need any bounds, unrelated to BorshSchema +// #[derive(borsh::BorshSchema)] +// struct SideLeft( +// A, +// ) +// where +// A: Display + Debug, +// B: Display + Debug; +#[derive(borsh::BorshSchema)] +enum Side +where + A: Display + Debug, + B: Display + Debug, +{ + Left(A), + Right(B), +} diff --git a/borsh/tests/compile_derives/test_generic_enums.rs b/borsh/tests/compile_derives/test_generic_enums.rs new file mode 100644 index 000000000..38ba06285 --- /dev/null +++ b/borsh/tests/compile_derives/test_generic_enums.rs @@ -0,0 +1,41 @@ +use borsh::{BorshDeserialize, BorshSerialize}; + +#[allow(unused)] +use alloc::{string::String, vec::Vec}; + +#[cfg(feature = "hashbrown")] +use hashbrown::HashMap; + +#[cfg(hash_collections)] +use core::{cmp::Eq, hash::Hash}; + +#[cfg(feature = "std")] +use std::collections::HashMap; + +use alloc::collections::BTreeMap; + +/// `T: Ord` bound is required for `BorshDeserialize` derive to be successful +#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] +enum E { + X { f: BTreeMap }, + Y(W), +} + +#[cfg(hash_collections)] +#[derive(BorshSerialize, BorshDeserialize, Debug)] +enum I1 { + B { + #[allow(unused)] + #[borsh(skip)] + x: HashMap, + y: String, + }, + C(K, Vec), +} + +#[cfg(hash_collections)] +#[derive(BorshSerialize, BorshDeserialize, Debug)] +enum I2 { + B { x: HashMap, y: String }, + C(K, #[borsh(skip)] U), +} diff --git a/borsh/tests/compile_derives/test_generic_structs.rs b/borsh/tests/compile_derives/test_generic_structs.rs new file mode 100644 index 000000000..96612cc53 --- /dev/null +++ b/borsh/tests/compile_derives/test_generic_structs.rs @@ -0,0 +1,98 @@ +#[cfg(feature = "hashbrown")] +use hashbrown::HashMap; + +#[cfg(hash_collections)] +use core::{cmp::Eq, hash::Hash}; + +#[cfg(feature = "std")] +use std::collections::HashMap; + +use alloc::{ + collections::BTreeMap, + string::String, +}; + +use borsh::{BorshDeserialize, BorshSerialize}; + +#[derive(BorshSerialize, BorshDeserialize, Debug)] +struct TupleA(W, u32); + +#[derive(BorshSerialize, BorshDeserialize, Debug)] +struct NamedA { + a: W, + b: u32, +} + +/// `T: PartialOrd` is injected here via field bound to avoid having this restriction on +/// the struct itself +#[cfg(hash_collections)] +#[derive(BorshSerialize)] +struct C1 { + a: String, + #[borsh(bound(serialize = "T: borsh::ser::BorshSerialize + Ord, + U: borsh::ser::BorshSerialize"))] + b: HashMap, +} + +/// `T: PartialOrd + Hash + Eq` is injected here via field bound to avoid having this restriction on +/// the struct itself +#[allow(unused)] +#[cfg(hash_collections)] +#[derive(BorshDeserialize)] +struct C2 { + a: String, + #[borsh(bound(deserialize = "T: Ord + Hash + Eq + borsh::de::BorshDeserialize, + U: borsh::de::BorshDeserialize"))] + b: HashMap, +} + +/// `T: Ord` bound is required for `BorshDeserialize` derive to be successful +#[derive(BorshSerialize, BorshDeserialize)] +struct D { + a: String, + b: BTreeMap, +} + +#[cfg(hash_collections)] +#[derive(BorshSerialize)] +struct G(#[borsh(skip)] HashMap, U); + +#[cfg(hash_collections)] +#[derive(BorshDeserialize)] +struct G1(#[borsh(skip)] HashMap, U); + +#[cfg(hash_collections)] +#[derive(BorshDeserialize)] +struct G2(HashMap, #[borsh(skip)] U); + +/// implicit derived `core::default::Default` bounds on `K` and `V` are dropped by empty bound +/// specified, as `HashMap` hash its own `Default` implementation +#[cfg(hash_collections)] +#[derive(BorshDeserialize)] +struct G3(#[borsh(skip, bound(deserialize = ""))] HashMap, U); + +#[cfg(hash_collections)] +#[derive(BorshSerialize, BorshDeserialize)] +struct H { + x: BTreeMap, + #[allow(unused)] + #[borsh(skip)] + y: U, +} + +trait TraitName { + type Associated; + fn method(&self); +} + + +#[allow(unused)] +#[derive(BorshSerialize)] +struct ParametrizedWrongDerive +where + T: TraitName, +{ + #[borsh(bound(serialize = "::Associated: borsh::ser::BorshSerialize"))] + field: ::Associated, + another: V, +} diff --git a/borsh/tests/test_macro_namespace_collisions.rs b/borsh/tests/compile_derives/test_macro_namespace_collisions.rs similarity index 79% rename from borsh/tests/test_macro_namespace_collisions.rs rename to borsh/tests/compile_derives/test_macro_namespace_collisions.rs index 83cf0435d..f228ae5b9 100644 --- a/borsh/tests/test_macro_namespace_collisions.rs +++ b/borsh/tests/compile_derives/test_macro_namespace_collisions.rs @@ -1,7 +1,5 @@ -#![cfg_attr(not(feature = "std"), no_std)] // Borsh macros should not collide with the local modules: // https://github.com/near/borsh-rs/issues/11 -#![cfg(feature = "derive")] mod std {} mod core {} diff --git a/borsh/tests/compile_derives/test_recursive_structs.rs b/borsh/tests/compile_derives/test_recursive_structs.rs new file mode 100644 index 000000000..865f8a5d4 --- /dev/null +++ b/borsh/tests/compile_derives/test_recursive_structs.rs @@ -0,0 +1,35 @@ +use borsh::{BorshDeserialize, BorshSerialize}; + +#[cfg(feature = "hashbrown")] +use hashbrown::HashMap; + +#[cfg(feature = "std")] +use std::collections::HashMap; + +#[cfg(hash_collections)] +use core::{cmp::Eq, hash::Hash}; +use alloc::{boxed::Box, string::String}; + + +#[cfg(hash_collections)] +#[derive(BorshSerialize, BorshDeserialize)] +struct CRec { + a: String, + b: HashMap>, +} + +// `impl BorshDeserialize for Box` pulls in => `ToOwned` +// => pulls in at least `Clone` +#[derive(Clone, BorshSerialize, BorshDeserialize)] +struct CRecA { + a: String, + b: Box, +} + + +#[cfg(hash_collections)] +#[derive(BorshSerialize, BorshDeserialize)] +struct CRecC { + a: String, + b: HashMap, +} diff --git a/borsh/tests/test_custom_reader.rs b/borsh/tests/custom_reader/test_custom_reader.rs similarity index 96% rename from borsh/tests/test_custom_reader.rs rename to borsh/tests/custom_reader/test_custom_reader.rs index 57773ca01..e0c6dc7de 100644 --- a/borsh/tests/test_custom_reader.rs +++ b/borsh/tests/custom_reader/test_custom_reader.rs @@ -1,10 +1,5 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(feature = "derive")] use borsh::{from_reader, to_vec, BorshDeserialize, BorshSerialize}; -#[cfg(not(feature = "std"))] -extern crate alloc; -#[cfg(not(feature = "std"))] use alloc::{ string::{String, ToString}, vec::Vec, diff --git a/borsh/tests/deserialization_errors/test_ascii_strings.rs b/borsh/tests/deserialization_errors/test_ascii_strings.rs new file mode 100644 index 000000000..ffcf90d8e --- /dev/null +++ b/borsh/tests/deserialization_errors/test_ascii_strings.rs @@ -0,0 +1,28 @@ +use alloc::string::ToString; +use borsh::from_slice; + +#[test] +fn test_non_ascii() { + let buf = borsh::to_vec(&[0xbf, 0xf3, 0xb3, 0x77][..]).unwrap(); + assert_eq!( + from_slice::(&buf) + .unwrap_err() + .to_string(), + "the byte at index 0 is not ASCII" + ); + + let buf = borsh::to_vec("żółw").unwrap(); + assert_eq!( + from_slice::(&buf) + .unwrap_err() + .to_string(), + "the byte at index 0 is not ASCII" + ); + + assert_eq!( + from_slice::(&[0xbf]) + .unwrap_err() + .to_string(), + "not an ASCII character" + ); +} diff --git a/borsh/tests/deserialization_errors/test_cells.rs b/borsh/tests/deserialization_errors/test_cells.rs new file mode 100644 index 000000000..b6dcb4d16 --- /dev/null +++ b/borsh/tests/deserialization_errors/test_cells.rs @@ -0,0 +1,13 @@ +use alloc::string::ToString; + +#[test] +fn test_ref_cell_try_borrow_error() { + let rcell = core::cell::RefCell::new("str"); + + let _active_borrow = rcell.try_borrow_mut().unwrap(); + + assert_eq!( + borsh::to_vec(&rcell).unwrap_err().to_string(), + "already mutably borrowed" + ); +} diff --git a/borsh/tests/test_de_errors.rs b/borsh/tests/deserialization_errors/test_initial.rs similarity index 97% rename from borsh/tests/test_de_errors.rs rename to borsh/tests/deserialization_errors/test_initial.rs index 88253823b..0fef5c5eb 100644 --- a/borsh/tests/test_de_errors.rs +++ b/borsh/tests/deserialization_errors/test_initial.rs @@ -1,12 +1,8 @@ -#![cfg_attr(not(feature = "std"), no_std)] use borsh::from_slice; #[cfg(feature = "derive")] use borsh::BorshDeserialize; -#[cfg(not(feature = "std"))] -extern crate alloc; -#[cfg(not(feature = "std"))] use alloc::{ format, string::{String, ToString}, diff --git a/borsh/tests/init_in_deserialize/snapshots/tests__init_in_deserialize__test_init_in_deserialize__simple_enum.snap b/borsh/tests/init_in_deserialize/snapshots/tests__init_in_deserialize__test_init_in_deserialize__simple_enum.snap new file mode 100644 index 000000000..4c1be9ef3 --- /dev/null +++ b/borsh/tests/init_in_deserialize/snapshots/tests__init_in_deserialize__test_init_in_deserialize__simple_enum.snap @@ -0,0 +1,7 @@ +--- +source: borsh/tests/init_in_deserialize/test_init_in_deserialize.rs +expression: encoded_a +--- +[ + 1, +] diff --git a/borsh/tests/snapshots/test_init_in_deserialize__simple_struct.snap b/borsh/tests/init_in_deserialize/snapshots/tests__init_in_deserialize__test_init_in_deserialize__simple_struct.snap similarity index 58% rename from borsh/tests/snapshots/test_init_in_deserialize__simple_struct.snap rename to borsh/tests/init_in_deserialize/snapshots/tests__init_in_deserialize__test_init_in_deserialize__simple_struct.snap index 787e3a9bd..e5d0c5f53 100644 --- a/borsh/tests/snapshots/test_init_in_deserialize__simple_struct.snap +++ b/borsh/tests/init_in_deserialize/snapshots/tests__init_in_deserialize__test_init_in_deserialize__simple_struct.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_init_in_deserialize.rs +source: borsh/tests/init_in_deserialize/test_init_in_deserialize.rs expression: encoded_a --- [ diff --git a/borsh/tests/test_init_in_deserialize.rs b/borsh/tests/init_in_deserialize/test_init_in_deserialize.rs similarity index 94% rename from borsh/tests/test_init_in_deserialize.rs rename to borsh/tests/init_in_deserialize/test_init_in_deserialize.rs index f081aacca..652cfc923 100644 --- a/borsh/tests/test_init_in_deserialize.rs +++ b/borsh/tests/init_in_deserialize/test_init_in_deserialize.rs @@ -1,6 +1,3 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(feature = "derive")] - use borsh::{from_slice, to_vec, BorshDeserialize, BorshSerialize}; #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] #[borsh(init=init)] diff --git a/borsh/tests/snapshots/test_bson_object_ids__object_id.snap b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_bson_object_ids__object_id.snap similarity index 66% rename from borsh/tests/snapshots/test_bson_object_ids__object_id.snap rename to borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_bson_object_ids__object_id.snap index f13bb0719..b83d23f16 100644 --- a/borsh/tests/snapshots/test_bson_object_ids__object_id.snap +++ b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_bson_object_ids__object_id.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_bson_object_ids.rs +source: borsh/tests/roundtrip/requires_derive_category/test_bson_object_ids.rs expression: serialized --- [ diff --git a/borsh/tests/snapshots/test_generic_struct__generic_enum.snap b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_enums__generic_enum.snap similarity index 81% rename from borsh/tests/snapshots/test_generic_struct__generic_enum.snap rename to borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_enums__generic_enum.snap index 633549fc9..24b29fd49 100644 --- a/borsh/tests/snapshots/test_generic_struct__generic_enum.snap +++ b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_enums__generic_enum.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_generic_struct.rs +source: borsh/tests/roundtrip/requires_derive_category/test_generic_enums.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_generic_struct__generic_associated_type_field.snap b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_structs__generic_associated_type_field.snap similarity index 68% rename from borsh/tests/snapshots/test_generic_struct__generic_associated_type_field.snap rename to borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_structs__generic_associated_type_field.snap index c9dea4caa..4c87615ce 100644 --- a/borsh/tests/snapshots/test_generic_struct__generic_associated_type_field.snap +++ b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_structs__generic_associated_type_field.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_generic_struct.rs +source: borsh/tests/roundtrip/requires_derive_category/test_generic_structs.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_generic_struct__generic_struct.snap b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_structs__generic_struct.snap similarity index 90% rename from borsh/tests/snapshots/test_generic_struct__generic_struct.snap rename to borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_structs__generic_struct.snap index 71d71b70a..446551acd 100644 --- a/borsh/tests/snapshots/test_generic_struct__generic_struct.snap +++ b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_structs__generic_struct.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_generic_struct.rs +source: borsh/tests/roundtrip/requires_derive_category/test_generic_structs.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_generic_struct__generic_struct_hashmap.snap b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_structs__generic_struct_hashmap.snap similarity index 81% rename from borsh/tests/snapshots/test_generic_struct__generic_struct_hashmap.snap rename to borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_structs__generic_struct_hashmap.snap index 277db2640..aaaf87db7 100644 --- a/borsh/tests/snapshots/test_generic_struct__generic_struct_hashmap.snap +++ b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_generic_structs__generic_struct_hashmap.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_generic_struct.rs +source: borsh/tests/roundtrip/requires_derive_category/test_generic_structs.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_recursive_structs__recursive_enum.snap b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_recursive_enums__recursive_enum.snap similarity index 72% rename from borsh/tests/snapshots/test_recursive_structs__recursive_enum.snap rename to borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_recursive_enums__recursive_enum.snap index 575f30490..dba7774df 100644 --- a/borsh/tests/snapshots/test_recursive_structs__recursive_enum.snap +++ b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_recursive_enums__recursive_enum.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_recursive_structs.rs +source: borsh/tests/roundtrip/requires_derive_category/test_recursive_enums.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_recursive_structs__recursive_struct.snap b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_recursive_structs__recursive_struct.snap similarity index 78% rename from borsh/tests/snapshots/test_recursive_structs__recursive_struct.snap rename to borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_recursive_structs__recursive_struct.snap index 030c7ce64..670510726 100644 --- a/borsh/tests/snapshots/test_recursive_structs__recursive_struct.snap +++ b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_recursive_structs__recursive_struct.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_recursive_structs.rs +source: borsh/tests/roundtrip/requires_derive_category/test_recursive_structs.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_ser_de_with__overriden_enum.snap b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_serde_with_third_party__overriden_enum.snap similarity index 84% rename from borsh/tests/snapshots/test_ser_de_with__overriden_enum.snap rename to borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_serde_with_third_party__overriden_enum.snap index cbd7214f3..48e9c90b6 100644 --- a/borsh/tests/snapshots/test_ser_de_with__overriden_enum.snap +++ b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_serde_with_third_party__overriden_enum.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_ser_de_with.rs +source: borsh/tests/roundtrip/requires_derive_category/test_serde_with_third_party.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_ser_de_with__overriden_struct.snap b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_serde_with_third_party__overriden_struct.snap similarity index 84% rename from borsh/tests/snapshots/test_ser_de_with__overriden_struct.snap rename to borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_serde_with_third_party__overriden_struct.snap index d077f6811..e1571b978 100644 --- a/borsh/tests/snapshots/test_ser_de_with__overriden_struct.snap +++ b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_serde_with_third_party__overriden_struct.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_ser_de_with.rs +source: borsh/tests/roundtrip/requires_derive_category/test_serde_with_third_party.rs expression: data --- [ diff --git a/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum-2.snap b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum-2.snap new file mode 100644 index 000000000..a0892f3ac --- /dev/null +++ b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum-2.snap @@ -0,0 +1,7 @@ +--- +source: borsh/tests/roundtrip/requires_derive_category/test_simple_enums.rs +expression: encoded +--- +[ + 1, +] diff --git a/borsh/tests/snapshots/test_simple_structs__mixed_enum-3.snap b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum-3.snap similarity index 58% rename from borsh/tests/snapshots/test_simple_structs__mixed_enum-3.snap rename to borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum-3.snap index 121d21f21..bd9ea817e 100644 --- a/borsh/tests/snapshots/test_simple_structs__mixed_enum-3.snap +++ b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum-3.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_simple_structs.rs +source: borsh/tests/roundtrip/requires_derive_category/test_simple_enums.rs expression: encoded --- [ diff --git a/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum-4.snap b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum-4.snap new file mode 100644 index 000000000..6d5bab687 --- /dev/null +++ b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum-4.snap @@ -0,0 +1,7 @@ +--- +source: borsh/tests/roundtrip/requires_derive_category/test_simple_enums.rs +expression: encoded +--- +[ + 3, +] diff --git a/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum.snap b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum.snap new file mode 100644 index 000000000..612064a5b --- /dev/null +++ b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_simple_enums__mixed_enum.snap @@ -0,0 +1,9 @@ +--- +source: borsh/tests/roundtrip/requires_derive_category/test_simple_enums.rs +expression: encoded +--- +[ + 0, + 13, + 0, +] diff --git a/borsh/tests/snapshots/test_simple_structs__ultimate_combined_all_features-2.snap b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_ultimate_many_features_combined__ultimate_combined_all_features-2.snap similarity index 97% rename from borsh/tests/snapshots/test_simple_structs__ultimate_combined_all_features-2.snap rename to borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_ultimate_many_features_combined__ultimate_combined_all_features-2.snap index c5dd98903..b1910a3ad 100644 --- a/borsh/tests/snapshots/test_simple_structs__ultimate_combined_all_features-2.snap +++ b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_ultimate_many_features_combined__ultimate_combined_all_features-2.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_simple_structs.rs +source: borsh/tests/roundtrip/requires_derive_category/test_ultimate_many_features_combined.rs expression: encoded_f1 --- [ diff --git a/borsh/tests/snapshots/test_simple_structs__ultimate_combined_all_features.snap b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_ultimate_many_features_combined__ultimate_combined_all_features.snap similarity index 95% rename from borsh/tests/snapshots/test_simple_structs__ultimate_combined_all_features.snap rename to borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_ultimate_many_features_combined__ultimate_combined_all_features.snap index 217417127..ff63dafec 100644 --- a/borsh/tests/snapshots/test_simple_structs__ultimate_combined_all_features.snap +++ b/borsh/tests/roundtrip/requires_derive_category/snapshots/tests__roundtrip__requires_derive_category__test_ultimate_many_features_combined__ultimate_combined_all_features.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_simple_structs.rs +source: borsh/tests/roundtrip/requires_derive_category/test_ultimate_many_features_combined.rs expression: encoded_a --- [ diff --git a/borsh/tests/test_bson_object_ids.rs b/borsh/tests/roundtrip/requires_derive_category/test_bson_object_ids.rs similarity index 89% rename from borsh/tests/test_bson_object_ids.rs rename to borsh/tests/roundtrip/requires_derive_category/test_bson_object_ids.rs index af4e5ebf9..60b0ed5b5 100644 --- a/borsh/tests/test_bson_object_ids.rs +++ b/borsh/tests/roundtrip/requires_derive_category/test_bson_object_ids.rs @@ -1,6 +1,4 @@ -#![cfg_attr(not(feature = "std"), no_std)] #![allow(clippy::float_cmp)] -#![cfg(feature = "derive")] use borsh::{from_slice, to_vec, BorshDeserialize, BorshSerialize}; use bson::oid::ObjectId; diff --git a/borsh/tests/test_enum_discriminants.rs b/borsh/tests/roundtrip/requires_derive_category/test_enum_discriminants.rs similarity index 51% rename from borsh/tests/test_enum_discriminants.rs rename to borsh/tests/roundtrip/requires_derive_category/test_enum_discriminants.rs index 93690ba6f..ac719fe57 100644 --- a/borsh/tests/test_enum_discriminants.rs +++ b/borsh/tests/roundtrip/requires_derive_category/test_enum_discriminants.rs @@ -1,10 +1,3 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(feature = "derive")] - -#[cfg(not(feature = "std"))] -extern crate alloc; - -#[cfg(not(feature = "std"))] use alloc::vec; use borsh::{from_slice, to_vec, BorshDeserialize, BorshSerialize}; @@ -184,112 +177,3 @@ fn test_discriminant_serde() { assert_eq!(from_slice::(&data).unwrap(), values[index]); } } - -#[macro_use] -mod common_macro; - -#[cfg(feature = "unstable__schema")] -mod schema { - use super::common_macro::schema_imports::*; - - #[allow(unused)] - #[derive(BorshSchema)] - #[borsh(use_discriminant = true)] - #[repr(i16)] - enum XY { - A, - B = 20, - C, - D(u32, u32), - E = 10, - F(u64), - } - - #[test] - fn test_schema_discriminant_no_unit_type() { - assert_eq!("XY".to_string(), XY::declaration()); - let mut defs = Default::default(); - XY::add_definitions_recursively(&mut defs); - assert_eq!( - schema_map! { - "XY" => Definition::Enum { - tag_width: 1, - variants: vec![ - (0, "A".to_string(), "XYA".to_string()), - (20, "B".to_string(), "XYB".to_string()), - (21, "C".to_string(), "XYC".to_string()), - (22, "D".to_string(), "XYD".to_string()), - (10, "E".to_string(), "XYE".to_string()), - (11, "F".to_string(), "XYF".to_string()) - ] - }, - "XYA" => Definition::Struct{ fields: Fields::Empty }, - "XYB" => Definition::Struct{ fields: Fields::Empty }, - "XYC" => Definition::Struct{ fields: Fields::Empty }, - "XYD" => Definition::Struct{ fields: Fields::UnnamedFields( - vec!["u32".to_string(), "u32".to_string()] - )}, - "XYE" => Definition::Struct{ fields: Fields::Empty }, - "XYF" => Definition::Struct{ fields: Fields::UnnamedFields( - vec!["u64".to_string()] - - )}, - "u32" => Definition::Primitive(4), - "u64" => Definition::Primitive(8) - }, - defs - ); - } - - #[allow(unused)] - #[derive(BorshSchema)] - #[borsh(use_discriminant = false)] - #[repr(i16)] - enum XYNoDiscriminant { - A, - B = 20, - C, - D(u32, u32), - E = 10, - F(u64), - } - - #[test] - fn test_schema_discriminant_no_unit_type_no_use_discriminant() { - assert_eq!( - "XYNoDiscriminant".to_string(), - XYNoDiscriminant::declaration() - ); - let mut defs = Default::default(); - XYNoDiscriminant::add_definitions_recursively(&mut defs); - assert_eq!( - schema_map! { - "XYNoDiscriminant" => Definition::Enum { - tag_width: 1, - variants: vec![ - (0, "A".to_string(), "XYNoDiscriminantA".to_string()), - (1, "B".to_string(), "XYNoDiscriminantB".to_string()), - (2, "C".to_string(), "XYNoDiscriminantC".to_string()), - (3, "D".to_string(), "XYNoDiscriminantD".to_string()), - (4, "E".to_string(), "XYNoDiscriminantE".to_string()), - (5, "F".to_string(), "XYNoDiscriminantF".to_string()) - ] - }, - "XYNoDiscriminantA" => Definition::Struct{ fields: Fields::Empty }, - "XYNoDiscriminantB" => Definition::Struct{ fields: Fields::Empty }, - "XYNoDiscriminantC" => Definition::Struct{ fields: Fields::Empty }, - "XYNoDiscriminantD" => Definition::Struct{ fields: Fields::UnnamedFields( - vec!["u32".to_string(), "u32".to_string()] - )}, - "XYNoDiscriminantE" => Definition::Struct{ fields: Fields::Empty }, - "XYNoDiscriminantF" => Definition::Struct{ fields: Fields::UnnamedFields( - vec!["u64".to_string()] - - )}, - "u32" => Definition::Primitive(4), - "u64" => Definition::Primitive(8) - }, - defs - ); - } -} diff --git a/borsh/tests/roundtrip/requires_derive_category/test_generic_enums.rs b/borsh/tests/roundtrip/requires_derive_category/test_generic_enums.rs new file mode 100644 index 000000000..7fde60862 --- /dev/null +++ b/borsh/tests/roundtrip/requires_derive_category/test_generic_enums.rs @@ -0,0 +1,29 @@ +use borsh::{from_slice, to_vec, BorshDeserialize, BorshSerialize}; + +use alloc::{ + string::{String, ToString}, + vec, + vec::Vec, +}; + +#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] +enum B { + X { f: Vec }, + Y(G), +} + +#[test] +fn test_generic_enum() { + let b: B = B::X { + f: vec!["one".to_string(), "two".to_string(), "three".to_string()], + }; + let c: B = B::Y(656556u64); + + let list = vec![b, c]; + let data = to_vec(&list).unwrap(); + #[cfg(feature = "std")] + insta::assert_debug_snapshot!(data); + let actual_list = from_slice::>>(&data).unwrap(); + + assert_eq!(list, actual_list); +} diff --git a/borsh/tests/roundtrip/requires_derive_category/test_generic_structs.rs b/borsh/tests/roundtrip/requires_derive_category/test_generic_structs.rs new file mode 100644 index 000000000..35576a670 --- /dev/null +++ b/borsh/tests/roundtrip/requires_derive_category/test_generic_structs.rs @@ -0,0 +1,109 @@ +use borsh::{from_slice, to_vec, BorshDeserialize, BorshSerialize}; +use core::marker::PhantomData; + +#[cfg(feature = "hashbrown")] +use hashbrown::HashMap; + +#[cfg(hash_collections)] +use core::{cmp::Eq, hash::Hash}; + +#[cfg(feature = "std")] +use std::collections::HashMap; + +use alloc::{ + string::{ToString, String}, + vec, + vec::Vec, +}; + +#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] +enum B { + X { f: Vec }, + Y(G), +} + +#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] +struct A { + x: Vec, + y: String, + b: B, + pd: PhantomData, + c: Result, + d: [u64; 5], +} + +#[test] +fn test_generic_struct() { + let a = A:: { + x: vec!["foo".to_string(), "bar".to_string()], + pd: Default::default(), + y: "world".to_string(), + b: B::X { f: vec![1, 2] }, + c: Err("error".to_string()), + d: [0, 1, 2, 3, 4], + }; + let data = to_vec(&a).unwrap(); + #[cfg(feature = "std")] + insta::assert_debug_snapshot!(data); + let actual_a = from_slice::>(&data).unwrap(); + assert_eq!(a, actual_a); +} + +trait TraitName { + type Associated; + fn method(&self); +} + +impl TraitName for u32 { + type Associated = String; + fn method(&self) {} +} + +#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] +struct Parametrized +where + T: TraitName, +{ + field: T::Associated, + another: V, +} + +#[test] +fn test_generic_associated_type_field() { + let a = Parametrized:: { + field: "value".to_string(), + another: "field".to_string(), + }; + let data = to_vec(&a).unwrap(); + #[cfg(feature = "std")] + insta::assert_debug_snapshot!(data); + let actual_a = from_slice::>(&data).unwrap(); + assert_eq!(a, actual_a); +} + +/// `T: PartialOrd` bound is required for `BorshSerialize` derive to be successful +/// `T: Hash + Eq` bound is required for `BorshDeserialize` derive to be successful +#[cfg(hash_collections)] +#[derive(BorshSerialize, BorshDeserialize)] +struct C { + a: String, + b: HashMap, +} + +#[cfg(hash_collections)] +#[test] +fn test_generic_struct_hashmap() { + let mut hashmap = HashMap::new(); + hashmap.insert(34, "another".to_string()); + hashmap.insert(14, "value".to_string()); + let a = C:: { + a: "field".to_string(), + b: hashmap, + }; + let data = to_vec(&a).unwrap(); + #[cfg(feature = "std")] + insta::assert_debug_snapshot!(data); + let actual_a = from_slice::>(&data).unwrap(); + assert_eq!(actual_a.b.get(&14), Some("value".to_string()).as_ref()); + assert_eq!(actual_a.b.get(&34), Some("another".to_string()).as_ref()); +} diff --git a/borsh/tests/roundtrip/requires_derive_category/test_recursive_enums.rs b/borsh/tests/roundtrip/requires_derive_category/test_recursive_enums.rs new file mode 100644 index 000000000..94885428f --- /dev/null +++ b/borsh/tests/roundtrip/requires_derive_category/test_recursive_enums.rs @@ -0,0 +1,28 @@ +use alloc::{ + string::{String, ToString}, + vec, + vec::Vec, +}; +use borsh::{from_slice, to_vec, BorshDeserialize, BorshSerialize}; + +#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] +enum ERecD { + B { x: String, y: i32 }, + C(u8, Vec), +} + +#[test] +fn test_recursive_enum() { + let one = ERecD::B { + x: "one".to_string(), + y: 3213123, + }; + let two = ERecD::C(10, vec![]); + + let three = ERecD::C(11, vec![one, two]); + let data = to_vec(&three).unwrap(); + #[cfg(feature = "std")] + insta::assert_debug_snapshot!(data); + let actual_three = from_slice::(&data).unwrap(); + assert_eq!(three, actual_three); +} diff --git a/borsh/tests/roundtrip/requires_derive_category/test_recursive_structs.rs b/borsh/tests/roundtrip/requires_derive_category/test_recursive_structs.rs new file mode 100644 index 000000000..80c41bdb6 --- /dev/null +++ b/borsh/tests/roundtrip/requires_derive_category/test_recursive_structs.rs @@ -0,0 +1,31 @@ +use borsh::{from_slice, to_vec, BorshDeserialize, BorshSerialize}; + +use alloc::{string::{String, ToString}, vec::Vec, vec}; +#[derive(Debug, BorshSerialize, BorshDeserialize, PartialEq, Eq)] +struct CRecB { + a: String, + b: Vec, +} + +#[test] +fn test_recursive_struct() { + let one = CRecB { + a: "one".to_string(), + b: vec![], + }; + let two = CRecB { + a: "two".to_string(), + b: vec![], + }; + + let three = CRecB { + a: "three".to_string(), + b: vec![one, two], + }; + + let data = to_vec(&three).unwrap(); + #[cfg(feature = "std")] + insta::assert_debug_snapshot!(data); + let actual_three = from_slice::(&data).unwrap(); + assert_eq!(three, actual_three); +} diff --git a/borsh/tests/test_ser_de_with.rs b/borsh/tests/roundtrip/requires_derive_category/test_serde_with_third_party.rs similarity index 93% rename from borsh/tests/test_ser_de_with.rs rename to borsh/tests/roundtrip/requires_derive_category/test_serde_with_third_party.rs index cb8e769bb..a308ce6cd 100644 --- a/borsh/tests/test_ser_de_with.rs +++ b/borsh/tests/roundtrip/requires_derive_category/test_serde_with_third_party.rs @@ -1,12 +1,3 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(feature = "derive")] - -#[cfg(feature = "std")] -use std::collections::BTreeMap; - -#[cfg(not(feature = "std"))] -extern crate alloc; -#[cfg(not(feature = "std"))] use alloc::{ collections::BTreeMap, string::{String, ToString}, diff --git a/borsh/tests/roundtrip/requires_derive_category/test_simple_enums.rs b/borsh/tests/roundtrip/requires_derive_category/test_simple_enums.rs new file mode 100644 index 000000000..94c20bbcf --- /dev/null +++ b/borsh/tests/roundtrip/requires_derive_category/test_simple_enums.rs @@ -0,0 +1,30 @@ +use borsh::{from_slice, to_vec, BorshDeserialize, BorshSerialize}; + +use alloc::vec; + +#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] +enum MixedWithUnitVariants { + A(u16), + B, + C { x: i32, y: i32 }, + D, +} + +#[test] +fn test_mixed_enum() { + let vars = vec![ + MixedWithUnitVariants::A(13), + MixedWithUnitVariants::B, + MixedWithUnitVariants::C { x: 132, y: -17 }, + MixedWithUnitVariants::D, + ]; + for variant in vars { + let encoded = to_vec(&variant).unwrap(); + #[cfg(feature = "std")] + insta::assert_debug_snapshot!(encoded); + + let decoded = from_slice::(&encoded).unwrap(); + + assert_eq!(variant, decoded); + } +} diff --git a/borsh/tests/test_simple_structs.rs b/borsh/tests/roundtrip/requires_derive_category/test_ultimate_many_features_combined.rs similarity index 85% rename from borsh/tests/test_simple_structs.rs rename to borsh/tests/roundtrip/requires_derive_category/test_ultimate_many_features_combined.rs index 1557536d0..fd9c4e8f2 100644 --- a/borsh/tests/test_simple_structs.rs +++ b/borsh/tests/roundtrip/requires_derive_category/test_ultimate_many_features_combined.rs @@ -1,20 +1,5 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(feature = "derive")] - -#[cfg(feature = "std")] -use std::{ - borrow, - collections::{BTreeMap, BTreeSet, LinkedList, VecDeque}, - ops, -}; - -#[cfg(not(feature = "std"))] use core::{ops, result::Result}; -#[cfg(not(feature = "std"))] -extern crate alloc; - -#[cfg(not(feature = "std"))] use alloc::{ borrow, boxed::Box, @@ -223,30 +208,3 @@ fn test_object_length() { assert_eq!(encoded_a_len, len_helper_result); } - -#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] -enum MixedWithUnitVariants { - A(u16), - B, - C { x: i32, y: i32 }, - D, -} - -#[test] -fn test_mixed_enum() { - let vars = vec![ - MixedWithUnitVariants::A(13), - MixedWithUnitVariants::B, - MixedWithUnitVariants::C { x: 132, y: -17 }, - MixedWithUnitVariants::D, - ]; - for variant in vars { - let encoded = to_vec(&variant).unwrap(); - #[cfg(feature = "std")] - insta::assert_debug_snapshot!(encoded); - - let decoded = from_slice::(&encoded).unwrap(); - - assert_eq!(variant, decoded); - } -} diff --git a/borsh/tests/snapshots/test_arrays__array_array_u8-10.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-10.snap similarity index 99% rename from borsh/tests/snapshots/test_arrays__array_array_u8-10.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-10.snap index b637161d4..28132949f 100644 --- a/borsh/tests/snapshots/test_arrays__array_array_u8-10.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-10.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u8-8.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-2.snap similarity index 87% rename from borsh/tests/snapshots/test_arrays__array_u8-8.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-2.snap index c7f4ccf09..9ad6500e6 100644 --- a/borsh/tests/snapshots/test_arrays__array_u8-8.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-2.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_i8-9.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-3.snap similarity index 93% rename from borsh/tests/snapshots/test_arrays__array_i8-9.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-3.snap index a8d3d95d7..0dee1b797 100644 --- a/borsh/tests/snapshots/test_arrays__array_i8-9.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-3.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_array_u8-4.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-4.snap similarity index 95% rename from borsh/tests/snapshots/test_arrays__array_array_u8-4.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-4.snap index b8dec42c5..c7617e617 100644 --- a/borsh/tests/snapshots/test_arrays__array_array_u8-4.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-4.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_array_u8-5.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-5.snap similarity index 96% rename from borsh/tests/snapshots/test_arrays__array_array_u8-5.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-5.snap index c1ee3e779..c54df4023 100644 --- a/borsh/tests/snapshots/test_arrays__array_array_u8-5.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-5.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_array_u8-6.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-6.snap similarity index 98% rename from borsh/tests/snapshots/test_arrays__array_array_u8-6.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-6.snap index 6c7ef444b..2da1a6e69 100644 --- a/borsh/tests/snapshots/test_arrays__array_array_u8-6.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-6.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_array_u8-7.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-7.snap similarity index 99% rename from borsh/tests/snapshots/test_arrays__array_array_u8-7.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-7.snap index 934fe16b1..3b6d43546 100644 --- a/borsh/tests/snapshots/test_arrays__array_array_u8-7.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-7.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_array_u8-8.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-8.snap similarity index 99% rename from borsh/tests/snapshots/test_arrays__array_array_u8-8.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-8.snap index 0a2d116f3..a815e4506 100644 --- a/borsh/tests/snapshots/test_arrays__array_array_u8-8.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-8.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_array_u8-9.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-9.snap similarity index 99% rename from borsh/tests/snapshots/test_arrays__array_array_u8-9.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-9.snap index 3d0afb25b..50308b6e1 100644 --- a/borsh/tests/snapshots/test_arrays__array_array_u8-9.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8-9.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_array_u8.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/snapshots/test_arrays__array_f32-10.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-10.snap similarity index 98% rename from borsh/tests/snapshots/test_arrays__array_f32-10.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-10.snap index 3f000cdd3..f92d614cf 100644 --- a/borsh/tests/snapshots/test_arrays__array_f32-10.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-10.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_f32-2.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-2.snap similarity index 57% rename from borsh/tests/snapshots/test_arrays__array_f32-2.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-2.snap index 510a4ceaf..553319cff 100644 --- a/borsh/tests/snapshots/test_arrays__array_f32-2.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-2.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_f32-3.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-3.snap similarity index 68% rename from borsh/tests/snapshots/test_arrays__array_f32-3.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-3.snap index 9ceb617b9..48059081d 100644 --- a/borsh/tests/snapshots/test_arrays__array_f32-3.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-3.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_f32-4.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-4.snap similarity index 74% rename from borsh/tests/snapshots/test_arrays__array_f32-4.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-4.snap index 394720695..22fe25ac8 100644 --- a/borsh/tests/snapshots/test_arrays__array_f32-4.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-4.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_f32-5.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-5.snap similarity index 78% rename from borsh/tests/snapshots/test_arrays__array_f32-5.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-5.snap index 3c20cb8dc..1a0b56135 100644 --- a/borsh/tests/snapshots/test_arrays__array_f32-5.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-5.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_f32-6.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-6.snap similarity index 86% rename from borsh/tests/snapshots/test_arrays__array_f32-6.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-6.snap index b6a11da57..d3b9e50b5 100644 --- a/borsh/tests/snapshots/test_arrays__array_f32-6.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-6.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_f32-7.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-7.snap similarity index 92% rename from borsh/tests/snapshots/test_arrays__array_f32-7.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-7.snap index d134dcc06..f2e746ef0 100644 --- a/borsh/tests/snapshots/test_arrays__array_f32-7.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-7.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_f32-8.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-8.snap similarity index 96% rename from borsh/tests/snapshots/test_arrays__array_f32-8.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-8.snap index a0ebf18fe..945ba3514 100644 --- a/borsh/tests/snapshots/test_arrays__array_f32-8.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-8.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_f32-9.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-9.snap similarity index 97% rename from borsh/tests/snapshots/test_arrays__array_f32-9.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-9.snap index ba7908994..18267a2ba 100644 --- a/borsh/tests/snapshots/test_arrays__array_f32-9.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32-9.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_f32.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/snapshots/test_arrays__array_i8-10.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-10.snap similarity index 93% rename from borsh/tests/snapshots/test_arrays__array_i8-10.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-10.snap index 8c93559dd..fa1e9c234 100644 --- a/borsh/tests/snapshots/test_arrays__array_i8-10.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-10.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-2.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-2.snap new file mode 100644 index 000000000..a9f95ae3c --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-2.snap @@ -0,0 +1,7 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[ + 100, +] diff --git a/borsh/tests/snapshots/test_arrays__array_i8-3.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-3.snap similarity index 50% rename from borsh/tests/snapshots/test_arrays__array_i8-3.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-3.snap index 8e6ff120a..01c4050fe 100644 --- a/borsh/tests/snapshots/test_arrays__array_i8-3.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-3.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u8-4.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-4.snap similarity index 55% rename from borsh/tests/snapshots/test_arrays__array_u8-4.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-4.snap index 90b6f7336..e2d83255a 100644 --- a/borsh/tests/snapshots/test_arrays__array_u8-4.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-4.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_i8-5.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-5.snap similarity index 58% rename from borsh/tests/snapshots/test_arrays__array_i8-5.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-5.snap index f520643a9..c36a38733 100644 --- a/borsh/tests/snapshots/test_arrays__array_i8-5.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-5.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u8-6.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-6.snap similarity index 68% rename from borsh/tests/snapshots/test_arrays__array_u8-6.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-6.snap index bf58dfd92..c7c3d5e44 100644 --- a/borsh/tests/snapshots/test_arrays__array_u8-6.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-6.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u8-7.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-7.snap similarity index 79% rename from borsh/tests/snapshots/test_arrays__array_u8-7.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-7.snap index c86237337..12c8de63f 100644 --- a/borsh/tests/snapshots/test_arrays__array_u8-7.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-7.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_array_u8-2.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-8.snap similarity index 87% rename from borsh/tests/snapshots/test_arrays__array_array_u8-2.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-8.snap index c7f4ccf09..9ad6500e6 100644 --- a/borsh/tests/snapshots/test_arrays__array_array_u8-2.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-8.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_array_u8-3.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-9.snap similarity index 93% rename from borsh/tests/snapshots/test_arrays__array_array_u8-3.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-9.snap index a8d3d95d7..0dee1b797 100644 --- a/borsh/tests/snapshots/test_arrays__array_array_u8-3.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8-9.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_i8.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/snapshots/test_arrays__array_u128-10.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-10.snap similarity index 99% rename from borsh/tests/snapshots/test_arrays__array_u128-10.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-10.snap index 6f1a91af9..18491b951 100644 --- a/borsh/tests/snapshots/test_arrays__array_u128-10.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-10.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u128-2.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-2.snap similarity index 77% rename from borsh/tests/snapshots/test_arrays__array_u128-2.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-2.snap index 837ffecfd..b57cec085 100644 --- a/borsh/tests/snapshots/test_arrays__array_u128-2.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-2.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u128-3.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-3.snap similarity index 86% rename from borsh/tests/snapshots/test_arrays__array_u128-3.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-3.snap index 22d00d5c8..565d12e7e 100644 --- a/borsh/tests/snapshots/test_arrays__array_u128-3.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-3.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u128-4.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-4.snap similarity index 90% rename from borsh/tests/snapshots/test_arrays__array_u128-4.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-4.snap index 6f2ab7761..ded1a2954 100644 --- a/borsh/tests/snapshots/test_arrays__array_u128-4.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-4.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u128-5.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-5.snap similarity index 92% rename from borsh/tests/snapshots/test_arrays__array_u128-5.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-5.snap index 6cc4e6be3..fd6704a49 100644 --- a/borsh/tests/snapshots/test_arrays__array_u128-5.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-5.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u128-6.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-6.snap similarity index 95% rename from borsh/tests/snapshots/test_arrays__array_u128-6.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-6.snap index f41b706f7..7f5aeee28 100644 --- a/borsh/tests/snapshots/test_arrays__array_u128-6.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-6.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u128-7.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-7.snap similarity index 97% rename from borsh/tests/snapshots/test_arrays__array_u128-7.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-7.snap index 3c5b91d28..6026991ef 100644 --- a/borsh/tests/snapshots/test_arrays__array_u128-7.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-7.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u128-8.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-8.snap similarity index 98% rename from borsh/tests/snapshots/test_arrays__array_u128-8.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-8.snap index b706bf62f..f2fe6084e 100644 --- a/borsh/tests/snapshots/test_arrays__array_u128-8.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-8.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u128-9.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-9.snap similarity index 99% rename from borsh/tests/snapshots/test_arrays__array_u128-9.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-9.snap index 1aa181a73..5c4b79e1b 100644 --- a/borsh/tests/snapshots/test_arrays__array_u128-9.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128-9.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u128.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/snapshots/test_arrays__array_u32-10.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-10.snap similarity index 97% rename from borsh/tests/snapshots/test_arrays__array_u32-10.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-10.snap index 99a7d323a..a962b95cb 100644 --- a/borsh/tests/snapshots/test_arrays__array_u32-10.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-10.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u32-2.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-2.snap similarity index 57% rename from borsh/tests/snapshots/test_arrays__array_u32-2.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-2.snap index 7152a9f78..eece67ced 100644 --- a/borsh/tests/snapshots/test_arrays__array_u32-2.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-2.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u32-3.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-3.snap similarity index 67% rename from borsh/tests/snapshots/test_arrays__array_u32-3.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-3.snap index 22aedb6c5..42672078c 100644 --- a/borsh/tests/snapshots/test_arrays__array_u32-3.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-3.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u32-4.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-4.snap similarity index 73% rename from borsh/tests/snapshots/test_arrays__array_u32-4.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-4.snap index b596e6f9f..3d70b08cc 100644 --- a/borsh/tests/snapshots/test_arrays__array_u32-4.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-4.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u32-5.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-5.snap similarity index 78% rename from borsh/tests/snapshots/test_arrays__array_u32-5.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-5.snap index a45f73262..de026c6f1 100644 --- a/borsh/tests/snapshots/test_arrays__array_u32-5.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-5.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u32-6.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-6.snap similarity index 86% rename from borsh/tests/snapshots/test_arrays__array_u32-6.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-6.snap index 38c87eba7..d0d3347de 100644 --- a/borsh/tests/snapshots/test_arrays__array_u32-6.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-6.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u32-7.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-7.snap similarity index 92% rename from borsh/tests/snapshots/test_arrays__array_u32-7.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-7.snap index bc037fc89..05cd06352 100644 --- a/borsh/tests/snapshots/test_arrays__array_u32-7.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-7.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u32-8.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-8.snap similarity index 96% rename from borsh/tests/snapshots/test_arrays__array_u32-8.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-8.snap index 07325c8be..d7324fe50 100644 --- a/borsh/tests/snapshots/test_arrays__array_u32-8.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-8.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u32-9.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-9.snap similarity index 97% rename from borsh/tests/snapshots/test_arrays__array_u32-9.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-9.snap index a39a7aec7..092ba8f14 100644 --- a/borsh/tests/snapshots/test_arrays__array_u32-9.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32-9.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u32.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/snapshots/test_arrays__array_u64-10.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-10.snap similarity index 98% rename from borsh/tests/snapshots/test_arrays__array_u64-10.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-10.snap index aa88ee95b..ab985b70d 100644 --- a/borsh/tests/snapshots/test_arrays__array_u64-10.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-10.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u64-2.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-2.snap similarity index 67% rename from borsh/tests/snapshots/test_arrays__array_u64-2.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-2.snap index ec22a64f4..1b933cdf3 100644 --- a/borsh/tests/snapshots/test_arrays__array_u64-2.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-2.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u64-3.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-3.snap similarity index 78% rename from borsh/tests/snapshots/test_arrays__array_u64-3.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-3.snap index 64a47f2c2..54ad21bb7 100644 --- a/borsh/tests/snapshots/test_arrays__array_u64-3.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-3.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u64-4.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-4.snap similarity index 83% rename from borsh/tests/snapshots/test_arrays__array_u64-4.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-4.snap index a9a977ee8..eda38fbe1 100644 --- a/borsh/tests/snapshots/test_arrays__array_u64-4.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-4.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u64-5.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-5.snap similarity index 86% rename from borsh/tests/snapshots/test_arrays__array_u64-5.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-5.snap index d0f13cf1a..3c5b55d1b 100644 --- a/borsh/tests/snapshots/test_arrays__array_u64-5.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-5.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u64-6.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-6.snap similarity index 92% rename from borsh/tests/snapshots/test_arrays__array_u64-6.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-6.snap index 1b9bff99e..c6cef8fa3 100644 --- a/borsh/tests/snapshots/test_arrays__array_u64-6.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-6.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u64-7.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-7.snap similarity index 96% rename from borsh/tests/snapshots/test_arrays__array_u64-7.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-7.snap index 48027f7b8..5cf45c517 100644 --- a/borsh/tests/snapshots/test_arrays__array_u64-7.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-7.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u64-8.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-8.snap similarity index 97% rename from borsh/tests/snapshots/test_arrays__array_u64-8.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-8.snap index fa01ede79..567f4d0d7 100644 --- a/borsh/tests/snapshots/test_arrays__array_u64-8.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-8.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u64-9.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-9.snap similarity index 98% rename from borsh/tests/snapshots/test_arrays__array_u64-9.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-9.snap index 45f758440..3e590a2ce 100644 --- a/borsh/tests/snapshots/test_arrays__array_u64-9.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64-9.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u64.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/snapshots/test_arrays__array_u8-10.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-10.snap similarity index 93% rename from borsh/tests/snapshots/test_arrays__array_u8-10.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-10.snap index 8c93559dd..fa1e9c234 100644 --- a/borsh/tests/snapshots/test_arrays__array_u8-10.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-10.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-2.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-2.snap new file mode 100644 index 000000000..a9f95ae3c --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-2.snap @@ -0,0 +1,7 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[ + 100, +] diff --git a/borsh/tests/snapshots/test_arrays__array_u8-3.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-3.snap similarity index 50% rename from borsh/tests/snapshots/test_arrays__array_u8-3.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-3.snap index 8e6ff120a..01c4050fe 100644 --- a/borsh/tests/snapshots/test_arrays__array_u8-3.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-3.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_i8-4.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-4.snap similarity index 55% rename from borsh/tests/snapshots/test_arrays__array_i8-4.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-4.snap index 90b6f7336..e2d83255a 100644 --- a/borsh/tests/snapshots/test_arrays__array_i8-4.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-4.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_u8-5.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-5.snap similarity index 58% rename from borsh/tests/snapshots/test_arrays__array_u8-5.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-5.snap index f520643a9..c36a38733 100644 --- a/borsh/tests/snapshots/test_arrays__array_u8-5.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-5.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_i8-6.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-6.snap similarity index 68% rename from borsh/tests/snapshots/test_arrays__array_i8-6.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-6.snap index bf58dfd92..c7c3d5e44 100644 --- a/borsh/tests/snapshots/test_arrays__array_i8-6.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-6.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_i8-7.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-7.snap similarity index 79% rename from borsh/tests/snapshots/test_arrays__array_i8-7.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-7.snap index c86237337..12c8de63f 100644 --- a/borsh/tests/snapshots/test_arrays__array_i8-7.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-7.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_arrays__array_i8-8.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-8.snap similarity index 87% rename from borsh/tests/snapshots/test_arrays__array_i8-8.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-8.snap index c7f4ccf09..9ad6500e6 100644 --- a/borsh/tests/snapshots/test_arrays__array_i8-8.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-8.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: buf --- [ diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-9.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-9.snap new file mode 100644 index 000000000..0dee1b797 --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8-9.snap @@ -0,0 +1,70 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[ + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100, +] diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_u8.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-10.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-10.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-10.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-2.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-2.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-2.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-3.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-3.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-3.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-4.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-4.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-4.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-5.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-5.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-5.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-6.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-6.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-6.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-7.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-7.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-7.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-8.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-8.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-8.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-9.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-9.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst-9.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst.snap new file mode 100644 index 000000000..827efceba --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__array_zst.snap @@ -0,0 +1,5 @@ +--- +source: borsh/tests/roundtrip/test_arrays.rs +expression: buf +--- +[] diff --git a/borsh/tests/snapshots/test_arrays__custom_struct_array.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__custom_struct_array.snap similarity index 55% rename from borsh/tests/snapshots/test_arrays__custom_struct_array.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__custom_struct_array.snap index ddbbd6866..59f610e1c 100644 --- a/borsh/tests/snapshots/test_arrays__custom_struct_array.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__custom_struct_array.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: serialized --- [ diff --git a/borsh/tests/snapshots/test_arrays__string_array.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__string_array.snap similarity index 76% rename from borsh/tests/snapshots/test_arrays__string_array.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__string_array.snap index a9049b67e..8b9312954 100644 --- a/borsh/tests/snapshots/test_arrays__string_array.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_arrays__string_array.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_arrays.rs +source: borsh/tests/roundtrip/test_arrays.rs expression: serialized --- [ diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__a.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__a.snap new file mode 100644 index 000000000..059de1ec5 --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__a.snap @@ -0,0 +1,11 @@ +--- +source: borsh/tests/roundtrip/test_ascii_strings.rs +expression: _buf +--- +[ + 1, + 0, + 0, + 0, + 97, +] diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__empty_string.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__empty_string.snap new file mode 100644 index 000000000..8d6091d60 --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__empty_string.snap @@ -0,0 +1,10 @@ +--- +source: borsh/tests/roundtrip/test_ascii_strings.rs +expression: _buf +--- +[ + 0, + 0, + 0, + 0, +] diff --git a/borsh/tests/snapshots/test_strings__hello_10.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__hello_10.snap similarity index 97% rename from borsh/tests/snapshots/test_strings__hello_10.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__hello_10.snap index 0402b06d5..c96f09e67 100644 --- a/borsh/tests/snapshots/test_strings__hello_10.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__hello_10.snap @@ -1,6 +1,6 @@ --- -source: borsh/tests/test_strings.rs -expression: buf +source: borsh/tests/roundtrip/test_ascii_strings.rs +expression: _buf --- [ 104, diff --git a/borsh/tests/snapshots/test_ascii_strings__hello_world.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__hello_world.snap similarity index 66% rename from borsh/tests/snapshots/test_ascii_strings__hello_world.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__hello_world.snap index b2d10ca5a..0e8744a11 100644 --- a/borsh/tests/snapshots/test_ascii_strings__hello_world.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__hello_world.snap @@ -1,6 +1,6 @@ --- -source: borsh/tests/test_ascii_strings.rs -expression: buf +source: borsh/tests/roundtrip/test_ascii_strings.rs +expression: _buf --- [ 11, diff --git a/borsh/tests/snapshots/test_strings__x_1024.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__x_1024.snap similarity index 99% rename from borsh/tests/snapshots/test_strings__x_1024.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__x_1024.snap index 89f7cf1dc..57ea3727f 100644 --- a/borsh/tests/snapshots/test_strings__x_1024.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_ascii_strings__x_1024.snap @@ -1,6 +1,6 @@ --- -source: borsh/tests/test_strings.rs -expression: buf +source: borsh/tests/roundtrip/test_ascii_strings.rs +expression: _buf --- [ 0, diff --git a/borsh/tests/snapshots/test_hash_map__1_element_hashmap.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__1_element_btreemap.snap similarity index 80% rename from borsh/tests/snapshots/test_hash_map__1_element_hashmap.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__1_element_btreemap.snap index 3c3005060..7b1ae6250 100644 --- a/borsh/tests/snapshots/test_hash_map__1_element_hashmap.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__1_element_btreemap.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_hash_map.rs +source: borsh/tests/roundtrip/test_btree_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_hash_map__1_element_generic_hashset.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__1_element_btreeset.snap similarity index 70% rename from borsh/tests/snapshots/test_hash_map__1_element_generic_hashset.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__1_element_btreeset.snap index 75b9173dc..c4375bdb0 100644 --- a/borsh/tests/snapshots/test_hash_map__1_element_generic_hashset.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__1_element_btreeset.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_hash_map.rs +source: borsh/tests/roundtrip/test_btree_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_hash_map__2_element_hashset.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__2_element_btreeset.snap similarity index 82% rename from borsh/tests/snapshots/test_hash_map__2_element_hashset.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__2_element_btreeset.snap index cb3336856..ffa88f726 100644 --- a/borsh/tests/snapshots/test_hash_map__2_element_hashset.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__2_element_btreeset.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_hash_map.rs +source: borsh/tests/roundtrip/test_btree_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_hash_map__8_element_hashmap.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__8_element_btreemap.snap similarity index 96% rename from borsh/tests/snapshots/test_hash_map__8_element_hashmap.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__8_element_btreemap.snap index 7355810d8..455f74efe 100644 --- a/borsh/tests/snapshots/test_hash_map__8_element_hashmap.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__8_element_btreemap.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_hash_map.rs +source: borsh/tests/roundtrip/test_btree_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_btree_map__default_btreemap.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__default_btreemap.snap similarity index 85% rename from borsh/tests/snapshots/test_btree_map__default_btreemap.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__default_btreemap.snap index d46d5e090..6ab50daa2 100644 --- a/borsh/tests/snapshots/test_btree_map__default_btreemap.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__default_btreemap.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_btree_map.rs +source: borsh/tests/roundtrip/test_btree_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_hash_map__generic_hashset.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__default_btreeset.snap similarity index 91% rename from borsh/tests/snapshots/test_hash_map__generic_hashset.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__default_btreeset.snap index 4d001beaa..dc78b6c55 100644 --- a/borsh/tests/snapshots/test_hash_map__generic_hashset.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__default_btreeset.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_hash_map.rs +source: borsh/tests/roundtrip/test_btree_map.rs expression: data --- [ diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__empty_btreemap.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__empty_btreemap.snap new file mode 100644 index 000000000..00b36c752 --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__empty_btreemap.snap @@ -0,0 +1,10 @@ +--- +source: borsh/tests/roundtrip/test_btree_map.rs +expression: data +--- +[ + 0, + 0, + 0, + 0, +] diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__empty_btreeset.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__empty_btreeset.snap new file mode 100644 index 000000000..00b36c752 --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_btree_map__empty_btreeset.snap @@ -0,0 +1,10 @@ +--- +source: borsh/tests/roundtrip/test_btree_map.rs +expression: data +--- +[ + 0, + 0, + 0, + 0, +] diff --git a/borsh/tests/snapshots/test_cow__cow_byte_slice.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_cow__cow_byte_slice.snap similarity index 75% rename from borsh/tests/snapshots/test_cow__cow_byte_slice.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_cow__cow_byte_slice.snap index a28105466..1bddf2804 100644 --- a/borsh/tests/snapshots/test_cow__cow_byte_slice.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_cow__cow_byte_slice.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_cow.rs +source: borsh/tests/roundtrip/test_cow.rs expression: encoded --- [ diff --git a/borsh/tests/snapshots/test_cow__cow_slice_of_cow_str.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_cow__cow_slice_of_cow_str.snap similarity index 91% rename from borsh/tests/snapshots/test_cow__cow_slice_of_cow_str.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_cow__cow_slice_of_cow_str.snap index 368354b4b..113d87595 100644 --- a/borsh/tests/snapshots/test_cow__cow_slice_of_cow_str.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_cow__cow_slice_of_cow_str.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_cow.rs +source: borsh/tests/roundtrip/test_cow.rs expression: encoded --- [ diff --git a/borsh/tests/snapshots/test_cow__cow_str.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_cow__cow_str.snap similarity index 79% rename from borsh/tests/snapshots/test_cow__cow_str.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_cow__cow_str.snap index f810057e3..83beb7e63 100644 --- a/borsh/tests/snapshots/test_cow__cow_str.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_cow__cow_str.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_cow.rs +source: borsh/tests/roundtrip/test_cow.rs expression: encoded --- [ diff --git a/borsh/tests/snapshots/test_btree_map__1_element_btreemap.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_generic_hashmap.snap similarity index 81% rename from borsh/tests/snapshots/test_btree_map__1_element_btreemap.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_generic_hashmap.snap index 51918d683..53a4f6c3b 100644 --- a/borsh/tests/snapshots/test_btree_map__1_element_btreemap.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_generic_hashmap.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_btree_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_hash_map__1_element_hashset.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_generic_hashset.snap similarity index 70% rename from borsh/tests/snapshots/test_hash_map__1_element_hashset.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_generic_hashset.snap index 75b9173dc..a1bd3cdee 100644 --- a/borsh/tests/snapshots/test_hash_map__1_element_hashset.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_generic_hashset.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_hash_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_hash_map__1_element_generic_hashmap.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_hashmap.snap similarity index 81% rename from borsh/tests/snapshots/test_hash_map__1_element_generic_hashmap.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_hashmap.snap index 3c3005060..53a4f6c3b 100644 --- a/borsh/tests/snapshots/test_hash_map__1_element_generic_hashmap.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_hashmap.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_hash_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_btree_map__1_element_btreeset.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_hashset.snap similarity index 70% rename from borsh/tests/snapshots/test_btree_map__1_element_btreeset.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_hashset.snap index 81296e58f..a1bd3cdee 100644 --- a/borsh/tests/snapshots/test_btree_map__1_element_btreeset.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__1_element_hashset.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_btree_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_btree_map__2_element_btreeset.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__2_element_generic_hashset.snap similarity index 82% rename from borsh/tests/snapshots/test_btree_map__2_element_btreeset.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__2_element_generic_hashset.snap index 43fe535d3..f74bdb6ed 100644 --- a/borsh/tests/snapshots/test_btree_map__2_element_btreeset.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__2_element_generic_hashset.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_btree_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_hash_map__2_element_generic_hashset.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__2_element_hashset.snap similarity index 82% rename from borsh/tests/snapshots/test_hash_map__2_element_generic_hashset.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__2_element_hashset.snap index cb3336856..f74bdb6ed 100644 --- a/borsh/tests/snapshots/test_hash_map__2_element_generic_hashset.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__2_element_hashset.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_hash_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_hash_map__8_element_generic_hashmap.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__8_element_generic_hashmap.snap similarity index 96% rename from borsh/tests/snapshots/test_hash_map__8_element_generic_hashmap.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__8_element_generic_hashmap.snap index 7355810d8..455c3f76b 100644 --- a/borsh/tests/snapshots/test_hash_map__8_element_generic_hashmap.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__8_element_generic_hashmap.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_hash_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_btree_map__8_element_btreemap.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__8_element_hashmap.snap similarity index 96% rename from borsh/tests/snapshots/test_btree_map__8_element_btreemap.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__8_element_hashmap.snap index fbf363aec..455c3f76b 100644 --- a/borsh/tests/snapshots/test_btree_map__8_element_btreemap.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__8_element_hashmap.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_btree_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_hash_map__generic_hash_hashmap.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__default_hashmap.snap similarity index 85% rename from borsh/tests/snapshots/test_hash_map__generic_hash_hashmap.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__default_hashmap.snap index 5a678e19b..094a56ab7 100644 --- a/borsh/tests/snapshots/test_hash_map__generic_hash_hashmap.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__default_hashmap.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_hash_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_hash_map__default_hashset.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__default_hashset.snap similarity index 91% rename from borsh/tests/snapshots/test_hash_map__default_hashset.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__default_hashset.snap index 4d001beaa..620f3cbb6 100644 --- a/borsh/tests/snapshots/test_hash_map__default_hashset.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__default_hashset.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_hash_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_hash_map__empty_generic_hashmap.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_generic_hashmap.snap similarity index 54% rename from borsh/tests/snapshots/test_hash_map__empty_generic_hashmap.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_generic_hashmap.snap index 8e2cff348..2f510b794 100644 --- a/borsh/tests/snapshots/test_hash_map__empty_generic_hashmap.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_generic_hashmap.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_hash_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_hash_map__empty_generic_hashset.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_generic_hashset.snap similarity index 54% rename from borsh/tests/snapshots/test_hash_map__empty_generic_hashset.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_generic_hashset.snap index 8e2cff348..2f510b794 100644 --- a/borsh/tests/snapshots/test_hash_map__empty_generic_hashset.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_generic_hashset.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_hash_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_btree_map__empty_btreemap.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_hashmap.snap similarity index 54% rename from borsh/tests/snapshots/test_btree_map__empty_btreemap.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_hashmap.snap index 48016f370..2f510b794 100644 --- a/borsh/tests/snapshots/test_btree_map__empty_btreemap.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_hashmap.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_btree_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_btree_map__empty_btreeset.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_hashset.snap similarity index 54% rename from borsh/tests/snapshots/test_btree_map__empty_btreeset.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_hashset.snap index 48016f370..2f510b794 100644 --- a/borsh/tests/snapshots/test_btree_map__empty_btreeset.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__empty_hashset.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_btree_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_hash_map__default_hashmap.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__generic_hash_hashmap.snap similarity index 85% rename from borsh/tests/snapshots/test_hash_map__default_hashmap.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__generic_hash_hashmap.snap index 5a678e19b..094a56ab7 100644 --- a/borsh/tests/snapshots/test_hash_map__default_hashmap.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__generic_hash_hashmap.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_hash_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_btree_map__default_btreeset.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__generic_hashset.snap similarity index 91% rename from borsh/tests/snapshots/test_btree_map__default_btreeset.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__generic_hashset.snap index 2a4536ea0..620f3cbb6 100644 --- a/borsh/tests/snapshots/test_btree_map__default_btreeset.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_hash_map__generic_hashset.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_btree_map.rs +source: borsh/tests/roundtrip/test_hash_map.rs expression: data --- [ diff --git a/borsh/tests/snapshots/test_primitives__isize_max.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__isize_max.snap similarity index 67% rename from borsh/tests/snapshots/test_primitives__isize_max.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__isize_max.snap index a7b3cf9e7..ecf8c569f 100644 --- a/borsh/tests/snapshots/test_primitives__isize_max.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__isize_max.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_primitives.rs +source: borsh/tests/roundtrip/test_primitives.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_primitives__isize_min.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__isize_min.snap similarity index 63% rename from borsh/tests/snapshots/test_primitives__isize_min.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__isize_min.snap index f03a79ce9..45c11a4ce 100644 --- a/borsh/tests/snapshots/test_primitives__isize_min.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__isize_min.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_primitives.rs +source: borsh/tests/roundtrip/test_primitives.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_primitives__isize_neg.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__isize_neg.snap similarity index 67% rename from borsh/tests/snapshots/test_primitives__isize_neg.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__isize_neg.snap index b2c2c532b..1a13c279a 100644 --- a/borsh/tests/snapshots/test_primitives__isize_neg.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__isize_neg.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_primitives.rs +source: borsh/tests/roundtrip/test_primitives.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_primitives__usize.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__isize_pos.snap similarity index 63% rename from borsh/tests/snapshots/test_primitives__usize.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__isize_pos.snap index 7632ea448..66322ee99 100644 --- a/borsh/tests/snapshots/test_primitives__usize.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__isize_pos.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_primitives.rs +source: borsh/tests/roundtrip/test_primitives.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_primitives__isize_pos.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__usize.snap similarity index 63% rename from borsh/tests/snapshots/test_primitives__isize_pos.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__usize.snap index 7632ea448..66322ee99 100644 --- a/borsh/tests/snapshots/test_primitives__isize_pos.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__usize.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_primitives.rs +source: borsh/tests/roundtrip/test_primitives.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_primitives__usize_max.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__usize_max.snap similarity index 67% rename from borsh/tests/snapshots/test_primitives__usize_max.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__usize_max.snap index 77e195a71..b7b2c1dcc 100644 --- a/borsh/tests/snapshots/test_primitives__usize_max.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__usize_max.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_primitives.rs +source: borsh/tests/roundtrip/test_primitives.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_primitives__usize_min.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__usize_min.snap similarity index 63% rename from borsh/tests/snapshots/test_primitives__usize_min.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__usize_min.snap index cc55a6f0c..8d4e178b5 100644 --- a/borsh/tests/snapshots/test_primitives__usize_min.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_primitives__usize_min.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_primitives.rs +source: borsh/tests/roundtrip/test_primitives.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_range__ranges.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_range__ranges.snap similarity index 83% rename from borsh/tests/snapshots/test_range__ranges.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_range__ranges.snap index 3800a4bd0..745592782 100644 --- a/borsh/tests/snapshots/test_range__ranges.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_range__ranges.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_range.rs +source: borsh/tests/roundtrip/test_range.rs expression: encoded --- [ diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__a.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__a.snap new file mode 100644 index 000000000..ecc450493 --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__a.snap @@ -0,0 +1,11 @@ +--- +source: borsh/tests/roundtrip/test_strings.rs +expression: _buf +--- +[ + 1, + 0, + 0, + 0, + 97, +] diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__empty_string.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__empty_string.snap new file mode 100644 index 000000000..269347a34 --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__empty_string.snap @@ -0,0 +1,10 @@ +--- +source: borsh/tests/roundtrip/test_strings.rs +expression: _buf +--- +[ + 0, + 0, + 0, + 0, +] diff --git a/borsh/tests/snapshots/test_ascii_strings__hello_10.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__hello_10.snap similarity index 98% rename from borsh/tests/snapshots/test_ascii_strings__hello_10.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__hello_10.snap index fca374e34..9391baae9 100644 --- a/borsh/tests/snapshots/test_ascii_strings__hello_10.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__hello_10.snap @@ -1,6 +1,6 @@ --- -source: borsh/tests/test_ascii_strings.rs -expression: buf +source: borsh/tests/roundtrip/test_strings.rs +expression: _buf --- [ 104, diff --git a/borsh/tests/snapshots/test_strings__hello_world.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__hello_world.snap similarity index 68% rename from borsh/tests/snapshots/test_strings__hello_world.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__hello_world.snap index 05585ea52..afe59469c 100644 --- a/borsh/tests/snapshots/test_strings__hello_world.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__hello_world.snap @@ -1,6 +1,6 @@ --- -source: borsh/tests/test_strings.rs -expression: buf +source: borsh/tests/roundtrip/test_strings.rs +expression: _buf --- [ 11, diff --git a/borsh/tests/snapshots/test_strings__non_ascii.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__non_ascii.snap similarity index 54% rename from borsh/tests/snapshots/test_strings__non_ascii.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__non_ascii.snap index bdb211d2d..4cc9796ff 100644 --- a/borsh/tests/snapshots/test_strings__non_ascii.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__non_ascii.snap @@ -1,6 +1,6 @@ --- -source: borsh/tests/test_strings.rs -expression: buf +source: borsh/tests/roundtrip/test_strings.rs +expression: _buf --- [ 4, diff --git a/borsh/tests/snapshots/test_ascii_strings__x_1024.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__x_1024.snap similarity index 99% rename from borsh/tests/snapshots/test_ascii_strings__x_1024.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__x_1024.snap index 4fbe58283..1c5ece36a 100644 --- a/borsh/tests/snapshots/test_ascii_strings__x_1024.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_strings__x_1024.snap @@ -1,6 +1,6 @@ --- -source: borsh/tests/test_ascii_strings.rs -expression: buf +source: borsh/tests/roundtrip/test_strings.rs +expression: _buf --- [ 0, diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_tuple__unary_tuple.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_tuple__unary_tuple.snap new file mode 100644 index 000000000..feb4466d7 --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_tuple__unary_tuple.snap @@ -0,0 +1,7 @@ +--- +source: borsh/tests/roundtrip/test_tuple.rs +expression: buf +--- +[ + 1, +] diff --git a/borsh/tests/snapshots/test_vecs__vec_f32-2.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32-2.snap similarity index 67% rename from borsh/tests/snapshots/test_vecs__vec_f32-2.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32-2.snap index e6b05d46b..ab8f836f5 100644 --- a/borsh/tests/snapshots/test_vecs__vec_f32-2.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32-2.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_f32-3.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32-3.snap similarity index 90% rename from borsh/tests/snapshots/test_vecs__vec_f32-3.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32-3.snap index ca82dd4ad..2aae80c3c 100644 --- a/borsh/tests/snapshots/test_vecs__vec_f32-3.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32-3.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_f32-4.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32-4.snap similarity index 98% rename from borsh/tests/snapshots/test_vecs__vec_f32-4.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32-4.snap index 8edf02163..b311f3c8a 100644 --- a/borsh/tests/snapshots/test_vecs__vec_f32-4.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32-4.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_ascii_strings__empty_string.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32.snap similarity index 56% rename from borsh/tests/snapshots/test_ascii_strings__empty_string.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32.snap index a3af6fd23..a4ab11f9c 100644 --- a/borsh/tests/snapshots/test_ascii_strings__empty_string.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_f32.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_ascii_strings.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_i8-2.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8-2.snap similarity index 60% rename from borsh/tests/snapshots/test_vecs__vec_i8-2.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8-2.snap index 48da93966..e8f66a538 100644 --- a/borsh/tests/snapshots/test_vecs__vec_i8-2.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8-2.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_i8-3.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8-3.snap similarity index 77% rename from borsh/tests/snapshots/test_vecs__vec_i8-3.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8-3.snap index 2387977df..850ec67e3 100644 --- a/borsh/tests/snapshots/test_vecs__vec_i8-3.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8-3.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_i8-4.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8-4.snap similarity index 95% rename from borsh/tests/snapshots/test_vecs__vec_i8-4.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8-4.snap index f93a18e3b..079e8cba1 100644 --- a/borsh/tests/snapshots/test_vecs__vec_i8-4.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8-4.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_strings__empty_string.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8.snap similarity index 56% rename from borsh/tests/snapshots/test_strings__empty_string.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8.snap index 6bad8f801..a4ab11f9c 100644 --- a/borsh/tests/snapshots/test_strings__empty_string.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_i8.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_strings.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_string-2.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string-2.snap similarity index 68% rename from borsh/tests/snapshots/test_vecs__vec_string-2.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string-2.snap index 6b7062d5f..e3b1d9f06 100644 --- a/borsh/tests/snapshots/test_vecs__vec_string-2.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string-2.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_string-3.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string-3.snap similarity index 90% rename from borsh/tests/snapshots/test_vecs__vec_string-3.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string-3.snap index 282f6a5a8..ed767b5ac 100644 --- a/borsh/tests/snapshots/test_vecs__vec_string-3.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string-3.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_string-4.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string-4.snap similarity index 98% rename from borsh/tests/snapshots/test_vecs__vec_string-4.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string-4.snap index 292a4735d..45e0dda20 100644 --- a/borsh/tests/snapshots/test_vecs__vec_string-4.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string-4.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_i8.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string.snap similarity index 56% rename from borsh/tests/snapshots/test_vecs__vec_i8.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string.snap index 327594d74..a4ab11f9c 100644 --- a/borsh/tests/snapshots/test_vecs__vec_i8.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_string.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_u32-2.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32-2.snap similarity index 67% rename from borsh/tests/snapshots/test_vecs__vec_u32-2.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32-2.snap index c857c3cfe..5630e0dd0 100644 --- a/borsh/tests/snapshots/test_vecs__vec_u32-2.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32-2.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_u32-3.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32-3.snap similarity index 90% rename from borsh/tests/snapshots/test_vecs__vec_u32-3.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32-3.snap index 1dd2223da..fd8bb5f7a 100644 --- a/borsh/tests/snapshots/test_vecs__vec_u32-3.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32-3.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_u32-4.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32-4.snap similarity index 98% rename from borsh/tests/snapshots/test_vecs__vec_u32-4.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32-4.snap index a8cd2b244..27dc82642 100644 --- a/borsh/tests/snapshots/test_vecs__vec_u32-4.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32-4.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_f32.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32.snap similarity index 56% rename from borsh/tests/snapshots/test_vecs__vec_f32.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32.snap index 327594d74..a4ab11f9c 100644 --- a/borsh/tests/snapshots/test_vecs__vec_f32.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u32.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_u8-2.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8-2.snap similarity index 60% rename from borsh/tests/snapshots/test_vecs__vec_u8-2.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8-2.snap index 48da93966..e8f66a538 100644 --- a/borsh/tests/snapshots/test_vecs__vec_u8-2.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8-2.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_u8-3.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8-3.snap similarity index 77% rename from borsh/tests/snapshots/test_vecs__vec_u8-3.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8-3.snap index 2387977df..850ec67e3 100644 --- a/borsh/tests/snapshots/test_vecs__vec_u8-3.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8-3.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_u8-4.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8-4.snap similarity index 95% rename from borsh/tests/snapshots/test_vecs__vec_u8-4.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8-4.snap index f93a18e3b..079e8cba1 100644 --- a/borsh/tests/snapshots/test_vecs__vec_u8-4.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8-4.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8.snap new file mode 100644 index 000000000..a4ab11f9c --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_u8.snap @@ -0,0 +1,10 @@ +--- +source: borsh/tests/roundtrip/test_vecs.rs +expression: buf +--- +[ + 0, + 0, + 0, + 0, +] diff --git a/borsh/tests/snapshots/test_vecs__vec_vec_u32-2.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32-2.snap similarity index 89% rename from borsh/tests/snapshots/test_vecs__vec_vec_u32-2.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32-2.snap index b589af9bb..2182aa7c9 100644 --- a/borsh/tests/snapshots/test_vecs__vec_vec_u32-2.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32-2.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_vec_u32-3.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32-3.snap similarity index 98% rename from borsh/tests/snapshots/test_vecs__vec_vec_u32-3.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32-3.snap index 4d0bb030c..abdbdd4de 100644 --- a/borsh/tests/snapshots/test_vecs__vec_vec_u32-3.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32-3.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_vec_u32-4.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32-4.snap similarity index 99% rename from borsh/tests/snapshots/test_vecs__vec_vec_u32-4.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32-4.snap index a0b72e6f0..534e212d6 100644 --- a/borsh/tests/snapshots/test_vecs__vec_vec_u32-4.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32-4.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32.snap new file mode 100644 index 000000000..a4ab11f9c --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u32.snap @@ -0,0 +1,10 @@ +--- +source: borsh/tests/roundtrip/test_vecs.rs +expression: buf +--- +[ + 0, + 0, + 0, + 0, +] diff --git a/borsh/tests/snapshots/test_vecs__vec_vec_u8-2.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8-2.snap similarity index 80% rename from borsh/tests/snapshots/test_vecs__vec_vec_u8-2.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8-2.snap index ee1026d1b..ca788f8d6 100644 --- a/borsh/tests/snapshots/test_vecs__vec_vec_u8-2.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8-2.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_vec_u8-3.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8-3.snap similarity index 96% rename from borsh/tests/snapshots/test_vecs__vec_vec_u8-3.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8-3.snap index fa47afd9c..c4d36d9b3 100644 --- a/borsh/tests/snapshots/test_vecs__vec_vec_u8-3.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8-3.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/snapshots/test_vecs__vec_vec_u8-4.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8-4.snap similarity index 99% rename from borsh/tests/snapshots/test_vecs__vec_vec_u8-4.snap rename to borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8-4.snap index d70dd6e1d..4a12f1468 100644 --- a/borsh/tests/snapshots/test_vecs__vec_vec_u8-4.snap +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8-4.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_vecs.rs +source: borsh/tests/roundtrip/test_vecs.rs expression: buf --- [ diff --git a/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8.snap b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8.snap new file mode 100644 index 000000000..a4ab11f9c --- /dev/null +++ b/borsh/tests/roundtrip/snapshots/tests__roundtrip__test_vecs__vec_vec_u8.snap @@ -0,0 +1,10 @@ +--- +source: borsh/tests/roundtrip/test_vecs.rs +expression: buf +--- +[ + 0, + 0, + 0, + 0, +] diff --git a/borsh/tests/test_arrays.rs b/borsh/tests/roundtrip/test_arrays.rs similarity index 95% rename from borsh/tests/test_arrays.rs rename to borsh/tests/roundtrip/test_arrays.rs index 7defd8132..1251ac03a 100644 --- a/borsh/tests/test_arrays.rs +++ b/borsh/tests/roundtrip/test_arrays.rs @@ -1,13 +1,9 @@ -#![cfg_attr(not(feature = "std"), no_std)] #![allow(clippy::float_cmp)] use borsh::{from_slice, to_vec}; #[cfg(feature = "derive")] use borsh::{BorshDeserialize, BorshSerialize}; -#[cfg(not(feature = "std"))] -extern crate alloc; -#[cfg(not(feature = "std"))] use alloc::string::{String, ToString}; macro_rules! test_array { diff --git a/borsh/tests/roundtrip/test_ascii_strings.rs b/borsh/tests/roundtrip/test_ascii_strings.rs new file mode 100644 index 000000000..14ba5e086 --- /dev/null +++ b/borsh/tests/roundtrip/test_ascii_strings.rs @@ -0,0 +1,53 @@ +use borsh::{from_slice, to_vec}; + +use alloc::{ + string::String, + vec::Vec, +}; + +/// Verifies serialisation and deserialisation of an ASCII string `value`. +fn check_ascii(value: &str) -> Vec { + // Caller promises value is ASCII. + let ascii_str = ascii::AsciiStr::from_ascii(&value).unwrap(); + let buf = to_vec(ascii_str).unwrap(); + // AsciiStr and AsciiString serialise the same way String does. + assert_eq!(buf, to_vec(&ascii::AsciiString::from(ascii_str)).unwrap()); + // Check round trip. + let got = from_slice::(&buf).unwrap(); + assert_eq!(ascii_str, got); + buf +} + +macro_rules! test_ascii_string { + ($test_name: ident, $str: expr, $snap:expr) => { + #[test] + fn $test_name() { + let value = String::from($str); + let _buf = check_ascii(&value); + #[cfg(feature = "std")] + if $snap { + insta::assert_debug_snapshot!(_buf); + } + } + }; +} + +test_ascii_string!(test_empty_string, "", true); +test_ascii_string!(test_a, "a", true); +test_ascii_string!(test_hello_world, "hello world", true); +test_ascii_string!(test_x_1024, "x".repeat(1024), true); +test_ascii_string!(test_x_4096, "x".repeat(4096), false); +test_ascii_string!(test_x_65535, "x".repeat(65535), false); +test_ascii_string!(test_hello_10, "hello world!".repeat(30), true); +test_ascii_string!(test_hello_1000, "hello Achilles!".repeat(1000), false); + +#[test] +fn test_ascii_char() { + use ascii::AsciiChar; + + let buf = to_vec(&AsciiChar::Dot).unwrap(); + assert_eq!(".".as_bytes(), buf); + assert_eq!(AsciiChar::Dot, from_slice::(&buf).unwrap()); + + from_slice::(&[b'\x80']).unwrap_err(); +} diff --git a/borsh/tests/test_btree_map.rs b/borsh/tests/roundtrip/test_btree_map.rs similarity index 91% rename from borsh/tests/test_btree_map.rs rename to borsh/tests/roundtrip/test_btree_map.rs index e85754a50..6967d2e0b 100644 --- a/borsh/tests/test_btree_map.rs +++ b/borsh/tests/roundtrip/test_btree_map.rs @@ -1,10 +1,3 @@ -#![cfg_attr(not(feature = "std"), no_std)] - -#[cfg(feature = "std")] -use std::collections::{BTreeMap, BTreeSet}; -#[cfg(not(feature = "std"))] -extern crate alloc; -#[cfg(not(feature = "std"))] use alloc::{ collections::{BTreeMap, BTreeSet}, string::{String, ToString}, @@ -14,9 +7,6 @@ use alloc::{ use borsh::{from_slice, BorshSerialize}; -#[macro_use] -mod common_macro; - macro_rules! btreeset_test_template [ [$test_name: ident, $($key: expr),* ] => [ #[allow(unused_mut)] diff --git a/borsh/tests/roundtrip/test_cells.rs b/borsh/tests/roundtrip/test_cells.rs new file mode 100644 index 000000000..a08df58e9 --- /dev/null +++ b/borsh/tests/roundtrip/test_cells.rs @@ -0,0 +1,23 @@ +use alloc::string::{String, ToString}; + +#[test] +fn test_cell_roundtrip() { + let cell = core::cell::Cell::new(42u32); + + let out = borsh::to_vec(&cell).unwrap(); + + let cell_round: core::cell::Cell = borsh::from_slice(&out).unwrap(); + + assert_eq!(cell, cell_round); +} + +#[test] +fn test_ref_cell_roundtrip() { + let rcell = core::cell::RefCell::new("str".to_string()); + + let out = borsh::to_vec(&rcell).unwrap(); + + let rcell_round: core::cell::RefCell = borsh::from_slice(&out).unwrap(); + + assert_eq!(rcell, rcell_round); +} diff --git a/borsh/tests/roundtrip/test_cow.rs b/borsh/tests/roundtrip/test_cow.rs new file mode 100644 index 000000000..d887fedc4 --- /dev/null +++ b/borsh/tests/roundtrip/test_cow.rs @@ -0,0 +1,71 @@ +use borsh::{from_slice, to_vec}; +use core::{matches, ops::Deref}; +use alloc::string::ToString; + +use alloc::{borrow::Cow, vec}; + +#[test] +fn test_cow_str() { + let input: Cow<'_, str> = Cow::Borrowed("static input"); + + let encoded = to_vec(&input).unwrap(); + + #[cfg(feature = "std")] + insta::assert_debug_snapshot!(encoded); + + let out: Cow<'_, str> = from_slice(&encoded).unwrap(); + + assert!(matches!(out, Cow::Owned(..))); + + assert_eq!(input, out); + assert_eq!(out, "static input"); +} + +#[test] +fn test_cow_byte_slice() { + let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let input: Cow<'_, [u8]> = Cow::Borrowed(&arr); + + let encoded = to_vec(&input).unwrap(); + + #[cfg(feature = "std")] + insta::assert_debug_snapshot!(encoded); + + let out: Cow<'_, [u8]> = from_slice(&encoded).unwrap(); + + assert!(matches!(out, Cow::Owned(..))); + + assert_eq!(input, out); + assert_eq!(out, vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); +} + +#[test] +fn test_cow_slice_of_cow_str() { + let arr = [ + Cow::Borrowed("first static input"), + Cow::Owned("second static input".to_string()), + ]; + let input: Cow<'_, [Cow<'_, str>]> = Cow::Borrowed(&arr); + + let encoded = to_vec(&input).unwrap(); + + #[cfg(feature = "std")] + insta::assert_debug_snapshot!(encoded); + + let out: Cow<'_, [Cow<'_, str>]> = from_slice(&encoded).unwrap(); + + assert!(matches!(out, Cow::Owned(..))); + + for element in out.deref() { + assert!(matches!(element, Cow::Owned(..))); + } + + assert_eq!(input, out); + assert_eq!( + out, + vec![ + Cow::Borrowed("first static input"), + Cow::Borrowed("second static input"), + ] + ); +} diff --git a/borsh/tests/test_hash_map.rs b/borsh/tests/roundtrip/test_hash_map.rs similarity index 96% rename from borsh/tests/test_hash_map.rs rename to borsh/tests/roundtrip/test_hash_map.rs index 6c470fba2..f94fdd70f 100644 --- a/borsh/tests/test_hash_map.rs +++ b/borsh/tests/roundtrip/test_hash_map.rs @@ -1,6 +1,3 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(hash_collections)] - #[cfg(feature = "std")] use core::hash::BuildHasher; @@ -15,9 +12,6 @@ use std::collections::{ #[cfg(not(feature = "std"))] use core::iter::IntoIterator; -#[cfg(not(feature = "std"))] -extern crate alloc; -#[cfg(not(feature = "std"))] use alloc::{ string::{String, ToString}, vec, @@ -26,9 +20,6 @@ use alloc::{ use borsh::{from_slice, BorshSerialize}; -#[macro_use] -mod common_macro; - macro_rules! hashset_test_template [ [$test_name: ident, $($key: expr),* ] => [ #[allow(unused_mut)] diff --git a/borsh/tests/test_nonzero_integers.rs b/borsh/tests/roundtrip/test_nonzero_integers.rs similarity index 94% rename from borsh/tests/test_nonzero_integers.rs rename to borsh/tests/roundtrip/test_nonzero_integers.rs index d41879097..459587b16 100644 --- a/borsh/tests/test_nonzero_integers.rs +++ b/borsh/tests/roundtrip/test_nonzero_integers.rs @@ -1,4 +1,3 @@ -#![cfg_attr(not(feature = "std"), no_std)] use borsh::from_slice; use core::num::*; diff --git a/borsh/tests/test_primitives.rs b/borsh/tests/roundtrip/test_primitives.rs similarity index 95% rename from borsh/tests/test_primitives.rs rename to borsh/tests/roundtrip/test_primitives.rs index aa74db385..58fbd773b 100644 --- a/borsh/tests/test_primitives.rs +++ b/borsh/tests/roundtrip/test_primitives.rs @@ -1,4 +1,3 @@ -#![cfg_attr(not(feature = "std"), no_std)] use borsh::{from_slice, to_vec}; macro_rules! test_primitive { diff --git a/borsh/tests/test_range.rs b/borsh/tests/roundtrip/test_range.rs similarity index 86% rename from borsh/tests/test_range.rs rename to borsh/tests/roundtrip/test_range.rs index 5c9de9b8d..d974f842f 100644 --- a/borsh/tests/test_range.rs +++ b/borsh/tests/roundtrip/test_range.rs @@ -1,5 +1,3 @@ -#![cfg_attr(not(feature = "std"), no_std)] - #[test] fn test_ranges() { let want = (1..2, 3..=4, 5.., ..6, ..=7, ..); diff --git a/borsh/tests/roundtrip/test_rc.rs b/borsh/tests/roundtrip/test_rc.rs new file mode 100644 index 000000000..acff642fa --- /dev/null +++ b/borsh/tests/roundtrip/test_rc.rs @@ -0,0 +1,37 @@ +pub use alloc::{rc, sync}; + +use borsh::{from_slice, to_vec}; + +#[test] +fn test_rc_roundtrip() { + let value = rc::Rc::new(8u8); + let serialized = to_vec(&value).unwrap(); + let deserialized = from_slice::>(&serialized).unwrap(); + assert_eq!(value, deserialized); +} + +#[test] +fn test_slice_rc() { + let original: &[i32] = &[1, 2, 3, 4, 6, 9, 10]; + let shared: rc::Rc<[i32]> = rc::Rc::from(original); + let serialized = to_vec(&shared).unwrap(); + let deserialized = from_slice::>(&serialized).unwrap(); + assert_eq!(original, &*deserialized); +} + +#[test] +fn test_arc_roundtrip() { + let value = sync::Arc::new(8u8); + let serialized = to_vec(&value).unwrap(); + let deserialized = from_slice::>(&serialized).unwrap(); + assert_eq!(value, deserialized); +} + +#[test] +fn test_slice_arc() { + let original: &[i32] = &[1, 2, 3, 4, 6, 9, 10]; + let shared: sync::Arc<[i32]> = sync::Arc::from(original); + let serialized = to_vec(&shared).unwrap(); + let deserialized = from_slice::>(&serialized).unwrap(); + assert_eq!(original, &*deserialized); +} diff --git a/borsh/tests/test_strings.rs b/borsh/tests/roundtrip/test_strings.rs similarity index 95% rename from borsh/tests/test_strings.rs rename to borsh/tests/roundtrip/test_strings.rs index e3bbe79bf..bcbfcd3c9 100644 --- a/borsh/tests/test_strings.rs +++ b/borsh/tests/roundtrip/test_strings.rs @@ -1,7 +1,3 @@ -#![cfg_attr(not(feature = "std"), no_std)] - -extern crate alloc; - use alloc::string::String; use borsh::{from_slice, to_vec}; diff --git a/borsh/tests/test_tuple.rs b/borsh/tests/roundtrip/test_tuple.rs similarity index 88% rename from borsh/tests/test_tuple.rs rename to borsh/tests/roundtrip/test_tuple.rs index 92e98e149..ee780a4a2 100644 --- a/borsh/tests/test_tuple.rs +++ b/borsh/tests/roundtrip/test_tuple.rs @@ -1,4 +1,3 @@ -#![cfg_attr(not(feature = "std"), no_std)] use borsh::{from_slice, to_vec}; #[test] diff --git a/borsh/tests/test_vecs.rs b/borsh/tests/roundtrip/test_vecs.rs similarity index 91% rename from borsh/tests/test_vecs.rs rename to borsh/tests/roundtrip/test_vecs.rs index e55babc73..6e9996199 100644 --- a/borsh/tests/test_vecs.rs +++ b/borsh/tests/roundtrip/test_vecs.rs @@ -1,9 +1,5 @@ -#![cfg_attr(not(feature = "std"), no_std)] use borsh::{from_slice, to_vec}; -#[cfg(not(feature = "std"))] -extern crate alloc; -#[cfg(not(feature = "std"))] use alloc::{ string::{String, ToString}, vec, diff --git a/borsh/tests/schema/container_extension/test_max_size.rs b/borsh/tests/schema/container_extension/test_max_size.rs new file mode 100644 index 000000000..d179b0e83 --- /dev/null +++ b/borsh/tests/schema/container_extension/test_max_size.rs @@ -0,0 +1,216 @@ +use crate::common_macro::schema_imports::*; + +#[track_caller] +fn test_ok(want: usize) { + let schema = BorshSchemaContainer::for_type::(); + assert_eq!(Ok(want), schema.max_serialized_size()); +} + +#[track_caller] +fn test_err(err: SchemaMaxSerializedSizeError) { + let schema = BorshSchemaContainer::for_type::(); + assert_eq!(Err(err), schema.max_serialized_size()); +} + +const MAX_LEN: usize = u32::MAX as usize; + +#[test] +fn max_serialized_size_primitives() { + test_ok::<()>(0); + test_ok::(1); + + test_ok::(4); + test_ok::(8); + + test_ok::(1); + test_ok::(2); + test_ok::(4); + test_ok::(8); + test_ok::(16); + + test_ok::(1); + test_ok::(2); + test_ok::(4); + test_ok::(8); + test_ok::(16); + + test_ok::(1); + test_ok::(2); + test_ok::(4); + test_ok::(8); + test_ok::(16); + + test_ok::(1); + test_ok::(2); + test_ok::(4); + test_ok::(8); + test_ok::(16); + + test_ok::(8); + test_ok::(8); + test_ok::(8); +} + +#[test] +fn max_serialized_size_built_in_types() { + test_ok::(0); + test_ok::>(2); + test_ok::>(8); + + test_ok::>(1); + test_ok::>(2); + test_ok::>(9); + test_ok::>>(1 + 4 + MAX_LEN); + + test_ok::<()>(0); + test_ok::<(u8,)>(1); + test_ok::<(u8, u32)>(5); + + test_ok::<[u8; 0]>(0); + test_ok::<[u8; 16]>(16); + test_ok::<[[u8; 4]; 4]>(16); + + test_ok::<[u16; 0]>(0); + test_ok::<[u16; 16]>(32); + test_ok::<[[u16; 4]; 4]>(32); + + test_ok::>(4 + MAX_LEN); + test_ok::(4 + MAX_LEN); + + test_err::>>(SchemaMaxSerializedSizeError::Overflow); + test_ok::>>(4 + MAX_LEN * 4); + test_ok::<[[[(); MAX_LEN]; MAX_LEN]; MAX_LEN]>(0); +} + +#[test] +fn max_serialized_size_derived_types() { + #[derive(BorshSchema)] + pub struct Empty; + + #[derive(BorshSchema)] + pub struct Named { + _foo: usize, + _bar: [u8; 15], + } + + #[derive(BorshSchema)] + #[allow(unused)] + pub struct Unnamed(usize, [u8; 15]); + + #[derive(BorshSchema)] + struct Multiple { + _usz0: usize, + _usz1: usize, + _usz2: usize, + _vec0: Vec, + _vec1: Vec, + } + + #[derive(BorshSchema)] + #[allow(unused)] + struct Recursive(Option>); + + test_ok::(0); + test_ok::(23); + test_ok::(23); + test_ok::(3 * 8 + 2 * (4 + MAX_LEN * 8)); + test_err::(SchemaMaxSerializedSizeError::Overflow); + test_err::(SchemaMaxSerializedSizeError::Recursive); +} + +#[test] +fn max_serialized_size_custom_enum() { + #[allow(dead_code)] + enum Maybe { + Just(T), + Nothing, + } + + impl BorshSchema for Maybe { + fn declaration() -> Declaration { + let res = format!(r#"Maybe<{}, {}>"#, N, T::declaration()); + res + } + fn add_definitions_recursively(definitions: &mut BTreeMap) { + let definition = Definition::Enum { + tag_width: N, + variants: vec![ + (0, "Just".into(), T::declaration()), + (1, "Nothing".into(), <()>::declaration()), + ], + }; + add_definition(Self::declaration(), definition, definitions); + T::add_definitions_recursively(definitions); + <()>::add_definitions_recursively(definitions); + } + } + + test_ok::>(0); + test_ok::>(2); + test_ok::>(8); + + test_ok::>(1); + test_ok::>(3); + test_ok::>(9); + + test_ok::>(4); + test_ok::>(6); + test_ok::>(12); +} + +#[test] +fn max_serialized_size_bound_vec() { + #[allow(dead_code)] + struct BoundVec; + + impl BorshSchema for BoundVec { + fn declaration() -> Declaration { + format!("BoundVec<{}, {}>", W, N) + } + fn add_definitions_recursively(definitions: &mut BTreeMap) { + let definition = Definition::Sequence { + length_width: W, + length_range: 0..=N, + elements: "u8".to_string(), + }; + add_definition(Self::declaration(), definition, definitions); + u8::add_definitions_recursively(definitions); + } + } + + test_ok::>(4); + test_ok::>(4 + u16::MAX as usize); + test_ok::>(24); + + test_ok::>(1); + test_ok::>(1 + u16::MAX as usize); + test_ok::>(21); + + test_ok::>(0); + test_ok::>(u16::MAX as usize); + test_ok::>(20); +} + +#[test] +fn max_serialized_size_small_vec() { + #[allow(dead_code)] + struct SmallVec(core::marker::PhantomData); + + impl BorshSchema for SmallVec { + fn declaration() -> Declaration { + format!(r#"SmallVec<{}>"#, T::declaration()) + } + fn add_definitions_recursively(definitions: &mut BTreeMap) { + let definition = Definition::Sequence { + length_width: 1, + length_range: 0..=u8::MAX as u64, + elements: T::declaration(), + }; + add_definition(Self::declaration(), definition, definitions); + T::add_definitions_recursively(definitions); + } + } + + test_ok::>(u8::MAX as usize + 1); + test_ok::>(u8::MAX as usize * 2 + 1); +} diff --git a/borsh/tests/test_schema_validate.rs b/borsh/tests/schema/container_extension/test_schema_validate.rs similarity index 89% rename from borsh/tests/test_schema_validate.rs rename to borsh/tests/schema/container_extension/test_schema_validate.rs index fe82a146b..91d02f793 100644 --- a/borsh/tests/test_schema_validate.rs +++ b/borsh/tests/schema/container_extension/test_schema_validate.rs @@ -1,16 +1,7 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(feature = "unstable__schema")] +use crate::common_macro::schema_imports::*; -#[cfg(feature = "std")] -use std::collections::BTreeMap; - -#[cfg(not(feature = "std"))] -extern crate alloc; -#[cfg(not(feature = "std"))] use alloc::{boxed::Box, collections::BTreeMap, format, string::ToString, vec::Vec}; -use borsh::schema::*; -use borsh::BorshSchema; #[track_caller] fn test_ok() { @@ -36,16 +27,20 @@ fn validate_for_derived_types() { } #[derive(BorshSchema)] + #[allow(unused)] pub struct Unnamed(usize, [u8; 15]); #[derive(BorshSchema)] + #[allow(unused)] struct Recursive(Option>); #[derive(BorshSchema)] + #[allow(unused)] struct RecursiveSequence(Vec); // thankfully, this one cannot be constructed #[derive(BorshSchema)] + #[allow(unused)] struct RecursiveArray(Box<[RecursiveArray; 3]>); test_ok::(); @@ -70,7 +65,7 @@ fn validate_for_zst_sequences() { } #[test] -fn max_serialized_size_bound_vec() { +fn validate_bound_vec() { #[allow(dead_code)] struct BoundVec; diff --git a/borsh/tests/test_schema_conflict.rs b/borsh/tests/schema/schema_conflict/test_schema_conflict.rs similarity index 94% rename from borsh/tests/test_schema_conflict.rs rename to borsh/tests/schema/schema_conflict/test_schema_conflict.rs index 6d516091d..b6c921078 100644 --- a/borsh/tests/test_schema_conflict.rs +++ b/borsh/tests/schema/schema_conflict/test_schema_conflict.rs @@ -1,12 +1,4 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(feature = "unstable__schema")] - -#[cfg(feature = "std")] -use std::collections::{BTreeMap, BTreeSet}; - -#[cfg(not(feature = "std"))] -extern crate alloc; -#[cfg(not(feature = "std"))] +use crate::common_macro::schema_imports::*; use alloc::{ collections::{BTreeMap, BTreeSet}, format, @@ -14,9 +6,6 @@ use alloc::{ vec::Vec, }; -use borsh::schema::{add_definition, Declaration, Definition, Fields}; -use borsh::BorshSchema; - struct ConflictingSchema; impl BorshSchema for ConflictingSchema { diff --git a/borsh/tests/snapshots/test_schema_enums__complex_enum_with_schema.snap b/borsh/tests/schema/snapshots/tests__schema__test_simple_enums__complex_enum_with_schema.snap similarity index 98% rename from borsh/tests/snapshots/test_schema_enums__complex_enum_with_schema.snap rename to borsh/tests/schema/snapshots/tests__schema__test_simple_enums__complex_enum_with_schema.snap index e852f2751..1cdf94d5f 100644 --- a/borsh/tests/snapshots/test_schema_enums__complex_enum_with_schema.snap +++ b/borsh/tests/schema/snapshots/tests__schema__test_simple_enums__complex_enum_with_schema.snap @@ -1,5 +1,5 @@ --- -source: borsh/tests/test_schema_enums.rs +source: borsh/tests/schema/test_simple_enums.rs expression: data --- [ diff --git a/borsh/tests/schema/test_arrays.rs b/borsh/tests/schema/test_arrays.rs new file mode 100644 index 000000000..71063edae --- /dev/null +++ b/borsh/tests/schema/test_arrays.rs @@ -0,0 +1,48 @@ +use crate::common_macro::schema_imports::*; +#[test] +fn simple_array() { + let actual_name = <[u64; 32]>::declaration(); + let mut actual_defs = schema_map!(); + <[u64; 32]>::add_definitions_recursively(&mut actual_defs); + assert_eq!("[u64; 32]", actual_name); + assert_eq!( + schema_map! { + "[u64; 32]" => Definition::Sequence { + length_width: Definition::ARRAY_LENGTH_WIDTH, + length_range: 32..=32, + elements: "u64".to_string() + }, + "u64" => Definition::Primitive(8) + }, + actual_defs + ); +} + +#[test] +fn nested_array() { + let actual_name = <[[[u64; 9]; 10]; 32]>::declaration(); + let mut actual_defs = schema_map!(); + <[[[u64; 9]; 10]; 32]>::add_definitions_recursively(&mut actual_defs); + assert_eq!("[[[u64; 9]; 10]; 32]", actual_name); + assert_eq!( + schema_map! { + "[u64; 9]" => Definition::Sequence { + length_width: Definition::ARRAY_LENGTH_WIDTH, + length_range: 9..=9, + elements: "u64".to_string() + }, + "[[u64; 9]; 10]" => Definition::Sequence { + length_width: Definition::ARRAY_LENGTH_WIDTH, + length_range: 10..=10, + elements: "[u64; 9]".to_string() + }, + "[[[u64; 9]; 10]; 32]" => Definition::Sequence { + length_width: Definition::ARRAY_LENGTH_WIDTH, + length_range: 32..=32, + elements: "[[u64; 9]; 10]".to_string() + }, + "u64" => Definition::Primitive(8) + }, + actual_defs + ); +} diff --git a/borsh/tests/schema/test_ascii_strings.rs b/borsh/tests/schema/test_ascii_strings.rs new file mode 100644 index 000000000..4226e711c --- /dev/null +++ b/borsh/tests/schema/test_ascii_strings.rs @@ -0,0 +1,32 @@ +use crate::common_macro::schema_imports::*; + +#[test] +fn test_ascii_strings() { + assert_eq!("AsciiString", ascii::AsciiStr::declaration()); + assert_eq!("AsciiString", ascii::AsciiString::declaration()); + assert_eq!("AsciiChar", ascii::AsciiChar::declaration()); + + let want_char = schema_map! { + "AsciiChar" => Definition::Primitive(1) + }; + let mut actual_defs = schema_map!(); + ascii::AsciiChar::add_definitions_recursively(&mut actual_defs); + assert_eq!(want_char, actual_defs); + + let want = schema_map! { + "AsciiString" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "AsciiChar".to_string() + }, + "AsciiChar" => Definition::Primitive(1) + }; + + let mut actual_defs = schema_map!(); + ascii::AsciiStr::add_definitions_recursively(&mut actual_defs); + assert_eq!(want, actual_defs); + + let mut actual_defs = schema_map!(); + ascii::AsciiString::add_definitions_recursively(&mut actual_defs); + assert_eq!(want, actual_defs); +} diff --git a/borsh/tests/schema/test_box.rs b/borsh/tests/schema/test_box.rs new file mode 100644 index 000000000..98068b73e --- /dev/null +++ b/borsh/tests/schema/test_box.rs @@ -0,0 +1,9 @@ +use crate::common_macro::schema_imports::*; + +#[test] +fn boxed_schema() { + let boxed_declaration = Box::::declaration(); + assert_eq!("String", boxed_declaration); + let boxed_declaration = Box::<[u8]>::declaration(); + assert_eq!("Vec", boxed_declaration); +} diff --git a/borsh/tests/schema/test_btree_map.rs b/borsh/tests/schema/test_btree_map.rs new file mode 100644 index 000000000..fe43be47f --- /dev/null +++ b/borsh/tests/schema/test_btree_map.rs @@ -0,0 +1,53 @@ +use crate::common_macro::schema_imports::*; + +use alloc::collections::{BTreeMap, BTreeSet}; + +#[test] +fn b_tree_map() { + let actual_name = BTreeMap::::declaration(); + let mut actual_defs = schema_map!(); + BTreeMap::::add_definitions_recursively(&mut actual_defs); + assert_eq!("BTreeMap", actual_name); + assert_eq!( + schema_map! { + "BTreeMap" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "(u64, String)".to_string(), + } , + "(u64, String)" => Definition::Tuple { elements: vec![ "u64".to_string(), "String".to_string()]}, + "u64" => Definition::Primitive(8), + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + }, + "u8" => Definition::Primitive(1) + }, + actual_defs + ); +} + +#[test] +fn b_tree_set() { + let actual_name = BTreeSet::::declaration(); + let mut actual_defs = schema_map!(); + BTreeSet::::add_definitions_recursively(&mut actual_defs); + assert_eq!("BTreeSet", actual_name); + assert_eq!( + schema_map! { + "BTreeSet" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "String".to_string(), + }, + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + }, + "u8" => Definition::Primitive(1) + }, + actual_defs + ); +} diff --git a/borsh/tests/schema/test_cells.rs b/borsh/tests/schema/test_cells.rs new file mode 100644 index 000000000..f29b7a591 --- /dev/null +++ b/borsh/tests/schema/test_cells.rs @@ -0,0 +1,40 @@ +use crate::common_macro::schema_imports::*; + +fn common_map_i32() -> BTreeMap { + schema_map! { + + "i32" => Definition::Primitive(4) + } +} + +fn common_map_slice_i32() -> BTreeMap { + schema_map! { + "Vec" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "i32".to_string() + }, + "i32" => Definition::Primitive(4) + } +} + +#[test] +fn test_cell() { + assert_eq!("i32", as BorshSchema>::declaration()); + + let mut actual_defs = schema_map!(); + as BorshSchema>::add_definitions_recursively(&mut actual_defs); + assert_eq!(common_map_i32(), actual_defs); +} + +#[test] +fn test_ref_cell_vec() { + assert_eq!( + "Vec", + > as BorshSchema>::declaration() + ); + + let mut actual_defs = schema_map!(); + > as BorshSchema>::add_definitions_recursively(&mut actual_defs); + assert_eq!(common_map_slice_i32(), actual_defs); +} diff --git a/borsh/tests/schema/test_cow.rs b/borsh/tests/schema/test_cow.rs new file mode 100644 index 000000000..989919edf --- /dev/null +++ b/borsh/tests/schema/test_cow.rs @@ -0,0 +1,68 @@ +use crate::common_macro::schema_imports::*; + +use alloc::borrow::Cow; + +#[test] +fn test_cow_str() { + assert_eq!("String", as BorshSchema>::declaration()); + + let mut actual_defs = schema_map!(); + as BorshSchema>::add_definitions_recursively(&mut actual_defs); + assert_eq!( + schema_map! { + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + }, + "u8" => Definition::Primitive(1) + }, + actual_defs + ); +} + +#[test] +fn test_cow_byte_slice() { + assert_eq!("Vec", as BorshSchema>::declaration()); + + let mut actual_defs = schema_map!(); + as BorshSchema>::add_definitions_recursively(&mut actual_defs); + assert_eq!( + schema_map! { + "Vec" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string(), + }, + "u8" => Definition::Primitive(1) + }, + actual_defs + ); +} + +#[test] +fn test_cow_slice_of_cow_str() { + assert_eq!( + "Vec", + ]> as BorshSchema>::declaration() + ); + + let mut actual_defs = schema_map!(); + ]> as BorshSchema>::add_definitions_recursively(&mut actual_defs); + assert_eq!( + schema_map! { + "Vec" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "String".to_string(), + }, + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + }, + "u8" => Definition::Primitive(1) + }, + actual_defs + ); +} diff --git a/borsh/tests/schema/test_enum_discriminants.rs b/borsh/tests/schema/test_enum_discriminants.rs new file mode 100644 index 000000000..eb502ab12 --- /dev/null +++ b/borsh/tests/schema/test_enum_discriminants.rs @@ -0,0 +1,102 @@ +use crate::common_macro::schema_imports::*; + +#[allow(unused)] +#[derive(BorshSchema)] +#[borsh(use_discriminant = true)] +#[repr(i16)] +enum XY { + A, + B = 20, + C, + D(u32, u32), + E = 10, + F(u64), +} + +#[test] +fn test_schema_discriminant_no_unit_type() { + assert_eq!("XY".to_string(), XY::declaration()); + let mut defs = Default::default(); + XY::add_definitions_recursively(&mut defs); + assert_eq!( + schema_map! { + "XY" => Definition::Enum { + tag_width: 1, + variants: vec![ + (0, "A".to_string(), "XYA".to_string()), + (20, "B".to_string(), "XYB".to_string()), + (21, "C".to_string(), "XYC".to_string()), + (22, "D".to_string(), "XYD".to_string()), + (10, "E".to_string(), "XYE".to_string()), + (11, "F".to_string(), "XYF".to_string()) + ] + }, + "XYA" => Definition::Struct{ fields: Fields::Empty }, + "XYB" => Definition::Struct{ fields: Fields::Empty }, + "XYC" => Definition::Struct{ fields: Fields::Empty }, + "XYD" => Definition::Struct{ fields: Fields::UnnamedFields( + vec!["u32".to_string(), "u32".to_string()] + )}, + "XYE" => Definition::Struct{ fields: Fields::Empty }, + "XYF" => Definition::Struct{ fields: Fields::UnnamedFields( + vec!["u64".to_string()] + + )}, + "u32" => Definition::Primitive(4), + "u64" => Definition::Primitive(8) + }, + defs + ); +} + +#[allow(unused)] +#[derive(BorshSchema)] +#[borsh(use_discriminant = false)] +#[repr(i16)] +enum XYNoDiscriminant { + A, + B = 20, + C, + D(u32, u32), + E = 10, + F(u64), +} + +#[test] +fn test_schema_discriminant_no_unit_type_no_use_discriminant() { + assert_eq!( + "XYNoDiscriminant".to_string(), + XYNoDiscriminant::declaration() + ); + let mut defs = Default::default(); + XYNoDiscriminant::add_definitions_recursively(&mut defs); + assert_eq!( + schema_map! { + "XYNoDiscriminant" => Definition::Enum { + tag_width: 1, + variants: vec![ + (0, "A".to_string(), "XYNoDiscriminantA".to_string()), + (1, "B".to_string(), "XYNoDiscriminantB".to_string()), + (2, "C".to_string(), "XYNoDiscriminantC".to_string()), + (3, "D".to_string(), "XYNoDiscriminantD".to_string()), + (4, "E".to_string(), "XYNoDiscriminantE".to_string()), + (5, "F".to_string(), "XYNoDiscriminantF".to_string()) + ] + }, + "XYNoDiscriminantA" => Definition::Struct{ fields: Fields::Empty }, + "XYNoDiscriminantB" => Definition::Struct{ fields: Fields::Empty }, + "XYNoDiscriminantC" => Definition::Struct{ fields: Fields::Empty }, + "XYNoDiscriminantD" => Definition::Struct{ fields: Fields::UnnamedFields( + vec!["u32".to_string(), "u32".to_string()] + )}, + "XYNoDiscriminantE" => Definition::Struct{ fields: Fields::Empty }, + "XYNoDiscriminantF" => Definition::Struct{ fields: Fields::UnnamedFields( + vec!["u64".to_string()] + + )}, + "u32" => Definition::Primitive(4), + "u64" => Definition::Primitive(8) + }, + defs + ); +} diff --git a/borsh/tests/test_schema_enums.rs b/borsh/tests/schema/test_generic_enums.rs similarity index 56% rename from borsh/tests/test_schema_enums.rs rename to borsh/tests/schema/test_generic_enums.rs index eea6dffc8..05d485e26 100644 --- a/borsh/tests/test_schema_enums.rs +++ b/borsh/tests/schema/test_generic_enums.rs @@ -1,199 +1,9 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![allow(dead_code)] // Local structures do not have their fields used. -#![cfg(feature = "unstable__schema")] +use crate::common_macro::schema_imports::*; -use borsh::{try_from_slice_with_schema, try_to_vec_with_schema}; -use core::fmt::{Debug, Display}; - -#[macro_use] -mod common_macro; -use common_macro::schema_imports::*; - -#[test] -pub fn simple_enum() { - #[derive(borsh::BorshSchema)] - enum A { - Bacon, - Eggs, - } - // https://github.com/near/borsh-rs/issues/112 - #[allow(unused)] - impl A { - pub fn declaration() -> usize { - 42 - } - } - assert_eq!("A".to_string(), ::declaration()); - let mut defs = Default::default(); - A::add_definitions_recursively(&mut defs); - assert_eq!( - schema_map! { - "ABacon" => Definition::Struct{ fields: Fields::Empty }, - "AEggs" => Definition::Struct{ fields: Fields::Empty }, - "A" => Definition::Enum { - tag_width: 1, - variants: vec![(0, "Bacon".to_string(), "ABacon".to_string()), (1, "Eggs".to_string(), "AEggs".to_string())] - } - }, - defs - ); -} - -#[test] -pub fn single_field_enum() { - #[derive(borsh::BorshSchema)] - enum A { - Bacon, - } - assert_eq!("A".to_string(), A::declaration()); - let mut defs = Default::default(); - A::add_definitions_recursively(&mut defs); - assert_eq!( - schema_map! { - "ABacon" => Definition::Struct {fields: Fields::Empty}, - "A" => Definition::Enum { - tag_width: 1, - variants: vec![(0, "Bacon".to_string(), "ABacon".to_string())] - } - }, - defs - ); -} - -/// test: Sausage wasn't populated with param Sausage -#[derive(borsh::BorshSchema, Debug)] -enum AWithSkip { - Bacon, - Eggs, - Salad(u32, C, u32), - Sausage { - #[borsh(skip)] - wrapper: W, - filling: u32, - }, -} - -/// test: inner structs in BorshSchema derive don't need any bounds, unrelated to BorshSchema -// #[derive(borsh::BorshSchema)] -// struct SideLeft( -// A, -// ) -// where -// A: Display + Debug, -// B: Display + Debug; -#[derive(borsh::BorshSchema)] -enum Side -where - A: Display + Debug, - B: Display + Debug, -{ - Left(A), - Right(B), -} - -#[test] -pub fn complex_enum_with_schema() { - #[derive( - borsh::BorshSchema, - Default, - borsh::BorshSerialize, - borsh::BorshDeserialize, - PartialEq, - Debug, - )] - struct Tomatoes; - #[derive( - borsh::BorshSchema, - Default, - borsh::BorshSerialize, - borsh::BorshDeserialize, - PartialEq, - Debug, - )] - struct Cucumber; - #[derive( - borsh::BorshSchema, - Default, - borsh::BorshSerialize, - borsh::BorshDeserialize, - PartialEq, - Debug, - )] - struct Oil; - #[derive( - borsh::BorshSchema, - Default, - borsh::BorshSerialize, - borsh::BorshDeserialize, - PartialEq, - Debug, - )] - struct Wrapper; - #[derive( - borsh::BorshSchema, - Default, - borsh::BorshSerialize, - borsh::BorshDeserialize, - PartialEq, - Debug, - )] - struct Filling; - #[derive( - borsh::BorshSchema, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq, Debug, - )] - enum A { - Bacon, - Eggs, - Salad(Tomatoes, Cucumber, Oil), - Sausage { wrapper: Wrapper, filling: Filling }, - } - - impl Default for A { - fn default() -> Self { - A::Sausage { - wrapper: Default::default(), - filling: Default::default(), - } - } - } - // First check schema. - assert_eq!("A".to_string(), A::declaration()); - let mut defs = Default::default(); - A::add_definitions_recursively(&mut defs); - assert_eq!( - schema_map! { - "Cucumber" => Definition::Struct {fields: Fields::Empty}, - "ASalad" => Definition::Struct{ fields: Fields::UnnamedFields(vec!["Tomatoes".to_string(), "Cucumber".to_string(), "Oil".to_string()])}, - "ABacon" => Definition::Struct {fields: Fields::Empty}, - "Oil" => Definition::Struct {fields: Fields::Empty}, - "A" => Definition::Enum { - tag_width: 1, - variants: vec![ - (0, "Bacon".to_string(), "ABacon".to_string()), - (1, "Eggs".to_string(), "AEggs".to_string()), - (2, "Salad".to_string(), "ASalad".to_string()), - (3, "Sausage".to_string(), "ASausage".to_string()) - ] - }, - "Wrapper" => Definition::Struct {fields: Fields::Empty}, - "Tomatoes" => Definition::Struct {fields: Fields::Empty}, - "ASausage" => Definition::Struct { fields: Fields::NamedFields(vec![ - ("wrapper".to_string(), "Wrapper".to_string()), - ("filling".to_string(), "Filling".to_string()) - ])}, - "AEggs" => Definition::Struct {fields: Fields::Empty}, - "Filling" => Definition::Struct {fields: Fields::Empty} - }, - defs - ); - // Then check that we serialize and deserialize with schema. - let obj = A::default(); - let data = try_to_vec_with_schema(&obj).unwrap(); - #[cfg(feature = "std")] - insta::assert_debug_snapshot!(data); - let obj2: A = try_from_slice_with_schema(&data).unwrap(); - assert_eq!(obj, obj2); -} +#[cfg(feature = "hashbrown")] +use hashbrown::HashMap; +#[cfg(feature = "std")] +use std::collections::HashMap; #[test] pub fn complex_enum_generics() { @@ -207,6 +17,7 @@ pub fn complex_enum_generics() { struct Wrapper; #[derive(borsh::BorshSchema)] struct Filling; + #[allow(unused)] #[derive(borsh::BorshSchema)] enum A { Bacon, @@ -252,7 +63,107 @@ pub fn complex_enum_generics() { ); } -fn common_map() -> BTreeMap { +// Checks that recursive definitions work. Also checks that re-instantiations of templated types work. +#[cfg(hash_collections)] +#[test] +pub fn complex_enum_generics2() { + #[derive(borsh::BorshSchema)] + struct Tomatoes; + #[derive(borsh::BorshSchema)] + struct Cucumber; + #[allow(unused)] + #[derive(borsh::BorshSchema)] + struct Oil { + seeds: HashMap, + liquid: Option, + } + #[allow(unused)] + #[derive(borsh::BorshSchema)] + struct Wrapper { + foo: Option, + bar: Box>, + } + #[derive(borsh::BorshSchema)] + struct Filling; + #[allow(unused)] + #[derive(borsh::BorshSchema)] + enum A { + Bacon, + Eggs, + Salad(Tomatoes, C, Oil), + Sausage { wrapper: W, filling: Filling }, + } + assert_eq!( + "A>".to_string(), + >>::declaration() + ); + let mut defs = Default::default(); + >>::add_definitions_recursively(&mut defs); + assert_eq!( + schema_map! { + "A>" => Definition::Enum { + tag_width: 1, + variants: vec![ + (0, "Bacon".to_string(), "ABacon".to_string()), + (1, "Eggs".to_string(), "AEggs".to_string()), + (2, "Salad".to_string(), "ASalad".to_string()), + (3, "Sausage".to_string(), "ASausage>".to_string()) + ] + }, + "A" => Definition::Enum { + tag_width: 1, + variants: vec![ + (0, "Bacon".to_string(), "ABacon".to_string()), + (1, "Eggs".to_string(), "AEggs".to_string()), + (2, "Salad".to_string(), "ASalad".to_string()), + (3, "Sausage".to_string(), "ASausage".to_string()) + ] + }, + "ABacon" => Definition::Struct {fields: Fields::Empty}, + "AEggs" => Definition::Struct {fields: Fields::Empty}, + "ASalad" => Definition::Struct {fields: Fields::UnnamedFields(vec!["Tomatoes".to_string(), "Cucumber".to_string(), "Oil".to_string()])}, + "ASalad" => Definition::Struct { fields: Fields::UnnamedFields( vec!["Tomatoes".to_string(), "String".to_string(), "Oil".to_string() ])}, + "ASausage>" => Definition::Struct {fields: Fields::NamedFields(vec![("wrapper".to_string(), "Wrapper".to_string()), ("filling".to_string(), "Filling".to_string())])}, + "ASausage" => Definition::Struct{ fields: Fields::NamedFields(vec![("wrapper".to_string(), "String".to_string()), ("filling".to_string(), "Filling".to_string())])}, + "Cucumber" => Definition::Struct {fields: Fields::Empty}, + "Filling" => Definition::Struct {fields: Fields::Empty}, + "HashMap" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "(u64, String)".to_string(), + }, + "Oil" => Definition::Struct { fields: Fields::NamedFields(vec![("seeds".to_string(), "HashMap".to_string()), ("liquid".to_string(), "Option".to_string())])}, + "Option" => Definition::Enum { + tag_width: 1, + variants: vec![ + (0, "None".to_string(), "()".to_string()), + (1, "Some".to_string(), "String".to_string()) + ] + }, + "Option" => Definition::Enum { + tag_width: 1, + variants: vec![ + (0, "None".to_string(), "()".to_string()), + (1, "Some".to_string(), "u64".to_string()) + ] + }, + "Tomatoes" => Definition::Struct {fields: Fields::Empty}, + "(u64, String)" => Definition::Tuple {elements: vec!["u64".to_string(), "String".to_string()]}, + "Wrapper" => Definition::Struct{ fields: Fields::NamedFields(vec![("foo".to_string(), "Option".to_string()), ("bar".to_string(), "A".to_string())])}, + "u64" => Definition::Primitive(8), + "()" => Definition::Primitive(0), + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + }, + "u8" => Definition::Primitive(1) + }, + defs + ); +} + +fn common_map_associated() -> BTreeMap { schema_map! { "EnumParametrized" => Definition::Enum { tag_width: 1, @@ -320,7 +231,7 @@ pub fn generic_associated_item1() { let mut defs = Default::default(); >::add_definitions_recursively(&mut defs); - assert_eq!(common_map(), defs); + assert_eq!(common_map_associated(), defs); } #[test] @@ -360,5 +271,5 @@ pub fn generic_associated_item2() { let mut defs = Default::default(); >::add_definitions_recursively(&mut defs); - assert_eq!(common_map(), defs); + assert_eq!(common_map_associated(), defs); } diff --git a/borsh/tests/test_schema_structs.rs b/borsh/tests/schema/test_generic_structs.rs similarity index 57% rename from borsh/tests/test_schema_structs.rs rename to borsh/tests/schema/test_generic_structs.rs index a7b3503af..b974988ac 100644 --- a/borsh/tests/test_schema_structs.rs +++ b/borsh/tests/schema/test_generic_structs.rs @@ -1,105 +1,11 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(feature = "unstable__schema")] - -use borsh::schema::*; +use crate::common_macro::schema_imports::*; #[cfg(feature = "hashbrown")] use hashbrown::HashMap; -use core::marker::PhantomData; #[cfg(feature = "std")] use std::collections::HashMap; -#[macro_use] -mod common_macro; -use common_macro::schema_imports::*; - -#[test] -pub fn unit_struct() { - #[derive(borsh::BorshSchema)] - struct A; - - // https://github.com/near/borsh-rs/issues/112 - #[allow(unused)] - impl A { - pub fn declaration() -> usize { - 42 - } - } - assert_eq!("A".to_string(), ::declaration()); - let mut defs = Default::default(); - A::add_definitions_recursively(&mut defs); - assert_eq!( - schema_map! { - "A" => Definition::Struct {fields: Fields::Empty} - }, - defs - ); -} - -#[test] -pub fn simple_struct() { - #[derive(borsh::BorshSchema)] - struct A { - _f1: u64, - _f2: String, - } - assert_eq!("A".to_string(), A::declaration()); - let mut defs = Default::default(); - A::add_definitions_recursively(&mut defs); - assert_eq!( - schema_map! { - "A" => Definition::Struct{ fields: Fields::NamedFields(vec![ - ("_f1".to_string(), "u64".to_string()), - ("_f2".to_string(), "String".to_string()) - ])}, - "u64" => Definition::Primitive(8), - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - }, - "u8" => Definition::Primitive(1) - }, - defs - ); -} - -#[test] -pub fn boxed() { - #[derive(borsh::BorshSchema)] - struct A { - _f1: Box, - _f2: Box, - _f3: Box<[u8]>, - } - assert_eq!("A".to_string(), A::declaration()); - let mut defs = Default::default(); - A::add_definitions_recursively(&mut defs); - assert_eq!( - schema_map! { - "Vec" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string(), - }, - "A" => Definition::Struct{ fields: Fields::NamedFields(vec![ - ("_f1".to_string(), "u64".to_string()), - ("_f2".to_string(), "String".to_string()), - ("_f3".to_string(), "Vec".to_string()) - ])}, - "u64" => Definition::Primitive(8), - "u8" => Definition::Primitive(1), - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - } - }, - defs - ); -} - #[test] pub fn wrapper_struct() { #[derive(borsh::BorshSchema)] @@ -116,30 +22,6 @@ pub fn wrapper_struct() { ); } -#[test] -pub fn tuple_struct() { - #[derive(borsh::BorshSchema)] - struct A(u64, String); - assert_eq!("A".to_string(), A::declaration()); - let mut defs = Default::default(); - A::add_definitions_recursively(&mut defs); - assert_eq!( - schema_map! { - "A" => Definition::Struct {fields: Fields::UnnamedFields(vec![ - "u64".to_string(), "String".to_string() - ])}, - "u64" => Definition::Primitive(8), - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - }, - "u8" => Definition::Primitive(1) - }, - defs - ); -} - #[test] pub fn tuple_struct_params() { #[derive(borsh::BorshSchema)] @@ -207,7 +89,7 @@ pub fn simple_generics() { ); } -fn common_map() -> BTreeMap { +fn common_map_associated() -> BTreeMap { schema_map! { "Parametrized" => Definition::Struct { @@ -255,7 +137,7 @@ pub fn generic_associated_item() { let mut defs = Default::default(); >::add_definitions_recursively(&mut defs); - assert_eq!(common_map(), defs); + assert_eq!(common_map_associated(), defs); } #[test] @@ -288,7 +170,7 @@ pub fn generic_associated_item2() { let mut defs = Default::default(); >::add_definitions_recursively(&mut defs); - assert_eq!(common_map(), defs); + assert_eq!(common_map_associated(), defs); } #[test] @@ -345,38 +227,3 @@ pub fn generic_associated_item3() { ); } -#[test] -pub fn with_phantom_data() { - #[allow(unused)] - #[derive(borsh::BorshSchema)] - struct Parametrized { - field: K, - another: PhantomData, - } - - assert_eq!( - "Parametrized".to_string(), - >::declaration() - ); - - let mut defs = Default::default(); - >::add_definitions_recursively(&mut defs); - assert_eq!( - schema_map! { - "Parametrized" => Definition::Struct { - fields: Fields::NamedFields(vec![ - ("field".to_string(), "String".to_string()), - ("another".to_string(), "()".to_string()) - ]) - }, - "()" => Definition::Primitive(0), - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - }, - "u8" => Definition::Primitive(1) - }, - defs - ); -} diff --git a/borsh/tests/schema/test_hash_map.rs b/borsh/tests/schema/test_hash_map.rs new file mode 100644 index 000000000..20b2d3fd2 --- /dev/null +++ b/borsh/tests/schema/test_hash_map.rs @@ -0,0 +1,59 @@ +use crate::common_macro::schema_imports::*; + +#[cfg(feature = "hashbrown")] +use hashbrown::{HashMap, HashSet}; +#[cfg(feature = "std")] +use std::collections::{HashMap, HashSet}; + +#[test] +fn simple_map() { + let actual_name = HashMap::::declaration(); + let mut actual_defs = schema_map!(); + HashMap::::add_definitions_recursively(&mut actual_defs); + assert_eq!("HashMap", actual_name); + assert_eq!( + schema_map! { + "HashMap" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "(u64, String)".to_string(), + } , + "(u64, String)" => Definition::Tuple { + elements: vec![ "u64".to_string(), "String".to_string()], + }, + "u64" => Definition::Primitive(8), + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + }, + "u8" => Definition::Primitive(1) + + }, + actual_defs + ); +} + +#[test] +fn simple_set() { + let actual_name = HashSet::::declaration(); + let mut actual_defs = schema_map!(); + HashSet::::add_definitions_recursively(&mut actual_defs); + assert_eq!("HashSet", actual_name); + assert_eq!( + schema_map! { + "HashSet" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "String".to_string(), + }, + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + }, + "u8" => Definition::Primitive(1) + }, + actual_defs + ); +} diff --git a/borsh/tests/schema/test_option.rs b/borsh/tests/schema/test_option.rs new file mode 100644 index 000000000..f04c1f906 --- /dev/null +++ b/borsh/tests/schema/test_option.rs @@ -0,0 +1,52 @@ +use crate::common_macro::schema_imports::*; + +#[test] +fn simple_option() { + let actual_name = Option::::declaration(); + let mut actual_defs = schema_map!(); + Option::::add_definitions_recursively(&mut actual_defs); + assert_eq!("Option", actual_name); + assert_eq!( + schema_map! { + "Option" => Definition::Enum { + tag_width: 1, + variants: vec![ + (0, "None".to_string(), "()".to_string()), + (1, "Some".to_string(), "u64".to_string()), + ] + }, + "u64" => Definition::Primitive(8), + "()" => Definition::Primitive(0) + }, + actual_defs + ); +} + +#[test] +fn nested_option() { + let actual_name = Option::>::declaration(); + let mut actual_defs = schema_map!(); + Option::>::add_definitions_recursively(&mut actual_defs); + assert_eq!("Option>", actual_name); + assert_eq!( + schema_map! { + "Option" => Definition::Enum { + tag_width: 1, + variants: vec![ + (0, "None".to_string(), "()".to_string()), + (1, "Some".to_string(), "u64".to_string()), + ] + }, + "Option>" => Definition::Enum { + tag_width: 1, + variants: vec![ + (0, "None".to_string(), "()".to_string()), + (1, "Some".to_string(), "Option".to_string()), + ] + }, + "u64" => Definition::Primitive(8), + "()" => Definition::Primitive(0) + }, + actual_defs + ); +} diff --git a/borsh/tests/schema/test_phantom_data.rs b/borsh/tests/schema/test_phantom_data.rs new file mode 100644 index 000000000..da38a3534 --- /dev/null +++ b/borsh/tests/schema/test_phantom_data.rs @@ -0,0 +1,47 @@ +use crate::common_macro::schema_imports::*; + +use core::marker::PhantomData; + +#[test] +fn phantom_data_schema() { + let phantom_declaration = PhantomData::::declaration(); + assert_eq!("()", phantom_declaration); + let phantom_declaration = PhantomData::>::declaration(); + assert_eq!("()", phantom_declaration); +} + +#[test] +pub fn generic_struct_with_phantom_data_derived() { + #[allow(unused)] + #[derive(borsh::BorshSchema)] + struct Parametrized { + field: K, + another: PhantomData, + } + + assert_eq!( + "Parametrized".to_string(), + >::declaration() + ); + + let mut defs = Default::default(); + >::add_definitions_recursively(&mut defs); + assert_eq!( + schema_map! { + "Parametrized" => Definition::Struct { + fields: Fields::NamedFields(vec![ + ("field".to_string(), "String".to_string()), + ("another".to_string(), "()".to_string()) + ]) + }, + "()" => Definition::Primitive(0), + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + }, + "u8" => Definition::Primitive(1) + }, + defs + ); +} diff --git a/borsh/tests/test_schema_primitives.rs b/borsh/tests/schema/test_primitives.rs similarity index 76% rename from borsh/tests/test_schema_primitives.rs rename to borsh/tests/schema/test_primitives.rs index 41146c8af..639fe0301 100644 --- a/borsh/tests/test_schema_primitives.rs +++ b/borsh/tests/schema/test_primitives.rs @@ -1,10 +1,4 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(hash_collections)] -#![cfg(feature = "unstable__schema")] - -#[macro_use] -mod common_macro; -use common_macro::schema_imports::*; +use crate::common_macro::schema_imports::*; #[test] fn isize_schema() { diff --git a/borsh/tests/schema/test_range.rs b/borsh/tests/schema/test_range.rs new file mode 100644 index 000000000..5adcbc5ee --- /dev/null +++ b/borsh/tests/schema/test_range.rs @@ -0,0 +1,49 @@ +use crate::common_macro::schema_imports::*; + +#[test] +fn range() { + assert_eq!("RangeFull", ::declaration()); + let mut actual_defs = schema_map!(); + ::add_definitions_recursively(&mut actual_defs); + assert_eq!( + schema_map! { + "RangeFull" => Definition::Struct { + fields: Fields::Empty + } + }, + actual_defs + ); + + let actual_name = >::declaration(); + let mut actual_defs = schema_map!(); + >::add_definitions_recursively(&mut actual_defs); + assert_eq!("Range", actual_name); + assert_eq!( + schema_map! { + "Range" => Definition::Struct { + fields: Fields::NamedFields(vec![ + ("start".into(), "u64".into()), + ("end".into(), "u64".into()), + ]) + }, + "u64" => Definition::Primitive(8) + }, + actual_defs + ); + + let actual_name = >::declaration(); + let mut actual_defs = schema_map!(); + >::add_definitions_recursively(&mut actual_defs); + assert_eq!("RangeTo", actual_name); + assert_eq!( + schema_map! { + "RangeTo" => Definition::Struct { + fields: Fields::NamedFields(vec![ + ("end".into(), "u64".into()), + ]) + }, + "u64" => Definition::Primitive(8) + }, + actual_defs + ); +} diff --git a/borsh/tests/schema/test_rc.rs b/borsh/tests/schema/test_rc.rs new file mode 100644 index 000000000..f9745bd83 --- /dev/null +++ b/borsh/tests/schema/test_rc.rs @@ -0,0 +1,53 @@ +use crate::common_macro::schema_imports::*; +use alloc::{rc, sync}; + +fn common_map_i32() -> BTreeMap { + schema_map! { + + "i32" => Definition::Primitive(4) + } +} + +fn common_map_slice_i32() -> BTreeMap { + schema_map! { + "Vec" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "i32".to_string() + }, + "i32" => Definition::Primitive(4) + } +} + +#[test] +fn test_rc() { + assert_eq!("i32", as BorshSchema>::declaration()); + + let mut actual_defs = schema_map!(); + as BorshSchema>::add_definitions_recursively(&mut actual_defs); + assert_eq!(common_map_i32(), actual_defs); +} + +#[test] +fn test_slice_rc() { + assert_eq!("Vec", as BorshSchema>::declaration()); + let mut actual_defs = schema_map!(); + as BorshSchema>::add_definitions_recursively(&mut actual_defs); + assert_eq!(common_map_slice_i32(), actual_defs); +} + +#[test] +fn test_arc() { + assert_eq!("i32", as BorshSchema>::declaration()); + let mut actual_defs = schema_map!(); + as BorshSchema>::add_definitions_recursively(&mut actual_defs); + assert_eq!(common_map_i32(), actual_defs); +} + +#[test] +fn test_slice_arc() { + assert_eq!("Vec", as BorshSchema>::declaration()); + let mut actual_defs = schema_map!(); + as BorshSchema>::add_definitions_recursively(&mut actual_defs); + assert_eq!(common_map_slice_i32(), actual_defs); +} diff --git a/borsh/tests/test_schema_recursive.rs b/borsh/tests/schema/test_recursive_enums.rs similarity index 51% rename from borsh/tests/test_schema_recursive.rs rename to borsh/tests/schema/test_recursive_enums.rs index 04c4f59ba..f5bc64e49 100644 --- a/borsh/tests/test_schema_recursive.rs +++ b/borsh/tests/schema/test_recursive_enums.rs @@ -1,11 +1,4 @@ -#![cfg(feature = "unstable__schema")] - -#[allow(unused)] -#[derive(borsh::BorshSchema)] -struct CRecC { - a: String, - b: BTreeMap, -} +use crate::common_macro::schema_imports::*; #[allow(unused)] #[derive(borsh::BorshSchema)] @@ -14,49 +7,6 @@ enum ERecD { C(u8, Vec), } -#[macro_use] -mod common_macro; -use common_macro::schema_imports::*; - -#[test] -pub fn recursive_struct_schema() { - let mut defs = Default::default(); - CRecC::add_definitions_recursively(&mut defs); - assert_eq!( - schema_map! { - "CRecC" => Definition::Struct { - fields: Fields::NamedFields( - vec![ - ( - "a".to_string(), - "String".to_string(), - ), - ( - "b".to_string(), - "BTreeMap".to_string(), - ), - ] - - ) - - }, - "BTreeMap" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "(String, CRecC)".to_string(), - }, - "(String, CRecC)" => Definition::Tuple {elements: vec!["String".to_string(), "CRecC".to_string()]}, - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - }, - "u8" => Definition::Primitive(1) - }, - defs - ); -} - #[test] pub fn recursive_enum_schema() { let mut defs = Default::default(); diff --git a/borsh/tests/schema/test_recursive_structs.rs b/borsh/tests/schema/test_recursive_structs.rs new file mode 100644 index 000000000..74ca19975 --- /dev/null +++ b/borsh/tests/schema/test_recursive_structs.rs @@ -0,0 +1,47 @@ +use crate::common_macro::schema_imports::*; + +#[allow(unused)] +#[derive(borsh::BorshSchema)] +struct CRecC { + a: String, + b: BTreeMap, +} + +#[test] +pub fn recursive_struct_schema() { + let mut defs = Default::default(); + CRecC::add_definitions_recursively(&mut defs); + assert_eq!( + schema_map! { + "CRecC" => Definition::Struct { + fields: Fields::NamedFields( + vec![ + ( + "a".to_string(), + "String".to_string(), + ), + ( + "b".to_string(), + "BTreeMap".to_string(), + ), + ] + + ) + + }, + "BTreeMap" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "(String, CRecC)".to_string(), + }, + "(String, CRecC)" => Definition::Tuple {elements: vec!["String".to_string(), "CRecC".to_string()]}, + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + }, + "u8" => Definition::Primitive(1) + }, + defs + ); +} diff --git a/borsh/tests/test_schema_with.rs b/borsh/tests/schema/test_schema_with_third_party.rs similarity index 96% rename from borsh/tests/test_schema_with.rs rename to borsh/tests/schema/test_schema_with_third_party.rs index 5800364e6..30562f89a 100644 --- a/borsh/tests/test_schema_with.rs +++ b/borsh/tests/schema/test_schema_with_third_party.rs @@ -1,15 +1,12 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(feature = "unstable__schema")] +use crate::common_macro::schema_imports::*; -#[macro_use] -mod common_macro; -use common_macro::schema_imports::*; +// use alloc::collections::BTreeMap; #[allow(unused)] struct ThirdParty(BTreeMap); #[allow(unused)] mod third_party_impl { - use super::common_macro::schema_imports::*; + use crate::common_macro::schema_imports::*; pub(super) fn declaration( ) -> borsh::schema::Declaration { diff --git a/borsh/tests/schema/test_simple_enums.rs b/borsh/tests/schema/test_simple_enums.rs new file mode 100644 index 000000000..27e94804e --- /dev/null +++ b/borsh/tests/schema/test_simple_enums.rs @@ -0,0 +1,160 @@ +use crate::common_macro::schema_imports::*; + +use borsh::{try_from_slice_with_schema, try_to_vec_with_schema}; + +#[test] +pub fn simple_enum() { + #[allow(dead_code)] + #[derive(borsh::BorshSchema)] + enum A { + Bacon, + Eggs, + } + // https://github.com/near/borsh-rs/issues/112 + #[allow(unused)] + impl A { + pub fn declaration() -> usize { + 42 + } + } + assert_eq!("A".to_string(), ::declaration()); + let mut defs = Default::default(); + A::add_definitions_recursively(&mut defs); + assert_eq!( + schema_map! { + "ABacon" => Definition::Struct{ fields: Fields::Empty }, + "AEggs" => Definition::Struct{ fields: Fields::Empty }, + "A" => Definition::Enum { + tag_width: 1, + variants: vec![(0, "Bacon".to_string(), "ABacon".to_string()), (1, "Eggs".to_string(), "AEggs".to_string())] + } + }, + defs + ); +} + +#[test] +pub fn single_field_enum() { + #[allow(dead_code)] + #[derive(borsh::BorshSchema)] + enum A { + Bacon, + } + assert_eq!("A".to_string(), A::declaration()); + let mut defs = Default::default(); + A::add_definitions_recursively(&mut defs); + assert_eq!( + schema_map! { + "ABacon" => Definition::Struct {fields: Fields::Empty}, + "A" => Definition::Enum { + tag_width: 1, + variants: vec![(0, "Bacon".to_string(), "ABacon".to_string())] + } + }, + defs + ); +} + +#[test] +pub fn complex_enum_with_schema() { + #[derive( + borsh::BorshSchema, + Default, + borsh::BorshSerialize, + borsh::BorshDeserialize, + PartialEq, + Debug, + )] + struct Tomatoes; + #[derive( + borsh::BorshSchema, + Default, + borsh::BorshSerialize, + borsh::BorshDeserialize, + PartialEq, + Debug, + )] + struct Cucumber; + #[derive( + borsh::BorshSchema, + Default, + borsh::BorshSerialize, + borsh::BorshDeserialize, + PartialEq, + Debug, + )] + struct Oil; + #[derive( + borsh::BorshSchema, + Default, + borsh::BorshSerialize, + borsh::BorshDeserialize, + PartialEq, + Debug, + )] + struct Wrapper; + #[derive( + borsh::BorshSchema, + Default, + borsh::BorshSerialize, + borsh::BorshDeserialize, + PartialEq, + Debug, + )] + struct Filling; + #[derive( + borsh::BorshSchema, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq, Debug, + )] + enum A { + Bacon, + Eggs, + Salad(Tomatoes, Cucumber, Oil), + Sausage { wrapper: Wrapper, filling: Filling }, + } + + impl Default for A { + fn default() -> Self { + A::Sausage { + wrapper: Default::default(), + filling: Default::default(), + } + } + } + // First check schema. + assert_eq!("A".to_string(), A::declaration()); + let mut defs = Default::default(); + A::add_definitions_recursively(&mut defs); + assert_eq!( + schema_map! { + "Cucumber" => Definition::Struct {fields: Fields::Empty}, + "ASalad" => Definition::Struct{ fields: Fields::UnnamedFields(vec!["Tomatoes".to_string(), "Cucumber".to_string(), "Oil".to_string()])}, + "ABacon" => Definition::Struct {fields: Fields::Empty}, + "Oil" => Definition::Struct {fields: Fields::Empty}, + "A" => Definition::Enum { + tag_width: 1, + variants: vec![ + (0, "Bacon".to_string(), "ABacon".to_string()), + (1, "Eggs".to_string(), "AEggs".to_string()), + (2, "Salad".to_string(), "ASalad".to_string()), + (3, "Sausage".to_string(), "ASausage".to_string()) + ] + }, + "Wrapper" => Definition::Struct {fields: Fields::Empty}, + "Tomatoes" => Definition::Struct {fields: Fields::Empty}, + "ASausage" => Definition::Struct { fields: Fields::NamedFields(vec![ + ("wrapper".to_string(), "Wrapper".to_string()), + ("filling".to_string(), "Filling".to_string()) + ])}, + "AEggs" => Definition::Struct {fields: Fields::Empty}, + "Filling" => Definition::Struct {fields: Fields::Empty} + }, + defs + ); + // Then check that we serialize and deserialize with schema. + let obj = A::default(); + let data = try_to_vec_with_schema(&obj).unwrap(); + #[cfg(feature = "std")] + insta::assert_debug_snapshot!(data); + let obj2: A = try_from_slice_with_schema(&data).unwrap(); + assert_eq!(obj, obj2); +} diff --git a/borsh/tests/schema/test_simple_structs.rs b/borsh/tests/schema/test_simple_structs.rs new file mode 100644 index 000000000..f8a325e17 --- /dev/null +++ b/borsh/tests/schema/test_simple_structs.rs @@ -0,0 +1,112 @@ +use crate::common_macro::schema_imports::*; + +#[test] +pub fn unit_struct() { + #[derive(borsh::BorshSchema)] + struct A; + + // https://github.com/near/borsh-rs/issues/112 + #[allow(unused)] + impl A { + pub fn declaration() -> usize { + 42 + } + } + assert_eq!("A".to_string(), ::declaration()); + let mut defs = Default::default(); + A::add_definitions_recursively(&mut defs); + assert_eq!( + schema_map! { + "A" => Definition::Struct {fields: Fields::Empty} + }, + defs + ); +} + +#[test] +pub fn simple_struct() { + #[derive(borsh::BorshSchema)] + struct A { + _f1: u64, + _f2: String, + } + assert_eq!("A".to_string(), A::declaration()); + let mut defs = Default::default(); + A::add_definitions_recursively(&mut defs); + assert_eq!( + schema_map! { + "A" => Definition::Struct{ fields: Fields::NamedFields(vec![ + ("_f1".to_string(), "u64".to_string()), + ("_f2".to_string(), "String".to_string()) + ])}, + "u64" => Definition::Primitive(8), + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + }, + "u8" => Definition::Primitive(1) + }, + defs + ); +} + +#[test] +pub fn tuple_struct() { + #[derive(borsh::BorshSchema)] + #[allow(unused)] + struct A(u64, String); + assert_eq!("A".to_string(), A::declaration()); + let mut defs = Default::default(); + A::add_definitions_recursively(&mut defs); + assert_eq!( + schema_map! { + "A" => Definition::Struct {fields: Fields::UnnamedFields(vec![ + "u64".to_string(), "String".to_string() + ])}, + "u64" => Definition::Primitive(8), + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + }, + "u8" => Definition::Primitive(1) + }, + defs + ); +} + +#[test] +pub fn boxed() { + #[derive(borsh::BorshSchema)] + struct A { + _f1: Box, + _f2: Box, + _f3: Box<[u8]>, + } + assert_eq!("A".to_string(), A::declaration()); + let mut defs = Default::default(); + A::add_definitions_recursively(&mut defs); + assert_eq!( + schema_map! { + "Vec" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string(), + }, + "A" => Definition::Struct{ fields: Fields::NamedFields(vec![ + ("_f1".to_string(), "u64".to_string()), + ("_f2".to_string(), "String".to_string()), + ("_f3".to_string(), "Vec".to_string()) + ])}, + "u64" => Definition::Primitive(8), + "u8" => Definition::Primitive(1), + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + } + }, + defs + ); +} diff --git a/borsh/tests/schema/test_strings.rs b/borsh/tests/schema/test_strings.rs new file mode 100644 index 000000000..f201aca59 --- /dev/null +++ b/borsh/tests/schema/test_strings.rs @@ -0,0 +1,36 @@ +use crate::common_macro::schema_imports::*; + +#[test] +fn test_string() { + let actual_name = str::declaration(); + assert_eq!("String", actual_name); + let actual_name = String::declaration(); + assert_eq!("String", actual_name); + let mut actual_defs = schema_map!(); + String::add_definitions_recursively(&mut actual_defs); + assert_eq!( + schema_map! { + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + }, + "u8" => Definition::Primitive(1) + }, + actual_defs + ); + + let mut actual_defs = schema_map!(); + str::add_definitions_recursively(&mut actual_defs); + assert_eq!( + schema_map! { + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + }, + "u8" => Definition::Primitive(1) + }, + actual_defs + ); +} diff --git a/borsh/tests/schema/test_tuple.rs b/borsh/tests/schema/test_tuple.rs new file mode 100644 index 000000000..e2c2eeb53 --- /dev/null +++ b/borsh/tests/schema/test_tuple.rs @@ -0,0 +1,70 @@ +use crate::common_macro::schema_imports::*; + +#[test] +fn test_unary_tuple_schema() { + assert_eq!("(bool,)", <(bool,)>::declaration()); + let mut defs = Default::default(); + <(bool,)>::add_definitions_recursively(&mut defs); + assert_eq!( + schema_map! { + "(bool,)" => Definition::Tuple { elements: vec!["bool".to_string()] }, + "bool" => Definition::Primitive(1) + }, + defs + ); +} + +#[test] +fn simple_tuple() { + let actual_name = <(u64, core::num::NonZeroU16, String)>::declaration(); + let mut actual_defs = schema_map!(); + <(u64, core::num::NonZeroU16, String)>::add_definitions_recursively(&mut actual_defs); + assert_eq!("(u64, NonZeroU16, String)", actual_name); + assert_eq!( + schema_map! { + "(u64, NonZeroU16, String)" => Definition::Tuple { + elements: vec![ + "u64".to_string(), + "NonZeroU16".to_string(), + "String".to_string() + ] + }, + "u64" => Definition::Primitive(8), + "NonZeroU16" => Definition::Primitive(2), + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + }, + "u8" => Definition::Primitive(1) + }, + actual_defs + ); +} + +#[test] +fn nested_tuple() { + let actual_name = <(u64, (u8, bool), String)>::declaration(); + let mut actual_defs = schema_map!(); + <(u64, (u8, bool), String)>::add_definitions_recursively(&mut actual_defs); + assert_eq!("(u64, (u8, bool), String)", actual_name); + assert_eq!( + schema_map! { + "(u64, (u8, bool), String)" => Definition::Tuple { elements: vec![ + "u64".to_string(), + "(u8, bool)".to_string(), + "String".to_string(), + ]}, + "(u8, bool)" => Definition::Tuple { elements: vec![ "u8".to_string(), "bool".to_string()]}, + "u64" => Definition::Primitive(8), + "u8" => Definition::Primitive(1), + "bool" => Definition::Primitive(1), + "String" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u8".to_string() + } + }, + actual_defs + ); +} diff --git a/borsh/tests/schema/test_vecs.rs b/borsh/tests/schema/test_vecs.rs new file mode 100644 index 000000000..cbc8f6109 --- /dev/null +++ b/borsh/tests/schema/test_vecs.rs @@ -0,0 +1,86 @@ +use crate::common_macro::schema_imports::*; + +#[test] +fn simple_vec() { + let actual_name = Vec::::declaration(); + let mut actual_defs = schema_map!(); + Vec::::add_definitions_recursively(&mut actual_defs); + assert_eq!("Vec", actual_name); + assert_eq!( + schema_map! { + "Vec" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u64".to_string(), + }, + "u64" => Definition::Primitive(8) + }, + actual_defs + ); +} + +#[test] +fn nested_vec() { + let actual_name = Vec::>::declaration(); + let mut actual_defs = schema_map!(); + Vec::>::add_definitions_recursively(&mut actual_defs); + assert_eq!("Vec>", actual_name); + assert_eq!( + schema_map! { + "Vec" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "u64".to_string(), + }, + "Vec>" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "Vec".to_string(), + }, + "u64" => Definition::Primitive(8) + }, + actual_defs + ); +} + +#[test] +fn slice_schema_container() { + let schema = schema_container_of::<[i64]>(); + + assert_eq!( + schema, + BorshSchemaContainer::new( + "Vec".to_string(), + schema_map! { + "Vec" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "i64".to_string(), + }, + "i64" => Definition::Primitive(8) + + } + ) + ) +} + +#[test] +fn vec_schema_container() { + let schema = schema_container_of::>(); + + assert_eq!( + schema, + BorshSchemaContainer::new( + "Vec".to_string(), + schema_map! { + "Vec" => Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, + elements: "i64".to_string(), + }, + "i64" => Definition::Primitive(8) + + } + ) + ) +} diff --git a/borsh/tests/snapshots/test_arrays__array_array_u8.snap b/borsh/tests/snapshots/test_arrays__array_array_u8.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_array_u8.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_f32.snap b/borsh/tests/snapshots/test_arrays__array_f32.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_f32.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_i8-2.snap b/borsh/tests/snapshots/test_arrays__array_i8-2.snap deleted file mode 100644 index 60a942eee..000000000 --- a/borsh/tests/snapshots/test_arrays__array_i8-2.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[ - 100, -] diff --git a/borsh/tests/snapshots/test_arrays__array_i8.snap b/borsh/tests/snapshots/test_arrays__array_i8.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_i8.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_u128.snap b/borsh/tests/snapshots/test_arrays__array_u128.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_u128.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_u32.snap b/borsh/tests/snapshots/test_arrays__array_u32.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_u32.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_u64.snap b/borsh/tests/snapshots/test_arrays__array_u64.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_u64.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_u8-2.snap b/borsh/tests/snapshots/test_arrays__array_u8-2.snap deleted file mode 100644 index 60a942eee..000000000 --- a/borsh/tests/snapshots/test_arrays__array_u8-2.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[ - 100, -] diff --git a/borsh/tests/snapshots/test_arrays__array_u8-9.snap b/borsh/tests/snapshots/test_arrays__array_u8-9.snap deleted file mode 100644 index a8d3d95d7..000000000 --- a/borsh/tests/snapshots/test_arrays__array_u8-9.snap +++ /dev/null @@ -1,70 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[ - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, -] diff --git a/borsh/tests/snapshots/test_arrays__array_u8.snap b/borsh/tests/snapshots/test_arrays__array_u8.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_u8.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_zst-10.snap b/borsh/tests/snapshots/test_arrays__array_zst-10.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_zst-10.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_zst-2.snap b/borsh/tests/snapshots/test_arrays__array_zst-2.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_zst-2.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_zst-3.snap b/borsh/tests/snapshots/test_arrays__array_zst-3.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_zst-3.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_zst-4.snap b/borsh/tests/snapshots/test_arrays__array_zst-4.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_zst-4.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_zst-5.snap b/borsh/tests/snapshots/test_arrays__array_zst-5.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_zst-5.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_zst-6.snap b/borsh/tests/snapshots/test_arrays__array_zst-6.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_zst-6.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_zst-7.snap b/borsh/tests/snapshots/test_arrays__array_zst-7.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_zst-7.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_zst-8.snap b/borsh/tests/snapshots/test_arrays__array_zst-8.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_zst-8.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_zst-9.snap b/borsh/tests/snapshots/test_arrays__array_zst-9.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_zst-9.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_arrays__array_zst.snap b/borsh/tests/snapshots/test_arrays__array_zst.snap deleted file mode 100644 index 6ffe3ab45..000000000 --- a/borsh/tests/snapshots/test_arrays__array_zst.snap +++ /dev/null @@ -1,5 +0,0 @@ ---- -source: borsh/tests/test_arrays.rs -expression: buf ---- -[] diff --git a/borsh/tests/snapshots/test_ascii_strings__a.snap b/borsh/tests/snapshots/test_ascii_strings__a.snap deleted file mode 100644 index 4ae7c4b7d..000000000 --- a/borsh/tests/snapshots/test_ascii_strings__a.snap +++ /dev/null @@ -1,11 +0,0 @@ ---- -source: borsh/tests/test_ascii_strings.rs -expression: buf ---- -[ - 1, - 0, - 0, - 0, - 97, -] diff --git a/borsh/tests/snapshots/test_hash_map__empty_hashmap.snap b/borsh/tests/snapshots/test_hash_map__empty_hashmap.snap deleted file mode 100644 index 8e2cff348..000000000 --- a/borsh/tests/snapshots/test_hash_map__empty_hashmap.snap +++ /dev/null @@ -1,10 +0,0 @@ ---- -source: borsh/tests/test_hash_map.rs -expression: data ---- -[ - 0, - 0, - 0, - 0, -] diff --git a/borsh/tests/snapshots/test_hash_map__empty_hashset.snap b/borsh/tests/snapshots/test_hash_map__empty_hashset.snap deleted file mode 100644 index 8e2cff348..000000000 --- a/borsh/tests/snapshots/test_hash_map__empty_hashset.snap +++ /dev/null @@ -1,10 +0,0 @@ ---- -source: borsh/tests/test_hash_map.rs -expression: data ---- -[ - 0, - 0, - 0, - 0, -] diff --git a/borsh/tests/snapshots/test_init_in_deserialize__simple_enum.snap b/borsh/tests/snapshots/test_init_in_deserialize__simple_enum.snap deleted file mode 100644 index 7082d6a7c..000000000 --- a/borsh/tests/snapshots/test_init_in_deserialize__simple_enum.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: borsh/tests/test_init_in_deserialize.rs -expression: encoded_a ---- -[ - 1, -] diff --git a/borsh/tests/snapshots/test_simple_structs__mixed_enum-2.snap b/borsh/tests/snapshots/test_simple_structs__mixed_enum-2.snap deleted file mode 100644 index e70b0c847..000000000 --- a/borsh/tests/snapshots/test_simple_structs__mixed_enum-2.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: borsh/tests/test_simple_structs.rs -expression: encoded ---- -[ - 1, -] diff --git a/borsh/tests/snapshots/test_simple_structs__mixed_enum-4.snap b/borsh/tests/snapshots/test_simple_structs__mixed_enum-4.snap deleted file mode 100644 index 130ef3f52..000000000 --- a/borsh/tests/snapshots/test_simple_structs__mixed_enum-4.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: borsh/tests/test_simple_structs.rs -expression: encoded ---- -[ - 3, -] diff --git a/borsh/tests/snapshots/test_simple_structs__mixed_enum.snap b/borsh/tests/snapshots/test_simple_structs__mixed_enum.snap deleted file mode 100644 index ac859bf65..000000000 --- a/borsh/tests/snapshots/test_simple_structs__mixed_enum.snap +++ /dev/null @@ -1,9 +0,0 @@ ---- -source: borsh/tests/test_simple_structs.rs -expression: encoded ---- -[ - 0, - 13, - 0, -] diff --git a/borsh/tests/snapshots/test_strings__a.snap b/borsh/tests/snapshots/test_strings__a.snap deleted file mode 100644 index 7d9c79791..000000000 --- a/borsh/tests/snapshots/test_strings__a.snap +++ /dev/null @@ -1,11 +0,0 @@ ---- -source: borsh/tests/test_strings.rs -expression: buf ---- -[ - 1, - 0, - 0, - 0, - 97, -] diff --git a/borsh/tests/snapshots/test_tuple__unary_tuple.snap b/borsh/tests/snapshots/test_tuple__unary_tuple.snap deleted file mode 100644 index c6cbc6703..000000000 --- a/borsh/tests/snapshots/test_tuple__unary_tuple.snap +++ /dev/null @@ -1,7 +0,0 @@ ---- -source: borsh/tests/test_tuple.rs -expression: buf ---- -[ - 1, -] diff --git a/borsh/tests/snapshots/test_vecs__vec_string.snap b/borsh/tests/snapshots/test_vecs__vec_string.snap deleted file mode 100644 index 327594d74..000000000 --- a/borsh/tests/snapshots/test_vecs__vec_string.snap +++ /dev/null @@ -1,10 +0,0 @@ ---- -source: borsh/tests/test_vecs.rs -expression: buf ---- -[ - 0, - 0, - 0, - 0, -] diff --git a/borsh/tests/snapshots/test_vecs__vec_u32.snap b/borsh/tests/snapshots/test_vecs__vec_u32.snap deleted file mode 100644 index 327594d74..000000000 --- a/borsh/tests/snapshots/test_vecs__vec_u32.snap +++ /dev/null @@ -1,10 +0,0 @@ ---- -source: borsh/tests/test_vecs.rs -expression: buf ---- -[ - 0, - 0, - 0, - 0, -] diff --git a/borsh/tests/snapshots/test_vecs__vec_u8.snap b/borsh/tests/snapshots/test_vecs__vec_u8.snap deleted file mode 100644 index 327594d74..000000000 --- a/borsh/tests/snapshots/test_vecs__vec_u8.snap +++ /dev/null @@ -1,10 +0,0 @@ ---- -source: borsh/tests/test_vecs.rs -expression: buf ---- -[ - 0, - 0, - 0, - 0, -] diff --git a/borsh/tests/snapshots/test_vecs__vec_vec_u32.snap b/borsh/tests/snapshots/test_vecs__vec_vec_u32.snap deleted file mode 100644 index 327594d74..000000000 --- a/borsh/tests/snapshots/test_vecs__vec_vec_u32.snap +++ /dev/null @@ -1,10 +0,0 @@ ---- -source: borsh/tests/test_vecs.rs -expression: buf ---- -[ - 0, - 0, - 0, - 0, -] diff --git a/borsh/tests/snapshots/test_vecs__vec_vec_u8.snap b/borsh/tests/snapshots/test_vecs__vec_vec_u8.snap deleted file mode 100644 index 327594d74..000000000 --- a/borsh/tests/snapshots/test_vecs__vec_vec_u8.snap +++ /dev/null @@ -1,10 +0,0 @@ ---- -source: borsh/tests/test_vecs.rs -expression: buf ---- -[ - 0, - 0, - 0, - 0, -] diff --git a/borsh/tests/test_ascii_strings.rs b/borsh/tests/test_ascii_strings.rs deleted file mode 100644 index a80d20f5f..000000000 --- a/borsh/tests/test_ascii_strings.rs +++ /dev/null @@ -1,124 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(feature = "ascii")] - -use borsh::{from_slice, to_vec}; - -extern crate alloc; -use alloc::string::String; - -/// Verifies serialisation and deserialisation of an ASCII string `value`. -fn check_ascii(value: &str) -> alloc::vec::Vec { - // Caller promises value is ASCII. - let ascii_str = ascii::AsciiStr::from_ascii(&value).unwrap(); - let buf = to_vec(ascii_str).unwrap(); - // AsciiStr and AsciiString serialise the same way String does. - assert_eq!(buf, to_vec(&ascii::AsciiString::from(ascii_str)).unwrap()); - // Check round trip. - let got = from_slice::(&buf).unwrap(); - assert_eq!(ascii_str, got); - buf -} - -macro_rules! test_ascii_string { - ($test_name: ident, $str: expr, $snap:expr) => { - #[test] - fn $test_name() { - let value = String::from($str); - let _buf = check_ascii(&value); - #[cfg(feature = "std")] - if $snap { - insta::assert_debug_snapshot!(_buf); - } - } - }; -} - -test_ascii_string!(test_empty_string, "", true); -test_ascii_string!(test_a, "a", true); -test_ascii_string!(test_hello_world, "hello world", true); -test_ascii_string!(test_x_1024, "x".repeat(1024), true); -test_ascii_string!(test_x_4096, "x".repeat(4096), false); -test_ascii_string!(test_x_65535, "x".repeat(65535), false); -test_ascii_string!(test_hello_10, "hello world!".repeat(30), true); -test_ascii_string!(test_hello_1000, "hello Achilles!".repeat(1000), false); - -#[test] -fn test_ascii_char() { - use ascii::AsciiChar; - - let buf = to_vec(&AsciiChar::Dot).unwrap(); - assert_eq!(".".as_bytes(), buf); - assert_eq!(AsciiChar::Dot, from_slice::(&buf).unwrap()); - - from_slice::(&[b'\x80']).unwrap_err(); -} - -mod de_errors { - use alloc::string::ToString; - use borsh::from_slice; - - #[test] - fn test_non_ascii() { - let buf = borsh::to_vec(&[0xbf, 0xf3, 0xb3, 0x77][..]).unwrap(); - assert_eq!( - from_slice::(&buf) - .unwrap_err() - .to_string(), - "the byte at index 0 is not ASCII" - ); - - let buf = borsh::to_vec("żółw").unwrap(); - assert_eq!( - from_slice::(&buf) - .unwrap_err() - .to_string(), - "the byte at index 0 is not ASCII" - ); - - assert_eq!( - from_slice::(&[0xbf]) - .unwrap_err() - .to_string(), - "not an ASCII character" - ); - } -} - -#[macro_use] -mod common_macro; - -#[cfg(feature = "unstable__schema")] -mod schema { - use super::common_macro::schema_imports::*; - - #[test] - fn test_ascii_strings() { - assert_eq!("AsciiString", ascii::AsciiStr::declaration()); - assert_eq!("AsciiString", ascii::AsciiString::declaration()); - assert_eq!("AsciiChar", ascii::AsciiChar::declaration()); - - let want_char = schema_map! { - "AsciiChar" => Definition::Primitive(1) - }; - let mut actual_defs = schema_map!(); - ascii::AsciiChar::add_definitions_recursively(&mut actual_defs); - assert_eq!(want_char, actual_defs); - - let want = schema_map! { - "AsciiString" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "AsciiChar".to_string() - }, - "AsciiChar" => Definition::Primitive(1) - }; - - let mut actual_defs = schema_map!(); - ascii::AsciiStr::add_definitions_recursively(&mut actual_defs); - assert_eq!(want, actual_defs); - - let mut actual_defs = schema_map!(); - ascii::AsciiString::add_definitions_recursively(&mut actual_defs); - assert_eq!(want, actual_defs); - } -} diff --git a/borsh/tests/test_cells.rs b/borsh/tests/test_cells.rs deleted file mode 100644 index 56aae36e3..000000000 --- a/borsh/tests/test_cells.rs +++ /dev/null @@ -1,92 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] - -extern crate alloc; -use alloc::string::{String, ToString}; - -#[test] -fn test_cell_roundtrip() { - let cell = core::cell::Cell::new(42u32); - - let out = borsh::to_vec(&cell).unwrap(); - - let cell_round: core::cell::Cell = borsh::from_slice(&out).unwrap(); - - assert_eq!(cell, cell_round); -} - -#[test] -fn test_ref_cell_roundtrip() { - let rcell = core::cell::RefCell::new("str".to_string()); - - let out = borsh::to_vec(&rcell).unwrap(); - - let rcell_round: core::cell::RefCell = borsh::from_slice(&out).unwrap(); - - assert_eq!(rcell, rcell_round); -} - -mod de_errors { - - use alloc::string::ToString; - - #[test] - fn test_ref_cell_try_borrow_error() { - let rcell = core::cell::RefCell::new("str"); - - let _active_borrow = rcell.try_borrow_mut().unwrap(); - - assert_eq!( - borsh::to_vec(&rcell).unwrap_err().to_string(), - "already mutably borrowed" - ); - } -} - -#[macro_use] -mod common_macro; - -#[cfg(feature = "unstable__schema")] -mod schema { - - use super::common_macro::schema_imports::*; - fn common_map_i32() -> BTreeMap { - schema_map! { - - "i32" => Definition::Primitive(4) - } - } - - fn common_map_slice_i32() -> BTreeMap { - schema_map! { - "Vec" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "i32".to_string() - }, - "i32" => Definition::Primitive(4) - } - } - - #[test] - fn test_cell() { - assert_eq!("i32", as BorshSchema>::declaration()); - - let mut actual_defs = schema_map!(); - as BorshSchema>::add_definitions_recursively(&mut actual_defs); - assert_eq!(common_map_i32(), actual_defs); - } - - #[test] - fn test_ref_cell_vec() { - assert_eq!( - "Vec", - > as BorshSchema>::declaration() - ); - - let mut actual_defs = schema_map!(); - > as BorshSchema>::add_definitions_recursively( - &mut actual_defs, - ); - assert_eq!(common_map_slice_i32(), actual_defs); - } -} diff --git a/borsh/tests/test_cow.rs b/borsh/tests/test_cow.rs deleted file mode 100644 index 25c41d2e8..000000000 --- a/borsh/tests/test_cow.rs +++ /dev/null @@ -1,157 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] - -use borsh::{from_slice, to_vec}; -use core::{matches, ops::Deref}; -extern crate alloc; -use alloc::string::ToString; - -#[cfg(feature = "std")] -use std::borrow::Cow; - -#[cfg(not(feature = "std"))] -use alloc::{borrow::Cow, vec}; - -#[test] -fn test_cow_str() { - let input: Cow<'_, str> = Cow::Borrowed("static input"); - - let encoded = to_vec(&input).unwrap(); - - #[cfg(feature = "std")] - insta::assert_debug_snapshot!(encoded); - - let out: Cow<'_, str> = from_slice(&encoded).unwrap(); - - assert!(matches!(out, Cow::Owned(..))); - - assert_eq!(input, out); - assert_eq!(out, "static input"); -} - -#[test] -fn test_cow_byte_slice() { - let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - let input: Cow<'_, [u8]> = Cow::Borrowed(&arr); - - let encoded = to_vec(&input).unwrap(); - - #[cfg(feature = "std")] - insta::assert_debug_snapshot!(encoded); - - let out: Cow<'_, [u8]> = from_slice(&encoded).unwrap(); - - assert!(matches!(out, Cow::Owned(..))); - - assert_eq!(input, out); - assert_eq!(out, vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); -} - -#[test] -fn test_cow_slice_of_cow_str() { - let arr = [ - Cow::Borrowed("first static input"), - Cow::Owned("second static input".to_string()), - ]; - let input: Cow<'_, [Cow<'_, str>]> = Cow::Borrowed(&arr); - - let encoded = to_vec(&input).unwrap(); - - #[cfg(feature = "std")] - insta::assert_debug_snapshot!(encoded); - - let out: Cow<'_, [Cow<'_, str>]> = from_slice(&encoded).unwrap(); - - assert!(matches!(out, Cow::Owned(..))); - - for element in out.deref() { - assert!(matches!(element, Cow::Owned(..))); - } - - assert_eq!(input, out); - assert_eq!( - out, - vec![ - Cow::Borrowed("first static input"), - Cow::Borrowed("second static input"), - ] - ); -} - -#[macro_use] -mod common_macro; - -#[cfg(feature = "unstable__schema")] -mod schema { - - use super::common_macro::schema_imports::*; - #[cfg(feature = "std")] - use std::borrow::Cow; - - #[cfg(not(feature = "std"))] - use alloc::borrow::Cow; - - #[test] - fn test_cow_str() { - assert_eq!("String", as BorshSchema>::declaration()); - - let mut actual_defs = schema_map!(); - as BorshSchema>::add_definitions_recursively(&mut actual_defs); - assert_eq!( - schema_map! { - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - }, - "u8" => Definition::Primitive(1) - }, - actual_defs - ); - } - - #[test] - fn test_cow_byte_slice() { - assert_eq!("Vec", as BorshSchema>::declaration()); - - let mut actual_defs = schema_map!(); - as BorshSchema>::add_definitions_recursively(&mut actual_defs); - assert_eq!( - schema_map! { - "Vec" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string(), - }, - "u8" => Definition::Primitive(1) - }, - actual_defs - ); - } - - #[test] - fn test_cow_slice_of_cow_str() { - assert_eq!( - "Vec", - ]> as BorshSchema>::declaration() - ); - - let mut actual_defs = schema_map!(); - ]> as BorshSchema>::add_definitions_recursively(&mut actual_defs); - assert_eq!( - schema_map! { - "Vec" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "String".to_string(), - }, - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - }, - "u8" => Definition::Primitive(1) - }, - actual_defs - ); - } -} diff --git a/borsh/tests/test_generic_struct.rs b/borsh/tests/test_generic_struct.rs deleted file mode 100644 index 7f87898c2..000000000 --- a/borsh/tests/test_generic_struct.rs +++ /dev/null @@ -1,238 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(feature = "derive")] -use core::marker::PhantomData; - -#[cfg(feature = "hashbrown")] -use hashbrown::HashMap; - -#[cfg(hash_collections)] -use core::{cmp::Eq, hash::Hash}; - -#[cfg(feature = "std")] -use std::collections::{BTreeMap, HashMap}; - -#[cfg(not(feature = "std"))] -extern crate alloc; -#[cfg(not(feature = "std"))] -use alloc::{ - collections::BTreeMap, - string::{String, ToString}, - vec, - vec::Vec, -}; -#[cfg(not(feature = "std"))] -use core::result::Result; - -use borsh::{from_slice, to_vec, BorshDeserialize, BorshSerialize}; - -#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] -struct A { - x: Vec, - y: String, - b: B, - pd: PhantomData, - c: Result, - d: [u64; 5], -} - -#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] -enum B { - X { f: Vec }, - Y(G), -} - -#[derive(BorshSerialize, BorshDeserialize, Debug)] -struct TupleA(W, u32); - -#[derive(BorshSerialize, BorshDeserialize, Debug)] -struct NamedA { - a: W, - b: u32, -} - -/// `T: PartialOrd` bound is required for `BorshSerialize` derive to be successful -/// `T: Hash + Eq` bound is required for `BorshDeserialize` derive to be successful -#[cfg(hash_collections)] -#[derive(BorshSerialize, BorshDeserialize)] -struct C { - a: String, - b: HashMap, -} - -/// `T: PartialOrd` is injected here via field bound to avoid having this restriction on -/// the struct itself -#[cfg(hash_collections)] -#[derive(BorshSerialize)] -struct C1 { - a: String, - #[borsh(bound(serialize = "T: borsh::ser::BorshSerialize + Ord, - U: borsh::ser::BorshSerialize"))] - b: HashMap, -} - -/// `T: PartialOrd + Hash + Eq` is injected here via field bound to avoid having this restriction on -/// the struct itself -#[allow(unused)] -#[cfg(hash_collections)] -#[derive(BorshDeserialize)] -struct C2 { - a: String, - #[borsh(bound(deserialize = "T: Ord + Hash + Eq + borsh::de::BorshDeserialize, - U: borsh::de::BorshDeserialize"))] - b: HashMap, -} - -/// `T: Ord` bound is required for `BorshDeserialize` derive to be successful -#[derive(BorshSerialize, BorshDeserialize)] -struct D { - a: String, - b: BTreeMap, -} - -#[cfg(hash_collections)] -#[derive(BorshSerialize)] -struct G(#[borsh(skip)] HashMap, U); - -#[cfg(hash_collections)] -#[derive(BorshDeserialize)] -struct G1(#[borsh(skip)] HashMap, U); - -#[cfg(hash_collections)] -#[derive(BorshDeserialize)] -struct G2(HashMap, #[borsh(skip)] U); - -/// implicit derived `core::default::Default` bounds on `K` and `V` are dropped by empty bound -/// specified, as `HashMap` hash its own `Default` implementation -#[cfg(hash_collections)] -#[derive(BorshDeserialize)] -struct G3(#[borsh(skip, bound(deserialize = ""))] HashMap, U); - -#[cfg(hash_collections)] -#[derive(BorshSerialize, BorshDeserialize)] -struct H { - x: BTreeMap, - #[allow(unused)] - #[borsh(skip)] - y: U, -} - -/// `T: Ord` bound is required for `BorshDeserialize` derive to be successful -#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] -enum E { - X { f: BTreeMap }, - Y(W), -} - -#[cfg(hash_collections)] -#[derive(BorshSerialize, BorshDeserialize, Debug)] -enum I1 { - B { - #[allow(unused)] - #[borsh(skip)] - x: HashMap, - y: String, - }, - C(K, Vec), -} - -#[cfg(hash_collections)] -#[derive(BorshSerialize, BorshDeserialize, Debug)] -enum I2 { - B { x: HashMap, y: String }, - C(K, #[borsh(skip)] U), -} - -trait TraitName { - type Associated; - fn method(&self); -} - -impl TraitName for u32 { - type Associated = String; - fn method(&self) {} -} - -#[allow(unused)] -#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] -struct Parametrized -where - T: TraitName, -{ - field: T::Associated, - another: V, -} - -#[allow(unused)] -#[derive(BorshSerialize)] -struct ParametrizedWronDerive -where - T: TraitName, -{ - #[borsh(bound(serialize = "::Associated: borsh::ser::BorshSerialize"))] - field: ::Associated, - another: V, -} - -#[test] -fn test_generic_struct() { - let a = A:: { - x: vec!["foo".to_string(), "bar".to_string()], - pd: Default::default(), - y: "world".to_string(), - b: B::X { f: vec![1, 2] }, - c: Err("error".to_string()), - d: [0, 1, 2, 3, 4], - }; - let data = to_vec(&a).unwrap(); - #[cfg(feature = "std")] - insta::assert_debug_snapshot!(data); - let actual_a = from_slice::>(&data).unwrap(); - assert_eq!(a, actual_a); -} - -#[test] -fn test_generic_associated_type_field() { - let a = Parametrized:: { - field: "value".to_string(), - another: "field".to_string(), - }; - let data = to_vec(&a).unwrap(); - #[cfg(feature = "std")] - insta::assert_debug_snapshot!(data); - let actual_a = from_slice::>(&data).unwrap(); - assert_eq!(a, actual_a); -} - -#[cfg(hash_collections)] -#[test] -fn test_generic_struct_hashmap() { - let mut hashmap = HashMap::new(); - hashmap.insert(34, "another".to_string()); - hashmap.insert(14, "value".to_string()); - let a = C:: { - a: "field".to_string(), - b: hashmap, - }; - let data = to_vec(&a).unwrap(); - #[cfg(feature = "std")] - insta::assert_debug_snapshot!(data); - let actual_a = from_slice::>(&data).unwrap(); - assert_eq!(actual_a.b.get(&14), Some("value".to_string()).as_ref()); - assert_eq!(actual_a.b.get(&34), Some("another".to_string()).as_ref()); -} - -#[test] -fn test_generic_enum() { - let b: B = B::X { - f: vec!["one".to_string(), "two".to_string(), "three".to_string()], - }; - let c: B = B::Y(656556u64); - - let list = vec![b, c]; - let data = to_vec(&list).unwrap(); - #[cfg(feature = "std")] - insta::assert_debug_snapshot!(data); - let actual_list = from_slice::>>(&data).unwrap(); - - assert_eq!(list, actual_list); -} diff --git a/borsh/tests/test_rc.rs b/borsh/tests/test_rc.rs deleted file mode 100644 index a4ca085c5..000000000 --- a/borsh/tests/test_rc.rs +++ /dev/null @@ -1,105 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(feature = "rc")] - -#[cfg(feature = "std")] -pub use std::{rc, sync}; - -extern crate alloc; -#[cfg(not(feature = "std"))] -pub use alloc::{rc, sync}; - -use borsh::{from_slice, to_vec}; - -#[test] -fn test_rc_roundtrip() { - let value = rc::Rc::new(8u8); - let serialized = to_vec(&value).unwrap(); - let deserialized = from_slice::>(&serialized).unwrap(); - assert_eq!(value, deserialized); -} - -#[test] -fn test_slice_rc() { - let original: &[i32] = &[1, 2, 3, 4, 6, 9, 10]; - let shared: rc::Rc<[i32]> = rc::Rc::from(original); - let serialized = to_vec(&shared).unwrap(); - let deserialized = from_slice::>(&serialized).unwrap(); - assert_eq!(original, &*deserialized); -} - -#[test] -fn test_arc_roundtrip() { - let value = sync::Arc::new(8u8); - let serialized = to_vec(&value).unwrap(); - let deserialized = from_slice::>(&serialized).unwrap(); - assert_eq!(value, deserialized); -} - -#[test] -fn test_slice_arc() { - let original: &[i32] = &[1, 2, 3, 4, 6, 9, 10]; - let shared: sync::Arc<[i32]> = sync::Arc::from(original); - let serialized = to_vec(&shared).unwrap(); - let deserialized = from_slice::>(&serialized).unwrap(); - assert_eq!(original, &*deserialized); -} - -#[macro_use] -mod common_macro; - -#[cfg(feature = "unstable__schema")] -mod schema { - use super::common_macro::schema_imports::*; - use alloc::{rc, sync}; - - fn common_map_i32() -> BTreeMap { - schema_map! { - - "i32" => Definition::Primitive(4) - } - } - - fn common_map_slice_i32() -> BTreeMap { - schema_map! { - "Vec" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "i32".to_string() - }, - "i32" => Definition::Primitive(4) - } - } - - #[test] - fn test_rc() { - assert_eq!("i32", as BorshSchema>::declaration()); - - let mut actual_defs = schema_map!(); - as BorshSchema>::add_definitions_recursively(&mut actual_defs); - assert_eq!(common_map_i32(), actual_defs); - } - - #[test] - fn test_slice_rc() { - assert_eq!("Vec", as BorshSchema>::declaration()); - let mut actual_defs = schema_map!(); - as BorshSchema>::add_definitions_recursively(&mut actual_defs); - assert_eq!(common_map_slice_i32(), actual_defs); - } - - #[test] - fn test_arc() { - assert_eq!("i32", as BorshSchema>::declaration()); - let mut actual_defs = schema_map!(); - as BorshSchema>::add_definitions_recursively(&mut actual_defs); - assert_eq!(common_map_i32(), actual_defs); - } - - #[test] - fn test_slice_arc() { - assert_eq!("Vec", as BorshSchema>::declaration()); - let mut actual_defs = schema_map!(); - as BorshSchema>::add_definitions_recursively(&mut actual_defs); - assert_eq!(common_map_slice_i32(), actual_defs); - } -} diff --git a/borsh/tests/test_recursive_structs.rs b/borsh/tests/test_recursive_structs.rs deleted file mode 100644 index dfbaf054f..000000000 --- a/borsh/tests/test_recursive_structs.rs +++ /dev/null @@ -1,89 +0,0 @@ -#![cfg(feature = "derive")] -use borsh::{from_slice, to_vec, BorshDeserialize, BorshSerialize}; - -#[cfg(feature = "hashbrown")] -use hashbrown::HashMap; - -#[cfg(feature = "std")] -use std::collections::HashMap; - -#[cfg(hash_collections)] -use core::{cmp::Eq, hash::Hash}; - -#[cfg(not(feature = "std"))] -extern crate alloc; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, string::String, vec::Vec}; - -#[cfg(hash_collections)] -#[derive(BorshSerialize, BorshDeserialize)] -struct CRec { - a: String, - b: HashMap>, -} - -// `impl BorshDeserialize for Box` pulls in => `ToOwned` -// => pulls in at least `Clone` -#[derive(Clone, BorshSerialize, BorshDeserialize)] -struct CRecA { - a: String, - b: Box, -} - -#[derive(Debug, BorshSerialize, BorshDeserialize, PartialEq, Eq)] -struct CRecB { - a: String, - b: Vec, -} - -#[cfg(hash_collections)] -#[derive(BorshSerialize, BorshDeserialize)] -struct CRecC { - a: String, - b: HashMap, -} - -#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] -enum ERecD { - B { x: String, y: i32 }, - C(u8, Vec), -} - -#[test] -fn test_recursive_struct() { - let one = CRecB { - a: "one".to_string(), - b: vec![], - }; - let two = CRecB { - a: "two".to_string(), - b: vec![], - }; - - let three = CRecB { - a: "three".to_string(), - b: vec![one, two], - }; - - let data = to_vec(&three).unwrap(); - #[cfg(feature = "std")] - insta::assert_debug_snapshot!(data); - let actual_three = from_slice::(&data).unwrap(); - assert_eq!(three, actual_three); -} - -#[test] -fn test_recursive_enum() { - let one = ERecD::B { - x: "one".to_string(), - y: 3213123, - }; - let two = ERecD::C(10, vec![]); - - let three = ERecD::C(11, vec![one, two]); - let data = to_vec(&three).unwrap(); - #[cfg(feature = "std")] - insta::assert_debug_snapshot!(data); - let actual_three = from_slice::(&data).unwrap(); - assert_eq!(three, actual_three); -} diff --git a/borsh/tests/test_schema_nested.rs b/borsh/tests/test_schema_nested.rs deleted file mode 100644 index a7dcd283e..000000000 --- a/borsh/tests/test_schema_nested.rs +++ /dev/null @@ -1,110 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(hash_collections)] -#![allow(dead_code)] // Local structures do not have their fields used. -#![cfg(feature = "unstable__schema")] - -use borsh::schema::*; -#[cfg(feature = "hashbrown")] -use hashbrown::HashMap; -#[cfg(feature = "std")] -use std::collections::HashMap; - -#[macro_use] -mod common_macro; -use common_macro::schema_imports::*; - -// Checks that recursive definitions work. Also checks that re-instantiations of templated types work. -#[test] -pub fn duplicated_instantiations() { - #[derive(borsh::BorshSchema)] - struct Tomatoes; - #[derive(borsh::BorshSchema)] - struct Cucumber; - #[derive(borsh::BorshSchema)] - struct Oil { - seeds: HashMap, - liquid: Option, - } - #[derive(borsh::BorshSchema)] - struct Wrapper { - foo: Option, - bar: Box>, - } - #[derive(borsh::BorshSchema)] - struct Filling; - #[derive(borsh::BorshSchema)] - enum A { - Bacon, - Eggs, - Salad(Tomatoes, C, Oil), - Sausage { wrapper: W, filling: Filling }, - } - assert_eq!( - "A>".to_string(), - >>::declaration() - ); - let mut defs = Default::default(); - >>::add_definitions_recursively(&mut defs); - assert_eq!( - schema_map! { - "A>" => Definition::Enum { - tag_width: 1, - variants: vec![ - (0, "Bacon".to_string(), "ABacon".to_string()), - (1, "Eggs".to_string(), "AEggs".to_string()), - (2, "Salad".to_string(), "ASalad".to_string()), - (3, "Sausage".to_string(), "ASausage>".to_string()) - ] - }, - "A" => Definition::Enum { - tag_width: 1, - variants: vec![ - (0, "Bacon".to_string(), "ABacon".to_string()), - (1, "Eggs".to_string(), "AEggs".to_string()), - (2, "Salad".to_string(), "ASalad".to_string()), - (3, "Sausage".to_string(), "ASausage".to_string()) - ] - }, - "ABacon" => Definition::Struct {fields: Fields::Empty}, - "AEggs" => Definition::Struct {fields: Fields::Empty}, - "ASalad" => Definition::Struct {fields: Fields::UnnamedFields(vec!["Tomatoes".to_string(), "Cucumber".to_string(), "Oil".to_string()])}, - "ASalad" => Definition::Struct { fields: Fields::UnnamedFields( vec!["Tomatoes".to_string(), "String".to_string(), "Oil".to_string() ])}, - "ASausage>" => Definition::Struct {fields: Fields::NamedFields(vec![("wrapper".to_string(), "Wrapper".to_string()), ("filling".to_string(), "Filling".to_string())])}, - "ASausage" => Definition::Struct{ fields: Fields::NamedFields(vec![("wrapper".to_string(), "String".to_string()), ("filling".to_string(), "Filling".to_string())])}, - "Cucumber" => Definition::Struct {fields: Fields::Empty}, - "Filling" => Definition::Struct {fields: Fields::Empty}, - "HashMap" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "(u64, String)".to_string(), - }, - "Oil" => Definition::Struct { fields: Fields::NamedFields(vec![("seeds".to_string(), "HashMap".to_string()), ("liquid".to_string(), "Option".to_string())])}, - "Option" => Definition::Enum { - tag_width: 1, - variants: vec![ - (0, "None".to_string(), "()".to_string()), - (1, "Some".to_string(), "String".to_string()) - ] - }, - "Option" => Definition::Enum { - tag_width: 1, - variants: vec![ - (0, "None".to_string(), "()".to_string()), - (1, "Some".to_string(), "u64".to_string()) - ] - }, - "Tomatoes" => Definition::Struct {fields: Fields::Empty}, - "(u64, String)" => Definition::Tuple {elements: vec!["u64".to_string(), "String".to_string()]}, - "Wrapper" => Definition::Struct{ fields: Fields::NamedFields(vec![("foo".to_string(), "Option".to_string()), ("bar".to_string(), "A".to_string())])}, - "u64" => Definition::Primitive(8), - "()" => Definition::Primitive(0), - "String" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "u8".to_string() - }, - "u8" => Definition::Primitive(1) - }, - defs - ); -} diff --git a/borsh/tests/test_schema_tuple.rs b/borsh/tests/test_schema_tuple.rs deleted file mode 100644 index c387e3c71..000000000 --- a/borsh/tests/test_schema_tuple.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(feature = "unstable__schema")] - -#[macro_use] -mod common_macro; -use common_macro::schema_imports::*; - -#[test] -fn test_unary_tuple_schema() { - assert_eq!("(bool,)", <(bool,)>::declaration()); - let mut defs = Default::default(); - <(bool,)>::add_definitions_recursively(&mut defs); - assert_eq!( - schema_map! { - "(bool,)" => Definition::Tuple { elements: vec!["bool".to_string()] }, - "bool" => Definition::Primitive(1) - }, - defs - ); -} diff --git a/borsh/tests/test_schema_vec.rs b/borsh/tests/test_schema_vec.rs deleted file mode 100644 index 789b3acc3..000000000 --- a/borsh/tests/test_schema_vec.rs +++ /dev/null @@ -1,49 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(hash_collections)] -#![cfg(feature = "unstable__schema")] - -#[macro_use] -mod common_macro; -use common_macro::schema_imports::*; - -#[test] -fn slice_schema_container() { - let schema = schema_container_of::<[i64]>(); - - assert_eq!( - schema, - BorshSchemaContainer::new( - "Vec".to_string(), - schema_map! { - "Vec" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "i64".to_string(), - }, - "i64" => Definition::Primitive(8) - - } - ) - ) -} - -#[test] -fn vec_schema_container() { - let schema = schema_container_of::>(); - - assert_eq!( - schema, - BorshSchemaContainer::new( - "Vec".to_string(), - schema_map! { - "Vec" => Definition::Sequence { - length_width: Definition::DEFAULT_LENGTH_WIDTH, - length_range: Definition::DEFAULT_LENGTH_RANGE, - elements: "i64".to_string(), - }, - "i64" => Definition::Primitive(8) - - } - ) - ) -} diff --git a/borsh/tests/tests.rs b/borsh/tests/tests.rs new file mode 100644 index 000000000..daaac5ec2 --- /dev/null +++ b/borsh/tests/tests.rs @@ -0,0 +1,129 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; + +#[macro_use] +mod common_macro; + +mod custom_reader { + #[cfg(feature = "derive")] + mod test_custom_reader; +} + +/// this module doesn't contain runnable tests; +/// it's included into module tree to ensure derived code doesn't raise compilation +/// errors +#[rustfmt::skip] +#[cfg(feature = "derive")] +mod compile_derives { + mod test_macro_namespace_collisions; + #[allow(unused)] + mod test_generic_structs; + mod test_generic_enums; + mod test_recursive_structs; + + #[cfg(feature = "unstable__schema")] + mod schema { + mod test_generic_enums; + } +} + +/// These are full roundtrip `BorshSerialize`/`BorshDeserialize` tests +#[rustfmt::skip] +mod roundtrip { + mod test_strings; + #[cfg(feature = "ascii")] + mod test_ascii_strings; + mod test_arrays; + mod test_vecs; + mod test_tuple; + mod test_primitives; + mod test_nonzero_integers; + mod test_range; + // mod test_phantom_data; // NOTE: there's nothing corresponding to `schema::test_phantom_data` + // mod test_option; // NOTE: there's nothing corresponding to `schema::test_option` + // mod test_box; // NOTE: there's nothing corresponding to `schema::test_box` + #[cfg(hash_collections)] + mod test_hash_map; + mod test_btree_map; + mod test_cow; + mod test_cells; + #[cfg(feature = "rc")] + mod test_rc; + + #[cfg(feature = "derive")] + mod requires_derive_category { + // mod test_simple_structs; // NOTE: there's nothing corresponding to `schema::test_simple_structs` + mod test_generic_structs; + mod test_simple_enums; + mod test_generic_enums; + mod test_recursive_structs; + mod test_recursive_enums; + mod test_serde_with_third_party; + mod test_enum_discriminants; + #[cfg(feature = "bytes")] + mod test_ultimate_many_features_combined; + #[cfg(feature = "bson")] + mod test_bson_object_ids; + } +} + +/// These are `BorshSchema` tests for various types +#[cfg(feature = "unstable__schema")] +#[rustfmt::skip] +mod schema { + #[cfg(feature = "ascii")] + mod test_ascii_strings; + mod test_strings; + mod test_arrays; + mod test_vecs; + mod test_tuple; + mod test_primitives; + // mod test_nonzero_integers; // NOTE: there's nothing corresponding to `roundtrip::test_nonzero_integers` + mod test_range; + mod test_phantom_data; + mod test_option; + mod test_box; + #[cfg(hash_collections)] + mod test_hash_map; + mod test_btree_map; + mod test_cow; + mod test_cells; + #[cfg(feature = "rc")] + mod test_rc; + mod test_simple_structs; + mod test_generic_structs; + mod test_simple_enums; + mod test_generic_enums; + mod test_recursive_structs; + mod test_recursive_enums; + mod test_schema_with_third_party; // NOTE: this test corresponds to `roundtrip::test_serde_with_third_party` + mod test_enum_discriminants; + // mod test_ultimate_many_features_combined; // NOTE: there's nothing corresponding to `roundtrip::test_ultimate_many_features_combined` + // mod test_bson_object_ids; // NOTE: there's nothing corresponding to `roundtrip::test_bson_object_ids` + mod schema_conflict { + mod test_schema_conflict; + } + + mod container_extension { + mod test_schema_validate; + mod test_max_size; + } +} + +mod deserialization_errors { + #[cfg(feature = "ascii")] + mod test_ascii_strings; + mod test_cells; + mod test_initial; +} + +mod init_in_deserialize { + #[cfg(feature = "derive")] + mod test_init_in_deserialize; +} + +mod zero_sized_types { + #[cfg(feature = "derive")] + mod test_zero_sized_types_forbidden; +} diff --git a/borsh/tests/test_zero_sized_types.rs b/borsh/tests/zero_sized_types/test_zero_sized_types_forbidden.rs similarity index 93% rename from borsh/tests/test_zero_sized_types.rs rename to borsh/tests/zero_sized_types/test_zero_sized_types_forbidden.rs index ce4a877eb..c48b9cf77 100644 --- a/borsh/tests/test_zero_sized_types.rs +++ b/borsh/tests/zero_sized_types/test_zero_sized_types_forbidden.rs @@ -1,19 +1,13 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![cfg(feature = "derive")] - -#[cfg(not(feature = "std"))] -extern crate alloc; -#[cfg(not(feature = "std"))] use alloc::{string::ToString, vec, vec::Vec}; #[cfg(feature = "std")] -use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, LinkedList, VecDeque}; +use std::collections::{HashMap, HashSet}; -#[cfg(not(feature = "std"))] -use alloc::collections::{BTreeMap, BTreeSet, LinkedList, VecDeque}; #[cfg(feature = "hashbrown")] use hashbrown::{HashMap, HashSet}; +use alloc::collections::{BTreeMap, BTreeSet, LinkedList, VecDeque}; + use borsh::from_slice; use borsh::to_vec; use borsh::BorshDeserialize;