Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/encodeURIComponent/S15.1.3.4_A1.3_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 [0xD800 - 0xDBFF] and string.charAt(k+1) not in
7 [0xDC00 - 0xDFFF], throw URIError
8 es5id: 15.1.3.4_A1.3_T1
9 es6id: 18.2.6.5
10 esid: sec-encodeuricomponent-uricomponent
11 description: >
12 Complex tests, string.charAt(k+1) in [0x0000, 0xD7FF, 0xD800,
13 0xDBFE, 0xDBFF, 0xE000, 0xFFFF]
14 includes: [decimalToHexString.js]
15 ---*/
16
17 var chars = [0x0000, 0xD7FF, 0xD800, 0xDBFE, 0xDBFF, 0xE000, 0xFFFF];
18 var errorCount = 0;
19 var count = 0;
20 var indexP;
21 var indexO = 0;
22
23 for (var index = 0xD800; index <= 0xDBFF; index++) {
24 count++;
25 var res = true;
26 for (var indexC = 0; indexC < chars.length; indexC++) {
27 var hex = decimalToHexString(index);
28 try {
29 encodeURIComponent(String.fromCharCode(index, chars[indexC]));
30 } catch (e) {
31 if ((e instanceof URIError) === true) continue;
32 }
33 res = false;
34 }
35 if (res !== true) {
36 if (indexO === 0) {
37 indexO = index;
38 } else {
39 if ((index - indexP) !== 1) {
40 if ((indexP - indexO) !== 0) {
41 var hexP = decimalToHexString(indexP);
42 var hexO = decimalToHexString(indexO);
43 $ERROR('#' + hexO + '-' + hexP + ' ');
44 }
45 else {
46 var hexP = decimalToHexString(indexP);
47 $ERROR('#' + hexP + ' ');
48 }
49 indexO = index;
50 }
51 }
52 indexP = index;
53 errorCount++;
54 }
55 }
56
57 if (errorCount > 0) {
58 if ((indexP - indexO) !== 0) {
59 var hexP = decimalToHexString(indexP);
60 var hexO = decimalToHexString(indexO);
61 $ERROR('#' + hexO + '-' + hexP + ' ');
62 } else {
63 var hexP = decimalToHexString(indexP);
64 $ERROR('#' + hexP + ' ');
65 }
66 $ERROR('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' ');
67 }