mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-16 15:23:57 +00:00
engine: leave a descending custom-list key as it was (#3949)
Comparing two values not in the list changed descending custom-list keys too: they no longer tied, so a later key could not order them. Only an ascending key sorts them now; with a descending one they tie, as before.
This commit is contained in:
2 files changed
+17
No files matched your search
@@ -135,6 +135,8 @@ fn do_sort(s: &mut Session, sheet: usize, r: RangeRef, header: bool, keys: Vec<S
|
||||
(Some(_), None) => Ordering::Less,
|
||||
(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,
|
||||
(None, None) => plain(),
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1632,6 +1632,21 @@ fn custom_list_sort_puts_unlisted_values_after_the_list_in_order() {
|
||||
assert_eq!(col, ["Priority", "High", "Medium", "Low", "Alpha", "Zulu"].map(Value::from));
|
||||
}
|
||||
|
||||
/// #3949 changes only an ascending custom-list key: with a descending one, two values not in the
|
||||
/// list still tie, so the next key orders them.
|
||||
#[test]
|
||||
fn descending_custom_list_sort_leaves_unlisted_values_to_the_next_key() {
|
||||
let mut s = s();
|
||||
s.execute("range.setValues", json!({"range": "A1", "values": [["Name", "N"], ["Zulu", 2], ["Alpha", 1], ["High", 3]]})).unwrap();
|
||||
let keys = json!([
|
||||
{"column": "A", "order": "desc", "customList": ["High", "Medium", "Low"]},
|
||||
{"column": "B", "order": "asc"}
|
||||
]);
|
||||
s.execute("data.sort", json!({"range": "A1:B4", "header": true, "keys": keys})).unwrap();
|
||||
let col: Vec<Value> = (2..=4).map(|r| v(&s, &format!("A{r}"))).collect();
|
||||
assert_eq!(col, ["Alpha", "Zulu", "High"].map(Value::from));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn data_sort_orders_vowelled_arabic_by_letters() {
|
||||
let mut s = s();
|
||||
|
||||
Reference in new issue
Block a user