tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

indexing.js (1097B)


      1 function testCharCodeAt() {
      2    var s = "abcdefghijklm1234567891000";
      3    for (var i=0; i<10; i++)
      4 assertEq(s.charCodeAt(i), 97 + i);
      5 
      6    var rope = s + "blah";
      7    assertEq(rope.charCodeAt(s.length + 3), 104);
      8 
      9    rope = s + "Foo987";
     10    assertEq(rope.charCodeAt(s.length + 4), 56);
     11 
     12    rope = "twoByte\u0580" + s;
     13    assertEq(rope.charCodeAt(7), 0x580);
     14    assertEq(rope.charCodeAt(14), 103);
     15 }
     16 testCharCodeAt();
     17 
     18 function testCharAt() {
     19    var s = "abcdefghijklm100000002345";
     20    assertEq(s.charAt(0), "a");
     21    assertEq(s.charAt(s.length-1), "5");
     22    assertEq(s.charAt(s.length), "");
     23 
     24    var rope = s + "abcZYX";
     25    assertEq(rope.charAt(s.length + 3), "Z");
     26 
     27    rope = s + "Foo987";
     28    assertEq(rope.charAt(s.length + 4), "8");
     29 
     30    rope = "twoByte\u0580" + s;
     31    assertEq(rope.charAt(7), "\u0580");
     32    assertEq(rope.charAt(14), "g");
     33 }
     34 testCharAt();
     35 
     36 function testIndex(s) {
     37    assertEq(s[0], "a");
     38    assertEq(s[s.length-1], "6");
     39 
     40    rope = "twoByte\u0512" + s
     41    assertEq(rope[7], "\u0512");
     42 }
     43 
     44 var s = "abcdefghijklm123456";
     45 testIndex(s);
     46 testIndex(s);
     47 testIndex(s);