use crate::common_macro::schema_imports::*; use alloc::collections::{VecDeque, LinkedList}; macro_rules! test_vec_like_collection_schema { [$test_name: ident, $type: ident] => [ #[test] fn $test_name() { let actual_name = $type::::declaration(); let mut actual_defs = schema_map!(); $type::::add_definitions_recursively(&mut actual_defs); assert_eq!(format!("{}", stringify!($type)), actual_name); assert_eq!( schema_map! { actual_name => 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_vec_like_collection_schema!(simple_vec, Vec); test_vec_like_collection_schema!(vec_deque, VecDeque); test_vec_like_collection_schema!(linked_list, LinkedList); #[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) } ) ) }