test262/website/resources/scripts/testcases2/15.1.3.3_encodeURI.json

177 lines
36 KiB
JSON

{
"testCollection": {
"name": "15.1.3.3_encodeURI",
"numTests": 28,
"tests": [
{
"section": "15.1.3.3",
"description": "Complex tests",
"test": "errorCount = 0;\ncount = 0;\nvar indexP;\nvar indexO = 0;\n\nfor (index = 0xDC00; index <= 0xDFFF; index++) {\n count++; \n hex = decimalToHexString(index);\n try {\n encodeURI(String.fromCharCode(index));\n } catch (e) { \n if ((e instanceof URIError) === true) continue; \n }\n if (indexO === 0) { \n indexO = index;\n } else {\n if ((index - indexP) !== 1) { \n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } \n else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n indexO = index;\n } \n }\n indexP = index;\n errorCount++; \n}\n\nif (errorCount > 0) {\n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n $ERROR('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' ');\n}\n\nfunction decimalToHexString(n) {\n n = Number(n);\n var h = \"\";\n for (var i = 3; i >= 0; i--) {\n if (n >= Math.pow(16, i)) {\n var t = Math.floor(n / Math.pow(16, i));\n n -= t * Math.pow(16, i);\n if ( t >= 10 ) {\n if ( t == 10 ) { h += \"A\"; }\n if ( t == 11 ) { h += \"B\"; }\n if ( t == 12 ) { h += \"C\"; }\n if ( t == 13 ) { h += \"D\"; }\n if ( t == 14 ) { h += \"E\"; }\n if ( t == 15 ) { h += \"F\"; }\n } else {\n h += String(t);\n }\n } else {\n h += \"0\";\n }\n }\n return h;\n}\n",
"id": "S15.1.3.3_A1.1_T1"
},
{
"section": "15.1.3.3",
"description": "Complex tests",
"test": "errorCount = 0;\ncount = 0;\nvar indexP;\nvar indexO = 0;\n\nfor (index = 0xDC00; index <= 0xDFFF; index++) { \n count++; \n hex = decimalToHexString(index);\n try {\n encodeURI(String.fromCharCode(index, 0x0041));\n } catch (e) { \n if ((e instanceof URIError) === true) continue; \n }\n if (indexO === 0) { \n indexO = index;\n } else {\n if ((index - indexP) !== 1) { \n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } \n else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n indexO = index;\n } \n }\n indexP = index;\n errorCount++; \n}\n\nif (errorCount > 0) {\n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n $ERROR('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' ');\n}\n\nfunction decimalToHexString(n) {\n n = Number(n);\n var h = \"\";\n for (var i = 3; i >= 0; i--) {\n if (n >= Math.pow(16, i)) {\n var t = Math.floor(n / Math.pow(16, i));\n n -= t * Math.pow(16, i);\n if ( t >= 10 ) {\n if ( t == 10 ) { h += \"A\"; }\n if ( t == 11 ) { h += \"B\"; }\n if ( t == 12 ) { h += \"C\"; }\n if ( t == 13 ) { h += \"D\"; }\n if ( t == 14 ) { h += \"E\"; }\n if ( t == 15 ) { h += \"F\"; }\n } else {\n h += String(t);\n }\n } else {\n h += \"0\";\n }\n }\n return h;\n}\n",
"id": "S15.1.3.3_A1.1_T2"
},
{
"section": "15.1.3.3",
"description": "Complex tests",
"test": "errorCount = 0;\ncount = 0;\nvar indexP;\nvar indexO = 0;\n\nfor (index = 0xD800; index <= 0xDBFF; index++) {\n count++; \n hex = decimalToHexString(index);\n try {\n encodeURI(String.fromCharCode(index));\n } catch (e) { \n if ((e instanceof URIError) === true) continue; \n }\n if (indexO === 0) { \n indexO = index;\n } else {\n if ((index - indexP) !== 1) { \n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } \n else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n indexO = index;\n } \n }\n indexP = index;\n errorCount++; \n}\n\nif (errorCount > 0) {\n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n $ERROR('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' ');\n}\n\nfunction decimalToHexString(n) {\n n = Number(n);\n var h = \"\";\n for (var i = 3; i >= 0; i--) {\n if (n >= Math.pow(16, i)) {\n var t = Math.floor(n / Math.pow(16, i));\n n -= t * Math.pow(16, i);\n if ( t >= 10 ) {\n if ( t == 10 ) { h += \"A\"; }\n if ( t == 11 ) { h += \"B\"; }\n if ( t == 12 ) { h += \"C\"; }\n if ( t == 13 ) { h += \"D\"; }\n if ( t == 14 ) { h += \"E\"; }\n if ( t == 15 ) { h += \"F\"; }\n } else {\n h += String(t);\n }\n } else {\n h += \"0\";\n }\n }\n return h;\n}\n",
"id": "S15.1.3.3_A1.2_T1"
},
{
"section": "15.1.3.3",
"description": "Complex tests",
"test": "errorCount = 0;\ncount = 0;\nvar indexP;\nvar indexO = 0;\n\nfor (index = 0xD800; index <= 0xDBFF; index++) { \n count++; \n hex = decimalToHexString(index);\n try {\n encodeURI(String.fromCharCode(0x0041, index));\n } catch (e) { \n if ((e instanceof URIError) === true) continue; \n }\n if (indexO === 0) { \n indexO = index;\n } else {\n if ((index - indexP) !== 1) { \n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } \n else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n indexO = index;\n } \n }\n indexP = index;\n errorCount++; \n}\n\nif (errorCount > 0) {\n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n $ERROR('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' ');\n}\n\nfunction decimalToHexString(n) {\n n = Number(n);\n var h = \"\";\n for (var i = 3; i >= 0; i--) {\n if (n >= Math.pow(16, i)) {\n var t = Math.floor(n / Math.pow(16, i));\n n -= t * Math.pow(16, i);\n if ( t >= 10 ) {\n if ( t == 10 ) { h += \"A\"; }\n if ( t == 11 ) { h += \"B\"; }\n if ( t == 12 ) { h += \"C\"; }\n if ( t == 13 ) { h += \"D\"; }\n if ( t == 14 ) { h += \"E\"; }\n if ( t == 15 ) { h += \"F\"; }\n } else {\n h += String(t);\n }\n } else {\n h += \"0\";\n }\n }\n return h;\n}\n",
"id": "S15.1.3.3_A1.2_T2"
},
{
"section": "15.1.3.3",
"description": "Complex tests, string.charAt(k+1) in [0x0000, 0xD7FF, 0xD800, 0xDBFE, 0xDBFF, 0xE000, 0xFFFF]",
"test": "chars = [0x0000, 0xD7FF, 0xD800, 0xDBFE, 0xDBFF, 0xE000, 0xFFFF];\nerrorCount = 0;\ncount = 0;\nvar indexP;\nvar indexO = 0;\n\nfor (index = 0xD800; index <= 0xDBFF; index++) {\n count++; \n res = true;\n for (indexC = 0; indexC < chars.length; indexC++) { \n hex = decimalToHexString(index);\n try {\n encodeURI(String.fromCharCode(index, chars[indexC])); \n } catch (e) { \n if ((e instanceof URIError) === true) continue;\n }\n res = false;\n }\n if (res !== true) {\n if (indexO === 0) { \n indexO = index;\n } else {\n if ((index - indexP) !== 1) { \n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } \n else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n indexO = index;\n } \n }\n indexP = index;\n errorCount++; \n } \n}\n\nif (errorCount > 0) {\n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n $ERROR('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' ');\n}\n\nfunction decimalToHexString(n) {\n n = Number(n);\n var h = \"\";\n for (var i = 3; i >= 0; i--) {\n if (n >= Math.pow(16, i)) {\n var t = Math.floor(n / Math.pow(16, i));\n n -= t * Math.pow(16, i);\n if ( t >= 10 ) {\n if ( t == 10 ) { h += \"A\"; }\n if ( t == 11 ) { h += \"B\"; }\n if ( t == 12 ) { h += \"C\"; }\n if ( t == 13 ) { h += \"D\"; }\n if ( t == 14 ) { h += \"E\"; }\n if ( t == 15 ) { h += \"F\"; }\n } else {\n h += String(t);\n }\n } else {\n h += \"0\";\n }\n }\n return h;\n}\n",
"id": "S15.1.3.3_A1.3_T1"
},
{
"section": "15.1.3.3",
"description": "Complex tests, use RFC 3629",
"test": "uriReserved = [\";\", \"/\", \"?\", \":\", \"@\", \"&\", \"=\", \"+\", \"$\", \",\"];\nuriUnescaped = [\"-\", \"_\", \".\", \"!\", \"~\", \"*\", \"'\", \"(\", \")\", \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \"M\", \"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\", \"Z\", \"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\", \"n\", \"o\", \"p\", \"q\", \"r\", \"s\", \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\", \"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"]; \nerrorCount = 0;\ncount = 0;\nvar indexP;\nvar indexO = 0;\n\nl : \nfor (index = 0x0000; index <= 0x007F; index++) {\n count++;\n str = String.fromCharCode(index);\n for (indexC = 0; indexC < uriReserved.length; indexC++) { \n if (uriReserved[indexC] === str) continue l;\n }\n for (indexC = 0; indexC < uriUnescaped.length; indexC++) {\n if (uriUnescaped[indexC] === str) continue l;\n } \n if (\"#\" === str) continue l; \n try {\n if (encodeURI(str).toUpperCase() === \"%\" + decimalToHexString(index).substring(2)) continue l; \n } catch(e) {} \n if (indexO === 0) { \n indexO = index;\n } else {\n if ((index - indexP) !== 1) { \n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } \n else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n indexO = index;\n } \n }\n indexP = index;\n errorCount++; \n}\n\nif (errorCount > 0) {\n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n $ERROR('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' ');\n}\n\nfunction decimalToHexString(n) {\n n = Number(n);\n var h = \"\";\n for (var i = 3; i >= 0; i--) {\n if (n >= Math.pow(16, i)) {\n var t = Math.floor(n / Math.pow(16, i));\n n -= t * Math.pow(16, i);\n if ( t >= 10 ) {\n if ( t == 10 ) { h += \"A\"; }\n if ( t == 11 ) { h += \"B\"; }\n if ( t == 12 ) { h += \"C\"; }\n if ( t == 13 ) { h += \"D\"; }\n if ( t == 14 ) { h += \"E\"; }\n if ( t == 15 ) { h += \"F\"; }\n } else {\n h += String(t);\n }\n } else {\n h += \"0\";\n }\n }\n return h;\n}\n",
"id": "S15.1.3.3_A2.1_T1"
},
{
"section": "15.1.3.3",
"description": "Complex tests, use RFC 3629",
"test": "errorCount = 0;\ncount = 0;\nvar indexP;\nvar indexO = 0; \nl:\nfor (index = 0x0080; index <= 0x07FF; index++) {\n count++; \n hex1 = decimalToHexString(0x0080 + (index & 0x003F)).substring(2);\n hex2 = decimalToHexString(0x00C0 + (index & 0x07C0) / 0x0040).substring(2); \n str = String.fromCharCode(index);\n try {\n if (encodeURI(str).toUpperCase() === \"%\" + hex2 + \"%\" + hex1) continue;\n } catch(e) {} \n if (indexO === 0) { \n indexO = index;\n } else {\n if ((index - indexP) !== 1) { \n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } \n else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n indexO = index;\n } \n }\n indexP = index;\n errorCount++; \n}\n\nif (errorCount > 0) {\n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n $ERROR('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' ');\n}\n\nfunction decimalToHexString(n) {\n n = Number(n);\n var h = \"\";\n for (var i = 3; i >= 0; i--) {\n if (n >= Math.pow(16, i)) {\n var t = Math.floor(n / Math.pow(16, i));\n n -= t * Math.pow(16, i);\n if ( t >= 10 ) {\n if ( t == 10 ) { h += \"A\"; }\n if ( t == 11 ) { h += \"B\"; }\n if ( t == 12 ) { h += \"C\"; }\n if ( t == 13 ) { h += \"D\"; }\n if ( t == 14 ) { h += \"E\"; }\n if ( t == 15 ) { h += \"F\"; }\n } else {\n h += String(t);\n }\n } else {\n h += \"0\";\n }\n }\n return h;\n}\n",
"id": "S15.1.3.3_A2.2_T1"
},
{
"section": "15.1.3.3",
"description": "Complex tests, use RFC 3629",
"test": "errorCount = 0;\ncount = 0;\nvar indexP;\nvar indexO = 0; \nfor (index = 0x0800; index <= 0xD7FF; index++) {\n count++; \n hex1 = decimalToHexString(0x0080 + (index & 0x003F)).substring(2);\n hex2 = decimalToHexString(0x0080 + (index & 0x0FC0) / 0x0040).substring(2);\n hex3 = decimalToHexString(0x00E0 + (index & 0xF000) / 0x1000).substring(2);\n str = String.fromCharCode(index);\n try {\n if (encodeURI(str).toUpperCase() === \"%\" + hex3 + \"%\" + hex2 + \"%\" + hex1) continue;\n } catch(e) {} \n if (indexO === 0) { \n indexO = index;\n } else {\n if ((index - indexP) !== 1) { \n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } \n else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n indexO = index;\n } \n }\n indexP = index;\n errorCount++; \n} \n\nif (errorCount > 0) {\n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n $ERROR('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' ');\n}\n\nfunction decimalToHexString(n) {\n n = Number(n);\n var h = \"\";\n for (var i = 3; i >= 0; i--) {\n if (n >= Math.pow(16, i)) {\n var t = Math.floor(n / Math.pow(16, i));\n n -= t * Math.pow(16, i);\n if ( t >= 10 ) {\n if ( t == 10 ) { h += \"A\"; }\n if ( t == 11 ) { h += \"B\"; }\n if ( t == 12 ) { h += \"C\"; }\n if ( t == 13 ) { h += \"D\"; }\n if ( t == 14 ) { h += \"E\"; }\n if ( t == 15 ) { h += \"F\"; }\n } else {\n h += String(t);\n }\n } else {\n h += \"0\";\n }\n }\n return h;\n}\n",
"id": "S15.1.3.3_A2.3_T1"
},
{
"section": "15.1.3.3",
"description": "Complex tests, use RFC 3629, string.charAt(k+1) in [0xDC00, 0xDDFF, 0xDFFF]",
"test": "chars = [0xDC00, 0xDDFF, 0xDFFF]; \nerrorCount = 0;\ncount = 0;\nvar indexP;\nvar indexO = 0; \nfor (index = 0xD800; index <= 0xDBFF; index++) {\n res = true;\n for (indexC = 0; indexC < chars.length; indexC++) {\n index1 = (index - 0xD800) * 0x400 + (chars[indexC] - 0xDC00) + 0x10000; \n hex1 = decimalToHexString(0x0080 + (index1 & 0x003F)).substring(2);\n hex2 = decimalToHexString(0x0080 + (index1 & 0x0FC0) / 0x0040).substring(2);\n hex3 = decimalToHexString(0x0080 + (index1 & 0x3F000) / 0x1000).substring(2);\n hex4 = decimalToHexString(0x00F0 + (index1 & 0x1C0000) / 0x40000).substring(2);\n str = String.fromCharCode(index, chars[indexC]);\n try {\n if (encodeURI(str).toUpperCase() !== \"%\" + hex4 + \"%\" + hex3 + \"%\" + hex2 + \"%\" + hex1) {\n res = false;\n }\n } catch(e) {res = false} \n }\n if (res !== true) { \n if (indexO === 0) { \n indexO = index;\n } else {\n if ((index - indexP) !== 1) { \n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } \n else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n indexO = index;\n } \n }\n indexP = index;\n errorCount++; \n }\n count++; \n}\n\nif (errorCount > 0) {\n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n $ERROR('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' ');\n}\n\nfunction decimalToHexString(n) {\n n = Number(n);\n var h = \"\";\n for (var i = 3; i >= 0; i--) {\n if (n >= Math.pow(16, i)) {\n var t = Math.floor(n / Math.pow(16, i));\n n -= t * Math.pow(16, i);\n if ( t >= 10 ) {\n if ( t == 10 ) { h += \"A\"; }\n if ( t == 11 ) { h += \"B\"; }\n if ( t == 12 ) { h += \"C\"; }\n if ( t == 13 ) { h += \"D\"; }\n if ( t == 14 ) { h += \"E\"; }\n if ( t == 15 ) { h += \"F\"; }\n } else {\n h += String(t);\n }\n } else {\n h += \"0\";\n }\n }\n return h;\n}\n",
"id": "S15.1.3.3_A2.4_T1"
},
{
"section": "15.1.3.3",
"description": "Complex tests, use RFC 3629, string.charAt(k) in [0xD800, 0xDBFF, 0xD9FF]",
"test": "chars = [0xD800, 0xDBFF, 0xD9FF]; \nerrorCount = 0;\ncount = 0;\nvar indexP;\nvar indexO = 0; \nfor (index = 0xDC00; index <= 0xDFFF; index++) {\n res = true;\n for (indexC = 0; indexC < chars.length; indexC++) {\n index1 = (chars[indexC] - 0xD800) * 0x400 + (index - 0xDC00) + 0x10000; \n hex1 = decimalToHexString(0x0080 + (index1 & 0x003F)).substring(2);\n hex2 = decimalToHexString(0x0080 + (index1 & 0x0FC0) / 0x0040).substring(2);\n hex3 = decimalToHexString(0x0080 + (index1 & 0x3F000) / 0x1000).substring(2);\n hex4 = decimalToHexString(0x00F0 + (index1 & 0x1C0000) / 0x40000).substring(2);\n str = String.fromCharCode(chars[indexC], index);\n try {\n if (encodeURI(str).toUpperCase() !== \"%\" + hex4 + \"%\" + hex3 + \"%\" + hex2 + \"%\" + hex1) {\n res = false;\n }\n } catch(e) {res = false} \n }\n if (res !== true) { \n if (indexO === 0) { \n indexO = index;\n } else {\n if ((index - indexP) !== 1) { \n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } \n else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n indexO = index;\n } \n }\n indexP = index;\n errorCount++; \n }\n count++; \n}\n\nif (errorCount > 0) {\n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n $ERROR('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' ');\n}\n\nfunction decimalToHexString(n) {\n n = Number(n);\n var h = \"\";\n for (var i = 3; i >= 0; i--) {\n if (n >= Math.pow(16, i)) {\n var t = Math.floor(n / Math.pow(16, i));\n n -= t * Math.pow(16, i);\n if ( t >= 10 ) {\n if ( t == 10 ) { h += \"A\"; }\n if ( t == 11 ) { h += \"B\"; }\n if ( t == 12 ) { h += \"C\"; }\n if ( t == 13 ) { h += \"D\"; }\n if ( t == 14 ) { h += \"E\"; }\n if ( t == 15 ) { h += \"F\"; }\n } else {\n h += String(t);\n }\n } else {\n h += \"0\";\n }\n }\n return h;\n}\n",
"id": "S15.1.3.3_A2.4_T2"
},
{
"section": "15.1.3.3",
"description": "Complex tests, use RFC 3629",
"test": "errorCount = 0;\ncount = 0;\nvar indexP;\nvar indexO = 0; \nfor (index = 0xE000; index <= 0xFFFF; index++) {\n count++; \n hex1 = decimalToHexString(0x0080 + (index & 0x003F)).substring(2);\n hex2 = decimalToHexString(0x0080 + (index & 0x0FC0) / 0x0040).substring(2);\n hex3 = decimalToHexString(0x00E0 + (index & 0xF000) / 0x1000).substring(2);\n str = String.fromCharCode(index);\n try {\n if (encodeURI(str).toUpperCase() === \"%\" + hex3 + \"%\" + hex2 + \"%\" + hex1) continue;\n } catch(e) {} \n if (indexO === 0) { \n indexO = index;\n } else {\n if ((index - indexP) !== 1) { \n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } \n else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n indexO = index;\n } \n }\n indexP = index;\n errorCount++; \n}\n\nif (errorCount > 0) {\n if ((indexP - indexO) !== 0) {\n var hexP = decimalToHexString(indexP);\n var hexO = decimalToHexString(indexO);\n $ERROR('#' + hexO + '-' + hexP + ' ');\n } else {\n var hexP = decimalToHexString(indexP);\n $ERROR('#' + hexP + ' ');\n } \n $ERROR('Total error: ' + errorCount + ' bad Unicode character in ' + count + ' ');\n}\n\nfunction decimalToHexString(n) {\n n = Number(n);\n var h = \"\";\n for (var i = 3; i >= 0; i--) {\n if (n >= Math.pow(16, i)) {\n var t = Math.floor(n / Math.pow(16, i));\n n -= t * Math.pow(16, i);\n if ( t >= 10 ) {\n if ( t == 10 ) { h += \"A\"; }\n if ( t == 11 ) { h += \"B\"; }\n if ( t == 12 ) { h += \"C\"; }\n if ( t == 13 ) { h += \"D\"; }\n if ( t == 14 ) { h += \"E\"; }\n if ( t == 15 ) { h += \"F\"; }\n } else {\n h += String(t);\n }\n } else {\n h += \"0\";\n }\n }\n return h;\n}\n",
"id": "S15.1.3.3_A2.5_T1"
},
{
"section": "15.1.3.3",
"description": "Complex tests",
"test": "uriReserved = [\";\", \"/\", \"?\", \":\", \"@\", \"&\", \"=\", \"+\", \"$\", \",\"];\nfor (indexC = 0; indexC < uriReserved.length; indexC++) {\n var str = uriReserved[indexC]; \n if (encodeURI(str) !== str) {\n $ERROR('#' + (indexC + 1) + ': unescapedURISet containing' + str);\n } \n}\n",
"id": "S15.1.3.3_A3.1_T1"
},
{
"section": "15.1.3.3",
"description": "Complex tests, uriUnescaped :: uriAlpha",
"test": "uriAlpha = [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \"M\", \"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\", \"Z\", \"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\", \"n\", \"o\", \"p\", \"q\", \"r\", \"s\", \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\"];\nfor (indexC = 0; indexC < uriAlpha.length; indexC++) {\n var str = uriAlpha[indexC]; \n if (encodeURI(str) !== str) {\n $ERROR('#' + (indexC + 1) + ': unescapedURISet containing ' + str);\n } \n}\n",
"id": "S15.1.3.3_A3.2_T1"
},
{
"section": "15.1.3.3",
"description": "Complex tests, uriUnescaped :: DecimalDigit",
"test": "DecimalDigit = [\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"];\nfor (indexC = 0; indexC < DecimalDigit.length; indexC++) {\n var str = DecimalDigit[indexC]; \n if (encodeURI(str) !== str) {\n $ERROR('#' + (indexC + 1) + ': unescapedURISet containing' + str);\n } \n}\n",
"id": "S15.1.3.3_A3.2_T2"
},
{
"section": "15.1.3.3",
"description": "Complex tests, uriUnescaped :: uriMark",
"test": "uriMark = [\"-\", \"_\", \".\", \"!\", \"~\", \"*\", \"'\", \"(\", \")\"];\nfor (indexC = 0; indexC < uriMark.length; indexC++) {\n var str = uriMark[indexC]; \n if (encodeURI(str) !== str) {\n $ERROR('#' + (indexC + 1) + ': unescapedURISet containing' + str);\n } \n}\n",
"id": "S15.1.3.3_A3.2_T3"
},
{
"section": "15.1.3.3",
"description": "encodeURI(\"#\") === \"#\"",
"test": "if (encodeURI(\"#\") !== \"#\") {\n $ERROR('#1: unescapedURISet containing \"#\"');\n} \n",
"id": "S15.1.3.3_A3.3_T1"
},
{
"section": "15.1.3.3",
"description": "Checking ENGLISH ALPHABET",
"test": "//CHECK#1\nif (encodeURI(\"http://unipro.ru/0123456789\") !== \"http://unipro.ru/0123456789\") {\n $ERROR('#1: http://unipro.ru/0123456789');\n}\n\n//CHECK#2\nif (encodeURI(\"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") !== \"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ\") {\n $ERROR('#2: aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ');\n}\n\n//CHECK#3\nif (encodeURI(\"aA_bB-cC.dD!eE~fF*gG'hH(iI)jJ;kK/lL?mM:nN@oO&pP=qQ+rR$sS,tT9uU8vV7wW6xX5yY4zZ\") !== \"aA_bB-cC.dD!eE~fF*gG'hH(iI)jJ;kK/lL?mM:nN@oO&pP=qQ+rR$sS,tT9uU8vV7wW6xX5yY4zZ\") {\n $ERROR('#3: ');\n}\n",
"id": "S15.1.3.3_A4_T1"
},
{
"section": "15.1.3.3",
"description": "Checking RUSSIAN ALPHABET",
"test": "//CHECK#1\nif ((encodeURI(\"http://ru.wikipedia.org/wiki/Юникод\") !== \"http://ru.wikipedia.org/wiki/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4\") && (encodeURI(\"http://ru.wikipedia.org/wiki/Юникод\") !== \"http://ru.wikipedia.org/wiki/\" + \"%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4\".toLowerCase())) {\n $ERROR('#1: http://ru.wikipedia.org/wiki/Юникод');\n}\n\n//CHECK#2\nif ((encodeURI(\"http://ru.wikipedia.org/wiki/Юникод#Ссылки\") !== \"http://ru.wikipedia.org/wiki/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4#%D0%A1%D1%81%D1%8B%D0%BB%D0%BA%D0%B8\") && (encodeURI(\"http://ru.wikipedia.org/wiki/Юникод#Ссылки\") !== \"http://ru.wikipedia.org/wiki/\" + \"%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4#%D0%A1%D1%81%D1%8B%D0%BB%D0%BA%D0%B8\".toLowerCase())) {\n $ERROR('#2: http://ru.wikipedia.org/wiki/Юникод#Ссылки');\n}\n\n//CHECK#3\nif ((encodeURI(\"http://ru.wikipedia.org/wiki/Юникод#Версии Юникода\") !== \"http://ru.wikipedia.org/wiki/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4#%D0%92%D0%B5%D1%80%D1%81%D0%B8%D0%B8%20%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4%D0%B0\") && ((encodeURI(\"http://ru.wikipedia.org/wiki/Юникод#Версии Юникода\") !== \"http://ru.wikipedia.org/wiki/\" + \"%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4#%D0%92%D0%B5%D1%80%D1%81%D0%B8%D0%B8%20%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4%D0%B0\".toLowerCase()))) {\n $ERROR('#3: http://ru.wikipedia.org/wiki/Юникод#Версии Юникода');\n}\n",
"id": "S15.1.3.3_A4_T2"
},
{
"section": "15.1.3.3",
"description": "Checking URL with Line Terminator",
"test": "//CHECK#1\nif ((encodeURI(\"http://unipro.ru/\\nabout\") !== \"http://unipro.ru/%0Aabout\") && encodeURI(\"http://unipro.ru/\\nabout\") !== \"http://unipro.ru/%0aabout\") {\n $ERROR('#1: http://unipro.ru/\\\\nabout');\n}\n\n//CHECK#2\nif ((encodeURI(\"http://unipro.ru/\\vabout\") !== \"http://unipro.ru/%0Babout\") && encodeURI(\"http://unipro.ru/\\vabout\") !== \"http://unipro.ru/%0babout\") {\n $ERROR('#2: http://unipro.ru/\\\\vabout');\n}\n\n//CHECK#3\nif ((encodeURI(\"http://unipro.ru/\\fabout\") !== \"http://unipro.ru/%0Cabout\") && encodeURI(\"http://unipro.ru/\\fabout\") !== \"http://unipro.ru/%0cabout\") {\n $ERROR('#3: http://unipro.ru/\\\\fabout');\n}\n\n//CHECK#4\nif ((encodeURI(\"http://unipro.ru/\\rabout\") !== \"http://unipro.ru/%0Dabout\") && encodeURI(\"http://unipro.ru/\\rabout\") !== \"http://unipro.ru/%0dabout\") {\n $ERROR('#4: http://unipro.ru/\\\\rabout');\n}\n",
"id": "S15.1.3.3_A4_T3"
},
{
"section": "15.1.3.3",
"description": "Test some url",
"test": "//CHECK#1\nif (encodeURI(\"\") !== \"\") {\n $ERROR('#1: \"\"');\n}\n\n//CHECK#2\nif (encodeURI(\"http://unipro.ru\") !== \"http://unipro.ru\") {\n $ERROR('#2: http://unipro.ru');\n}\n\n//CHECK#3\nif (encodeURI(\"http://www.google.ru/support/jobs/bin/static.py?page=why-ru.html&sid=liveandwork\") !== \"http://www.google.ru/support/jobs/bin/static.py?page=why-ru.html&sid=liveandwork\") {\n $ERROR('#3: http://www.google.ru/support/jobs/bin/static.py?page=why-ru.html&sid=liveandwork\"');\n} \n\n//CHECK#4\nif (encodeURI(\"http://en.wikipedia.org/wiki/UTF-8#Description\") !== \"http://en.wikipedia.org/wiki/UTF-8#Description\") {\n $ERROR('#4: http://en.wikipedia.org/wiki/UTF-8#Description');\n}\n",
"id": "S15.1.3.3_A4_T4"
},
{
"section": "15.1.3.3, 15.2.4.7, 12.6.4",
"description": "Checking use propertyIsEnumerable, for-in",
"test": "//CHECK#1\nif (encodeURI.propertyIsEnumerable('length') !== false) {\n $ERROR('#1: encodeURI.propertyIsEnumerable(\\'length\\') === false. Actual: ' + (encodeURI.propertyIsEnumerable('length')));\n}\n\n//CHECK#2\nresult = true;\nfor (p in encodeURI){\n if (p === \"length\") {\n result = false;\n } \n}\n\nif (result !== true) {\n $ERROR('#2: result = true; for (p in encodeURI) { if (p === \"length\") result = false; } result === true;');\n}\n",
"id": "S15.1.3.3_A5.1"
},
{
"section": "15.1.3.3, 15.2.4.5, 11.4.1",
"description": "Checking use hasOwnProperty, delete",
"test": "//CHECK#1\nif (encodeURI.hasOwnProperty('length') !== true) {\n $FAIL('#1: encodeURI.hasOwnProperty(\\'length\\') === true. Actual: ' + (encodeURI.hasOwnProperty('length')));\n}\n\ndelete encodeURI.length;\n\n//CHECK#2\nif (encodeURI.hasOwnProperty('length') !== true) {\n $ERROR('#2: delete encodeURI.length; encodeURI.hasOwnProperty(\\'length\\') === true. Actual: ' + (encodeURI.hasOwnProperty('length')));\n}\n\n//CHECK#3\nif (encodeURI.length === undefined) {\n $ERROR('#3: delete encodeURI.length; encodeURI.length !== undefined');\n}\n\n\n\n",
"id": "S15.1.3.3_A5.2"
},
{
"section": "15.1.3.3",
"description": "Checking if varying the length property fails",
"test": "//CHECK#1\nx = encodeURI.length;\nencodeURI.length = Infinity;\nif (encodeURI.length !== x) {\n $ERROR('#1: x = encodeURI.length; encodeURI.length = Infinity; encodeURI.length === x. Actual: ' + (encodeURI.length));\n}\n\n",
"id": "S15.1.3.3_A5.3"
},
{
"section": "15.1.3.3",
"description": "encodeURI.length === 1",
"test": "//CHECK#1\nif (encodeURI.length !== 1) {\n $ERROR('#1: encodeURI.length === 1. Actual: ' + (encodeURI.length));\n} \n\n",
"id": "S15.1.3.3_A5.4"
},
{
"section": "15.1.3.3, 15.2.4.7, 12.6.4",
"description": "Checking use propertyIsEnumerable, for-in",
"test": "//CHECK#1\nif (this.propertyIsEnumerable('encodeURI') !== false) {\n $ERROR('#1: this.propertyIsEnumerable(\\'encodeURI\\') === false. Actual: ' + (this.propertyIsEnumerable('encodeURI')));\n}\n\n//CHECK#2\nresult = true;\nfor (p in this){\n if (p === \"encodeURI\") {\n result = false;\n } \n}\n\nif (result !== true) {\n $ERROR('#2: result = true; for (p in this) { if (p === \"encodeURI\") result = false; } result === true;');\n}\n",
"id": "S15.1.3.3_A5.5"
},
{
"section": "15.1.3.3",
"description": "Checking encodeURI.prototype",
"test": "//CHECK#1\nif (encodeURI.prototype !== undefined) {\n $ERROR('#1: encodeURI.prototype === undefined. Actual: ' + (encodeURI.prototype));\n}\n",
"id": "S15.1.3.3_A5.6"
},
{
"section": "15.1.3.3, 11.2.2",
"description": "If property does not implement the internal [[Construct]] method, throw a TypeError exception",
"test": "//CHECK#1\n\ntry {\n new encodeURI();\n $ERROR('#1.1: new encodeURI() throw TypeError. Actual: ' + (new encodeURI()));\n} catch (e) {\n if ((e instanceof TypeError) !== true) {\n $ERROR('#1.2: new encodeURI() throw TypeError. Actual: ' + (e));\n }\n}\n",
"id": "S15.1.3.3_A5.7"
},
{
"section": "15.1.3.3, 9.8, 8.6.2.6",
"description": "If Type(value) is Object, evaluate ToPrimitive(value, String)",
"test": "//CHECK#1\nvar object = {valueOf: function() {return \"^\"}};\nif (encodeURI(object) !== \"%5Bobject%20Object%5D\") {\n $ERROR('#1: var object = {valueOf: function() {return \"^\"}}; encodeURI(object) === %5Bobject%20Object%5D. Actual: ' + (encodeURI(object)));\n}\n\n//CHECK#2\nvar object = {valueOf: function() {return \"\"}, toString: function() {return \"^\"}};\nif (encodeURI(object) !== \"%5E\") {\n $ERROR('#2: var object = {valueOf: function() {return \"\"}, toString: function() {return \"^\"}}; encodeURI(object) === \"%5E\". Actual: ' + (encodeURI(object)));\n} \n\n//CHECK#3\nvar object = {valueOf: function() {return \"^\"}, toString: function() {return {}}};\nif (encodeURI(object) !== \"%5E\") {\n $ERROR('#3: var object = {valueOf: function() {return \"^\"}, toString: function() {return {}}}; encodeURI(object) === \"%5E\". Actual: ' + (encodeURI(object)));\n}\n\n//CHECK#4\ntry {\n var object = {valueOf: function() {throw \"error\"}, toString: function() {return \"^\"}};\n if (encodeURI(object) !== \"%5E\") {\n $ERROR('#4.1: var object = {valueOf: function() {throw \"error\"}, toString: function() {return \"^\"}}; encodeURI(object) === \"%5E\". Actual: ' + (encodeURI(object)));\n }\n}\ncatch (e) {\n if (e === \"error\") {\n $ERROR('#4.2: var object = {valueOf: function() {throw \"error\"}, toString: function() {return \"^\"}}; encodeURI(object) not throw \"error\"');\n } else {\n $ERROR('#4.3: var object = {valueOf: function() {throw \"error\"}, toString: function() {return \"^\"}}; encodeURI(object) not throw Error. Actual: ' + (e));\n }\n}\n\n//CHECK#5\nvar object = {toString: function() {return \"^\"}};\nif (encodeURI(object) !== \"%5E\") {\n $ERROR('#5: var object = {toString: function() {return \"^\"}}; encodeURI(object) === \"%5E\". Actual: ' + (encodeURI(object)));\n}\n\n//CHECK#6\nvar object = {valueOf: function() {return {}}, toString: function() {return \"^\"}}\nif (encodeURI(object) !== \"%5E\") {\n $ERROR('#6: var object = {valueOf: function() {return {}}, toString: function() {return \"^\"}}; encodeURI(object) === \"%5E\". Actual: ' + (encodeURI(object)));\n}\n\n//CHECK#7\ntry {\n var object = {valueOf: function() {return \"^\"}, toString: function() {throw \"error\"}};\n encodeURI(object);\n $ERROR('#7.1: var object = {valueOf: function() {return \"^\"}, toString: function() {throw \"error\"}}; encodeURI(object) throw \"error\". Actual: ' + (encodeURI(object)));\n} \ncatch (e) {\n if (e !== \"error\") {\n $ERROR('#7.2: var object = {valueOf: function() {return \"^\"}, toString: function() {throw \"error\"}}; encodeURI(object) throw \"error\". Actual: ' + (e));\n } \n}\n\n//CHECK#8\ntry {\n var object = {valueOf: function() {return {}}, toString: function() {return {}}};\n encodeURI(object);\n $ERROR('#8.1: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; encodeURI(object) throw TypeError. Actual: ' + (encodeURI(object)));\n} \ncatch (e) {\n if ((e instanceof TypeError) !== true) {\n $ERROR('#8.2: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; encodeURI(object) throw TypeError. Actual: ' + (e));\n } \n}\n",
"id": "S15.1.3.3_A6_T1"
}
]
}
}