Skip to content

Commit

Permalink
Use assert_eq! instead of manual matches because now NamespaceError i…
Browse files Browse the repository at this point in the history
…mplements PartialEq
  • Loading branch information
Mingun committed Oct 12, 2024
1 parent 8a3a140 commit 00a0962
Showing 1 changed file with 49 additions and 78 deletions.
127 changes: 49 additions & 78 deletions src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,18 +1040,15 @@ mod namespaces {
fn rebound_to_incorrect_ns() {
let mut resolver = NamespaceResolver::default();
let s = resolver.buffer.len();
match resolver.push(&BytesStart::from_content(
" xmlns:xml='not_correct_namespace'",
0,
)) {
Err(NamespaceError::InvalidXmlPrefixBind(namespace)) => {
assert_eq!(namespace, b"not_correct_namespace");
}
x => panic!(
"Expected `Err(InvalidPrefixBind {{ .. }})`, but got `{:?}`",
x
),
}
assert_eq!(
resolver.push(&BytesStart::from_content(
" xmlns:xml='not_correct_namespace'",
0,
)),
Err(NamespaceError::InvalidXmlPrefixBind(
b"not_correct_namespace".to_vec()
)),
);
assert_eq!(&resolver.buffer[s..], b"");
}

Expand All @@ -1060,15 +1057,10 @@ mod namespaces {
fn unbound() {
let mut resolver = NamespaceResolver::default();
let s = resolver.buffer.len();
match resolver.push(&BytesStart::from_content(" xmlns:xml=''", 0)) {
Err(NamespaceError::InvalidXmlPrefixBind(namespace)) => {
assert_eq!(namespace, b"");
}
x => panic!(
"Expected `Err(InvalidPrefixBind {{ .. }})`, but got `{:?}`",
x
),
}
assert_eq!(
resolver.push(&BytesStart::from_content(" xmlns:xml=''", 0)),
Err(NamespaceError::InvalidXmlPrefixBind(b"".to_vec())),
);
assert_eq!(&resolver.buffer[s..], b"");
}

Expand All @@ -1077,18 +1069,13 @@ mod namespaces {
fn other_prefix_bound_to_xml_namespace() {
let mut resolver = NamespaceResolver::default();
let s = resolver.buffer.len();
match resolver.push(&BytesStart::from_content(
" xmlns:not_xml='http://www.w3.org/XML/1998/namespace'",
0,
)) {
Err(NamespaceError::InvalidPrefixForXml(prefix)) => {
assert_eq!(prefix, b"not_xml");
}
x => panic!(
"Expected `Err(InvalidPrefixBind {{ .. }})`, but got `{:?}`",
x
),
}
assert_eq!(
resolver.push(&BytesStart::from_content(
" xmlns:not_xml='http://www.w3.org/XML/1998/namespace'",
0,
)),
Err(NamespaceError::InvalidPrefixForXml(b"not_xml".to_vec())),
);
assert_eq!(&resolver.buffer[s..], b"");
}
}
Expand Down Expand Up @@ -1122,18 +1109,15 @@ mod namespaces {
fn rebound_to_correct_ns() {
let mut resolver = NamespaceResolver::default();
let s = resolver.buffer.len();
match resolver.push(&BytesStart::from_content(
" xmlns:xmlns='http://www.w3.org/2000/xmlns/'",
0,
)) {
Err(NamespaceError::InvalidXmlnsPrefixBind(namespace)) => {
assert_eq!(namespace, b"http://www.w3.org/2000/xmlns/");
}
x => panic!(
"Expected `Err(InvalidPrefixBind {{ .. }})`, but got `{:?}`",
x
),
}
assert_eq!(
resolver.push(&BytesStart::from_content(
" xmlns:xmlns='http://www.w3.org/2000/xmlns/'",
0,
)),
Err(NamespaceError::InvalidXmlnsPrefixBind(
b"http://www.w3.org/2000/xmlns/".to_vec()
)),
);
assert_eq!(&resolver.buffer[s..], b"");
}

Expand All @@ -1142,18 +1126,15 @@ mod namespaces {
fn rebound_to_incorrect_ns() {
let mut resolver = NamespaceResolver::default();
let s = resolver.buffer.len();
match resolver.push(&BytesStart::from_content(
" xmlns:xmlns='not_correct_namespace'",
0,
)) {
Err(NamespaceError::InvalidXmlnsPrefixBind(namespace)) => {
assert_eq!(namespace, b"not_correct_namespace");
}
x => panic!(
"Expected `Err(InvalidPrefixBind {{ .. }})`, but got `{:?}`",
x
),
}
assert_eq!(
resolver.push(&BytesStart::from_content(
" xmlns:xmlns='not_correct_namespace'",
0,
)),
Err(NamespaceError::InvalidXmlnsPrefixBind(
b"not_correct_namespace".to_vec()
)),
);
assert_eq!(&resolver.buffer[s..], b"");
}

Expand All @@ -1162,15 +1143,10 @@ mod namespaces {
fn unbound() {
let mut resolver = NamespaceResolver::default();
let s = resolver.buffer.len();
match resolver.push(&BytesStart::from_content(" xmlns:xmlns=''", 0)) {
Err(NamespaceError::InvalidXmlnsPrefixBind(namespace)) => {
assert_eq!(namespace, b"");
}
x => panic!(
"Expected `Err(InvalidPrefixBind {{ .. }})`, but got `{:?}`",
x
),
}
assert_eq!(
resolver.push(&BytesStart::from_content(" xmlns:xmlns=''", 0)),
Err(NamespaceError::InvalidXmlnsPrefixBind(b"".to_vec())),
);
assert_eq!(&resolver.buffer[s..], b"");
}

Expand All @@ -1179,18 +1155,13 @@ mod namespaces {
fn other_prefix_bound_to_xmlns_namespace() {
let mut resolver = NamespaceResolver::default();
let s = resolver.buffer.len();
match resolver.push(&BytesStart::from_content(
" xmlns:not_xmlns='http://www.w3.org/2000/xmlns/'",
0,
)) {
Err(NamespaceError::InvalidPrefixForXmlns(prefix)) => {
assert_eq!(prefix, b"not_xmlns");
}
x => panic!(
"Expected `Err(InvalidPrefixBind {{ .. }})`, but got `{:?}`",
x
),
}
assert_eq!(
resolver.push(&BytesStart::from_content(
" xmlns:not_xmlns='http://www.w3.org/2000/xmlns/'",
0,
)),
Err(NamespaceError::InvalidPrefixForXmlns(b"not_xmlns".to_vec())),
);
assert_eq!(&resolver.buffer[s..], b"");
}
}
Expand Down

0 comments on commit 00a0962

Please sign in to comment.