Debian Codegraph @

js/src/tests/test262/built-ins/encodeURI/S15.1.3.3_A2.2_T1.js

raw
1 // Copyright 2009 the Sputnik authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 info: |
6 If string.charAt(k) in [0x0080 - 0x07FF], return 2 octets (00000yyy
7 yyzzzzzz -> 110yyyyy 10zzzzzz)
8 esid: sec-encodeuri-uri
9 description: Complex tests, use RFC 3629
10 includes: [decimalToHexString.js]
11 ---*/
12
13 var errorCount = 0;
14 var count = 0;
15 var indexP;
16 var indexO = 0;
17 l:
18 for (var index = 0x0080; index <= 0x07FF; index++) {
19 count++;
20 var hex1 = decimalToPercentHexString(0x0080 + (index & 0x003F));
21 var hex2 = decimalToPercentHexString(0x00C0 + (index & 0x07C0) / 0x0040);
22 var str = String.fromCharCode(index);
23 if (encodeURI(str).toUpperCase() === hex2 + hex1) continue;
24
25 if (indexO === 0) {
26 indexO = index;
27 } else {
28 if ((index - indexP) !== 1) {
29 if ((indexP - indexO) !== 0) {
30 var hexP = decimalToHexString(indexP);
31 var hexO = decimalToHexString(indexO);
32 throw new Test262Error('#' + hexO + '-' + hexP + ' ');
33 }
34 else {
35 var hexP = decimalToHexString(indexP);
36 throw new Test262Error('#' + hexP + ' ');
37 }
38 indexO = index;
39 }
40 }
41 indexP = index;
42 errorCount++;
43 }
44
45 if (errorCount > 0) {
46 if ((indexP - indexO) !== 0) {
47 var hexP = decimalToHexString(indexP);
48 var hexO = decimalToHexString(indexO);
49 throw new Test262Error('#' + hexO + '-' + hexP + ' ');
50 } else {
51 var hexP = decimalToHexString(indexP);
52 throw new Test262Error('#' + hexP + ' ');
53 }
54 throw new Test262Error('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' ');
55 }
56
57 reportCompare(0, 0);