ScanNodes: Remove _with_context methods, make them the default

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2023-04-19 13:32:09 +02:00
parent af9e47f0a8
commit 7c6298ca50
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -143,18 +143,7 @@ struct ScanNodes<'a, T: Debug> {
} }
impl<'a> ScanNodes<'a, NonStrictComparison> { impl<'a> ScanNodes<'a, NonStrictComparison> {
fn new(nodes: Vec<Node>) -> ScanNodes<'a, NonStrictComparison> { fn new(nodes: Vec<Node>, context: Option<&'a Context>) -> ScanNodes<'a, NonStrictComparison> {
Self {
nodes,
context: None,
_strict: PhantomData,
}
}
fn new_with_context(
nodes: Vec<Node>,
context: Option<&'a Context>,
) -> ScanNodes<'a, NonStrictComparison> {
Self { Self {
nodes, nodes,
context, context,
@ -164,15 +153,7 @@ impl<'a> ScanNodes<'a, NonStrictComparison> {
} }
impl<'a> ScanNodes<'a, StrictComparison> { impl<'a> ScanNodes<'a, StrictComparison> {
fn new_strict(nodes: Vec<Node>) -> ScanNodes<'a, StrictComparison> { fn new_strict(
Self {
nodes,
context: None,
_strict: PhantomData,
}
}
fn new_strict_with_context(
nodes: Vec<Node>, nodes: Vec<Node>,
context: Option<&'a Context>, context: Option<&'a Context>,
) -> ScanNodes<'a, StrictComparison> { ) -> ScanNodes<'a, StrictComparison> {
@ -317,14 +298,11 @@ impl<'a, 'b> PartialEq<&Element> for ScanElement<'a, 'b> {
_ => (), _ => (),
} }
let nodes = ScanNodes::new_strict_with_context( let nodes =
self.elem.nodes().cloned().collect(), ScanNodes::new_strict(self.elem.nodes().cloned().collect(), self.context);
self.context,
);
nodes == onodes nodes == onodes
} else { } else {
let nodes = let nodes = ScanNodes::new(self.elem.nodes().cloned().collect(), self.context);
ScanNodes::new_with_context(self.elem.nodes().cloned().collect(), self.context);
nodes == onodes nodes == onodes
} }
} else { } else {
@ -347,12 +325,12 @@ mod tests {
let elem1 = Node::Element(Element::from_str("<foo xmlns='bar'/>").unwrap()); let elem1 = Node::Element(Element::from_str("<foo xmlns='bar'/>").unwrap());
assert_eq!( assert_eq!(
ScanNodes::new_strict(vec![elem1.clone()]), ScanNodes::new_strict(vec![elem1.clone()], None),
vec![elem1.clone()], vec![elem1.clone()],
); );
assert_ne!( assert_ne!(
ScanNodes::new_strict(vec![text1.clone()]), ScanNodes::new_strict(vec![text1.clone()], None),
vec![text2.clone()], vec![text2.clone()],
); );
} }
@ -364,32 +342,32 @@ mod tests {
let elem1 = Node::Element(Element::from_str("<foo xmlns='bar'/>").unwrap()); let elem1 = Node::Element(Element::from_str("<foo xmlns='bar'/>").unwrap());
assert_eq!( assert_eq!(
ScanNodes::new_strict(vec![elem1.clone()]), ScanNodes::new_strict(vec![elem1.clone()], None),
vec![elem1.clone()], vec![elem1.clone()],
); );
assert_eq!( assert_eq!(
ScanNodes::new_strict(vec![text1.clone(), elem1.clone(), text2.clone()]), ScanNodes::new_strict(vec![text1.clone(), elem1.clone(), text2.clone()], None),
vec![elem1.clone()], vec![elem1.clone()],
); );
assert_eq!( assert_eq!(
ScanNodes::new_strict(vec![text1.clone(), elem1.clone()]), ScanNodes::new_strict(vec![text1.clone(), elem1.clone()], None),
vec![elem1.clone(), text2.clone()], vec![elem1.clone(), text2.clone()],
); );
assert_eq!( assert_eq!(
ScanNodes::new_strict(vec![elem1.clone(), text1.clone(), elem1.clone()]), ScanNodes::new_strict(vec![elem1.clone(), text1.clone(), elem1.clone()], None),
vec![elem1.clone(), elem1.clone()], vec![elem1.clone(), elem1.clone()],
); );
assert_ne!( assert_ne!(
ScanNodes::new_strict(vec![elem1.clone(), text1.clone(), elem1.clone()]), ScanNodes::new_strict(vec![elem1.clone(), text1.clone(), elem1.clone()], None),
vec![elem1.clone()], vec![elem1.clone()],
); );
assert_ne!( assert_ne!(
ScanNodes::new_strict(vec![Node::Text(String::from("\n\tfoo\n"))]), ScanNodes::new_strict(vec![Node::Text(String::from("\n\tfoo\n"))], None),
vec![Node::Text(String::from("\n\tfoo"))], vec![Node::Text(String::from("\n\tfoo"))],
); );
} }