js/src/tests/Intl/Collator/compare.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 // Tests the compare function with a diverse set of locales and options.
michael@0 7
michael@0 8 var input = [
michael@0 9 "Argentina",
michael@0 10 "Oerlikon",
michael@0 11 "Offenbach",
michael@0 12 "Sverige",
michael@0 13 "Vaticano",
michael@0 14 "Zimbabwe",
michael@0 15 "la France",
michael@0 16 "¡viva España!",
michael@0 17 "Österreich",
michael@0 18 "中国",
michael@0 19 "日本",
michael@0 20 "한국",
michael@0 21 ];
michael@0 22
michael@0 23 var collator, expected;
michael@0 24
michael@0 25 function assertEqualArray(actual, expected, collator) {
michael@0 26 var description = JSON.stringify(collator.resolvedOptions());
michael@0 27 assertEq(actual.length, expected.length, "array length, " + description);
michael@0 28 for (var i = 0; i < actual.length; i++) {
michael@0 29 assertEq(actual[i], expected[i], "element " + i + ", " + description);
michael@0 30 }
michael@0 31 }
michael@0 32
michael@0 33
michael@0 34 // Locale en-US; default options.
michael@0 35 collator = new Intl.Collator("en-US");
michael@0 36 expected = [
michael@0 37 "¡viva España!",
michael@0 38 "Argentina",
michael@0 39 "la France",
michael@0 40 "Oerlikon",
michael@0 41 "Offenbach",
michael@0 42 "Österreich",
michael@0 43 "Sverige",
michael@0 44 "Vaticano",
michael@0 45 "Zimbabwe",
michael@0 46 "한국",
michael@0 47 "中国",
michael@0 48 "日本",
michael@0 49 ];
michael@0 50 assertEqualArray(input.sort(collator.compare), expected, collator);
michael@0 51
michael@0 52 // Locale sv-SE; default options.
michael@0 53 // Swedish treats "Ö" as a separate character, which sorts after "Z".
michael@0 54 collator = new Intl.Collator("sv-SE");
michael@0 55 expected = [
michael@0 56 "¡viva España!",
michael@0 57 "Argentina",
michael@0 58 "la France",
michael@0 59 "Oerlikon",
michael@0 60 "Offenbach",
michael@0 61 "Sverige",
michael@0 62 "Vaticano",
michael@0 63 "Zimbabwe",
michael@0 64 "Österreich",
michael@0 65 "한국",
michael@0 66 "中国",
michael@0 67 "日本",
michael@0 68 ];
michael@0 69 assertEqualArray(input.sort(collator.compare), expected, collator);
michael@0 70
michael@0 71 // Locale sv-SE; ignore punctuation.
michael@0 72 collator = new Intl.Collator("sv-SE", {ignorePunctuation: true});
michael@0 73 expected = [
michael@0 74 "Argentina",
michael@0 75 "la France",
michael@0 76 "Oerlikon",
michael@0 77 "Offenbach",
michael@0 78 "Sverige",
michael@0 79 "Vaticano",
michael@0 80 "¡viva España!",
michael@0 81 "Zimbabwe",
michael@0 82 "Österreich",
michael@0 83 "한국",
michael@0 84 "中国",
michael@0 85 "日本",
michael@0 86 ];
michael@0 87 assertEqualArray(input.sort(collator.compare), expected, collator);
michael@0 88
michael@0 89 // Locale de-DE; default options.
michael@0 90 // In German standard sorting, umlauted characters are treated as variants
michael@0 91 // of their base characters: ä ≅ a, ö ≅ o, ü ≅ u.
michael@0 92 collator = new Intl.Collator("de-DE");
michael@0 93 expected = [
michael@0 94 "¡viva España!",
michael@0 95 "Argentina",
michael@0 96 "la France",
michael@0 97 "Oerlikon",
michael@0 98 "Offenbach",
michael@0 99 "Österreich",
michael@0 100 "Sverige",
michael@0 101 "Vaticano",
michael@0 102 "Zimbabwe",
michael@0 103 "한국",
michael@0 104 "中国",
michael@0 105 "日本",
michael@0 106 ];
michael@0 107 assertEqualArray(input.sort(collator.compare), expected, collator);
michael@0 108
michael@0 109 // Locale de-DE; phonebook sort order.
michael@0 110 // In German phonebook sorting, umlauted characters are expanded to two-vowel
michael@0 111 // sequences: ä → ae, ö → oe, ü → ue.
michael@0 112 collator = new Intl.Collator("de-DE-u-co-phonebk");
michael@0 113 expected = [
michael@0 114 "¡viva España!",
michael@0 115 "Argentina",
michael@0 116 "la France",
michael@0 117 "Oerlikon",
michael@0 118 "Österreich",
michael@0 119 "Offenbach",
michael@0 120 "Sverige",
michael@0 121 "Vaticano",
michael@0 122 "Zimbabwe",
michael@0 123 "한국",
michael@0 124 "中国",
michael@0 125 "日本",
michael@0 126 ];
michael@0 127 assertEqualArray(input.sort(collator.compare), expected, collator);
michael@0 128
michael@0 129 reportCompare(0, 0, 'ok');

mercurial