| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = '15.5.3.2-3.js'; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
var SECTION = "15.5.3.2-3"; |
| 28 |
var VERSION = "ECMA_1"; |
| 29 |
startTest(); |
| 30 |
var TITLE = "String.fromCharCode()"; |
| 31 |
|
| 32 |
writeHeaderToLog( SECTION + " "+ TITLE); |
| 33 |
|
| 34 |
for ( CHARCODE = 0; CHARCODE < 256; CHARCODE++ ) { |
| 35 |
new TestCase( SECTION, |
| 36 |
"(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)", |
| 37 |
ToUint16(CHARCODE), |
| 38 |
(String.fromCharCode(CHARCODE)).charCodeAt(0) |
| 39 |
); |
| 40 |
} |
| 41 |
for ( CHARCODE = 256; CHARCODE < 65536; CHARCODE+=333 ) { |
| 42 |
new TestCase( SECTION, |
| 43 |
"(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)", |
| 44 |
ToUint16(CHARCODE), |
| 45 |
(String.fromCharCode(CHARCODE)).charCodeAt(0) |
| 46 |
); |
| 47 |
} |
| 48 |
for ( CHARCODE = 65535; CHARCODE < 65538; CHARCODE++ ) { |
| 49 |
new TestCase( SECTION, |
| 50 |
"(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)", |
| 51 |
ToUint16(CHARCODE), |
| 52 |
(String.fromCharCode(CHARCODE)).charCodeAt(0) |
| 53 |
); |
| 54 |
} |
| 55 |
for ( CHARCODE = Math.pow(2,32)-1; CHARCODE < Math.pow(2,32)+1; CHARCODE++ ) { |
| 56 |
new TestCase( SECTION, |
| 57 |
"(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)", |
| 58 |
ToUint16(CHARCODE), |
| 59 |
(String.fromCharCode(CHARCODE)).charCodeAt(0) |
| 60 |
); |
| 61 |
} |
| 62 |
for ( CHARCODE = 0; CHARCODE > -65536; CHARCODE-=3333 ) { |
| 63 |
new TestCase( SECTION, |
| 64 |
"(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)", |
| 65 |
ToUint16(CHARCODE), |
| 66 |
(String.fromCharCode(CHARCODE)).charCodeAt(0) |
| 67 |
); |
| 68 |
} |
| 69 |
new TestCase( SECTION, "(String.fromCharCode(65535)).charCodeAt(0)", 65535, (String.fromCharCode(65535)).charCodeAt(0) ); |
| 70 |
new TestCase( SECTION, "(String.fromCharCode(65536)).charCodeAt(0)", 0, (String.fromCharCode(65536)).charCodeAt(0) ); |
| 71 |
new TestCase( SECTION, "(String.fromCharCode(65537)).charCodeAt(0)", 1, (String.fromCharCode(65537)).charCodeAt(0) ); |
| 72 |
|
| 73 |
test(); |
| 74 |
|
| 75 |
function ToUint16( num ) { |
| 76 |
num = Number( num ); |
| 77 |
if ( isNaN( num ) || num == 0 || num == Number.POSITIVE_INFINITY || num == Number.NEGATIVE_INFINITY ) { |
| 78 |
return 0; |
| 79 |
} |
| 80 |
|
| 81 |
var sign = ( num < 0 ) ? -1 : 1; |
| 82 |
|
| 83 |
num = sign * Math.floor( Math.abs( num ) ); |
| 84 |
num = num % Math.pow(2,16); |
| 85 |
num = ( num > -65536 && num < 0) ? 65536 + num : num; |
| 86 |
return num; |
| 87 |
} |
| 88 |
|