Skip to content

Commit

Permalink
add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
willco-1 committed Sep 10, 2024
1 parent 2fca3af commit 205a353
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
35 changes: 35 additions & 0 deletions borsh/tests/schema/test_ip_addr.rs
Original file line number Diff line number Diff line change
@@ -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
);
}
13 changes: 7 additions & 6 deletions borsh/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 205a353

Please sign in to comment.