diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/jit-test/tests/cacheir/string-codePointAt-surrogate.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/cacheir/string-codePointAt-surrogate.js')
-rw-r--r-- | js/src/jit-test/tests/cacheir/string-codePointAt-surrogate.js | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/cacheir/string-codePointAt-surrogate.js b/js/src/jit-test/tests/cacheir/string-codePointAt-surrogate.js new file mode 100644 index 0000000000..961953a598 --- /dev/null +++ b/js/src/jit-test/tests/cacheir/string-codePointAt-surrogate.js @@ -0,0 +1,103 @@ +function testLinear() { + var s = "\u{10000}\u{10001}\u{10002}\u{10003}\u{10004}\u{10005}\u{10006}\u{10007}"; + + for (var i = 0; i < 200; ++i) { + // Iterate over all possible string indices, which includes reading + // unpaired lead surrogates. + var index = i % s.length; + + var c = s.codePointAt(index); + var e = ((index & 1) ? 0xdc00 : 0x10000) + (index >> 1); + assertEq(c, e); + } +} +for (var i = 0; i < 2; ++i) { + testLinear(); +} + +function testLinearOnlyValidCodePoints() { + var s = "\u{10000}\u{10001}\u{10002}\u{10003}\u{10004}\u{10005}\u{10006}\u{10007}"; + + for (var i = 0; i < 200; ++i) { + // Iterator over all valid code point indices. (Code points are at all even + // string indices.) + var index = (i % s.length) & ~1; + + var c = s.codePointAt(index); + var e = ((index & 1) ? 0xdc00 : 0x10000) + (index >> 1); + assertEq(c, e); + } +} +for (var i = 0; i < 2; ++i) { + testLinearOnlyValidCodePoints(); +} + +function testRope() { + var left = "\u{10000}\u{10001}\u{10002}\u{10003}\u{10004}\u{10005}\u{10006}\u{10007}"; + var right = "\u{10008}\u{10009}\u{1000A}\u{1000B}\u{1000C}\u{1000D}\u{1000E}\u{1000F}"; + + for (var i = 0; i < 200; ++i) { + var s = newRope(left, right); + + // Iterate over all possible string indices, which includes reading + // unpaired lead surrogates. + var index = i % s.length; + + var c = s.codePointAt(index); + var e = ((index & 1) ? 0xdc00 : 0x10000) + (index >> 1); + assertEq(c, e); + } +} +for (var i = 0; i < 2; ++i) { + testRope(); +} + +function testRopeOnlyValidCodePoints() { + var left = "\u{10000}\u{10001}\u{10002}\u{10003}\u{10004}\u{10005}\u{10006}\u{10007}"; + var right = "\u{10008}\u{10009}\u{1000A}\u{1000B}\u{1000C}\u{1000D}\u{1000E}\u{1000F}"; + + for (var i = 0; i < 200; ++i) { + var s = newRope(left, right); + + // Iterator over all valid code point indices. (Code points are at all even + // string indices.) + var index = (i % s.length) & ~1; + + var c = s.codePointAt(index); + var e = ((index & 1) ? 0xdc00 : 0x10000) + (index >> 1); + assertEq(c, e); + } +} +for (var i = 0; i < 2; ++i) { + testRopeOnlyValidCodePoints(); +} + +function testUnpairedLead() { + var s = "\u{d800}\u{d801}\u{d802}\u{d803}\u{d804}\u{d805}\u{d806}\u{d807}"; + + for (var i = 0; i < 200; ++i) { + var index = i % s.length; + + var c = s.codePointAt(index); + var e = 0xd800 + index; + assertEq(c, e); + } +} +for (var i = 0; i < 2; ++i) { + testUnpairedLead(); +} + +function testUnpairedTail() { + var s = "\u{dc00}\u{dc01}\u{dc02}\u{dc03}\u{dc04}\u{dc05}\u{dc06}\u{dc07}"; + + for (var i = 0; i < 200; ++i) { + var index = i % s.length; + + var c = s.codePointAt(index); + var e = 0xdc00 + index; + assertEq(c, e); + } +} +for (var i = 0; i < 2; ++i) { + testUnpairedTail(); +} |