commit 7414b93481847c6f67abcfb473c6a941f315e52c
parent 0e7435fc4d4f2f33039882456d67d1074b6854e0
Author: noriaki watanabe <nabeyang@gmail.com>
Date: Thu, 1 Jan 2026 21:07:33 +0000
Bug 2008282 - selectors/parser tests should use assert_eq instead of matches! when checking concrete Component values r=emilio,firefox-style-system-reviewers
In the selector parser tests (servo/components/selectors/parser.rs), replace use of the
`matches!` macro with `assert_eq!` when the intent is to verify both the variant and
the exact value of a returned Component.
Prior to this change, several tests were written like:
```
assert!(matches!(
iter.next(),
Some(&Component::PseudoElement(PseudoElement::Before))
));
```
Even though the pattern includes a specific value, using `matches!` only asserts
that the pattern shape matches, and does not provide helpful diagnostic output
on failure.
Using `assert_eq!` for these cases makes the intent explicit and produces clearer
expected vs actual output when tests fail. This change improves readability
and debuggability of the tests without altering their semantics.
Where only the variant shape matters (no concrete fields to check), `matches!` can
still be appropriate. But in the affected cases, the concrete value was already
being specified, so `assert_eq!` is a better fit.
Differential Revision: https://phabricator.services.mozilla.com/D277729
Diffstat:
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/servo/components/selectors/parser.rs b/servo/components/selectors/parser.rs
@@ -4681,7 +4681,13 @@ pub mod tests {
assert_eq!(iter.next(), None);
let combinator = iter.next_sequence();
assert_eq!(combinator, Some(Combinator::PseudoElement));
- assert!(matches!(iter.next(), Some(&Component::LocalName(..))));
+ assert_eq!(
+ iter.next(),
+ Some(&Component::LocalName(LocalName {
+ name: DummyAtom::from("q"),
+ lower_name: DummyAtom::from("q"),
+ }))
+ );
assert_eq!(iter.next(), None);
assert_eq!(iter.next_sequence(), None);
}
@@ -4698,10 +4704,10 @@ pub mod tests {
assert_eq!(iter.next(), None);
let combinator = iter.next_sequence();
assert_eq!(combinator, Some(Combinator::PseudoElement));
- assert!(matches!(
+ assert_eq!(
iter.next(),
Some(&Component::PseudoElement(PseudoElement::Before))
- ));
+ );
assert_eq!(iter.next(), None);
let combinator = iter.next_sequence();
assert_eq!(combinator, Some(Combinator::PseudoElement));
@@ -4728,10 +4734,10 @@ pub mod tests {
assert_eq!(iter.next(), None);
let combinator = iter.next_sequence();
assert_eq!(combinator, Some(Combinator::PseudoElement));
- assert!(matches!(
+ assert_eq!(
iter.next(),
Some(&Component::PseudoElement(PseudoElement::DetailsContent))
- ));
+ );
assert_eq!(iter.next(), None);
let combinator = iter.next_sequence();
assert_eq!(combinator, Some(Combinator::PseudoElement));