From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../tests/warp/string-compare-char-string.js | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 js/src/jit-test/tests/warp/string-compare-char-string.js (limited to 'js/src/jit-test/tests/warp/string-compare-char-string.js') diff --git a/js/src/jit-test/tests/warp/string-compare-char-string.js b/js/src/jit-test/tests/warp/string-compare-char-string.js new file mode 100644 index 0000000000..f56009f5a1 --- /dev/null +++ b/js/src/jit-test/tests/warp/string-compare-char-string.js @@ -0,0 +1,60 @@ +// Test comparison against single-element character strings. + +function makeComparator(code) { + var str = String.fromCharCode(code); + + return Function("ch", "code", ` + assertEq(ch == "${str}", code == ${code} && ch.length == 1); + assertEq(ch != "${str}", code != ${code} || ch.length != 1); + + assertEq(ch < "${str}", code < ${code} || (code == ${code} && ch.length < 1)); + assertEq(ch <= "${str}", code < ${code} || (code == ${code} && ch.length <= 1)); + assertEq(ch > "${str}", code > ${code} || (code == ${code} && ch.length > 1)); + assertEq(ch >= "${str}", code > ${code} || (code == ${code} && ch.length >= 1)); + `); +} + +function testCompare(strings, comparator) { + // Don't Ion compile to ensure |comparator| won't be inlined. + with ({}) ; + + for (let i = 0; i < 1000; ++i) { + let str = strings[i % strings.length]; + + comparator("", -1); + + for (let j = 0; j < str.length; ++j) { + let ch = str.charAt(j); + let code = str.charCodeAt(j); + + comparator(ch, code); + comparator(ch + "A", code); + } + } +} + +// Compare against the Latin-1 character U+0062 ('b'). +testCompare([ + "", + "a", "b", "c", + "a-", "b-", "c-", + "a\u{100}", "b\u{100}", "c\u{100}", +], makeComparator(0x62)); + +// Compare against the maximum Latin-1 character U+00FF. +testCompare([ + "", + "a", "b", "c", + "a-", "b-", "c-", + "\u{fe}", "\u{ff}", "\u{100}", + "\u{fe}-", "\u{ff}-", "\u{100}-", +], makeComparator(0xff)); + +// Compare against the Two-byte character U+0101. +testCompare([ + "", + "a", "b", "c", + "a-", "b-", "c-", + "\u{100}", "\u{101}", "\u{102}", + "\u{100}-", "\u{101}-", "\u{102}-", +], makeComparator(0x101)); -- cgit v1.2.3