mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
fix: 排序默认比较改 UTF-16 码元序
This commit is contained in:
@@ -351,6 +351,24 @@ fn array_sort_propagates_comparator_exception() {
|
||||
assert_eq!(to_str(&vm, result), "cmp");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn array_sort_default_orders_by_utf16_code_units() {
|
||||
// 默认排序按 UTF-16 码元字典序(规范 CompareArrayElements):补充平面字符
|
||||
// 以高代理(U+D800 及以上)参与比较,小于 U+E000..U+FFFF,与码点序分歧。
|
||||
// 前三例为判别例(码点序下结果相反),后两例为边界钉(两口径一致)。
|
||||
let cases = [
|
||||
("['\\u{10000}','\\uFFFF'].sort().join('')", "\u{10000}\u{FFFF}"),
|
||||
("['\\uFFFF','\\u{10000}'].toSorted().join('')", "\u{10000}\u{FFFF}"),
|
||||
("['\\u{10000}','A','\\uFFFF'].sort().join('')", "A\u{10000}\u{FFFF}"),
|
||||
("['\\uD7FF','\\u{10000}'].sort().join('')", "\u{D7FF}\u{10000}"),
|
||||
("['\\u{12345}','\\u{10000}'].sort().join('')", "\u{10000}\u{12345}"),
|
||||
];
|
||||
for (source, expected) in cases {
|
||||
let (vm, result) = eval(source).unwrap();
|
||||
assert_eq!(to_str(&vm, result), expected, "source: {source}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn array_callback_type_errors_are_not_sentinels() {
|
||||
let (vm, result) = eval("try { [1].map(null) } catch (e) { e.name }").unwrap();
|
||||
|
||||
Reference in New Issue
Block a user