Ensure last array items (array[$]) compare correctly (#1534)

This commit is contained in:
CelebrateVC 2022-12-20 05:31:53 -05:00 committed by GitHub
parent 44c3f32f69
commit 3048748573
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -46,7 +46,7 @@ impl Value {
(None, Some(_)) => Some(Ordering::Less), (None, Some(_)) => Some(Ordering::Less),
(_, _) => Some(Ordering::Equal), (_, _) => Some(Ordering::Equal),
}, },
Part::Last => match (a.first(), b.first()) { Part::Last => match (a.last(), b.last()) {
(Some(a), Some(b)) => a.compare(b, path.next(), collate, numeric), (Some(a), Some(b)) => a.compare(b, path.next(), collate, numeric),
(Some(_), None) => Some(Ordering::Greater), (Some(_), None) => Some(Ordering::Greater),
(None, Some(_)) => Some(Ordering::Less), (None, Some(_)) => Some(Ordering::Less),
@ -192,4 +192,13 @@ mod tests {
let res = one.compare(&two, &idi, false, false); let res = one.compare(&two, &idi, false, false);
assert_eq!(res, Some(Ordering::Greater)); assert_eq!(res, Some(Ordering::Greater));
} }
#[test]
fn compare_last() {
let idi = Idiom::parse("test[$]");
let one = Value::parse("{ test: [1,5] }");
let two = Value::parse("{ test: [2,4] }");
let res = one.compare(&two, &idi, false, false);
assert_eq!(res, Some(Ordering::Greater))
}
} }