ScanElement now owns the Element
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
d97bc62121
commit
1e02dd2d1f
1 changed files with 26 additions and 26 deletions
|
@ -85,7 +85,7 @@ impl<'a> PartialEq<Node> for ScanNode<'a> {
|
|||
match (&self.node, other) {
|
||||
(Node::Text(text1), Node::Text(text2)) => text1 == text2,
|
||||
(Node::Element(elem1), Node::Element(elem2)) => {
|
||||
ScanElement::new(&elem1).with_context(self.context) == elem2
|
||||
ScanElement::new(elem1.clone()).with_context(self.context) == elem2
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
|
@ -202,12 +202,12 @@ impl<'a> PartialEq<Vec<Node>> for ScanNodes<'a, NonStrictComparison> {
|
|||
/// changes the way the comparison is done.
|
||||
/// Also uses the custom ScanNode implementation.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ScanElement<'a, 'b> {
|
||||
elem: &'a Element,
|
||||
context: Option<&'b Context>,
|
||||
pub struct ScanElement<'a> {
|
||||
elem: Element,
|
||||
context: Option<&'a Context>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> Deref for ScanElement<'a, 'b> {
|
||||
impl<'a> Deref for ScanElement<'a> {
|
||||
type Target = Element;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
@ -215,8 +215,8 @@ impl<'a, 'b> Deref for ScanElement<'a, 'b> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> ScanElement<'a, 'static> {
|
||||
pub fn new(elem: &'a Element) -> ScanElement {
|
||||
impl<'a> ScanElement<'a> {
|
||||
pub fn new(elem: Element) -> ScanElement<'a> {
|
||||
Self {
|
||||
elem,
|
||||
context: None,
|
||||
|
@ -224,8 +224,8 @@ impl<'a> ScanElement<'a, 'static> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> ScanElement<'a, 'b> {
|
||||
pub fn with_context(self, context: Option<&'b Context>) -> ScanElement<'a, 'b> {
|
||||
impl<'a> ScanElement<'a> {
|
||||
pub fn with_context(self, context: Option<&'a Context>) -> ScanElement<'a> {
|
||||
Self {
|
||||
elem: self.elem,
|
||||
context,
|
||||
|
@ -233,7 +233,7 @@ impl<'a, 'b> ScanElement<'a, 'b> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> PartialEq<&Element> for ScanElement<'a, 'b> {
|
||||
impl<'a> PartialEq<&Element> for ScanElement<'a> {
|
||||
fn eq(&self, other: &&Element) -> bool {
|
||||
let self_ns = self.elem.ns();
|
||||
if self.elem.name() == other.name() && self_ns == other.ns() {
|
||||
|
@ -375,7 +375,7 @@ mod tests {
|
|||
.parse()
|
||||
.unwrap();
|
||||
let elem2: Element = "<presence xmlns='foo'><foo/></presence>".parse().unwrap();
|
||||
let scan1 = ScanElement::new(&elem1);
|
||||
let scan1 = ScanElement::new(elem1);
|
||||
|
||||
assert_eq!(scan1, &elem2);
|
||||
}
|
||||
|
@ -388,7 +388,7 @@ mod tests {
|
|||
let elem2: Element = "<presence xmlns='foo'>\n\tfoo\t</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan1 = ScanElement::new(&elem1);
|
||||
let scan1 = ScanElement::new(elem1);
|
||||
|
||||
assert_ne!(scan1, &elem2);
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ mod tests {
|
|||
#[test]
|
||||
fn compare_element_strict_attributes_success() {
|
||||
let elem1: Element = "<presence xmlns='foo'/>".parse().unwrap();
|
||||
let scan1 = ScanElement::new(&elem1);
|
||||
let scan1 = ScanElement::new(elem1.clone());
|
||||
|
||||
assert_eq!(scan1, &elem1);
|
||||
|
||||
|
@ -410,7 +410,7 @@ mod tests {
|
|||
</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan2 = ScanElement::new(&elem2);
|
||||
let scan2 = ScanElement::new(elem2);
|
||||
|
||||
assert_eq!(scan2, &elem3);
|
||||
}
|
||||
|
@ -419,7 +419,7 @@ mod tests {
|
|||
fn compare_element_strict_attributes_failure() {
|
||||
let elem1: Element = "<presence xmlns='foo' foo='bar'/>".parse().unwrap();
|
||||
let elem2: Element = "<presence xmlns='foo'/>".parse().unwrap();
|
||||
let scan1 = ScanElement::new(&elem1);
|
||||
let scan1 = ScanElement::new(elem1);
|
||||
|
||||
assert_ne!(scan1, &elem2);
|
||||
}
|
||||
|
@ -443,7 +443,7 @@ mod tests {
|
|||
</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan1 = ScanElement::new(&elem1);
|
||||
let scan1 = ScanElement::new(elem1);
|
||||
|
||||
assert_eq!(scan1, &elem2);
|
||||
}
|
||||
|
@ -464,7 +464,7 @@ mod tests {
|
|||
</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan1 = ScanElement::new(&elem1);
|
||||
let scan1 = ScanElement::new(elem1);
|
||||
|
||||
assert_ne!(scan1, &elem2);
|
||||
}
|
||||
|
@ -474,7 +474,7 @@ mod tests {
|
|||
let elem1: Element = "<presence scansion:strict='false' xmlns='foo'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan1 = ScanElement::new(&elem1);
|
||||
let scan1 = ScanElement::new(elem1.clone());
|
||||
|
||||
assert_eq!(scan1, &elem1);
|
||||
|
||||
|
@ -488,7 +488,7 @@ mod tests {
|
|||
</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan2 = ScanElement::new(&elem2);
|
||||
let scan2 = ScanElement::new(elem2);
|
||||
|
||||
assert_eq!(scan2, &elem3);
|
||||
}
|
||||
|
@ -499,7 +499,7 @@ mod tests {
|
|||
.parse()
|
||||
.unwrap();
|
||||
let elem2: Element = "<presence xmlns='foo' />".parse().unwrap();
|
||||
let scan1 = ScanElement::new(&elem1);
|
||||
let scan1 = ScanElement::new(elem1);
|
||||
|
||||
assert_ne!(scan1, &elem2);
|
||||
|
||||
|
@ -513,7 +513,7 @@ mod tests {
|
|||
</presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan2 = ScanElement::new(&elem2);
|
||||
let scan2 = ScanElement::new(elem2);
|
||||
|
||||
assert_ne!(scan2, &elem3);
|
||||
}
|
||||
|
@ -524,7 +524,7 @@ mod tests {
|
|||
.parse()
|
||||
.unwrap();
|
||||
let elem2: Element = "<presence xmlns='foo'><foo/></presence>".parse().unwrap();
|
||||
let scan1 = ScanElement::new(&elem1);
|
||||
let scan1 = ScanElement::new(elem1);
|
||||
|
||||
assert_eq!(scan1, &elem2);
|
||||
|
||||
|
@ -533,7 +533,7 @@ mod tests {
|
|||
let elem4: Element = "<presence xmlns='jabber:client'><foo/></presence>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan3 = ScanElement::new(&elem3);
|
||||
let scan3 = ScanElement::new(elem3);
|
||||
|
||||
assert_eq!(scan3, &elem4);
|
||||
}
|
||||
|
@ -550,7 +550,7 @@ mod tests {
|
|||
</message>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan2 = ScanElement::new(&elem2);
|
||||
let scan2 = ScanElement::new(elem2);
|
||||
|
||||
assert_ne!(scan2, &elem3);
|
||||
}
|
||||
|
@ -567,7 +567,7 @@ mod tests {
|
|||
</message>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let scan1 = ScanElement::new(&elem1);
|
||||
let scan1 = ScanElement::new(elem1);
|
||||
|
||||
assert_ne!(scan1, &elem2);
|
||||
}
|
||||
|
@ -578,7 +578,7 @@ mod tests {
|
|||
.parse()
|
||||
.unwrap();
|
||||
let elem2: Element = "<message xmlns='foo' id='some-id' />".parse().unwrap();
|
||||
let scan1 = ScanElement::new(&elem1);
|
||||
let scan1 = ScanElement::new(elem1);
|
||||
|
||||
assert_eq!(scan1, &elem2);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue