mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-16 15:23:57 +00:00
engine: a blank goes last in a descending custom-list key (#3949)
In a descending custom-list key a blank tied with values not in the list, which come first, while it still went after the listed values, so the order depended on the input. It now goes last.
This commit is contained in:
2 files changed
+14
-1
No files matched your search
@@ -136,7 +136,8 @@ fn do_sort(s: &mut Session, sheet: usize, r: RangeRef, header: bool, keys: Vec<S
|
||||
(None, Some(_)) => Ordering::Greater,
|
||||
// Values not in the list follow the listed ones in the usual order, as in Excel.
|
||||
// A descending key is left as it was: they tie, so the next key decides.
|
||||
(None, None) if k.desc => Ordering::Equal,
|
||||
// A blank has no place in the list either, but still goes last.
|
||||
(None, None) if k.desc => va.is_empty().cmp(&vb.is_empty()),
|
||||
(None, None) => plain(),
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1647,6 +1647,18 @@ fn descending_custom_list_sort_leaves_unlisted_values_to_the_next_key() {
|
||||
assert_eq!(col, ["Alpha", "Zulu", "High"].map(Value::from));
|
||||
}
|
||||
|
||||
/// A blank in a descending custom-list key goes last, after the list, rather than tying with the
|
||||
/// values that are not in the list (which come first), so the order is the same whatever the input.
|
||||
#[test]
|
||||
fn descending_custom_list_sort_puts_blanks_last() {
|
||||
let mut s = s();
|
||||
s.execute("range.setValues", json!({"range": "A1", "values": [["Name"], [null], ["High"], ["Zulu"]]})).unwrap();
|
||||
let key = json!({"column": "A", "order": "desc", "customList": ["High", "Medium", "Low"]});
|
||||
s.execute("data.sort", json!({"range": "A1:A4", "header": true, "keys": [key]})).unwrap();
|
||||
let col: Vec<Value> = (2..=4).map(|r| v(&s, &format!("A{r}"))).collect();
|
||||
assert_eq!(col, [Value::from("Zulu"), Value::from("High"), Value::Empty]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn data_sort_orders_vowelled_arabic_by_letters() {
|
||||
let mut s = s();
|
||||
|
||||
Reference in new issue
Block a user