Skip to content

Commit 9262fbf

Browse files
committed
test: add test_ident_ord
1 parent 56dbd4d commit 9262fbf

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/ast/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ impl Ord for Ident {
238238
} = other;
239239

240240
// First compare by value, then by quote_style
241-
value.cmp(other_value)
241+
value
242+
.cmp(other_value)
242243
.then_with(|| quote_style.cmp(other_quote_style))
243244
}
244245
}
@@ -9768,6 +9769,8 @@ impl fmt::Display for NullInclusion {
97689769

97699770
#[cfg(test)]
97709771
mod tests {
9772+
use crate::tokenizer::Location;
9773+
97719774
use super::*;
97729775

97739776
#[test]
@@ -10063,4 +10066,16 @@ mod tests {
1006310066
test_steps(OneOrManyWithParens::Many(vec![2]), vec![2], 3);
1006410067
test_steps(OneOrManyWithParens::Many(vec![3, 4]), vec![3, 4], 4);
1006510068
}
10069+
10070+
// Tests that the position in the code of an `Ident` does not affect its
10071+
// ordering.
10072+
#[test]
10073+
fn test_ident_ord() {
10074+
let mut a = Ident::with_span(Span::new(Location::new(1, 1), Location::new(1, 1)), "a");
10075+
let mut b = Ident::with_span(Span::new(Location::new(2, 2), Location::new(2, 2)), "b");
10076+
10077+
assert!(a < b);
10078+
std::mem::swap(&mut a.span, &mut b.span);
10079+
assert!(a < b);
10080+
}
1006610081
}

0 commit comments

Comments
 (0)