Skip to content

Commit

Permalink
Make namespaces tests independent from initial buffer content
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Sep 4, 2023
1 parent 9c48188 commit 4a6e08b
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,16 +564,17 @@ mod namespaces {
let ns = Namespace(b"default");

let mut resolver = NamespaceResolver::default();
let s = resolver.buffer.len();

resolver.push(&BytesStart::from_content(" xmlns='default'", 0));
assert_eq!(resolver.buffer, b"default");
assert_eq!(&resolver.buffer[s..], b"default");

// Check that tags without namespaces does not change result
resolver.push(&BytesStart::from_content("", 0));
assert_eq!(resolver.buffer, b"default");
assert_eq!(&resolver.buffer[s..], b"default");
resolver.pop();

assert_eq!(resolver.buffer, b"default");
assert_eq!(&resolver.buffer[s..], b"default");
assert_eq!(
resolver.resolve(name, true),
(Bound(ns), LocalName(b"simple"))
Expand All @@ -593,11 +594,12 @@ mod namespaces {
let new_ns = Namespace(b"new");

let mut resolver = NamespaceResolver::default();
let s = resolver.buffer.len();

resolver.push(&BytesStart::from_content(" xmlns='old'", 0));
resolver.push(&BytesStart::from_content(" xmlns='new'", 0));

assert_eq!(resolver.buffer, b"oldnew");
assert_eq!(&resolver.buffer[s..], b"oldnew");
assert_eq!(
resolver.resolve(name, true),
(Bound(new_ns), LocalName(b"simple"))
Expand All @@ -609,7 +611,7 @@ mod namespaces {
assert_eq!(resolver.find(name), Bound(new_ns));

resolver.pop();
assert_eq!(resolver.buffer, b"old");
assert_eq!(&resolver.buffer[s..], b"old");
assert_eq!(
resolver.resolve(name, true),
(Bound(old_ns), LocalName(b"simple"))
Expand All @@ -631,11 +633,12 @@ mod namespaces {
let old_ns = Namespace(b"old");

let mut resolver = NamespaceResolver::default();
let s = resolver.buffer.len();

resolver.push(&BytesStart::from_content(" xmlns='old'", 0));
resolver.push(&BytesStart::from_content(" xmlns=''", 0));

assert_eq!(resolver.buffer, b"old");
assert_eq!(&resolver.buffer[s..], b"old");
assert_eq!(
resolver.resolve(name, true),
(Unbound, LocalName(b"simple"))
Expand All @@ -647,7 +650,7 @@ mod namespaces {
assert_eq!(resolver.find(name), Unbound);

resolver.pop();
assert_eq!(resolver.buffer, b"old");
assert_eq!(&resolver.buffer[s..], b"old");
assert_eq!(
resolver.resolve(name, true),
(Bound(old_ns), LocalName(b"simple"))
Expand All @@ -671,16 +674,17 @@ mod namespaces {
let ns = Namespace(b"default");

let mut resolver = NamespaceResolver::default();
let s = resolver.buffer.len();

resolver.push(&BytesStart::from_content(" xmlns:p='default'", 0));
assert_eq!(resolver.buffer, b"pdefault");
assert_eq!(&resolver.buffer[s..], b"pdefault");

// Check that tags without namespaces does not change result
resolver.push(&BytesStart::from_content("", 0));
assert_eq!(resolver.buffer, b"pdefault");
assert_eq!(&resolver.buffer[s..], b"pdefault");
resolver.pop();

assert_eq!(resolver.buffer, b"pdefault");
assert_eq!(&resolver.buffer[s..], b"pdefault");
assert_eq!(
resolver.resolve(name, true),
(Bound(ns), LocalName(b"with-declared-prefix"))
Expand All @@ -700,11 +704,12 @@ mod namespaces {
let new_ns = Namespace(b"new");

let mut resolver = NamespaceResolver::default();
let s = resolver.buffer.len();

resolver.push(&BytesStart::from_content(" xmlns:p='old'", 0));
resolver.push(&BytesStart::from_content(" xmlns:p='new'", 0));

assert_eq!(resolver.buffer, b"poldpnew");
assert_eq!(&resolver.buffer[s..], b"poldpnew");
assert_eq!(
resolver.resolve(name, true),
(Bound(new_ns), LocalName(b"with-declared-prefix"))
Expand All @@ -716,7 +721,7 @@ mod namespaces {
assert_eq!(resolver.find(name), Bound(new_ns));

resolver.pop();
assert_eq!(resolver.buffer, b"pold");
assert_eq!(&resolver.buffer[s..], b"pold");
assert_eq!(
resolver.resolve(name, true),
(Bound(old_ns), LocalName(b"with-declared-prefix"))
Expand All @@ -738,11 +743,12 @@ mod namespaces {
let old_ns = Namespace(b"old");

let mut resolver = NamespaceResolver::default();
let s = resolver.buffer.len();

resolver.push(&BytesStart::from_content(" xmlns:p='old'", 0));
resolver.push(&BytesStart::from_content(" xmlns:p=''", 0));

assert_eq!(resolver.buffer, b"poldp");
assert_eq!(&resolver.buffer[s..], b"poldp");
assert_eq!(
resolver.resolve(name, true),
(Unknown(b"p".to_vec()), LocalName(b"with-declared-prefix"))
Expand All @@ -754,7 +760,7 @@ mod namespaces {
assert_eq!(resolver.find(name), Unknown(b"p".to_vec()));

resolver.pop();
assert_eq!(resolver.buffer, b"pold");
assert_eq!(&resolver.buffer[s..], b"pold");
assert_eq!(
resolver.resolve(name, true),
(Bound(old_ns), LocalName(b"with-declared-prefix"))
Expand Down

0 comments on commit 4a6e08b

Please sign in to comment.