diff --git a/borsh/tests/schema/test_ip_addr.rs b/borsh/tests/schema/test_ip_addr.rs new file mode 100644 index 000000000..9f531fd1f --- /dev/null +++ b/borsh/tests/schema/test_ip_addr.rs @@ -0,0 +1,35 @@ +use crate::common_macro::schema_imports::*; + +#[cfg(feature = "std")] +use std::net::IpAddr; + +#[test] +fn ip_addr_schema() { + let actual_name = IpAddr::declaration(); + let mut actual_defs = schema_map!(); + IpAddr::add_definitions_recursively(&mut actual_defs); + + assert_eq!("IpAddr", actual_name); + assert_eq!( + schema_map! { + "IpAddr" => Definition::Union { + variants: vec![ + "IpAddr::V4".to_string(), + "IpAddr::V6".to_string() + ], + }, + "IpAddr::V4" => Definition::Tuple { + elements: vec!["u8".to_string(), "u8".to_string(), "u8".to_string(), "u8".to_string()], + }, + "IpAddr::V6" => Definition::Tuple { + elements: vec![ + "u16".to_string(), "u16".to_string(), "u16".to_string(), "u16".to_string(), + "u16".to_string(), "u16".to_string(), "u16".to_string(), "u16".to_string(), + ], + }, + "u8" => Definition::Primitive(1), + "u16" => Definition::Primitive(2), + }, + actual_defs + ); +} diff --git a/borsh/tests/tests.rs b/borsh/tests/tests.rs index daaac5ec2..2550c0f07 100644 --- a/borsh/tests/tests.rs +++ b/borsh/tests/tests.rs @@ -12,7 +12,7 @@ mod custom_reader { /// this module doesn't contain runnable tests; /// it's included into module tree to ensure derived code doesn't raise compilation -/// errors +/// errors #[rustfmt::skip] #[cfg(feature = "derive")] mod compile_derives { @@ -31,9 +31,9 @@ mod compile_derives { /// These are full roundtrip `BorshSerialize`/`BorshDeserialize` tests #[rustfmt::skip] mod roundtrip { - mod test_strings; + mod test_strings; #[cfg(feature = "ascii")] - mod test_ascii_strings; + mod test_ascii_strings; mod test_arrays; mod test_vecs; mod test_tuple; @@ -59,7 +59,7 @@ mod roundtrip { mod test_generic_enums; mod test_recursive_structs; mod test_recursive_enums; - mod test_serde_with_third_party; + mod test_serde_with_third_party; mod test_enum_discriminants; #[cfg(feature = "bytes")] mod test_ultimate_many_features_combined; @@ -73,12 +73,13 @@ mod roundtrip { #[rustfmt::skip] mod schema { #[cfg(feature = "ascii")] - mod test_ascii_strings; - mod test_strings; + mod test_ascii_strings; + mod test_strings; mod test_arrays; mod test_vecs; mod test_tuple; mod test_primitives; + mod test_ip_addr; // mod test_nonzero_integers; // NOTE: there's nothing corresponding to `roundtrip::test_nonzero_integers` mod test_range; mod test_phantom_data;