forked from mongodb/mongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomparisonWithCollation.js
64 lines (55 loc) · 3.45 KB
/
comparisonWithCollation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Tests the shell util '_compareStringsWithCollation'
*/
assert.eq(_compareStringsWithCollation("abc", "abc", {locale: "en_US"}), 0);
assert.gt(_compareStringsWithCollation("bcd", "abc", {locale: "en_US"}), 0);
assert.lt(_compareStringsWithCollation("abc", "ABC", {locale: "en_US"}), 0);
// "simple" locale.
assert.eq(_compareStringsWithCollation("abc", "abc", {locale: "simple"}), 0);
assert.lt(_compareStringsWithCollation("ABC", "abc", {locale: "simple"}), 0);
assert.gt(_compareStringsWithCollation("abc", "ABC", {locale: "simple"}), 0);
// zero length strings and null bytes
assert.eq(_compareStringsWithCollation("", "", {locale: "en_US"}), 0);
assert.gt(_compareStringsWithCollation("abc", "", {locale: "en_US"}), 0);
assert.gt(_compareStringsWithCollation("abc", "", {locale: "en_US", strength: 2}), 0);
assert.eq(_compareStringsWithCollation("\0", "", {locale: "en_US"}), 0);
assert.lt(_compareStringsWithCollation("\0", "ab", {locale: "en_US"}), 0);
assert.gt(_compareStringsWithCollation("a\0c", "a\0b", {locale: "en_US"}), 0);
assert.eq(_compareStringsWithCollation("a", "a\0", {locale: "en_US"}), 0);
// case-level and diatrics
assert.eq(_compareStringsWithCollation("abc", "ABC", {locale: "en_US", strength: 1}), 0);
assert.eq(_compareStringsWithCollation("abc", "ABC", {locale: "en_US", strength: 2}), 0);
assert.lt(_compareStringsWithCollation("abc", "ABC", {locale: "en_US", strength: 3}), 0);
assert.lt(
_compareStringsWithCollation("abc", "ABC", {locale: "en_US", strength: 1, caseLevel: true}), 0);
assert.lt(
_compareStringsWithCollation("abc", "ABC", {locale: "en_US", strength: 2, caseLevel: true}), 0);
assert.eq(_compareStringsWithCollation("eaio", "éáïô", {locale: "en_US", strength: 1}), 0);
assert.lt(_compareStringsWithCollation("eaio", "éáïô", {locale: "en_US", strength: 2}), 0);
assert.gt(_compareStringsWithCollation("abc", "ABC", {locale: "en_US", caseFirst: "upper"}), 0);
assert.lt(_compareStringsWithCollation("abc", "ABC", {locale: "en_US", caseFirst: "lower"}), 0);
// numeric ordering
assert.gt(_compareStringsWithCollation("10", "2", {locale: "en_US", numericOrdering: true}), 0);
assert.lt(_compareStringsWithCollation("10", "2", {locale: "en_US", numericOrdering: false}), 0);
// Ignore whitespace and punctuation
assert.eq(_compareStringsWithCollation("a b, c", "abc", {locale: "en_US", alternate: "shifted"}),
0);
assert.neq(_compareStringsWithCollation(
"a b, c", "abc", {locale: "en_US", strength: 4, alternate: "shifted"}),
0);
assert.eq(_compareStringsWithCollation(
"a b, c", "abc", {locale: "en_US", alternate: "shifted", maxVariable: "punct"}),
0);
assert.neq(_compareStringsWithCollation(
"a b, c", "abc", {locale: "en_US", alternate: "shifted", maxVariable: "space"}),
0);
assert.eq(_compareStringsWithCollation(
"a b c", "abc", {locale: "en_US", alternate: "shifted", maxVariable: "space"}),
0);
// error cases
assert.throwsWithCode(() => _compareStringsWithCollation("", ""), 9367804);
assert.throwsWithCode(() => _compareStringsWithCollation(1, "", {locale: "en_US"}), 9367801);
assert.throwsWithCode(() => _compareStringsWithCollation("", 1, {locale: "en_US"}), 9367803);
assert.throwsWithCode(() => _compareStringsWithCollation({a: ""}, "", {locale: "en_US"}), 9367801);
assert.throwsWithCode(() => _compareStringsWithCollation("", "", ""), 9367805);
assert.throwsWithCode(() => _compareStringsWithCollation("", "", {}), 40414);