Debian Codegraph @

js/src/tests/test262/built-ins/encodeURIComponent/S15.1.3.4_A1.2_T2.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 [0xD800 - 0xDBFF] and string.length = k + 1, throw
7 URIError
8 esid: sec-encodeuricomponent-uricomponent
9 description: Complex tests
10 includes: [decimalToHexString.js]
11 ---*/
12
13 var errorCount = 0;
14 var count = 0;
15 var indexP;
16 var indexO = 0;
17
18 for (var index = 0xD800; index <= 0xDBFF; index++) {
19 count++;
20 try {
21 encodeURIComponent(String.fromCharCode(0x0041, index));
22 } catch (e) {
23 if ((e instanceof URIError) === true) 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);