diff --git a/src/attribute.rs b/src/attribute.rs index 134789e..856360c 100644 --- a/src/attribute.rs +++ b/src/attribute.rs @@ -447,6 +447,10 @@ mod tests { Attribute::new("ASNumber".parse().unwrap(), "32934".parse().unwrap()), "ASNumber: 32934\n" )] + #[case( + Attribute::new("ASNumber".parse().unwrap(), Value::unchecked_single(None)), + "ASNumber: \n" + )] #[case( Attribute::new("ASName".parse().unwrap(), "FACEBOOK".parse().unwrap()), "ASName: FACEBOOK\n" @@ -482,6 +486,21 @@ mod tests { " invalid prefixes from peers and customers.\n", ) )] + #[case( + Attribute::new( + "remarks".parse().unwrap(), + Value::unchecked_multi( + vec![ + None, + None + ] + ) + ), + concat!( + "remarks: \n", + " \n", + ) + )] fn attribute_display_multi_line(#[case] attribute: Attribute, #[case] expected: &str) { assert_eq!(attribute.to_string(), expected); } @@ -533,6 +552,14 @@ mod tests { assert_eq!(name_display, "address"); } + #[rstest] + #[case("role")] + #[case("person")] + fn name_deref(#[case] s: &str) { + let name = Name::unchecked(s); + assert_eq!(*name, *s); + } + #[rstest] #[case("role")] #[case("person")] diff --git a/src/object.rs b/src/object.rs index ab5f810..2a8c436 100644 --- a/src/object.rs +++ b/src/object.rs @@ -456,6 +456,87 @@ mod tests { assert_eq!(borrowed.to_string(), expected); } + #[rstest] + #[case( + Object::new(vec![ + Attribute::unchecked_single("role", "ACME Company"), + ]), + 1 + )] + #[case( + Object::new(vec![ + Attribute::unchecked_single("role", "ACME Company"), + Attribute::unchecked_single("address", "Packet Street 6"), + Attribute::unchecked_single("address", "128 Series of Tubes"), + Attribute::unchecked_single("address", "Internet"), + Attribute::unchecked_single("email", "rpsl-rs@github.com"), + Attribute::unchecked_single("nic-hdl", "RPSL1-RIPE"), + Attribute::unchecked_single("source", "RIPE"), + ]), + 7 + )] + fn object_len(#[case] object: Object, #[case] expected: usize) { + assert_eq!(object.len(), expected); + } + + #[rstest] + #[case( + Object::new(vec![ + Attribute::unchecked_single("role", "ACME Company"), + Attribute::unchecked_single("address", "Packet Street 6"), + Attribute::unchecked_single("address", "128 Series of Tubes"), + Attribute::unchecked_single("address", "Internet"), + Attribute::unchecked_single("email", "rpsl-rs@github.com"), + Attribute::unchecked_single("nic-hdl", "RPSL1-RIPE"), + Attribute::unchecked_single("source", "RIPE"), + ]), + 2, + Attribute::unchecked_single("address", "128 Series of Tubes"), + )] + fn object_index(#[case] object: Object, #[case] index: usize, #[case] expected: Attribute) { + assert_eq!(object[index], expected); + } + + #[rstest] + #[case( + vec![ + Attribute::unchecked_single("role", "ACME Company"), + Attribute::unchecked_single("address", "Packet Street 6"), + Attribute::unchecked_single("address", "128 Series of Tubes"), + Attribute::unchecked_single("address", "Internet"), + Attribute::unchecked_single("email", "rpsl-rs@github.com"), + Attribute::unchecked_single("nic-hdl", "RPSL1-RIPE"), + Attribute::unchecked_single("source", "RIPE"), + ], + )] + fn object_deref(#[case] attributes: Vec>) { + let object = Object::new(attributes.clone()); + assert_eq!(*object, attributes); + } + + #[rstest] + #[case( + vec![ + Attribute::unchecked_single("role", "ACME Company"), + Attribute::unchecked_single("address", "Packet Street 6"), + Attribute::unchecked_single("address", "128 Series of Tubes"), + Attribute::unchecked_single("address", "Internet"), + Attribute::unchecked_single("email", "rpsl-rs@github.com"), + Attribute::unchecked_single("nic-hdl", "RPSL1-RIPE"), + Attribute::unchecked_single("source", "RIPE"), + ], + )] + fn object_into_iter(#[case] attributes: Vec>) { + let object = Object::new(attributes.clone()); + + let attr_iter = attributes.into_iter(); + let obj_iter = object.into_iter(); + + for (a, b) in attr_iter.zip(obj_iter) { + assert_eq!(a, b); + } + } + #[rstest] #[case( Object::new(vec![ diff --git a/src/parser/core.rs b/src/parser/core.rs index 5430a8d..406a45c 100644 --- a/src/parser/core.rs +++ b/src/parser/core.rs @@ -159,7 +159,7 @@ mod tests { #[test] /// When parsing RPSL, the resulting object contains the original source it was created from. - fn parsed_object_contains_source() { + fn object_block_parsed_object_contains_source() { let rpsl = &mut concat!( "email: rpsl-rs@github.com\n", "nic-hdl: RPSL1-RIPE\n", @@ -183,6 +183,29 @@ mod tests { assert!(parser.parse_next(object).is_err()); } + #[rstest] + #[case( + &mut concat!( + "\n\n", + "email: rpsl-rs@github.com\n", + "nic-hdl: RPSL1-RIPE\n", + "\n", + "\n\n\n" + ), + vec![ + Attribute::unchecked_single("email", "rpsl-rs@github.com"), + Attribute::unchecked_single("nic-hdl", "RPSL1-RIPE") + ] + )] + fn object_block_padded_valid(#[case] given: &mut &str, #[case] attributes: Vec) { + let expected = Object::from_parsed(given, attributes); + + let mut parser = object_block_padded::<_, ContextError>(object_block()); + let parsed = parser.parse_next(given).unwrap(); + + assert_eq!(parsed, expected); + } + #[rstest] #[case( &mut "% Note: This is a server message\n"