summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/cacheir/string-codePointAt-surrogate.js
blob: 961953a5989b9b38a283eedd29b5e12d8c30b480 (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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();
}