From 2c2bc1ad361f6a6f4df6c1a180a01a5a3292e7d6 Mon Sep 17 00:00:00 2001 From: Bryant Luk Date: Sat, 11 Nov 2023 09:22:18 -0600 Subject: [PATCH] Use public methods in tests --- maybe_xml/src/token.rs | 24 +++---- maybe_xml/src/token/prop.rs | 129 +++++++++++++++++++++++------------- 2 files changed, 95 insertions(+), 58 deletions(-) diff --git a/maybe_xml/src/token.rs b/maybe_xml/src/token.rs index 9aba3e9..16879d6 100644 --- a/maybe_xml/src/token.rs +++ b/maybe_xml/src/token.rs @@ -335,46 +335,46 @@ mod tests { #[test] fn start_tag_as_ref() { - let start_tag = StartTag(""); + let start_tag = StartTag::from_str(""); assert_eq!(start_tag.as_bytes(), "".as_bytes()); } #[test] fn start_tag_from() { - let start_tag = StartTag(""); + let start_tag = StartTag::from_str(""); assert_eq!(start_tag.as_str(), ""); - let start_tag = StartTag(""); + let start_tag = StartTag::from_str(""); assert_eq!(start_tag.as_str(), ""); let expected = ""; - let start_tag = StartTag(expected); + let start_tag = StartTag::from_str(expected); assert_eq!(start_tag.as_str(), ""); } #[test] fn start_tag_partial_eq() { - let start_tag = StartTag(""); + let start_tag = StartTag::from_str(""); assert_eq!(start_tag.as_str(), ""); assert_eq!(start_tag.as_bytes(), "".as_bytes()); } #[test] fn empty_start_tag_name() { - let start_tag = StartTag("<>"); + let start_tag = StartTag::from_str("<>"); assert_eq!(start_tag.name().as_bytes(), b""); assert_eq!(start_tag.name().as_str(), ""); } #[test] fn start_tag_attributes() { - let start_tag = StartTag(""); + let start_tag = StartTag::from_str(""); assert_eq!( start_tag.attributes(), Some(Attributes::from_str("attr=\"1\"")) ); - let start_tag = StartTag(""); + let start_tag = StartTag::from_str(""); assert_eq!( start_tag.attributes(), Some(Attributes::from_str("attr=\"1\" id=\"#example\"")) @@ -383,20 +383,20 @@ mod tests { #[test] fn empty_empty_element_tag_name() { - let empty_element_tag = EmptyElementTag(""); + let empty_element_tag = EmptyElementTag::from_str(""); assert_eq!(empty_element_tag.name().as_bytes(), b""); assert_eq!(empty_element_tag.name().as_str(), ""); } #[test] fn empty_element_tag_attributes() { - let empty_element_tag = EmptyElementTag(""); + let empty_element_tag = EmptyElementTag::from_str(""); assert_eq!( empty_element_tag.attributes(), Some(Attributes::from_str("attr=\"1\"")) ); - let empty_element_tag = EmptyElementTag(""); + let empty_element_tag = EmptyElementTag::from_str(""); assert_eq!( empty_element_tag.attributes(), Some(Attributes::from("attr=\"1\" id=\"#example\"")) @@ -405,7 +405,7 @@ mod tests { #[test] fn empty_end_tag_name() { - let end_tag = EndTag(""); + let end_tag = EndTag::from_str(""); assert_eq!(end_tag.name().as_bytes(), b""); assert_eq!(end_tag.name().as_str(), ""); } diff --git a/maybe_xml/src/token/prop.rs b/maybe_xml/src/token/prop.rs index 5872834..d154915 100644 --- a/maybe_xml/src/token/prop.rs +++ b/maybe_xml/src/token/prop.rs @@ -379,137 +379,174 @@ mod tests { #[test] fn tag_name() { - let tag_name = TagName("br"); + let tag_name = TagName::from_str("br"); assert_eq!(tag_name.as_bytes(), b"br"); assert_eq!(tag_name.as_str(), "br"); } #[test] fn tag_name_with_namespace_prefix() { - let tag_name = TagName("customer:id"); - assert_eq!(tag_name.local(), LocalName("id")); + let tag_name = TagName::from_str("customer:id"); + assert_eq!(tag_name.local(), LocalName::from_str("id")); assert_eq!(tag_name.local().as_str(), "id"); assert_eq!( tag_name.namespace_prefix(), - Some(NamespacePrefix("customer")) + Some(NamespacePrefix::from_str("customer")) ); assert_eq!(tag_name.namespace_prefix().unwrap().as_str(), "customer"); } #[test] fn tag_name_without_namespace_prefix() { - let tag_name = TagName("id"); - assert_eq!(tag_name.local(), LocalName("id")); + let tag_name = TagName::from_str("id"); + assert_eq!(tag_name.local(), LocalName::from_str("id")); assert_eq!(tag_name.local().as_str(), "id"); assert_eq!(tag_name.namespace_prefix(), None); } #[test] fn empty_attributes() { - let attributes = Attributes(""); + let attributes = Attributes::from_str(""); assert_eq!(attributes.into_iter().next(), None); } #[test] fn attributes_single() { - let attributes = Attributes("attr=\"1\""); + let attributes = Attributes::from_str("attr=\"1\""); let mut attributes_iter = attributes.into_iter(); - assert_eq!(attributes_iter.next(), Some(Attribute("attr=\"1\""))); + assert_eq!( + attributes_iter.next(), + Some(Attribute::from_str("attr=\"1\"")) + ); assert_eq!(attributes_iter.next(), None); let mut attributes_into_iter = attributes.into_iter(); - assert_eq!(attributes_into_iter.next(), Some(Attribute("attr=\"1\""))); + assert_eq!( + attributes_into_iter.next(), + Some(Attribute::from_str("attr=\"1\"")) + ); assert_eq!(attributes_into_iter.next(), None); } #[test] fn attributes_single_with_spaces() { - let attributes = Attributes(" attr=\"1 example\" "); + let attributes = Attributes::from_str(" attr=\"1 example\" "); let mut attributes_iter = attributes.into_iter(); assert_eq!( attributes_iter.next(), - Some(Attribute("attr=\"1 example\"")) + Some(Attribute::from_str("attr=\"1 example\"")) ); assert_eq!(attributes_iter.next(), None); let mut attributes_into_iter = attributes.into_iter(); assert_eq!( attributes_into_iter.next(), - Some(Attribute("attr=\"1 example\"")) + Some(Attribute::from_str("attr=\"1 example\"")) ); assert_eq!(attributes_into_iter.next(), None); } #[test] fn attributes_multiple() { - let attributes = Attributes("attr=\"1\" id='test' name=invalid name=\"multiple example\""); + let attributes = + Attributes::from_str("attr=\"1\" id='test' name=invalid name=\"multiple example\""); let mut attributes_iter = attributes.into_iter(); - assert_eq!(attributes_iter.next(), Some(Attribute("attr=\"1\""))); - assert_eq!(attributes_iter.next(), Some(Attribute("id='test'"))); - assert_eq!(attributes_iter.next(), Some(Attribute("name=invalid"))); assert_eq!( attributes_iter.next(), - Some(Attribute("name=\"multiple example\"")) + Some(Attribute::from_str("attr=\"1\"")) + ); + assert_eq!( + attributes_iter.next(), + Some(Attribute::from_str("id='test'")) + ); + assert_eq!( + attributes_iter.next(), + Some(Attribute::from_str("name=invalid")) + ); + assert_eq!( + attributes_iter.next(), + Some(Attribute::from_str("name=\"multiple example\"")) ); assert_eq!(attributes_iter.next(), None); let mut attributes_into_iter = attributes.into_iter(); - assert_eq!(attributes_into_iter.next(), Some(Attribute("attr=\"1\""))); - assert_eq!(attributes_into_iter.next(), Some(Attribute("id='test'"))); - assert_eq!(attributes_into_iter.next(), Some(Attribute("name=invalid"))); assert_eq!( attributes_into_iter.next(), - Some(Attribute("name=\"multiple example\"")) + Some(Attribute::from_str("attr=\"1\"")) + ); + assert_eq!( + attributes_into_iter.next(), + Some(Attribute::from_str("id='test'")) + ); + assert_eq!( + attributes_into_iter.next(), + Some(Attribute::from_str("name=invalid")) + ); + assert_eq!( + attributes_into_iter.next(), + Some(Attribute::from_str("name=\"multiple example\"")) ); assert_eq!(attributes_into_iter.next(), None); } #[test] fn attributes_multiple_with_spaces() { - let attributes = Attributes( + let attributes = Attributes::from_str( " attr=\"1\" id='test' test = new name= invalid standalone name=\"example\" ", ); let mut attributes_into_iter = attributes.into_iter(); - assert_eq!(attributes_into_iter.next(), Some(Attribute("attr=\"1\""))); - assert_eq!(attributes_into_iter.next(), Some(Attribute("id='test'"))); - assert_eq!(attributes_into_iter.next(), Some(Attribute("test = new"))); assert_eq!( attributes_into_iter.next(), - Some(Attribute("name= invalid")) + Some(Attribute::from_str("attr=\"1\"")) + ); + assert_eq!( + attributes_into_iter.next(), + Some(Attribute::from_str("id='test'")) + ); + assert_eq!( + attributes_into_iter.next(), + Some(Attribute::from_str("test = new")) + ); + assert_eq!( + attributes_into_iter.next(), + Some(Attribute::from_str("name= invalid")) + ); + assert_eq!( + attributes_into_iter.next(), + Some(Attribute::from_str("standalone")) ); - assert_eq!(attributes_into_iter.next(), Some(Attribute("standalone"))); assert_eq!( attributes_into_iter.next(), - Some(Attribute("name=\"example\"")) + Some(Attribute::from_str("name=\"example\"")) ); assert_eq!(attributes_into_iter.next(), None); } #[test] fn attribute_name_and_value() { - let attribute = Attribute("attr=\"1\""); - assert_eq!(attribute.name(), AttributeName("attr")); - assert_eq!(attribute.value(), Some(AttributeValue("1"))); + let attribute = Attribute::from_str("attr=\"1\""); + assert_eq!(attribute.name(), AttributeName::from_str("attr")); + assert_eq!(attribute.value(), Some(AttributeValue::from_str("1"))); - let attribute = Attribute("id='test'"); - assert_eq!(attribute.name(), AttributeName("id")); - assert_eq!(attribute.value(), Some(AttributeValue("test"))); + let attribute = Attribute::from_str("id='test'"); + assert_eq!(attribute.name(), AttributeName::from_str("id")); + assert_eq!(attribute.value(), Some(AttributeValue::from_str("test"))); - let attribute = Attribute("test =new"); - assert_eq!(attribute.name(), AttributeName("test")); - assert_eq!(attribute.value(), Some(AttributeValue("new"))); + let attribute = Attribute::from_str("test =new"); + assert_eq!(attribute.name(), AttributeName::from_str("test")); + assert_eq!(attribute.value(), Some(AttributeValue::from_str("new"))); - let attribute = Attribute("name= invalid"); - assert_eq!(attribute.name(), AttributeName("name")); - assert_eq!(attribute.value(), Some(AttributeValue("invalid"))); + let attribute = Attribute::from_str("name= invalid"); + assert_eq!(attribute.name(), AttributeName::from_str("name")); + assert_eq!(attribute.value(), Some(AttributeValue::from_str("invalid"))); - let attribute = Attribute("standalone"); - assert_eq!(attribute.name(), AttributeName("standalone")); + let attribute = Attribute::from_str("standalone"); + assert_eq!(attribute.name(), AttributeName::from_str("standalone")); assert_eq!(attribute.value(), None); - let attribute = Attribute("xml:example=\"test\""); - assert_eq!(attribute.name(), AttributeName("xml:example")); - assert_eq!(attribute.value(), Some(AttributeValue("test"))); + let attribute = Attribute::from_str("xml:example=\"test\""); + assert_eq!(attribute.name(), AttributeName::from_str("xml:example")); + assert_eq!(attribute.value(), Some(AttributeValue::from_str("test"))); } }