| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = '15.1.2.4.js'; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
var SECTION = "15.1.2.4"; |
| 56 |
var VERSION = "ECMA_1"; |
| 57 |
startTest(); |
| 58 |
var TITLE = "escape(string)"; |
| 59 |
|
| 60 |
writeHeaderToLog( SECTION + " "+ TITLE); |
| 61 |
|
| 62 |
new TestCase( SECTION, "escape.length", 1, escape.length ); |
| 63 |
new TestCase( SECTION, "escape.length = null; escape.length", 1, eval("escape.length = null; escape.length") ); |
| 64 |
new TestCase( SECTION, "delete escape.length", false, delete escape.length ); |
| 65 |
new TestCase( SECTION, "delete escape.length; escape.length", 1, eval("delete escape.length; escape.length") ); |
| 66 |
new TestCase( SECTION, "var MYPROPS=''; for ( var p in escape ) { MYPROPS+= p}; MYPROPS", "prototype", eval("var MYPROPS=''; for ( var p in escape ) { MYPROPS+= p}; MYPROPS") ); |
| 67 |
|
| 68 |
new TestCase( SECTION, "escape()", "undefined", escape() ); |
| 69 |
new TestCase( SECTION, "escape('')", "", escape('') ); |
| 70 |
new TestCase( SECTION, "escape( null )", "null", escape(null) ); |
| 71 |
new TestCase( SECTION, "escape( void 0 )", "undefined", escape(void 0) ); |
| 72 |
new TestCase( SECTION, "escape( true )", "true", escape( true ) ); |
| 73 |
new TestCase( SECTION, "escape( false )", "false", escape( false ) ); |
| 74 |
|
| 75 |
new TestCase( SECTION, "escape( new Boolean(true) )", "true", escape(new Boolean(true)) ); |
| 76 |
new TestCase( SECTION, "escape( new Boolean(false) )", "false", escape(new Boolean(false)) ); |
| 77 |
|
| 78 |
new TestCase( SECTION, "escape( Number.NaN )", "NaN", escape(Number.NaN) ); |
| 79 |
new TestCase( SECTION, "escape( -0 )", "0", escape( -0 ) ); |
| 80 |
new TestCase( SECTION, "escape( 'Infinity' )", "Infinity", escape( "Infinity" ) ); |
| 81 |
new TestCase( SECTION, "escape( Number.POSITIVE_INFINITY )", "Infinity", escape( Number.POSITIVE_INFINITY ) ); |
| 82 |
new TestCase( SECTION, "escape( Number.NEGATIVE_INFINITY )", "-Infinity", escape( Number.NEGATIVE_INFINITY ) ); |
| 83 |
|
| 84 |
var ASCII_TEST_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./"; |
| 85 |
|
| 86 |
new TestCase( SECTION, "escape( " +ASCII_TEST_STRING+" )", ASCII_TEST_STRING, escape( ASCII_TEST_STRING ) ); |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
for ( var CHARCODE = 0; CHARCODE < 32; CHARCODE++ ) { |
| 91 |
new TestCase( SECTION, |
| 92 |
"escape(String.fromCharCode("+CHARCODE+"))", |
| 93 |
"%"+ToHexString(CHARCODE), |
| 94 |
escape(String.fromCharCode(CHARCODE)) ); |
| 95 |
} |
| 96 |
for ( var CHARCODE = 128; CHARCODE < 256; CHARCODE++ ) { |
| 97 |
new TestCase( SECTION, |
| 98 |
"escape(String.fromCharCode("+CHARCODE+"))", |
| 99 |
"%"+ToHexString(CHARCODE), |
| 100 |
escape(String.fromCharCode(CHARCODE)) ); |
| 101 |
} |
| 102 |
|
| 103 |
for ( var CHARCODE = 256; CHARCODE < 1024; CHARCODE++ ) { |
| 104 |
new TestCase( SECTION, |
| 105 |
"escape(String.fromCharCode("+CHARCODE+"))", |
| 106 |
"%u"+ ToUnicodeString(CHARCODE), |
| 107 |
escape(String.fromCharCode(CHARCODE)) ); |
| 108 |
} |
| 109 |
for ( var CHARCODE = 65500; CHARCODE < 65536; CHARCODE++ ) { |
| 110 |
new TestCase( SECTION, |
| 111 |
"escape(String.fromCharCode("+CHARCODE+"))", |
| 112 |
"%u"+ ToUnicodeString(CHARCODE), |
| 113 |
escape(String.fromCharCode(CHARCODE)) ); |
| 114 |
} |
| 115 |
|
| 116 |
test(); |
| 117 |
|
| 118 |
function ToUnicodeString( n ) { |
| 119 |
var string = ToHexString(n); |
| 120 |
|
| 121 |
for ( var PAD = (4 - string.length ); PAD > 0; PAD-- ) { |
| 122 |
string = "0" + string; |
| 123 |
} |
| 124 |
|
| 125 |
return string; |
| 126 |
} |
| 127 |
function ToHexString( n ) { |
| 128 |
var hex = new Array(); |
| 129 |
|
| 130 |
for ( var mag = 1; Math.pow(16,mag) <= n ; mag++ ) { |
| 131 |
; |
| 132 |
} |
| 133 |
|
| 134 |
for ( index = 0, mag -= 1; mag > 0; index++, mag-- ) { |
| 135 |
hex[index] = Math.floor( n / Math.pow(16,mag) ); |
| 136 |
n -= Math.pow(16,mag) * Math.floor( n/Math.pow(16,mag) ); |
| 137 |
} |
| 138 |
|
| 139 |
hex[hex.length] = n % 16; |
| 140 |
|
| 141 |
var string =""; |
| 142 |
|
| 143 |
for ( var index = 0 ; index < hex.length ; index++ ) { |
| 144 |
switch ( hex[index] ) { |
| 145 |
case 10: |
| 146 |
string += "A"; |
| 147 |
break; |
| 148 |
case 11: |
| 149 |
string += "B"; |
| 150 |
break; |
| 151 |
case 12: |
| 152 |
string += "C"; |
| 153 |
break; |
| 154 |
case 13: |
| 155 |
string += "D"; |
| 156 |
break; |
| 157 |
case 14: |
| 158 |
string += "E"; |
| 159 |
break; |
| 160 |
case 15: |
| 161 |
string += "F"; |
| 162 |
break; |
| 163 |
default: |
| 164 |
string += hex[index]; |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
if ( string.length == 1 ) { |
| 169 |
string = "0" + string; |
| 170 |
} |
| 171 |
return string; |
| 172 |
} |