summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/warp/string-compare-char-in-bounds.js
blob: 31c48a43fd6d7145d28406ac57acac2ea0700746 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// |str.char(idx) == "b"| is compiled as |str.charCodeAt(idx) == 0x62|.

const strings = [
  "a", "b", "c",
  "a-", "b-", "c-",
];

for (let i = 0; i < 1000; ++i) {
  let str = strings[i % strings.length];

  for (let j = 0; j < str.length; ++j) {
    let ch = str.charAt(j);
    let code = str.charCodeAt(j);

    assertEq(ch == "b", code == 0x62);
    assertEq(ch != "b", code != 0x62);

    assertEq(ch < "b", code < 0x62);
    assertEq(ch <= "b", code <= 0x62);

    assertEq(ch > "b", code > 0x62);
    assertEq(ch >= "b", code >= 0x62);
  }
}