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