js/src/tests/ecma_6/String/normalize-generateddata.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(!xulRuntime.shell||!("normalize"in(String.prototype))) -- uses shell load() function, String.prototype.normalize is not enabled in all builds
michael@0 2 var BUGNUMBER = 918987;
michael@0 3 var summary = 'String.prototype.normalize';
michael@0 4
michael@0 5 print(BUGNUMBER + ": " + summary);
michael@0 6
michael@0 7 /**************
michael@0 8 * BEGIN TEST *
michael@0 9 **************/
michael@0 10
michael@0 11 load('ecma_6/String/normalize-generateddata-input.js');
michael@0 12
michael@0 13 function codePointsToString(points) {
michael@0 14 return points.map(x => String.fromCodePoint(x)).join("");
michael@0 15 }
michael@0 16 function stringify(points) {
michael@0 17 return points.map(x => x.toString(16)).join();
michael@0 18 }
michael@0 19
michael@0 20 function runTest(test) {
michael@0 21 var source = codePointsToString(test.source);
michael@0 22 var NFC = codePointsToString(test.NFC);
michael@0 23 var NFD = codePointsToString(test.NFD);
michael@0 24 var NFKC = codePointsToString(test.NFKC);
michael@0 25 var NFKD = codePointsToString(test.NFKD);
michael@0 26 var sourceStr = stringify(test.source);
michael@0 27 var nfcStr = stringify(test.NFC);
michael@0 28 var nfdStr = stringify(test.NFD);
michael@0 29 var nfkcStr = stringify(test.NFKC);
michael@0 30 var nfkdStr = stringify(test.NFKD);
michael@0 31
michael@0 32 /* NFC */
michael@0 33 assertEq(source.normalize(), NFC, "NFC of " + sourceStr);
michael@0 34 assertEq(NFC.normalize(), NFC, "NFC of " + nfcStr);
michael@0 35 assertEq(NFD.normalize(), NFC, "NFC of " + nfdStr);
michael@0 36 assertEq(NFKC.normalize(), NFKC, "NFC of " + nfkcStr);
michael@0 37 assertEq(NFKD.normalize(), NFKC, "NFC of " + nfkdStr);
michael@0 38
michael@0 39 assertEq(source.normalize(undefined), NFC, "NFC of " + sourceStr);
michael@0 40 assertEq(NFC.normalize(undefined), NFC, "NFC of " + nfcStr);
michael@0 41 assertEq(NFD.normalize(undefined), NFC, "NFC of " + nfdStr);
michael@0 42 assertEq(NFKC.normalize(undefined), NFKC, "NFC of " + nfkcStr);
michael@0 43 assertEq(NFKD.normalize(undefined), NFKC, "NFC of " + nfkdStr);
michael@0 44
michael@0 45 assertEq(source.normalize("NFC"), NFC, "NFC of " + sourceStr);
michael@0 46 assertEq(NFC.normalize("NFC"), NFC, "NFC of " + nfcStr);
michael@0 47 assertEq(NFD.normalize("NFC"), NFC, "NFC of " + nfdStr);
michael@0 48 assertEq(NFKC.normalize("NFC"), NFKC, "NFC of " + nfkcStr);
michael@0 49 assertEq(NFKD.normalize("NFC"), NFKC, "NFC of " + nfkdStr);
michael@0 50
michael@0 51 /* NFD */
michael@0 52 assertEq(source.normalize("NFD"), NFD, "NFD of " + sourceStr);
michael@0 53 assertEq(NFC.normalize("NFD"), NFD, "NFD of " + nfcStr);
michael@0 54 assertEq(NFD.normalize("NFD"), NFD, "NFD of " + nfdStr);
michael@0 55 assertEq(NFKC.normalize("NFD"), NFKD, "NFD of " + nfkcStr);
michael@0 56 assertEq(NFKD.normalize("NFD"), NFKD, "NFD of " + nfkdStr);
michael@0 57
michael@0 58 /* NFKC */
michael@0 59 assertEq(source.normalize("NFKC"), NFKC, "NFKC of " + sourceStr);
michael@0 60 assertEq(NFC.normalize("NFKC"), NFKC, "NFKC of " + nfcStr);
michael@0 61 assertEq(NFD.normalize("NFKC"), NFKC, "NFKC of " + nfdStr);
michael@0 62 assertEq(NFKC.normalize("NFKC"), NFKC, "NFKC of " + nfkcStr);
michael@0 63 assertEq(NFKD.normalize("NFKC"), NFKC, "NFKC of " + nfkdStr);
michael@0 64
michael@0 65 /* NFKD */
michael@0 66 assertEq(source.normalize("NFKD"), NFKD, "NFKD of " + sourceStr);
michael@0 67 assertEq(NFC.normalize("NFKD"), NFKD, "NFKD of " + nfcStr);
michael@0 68 assertEq(NFD.normalize("NFKD"), NFKD, "NFKD of " + nfdStr);
michael@0 69 assertEq(NFKC.normalize("NFKD"), NFKD, "NFKD of " + nfkcStr);
michael@0 70 assertEq(NFKD.normalize("NFKD"), NFKD, "NFKD of " + nfkdStr);
michael@0 71 }
michael@0 72
michael@0 73 for (var test0 of tests_part0) {
michael@0 74 runTest(test0);
michael@0 75 }
michael@0 76 var part1 = new Set();
michael@0 77 for (var test1 of tests_part1) {
michael@0 78 part1.add(test1.source[0]);
michael@0 79 runTest(test1);
michael@0 80 }
michael@0 81 for (var test2 of tests_part2) {
michael@0 82 runTest(test2);
michael@0 83 }
michael@0 84 for (var test3 of tests_part3) {
michael@0 85 runTest(test3);
michael@0 86 }
michael@0 87
michael@0 88 /* not listed in Part 1 */
michael@0 89 for (var x = 0; x <= 0x2FFFF; x++) {
michael@0 90 if (part1.has(x)) {
michael@0 91 continue;
michael@0 92 }
michael@0 93 var xstr = x.toString(16);
michael@0 94 var c = String.fromCodePoint(x);
michael@0 95 assertEq(c.normalize(), c, "NFC of " + xstr);
michael@0 96 assertEq(c.normalize(undefined), c, "NFC of " + xstr);
michael@0 97 assertEq(c.normalize("NFC"), c, "NFC of " + xstr);
michael@0 98 assertEq(c.normalize("NFD"), c, "NFD of " + xstr);
michael@0 99 assertEq(c.normalize("NFKC"), c, "NFKC of " + xstr);
michael@0 100 assertEq(c.normalize("NFKD"), c, "NFKD of " + xstr);
michael@0 101 }
michael@0 102
michael@0 103 var myobj = {toString : (function () "a\u0301"), normalize : String.prototype.normalize};
michael@0 104 assertEq(myobj.normalize(), "\u00E1");
michael@0 105
michael@0 106 assertThrowsInstanceOf(function() {
michael@0 107 "abc".normalize("NFE");
michael@0 108 }, RangeError,
michael@0 109 "String.prototype.normalize should raise RangeError on invalid form");
michael@0 110
michael@0 111 assertEq("".normalize(), "");
michael@0 112
michael@0 113 /* JSRope test */
michael@0 114 var a = "";
michael@0 115 var b = "";
michael@0 116 for (var i = 0; i < 100; i++) {
michael@0 117 a += "\u0100";
michael@0 118 b += "\u0041\u0304";
michael@0 119 }
michael@0 120 assertEq(a.normalize("NFD"), b);
michael@0 121
michael@0 122 /******************************************************************************/
michael@0 123
michael@0 124 if (typeof reportCompare === "function")
michael@0 125 reportCompare(true, true);
michael@0 126 print("Tests complete");

mercurial