1
/* The contents of this file are subject to the Netscape Public
2
* License Version 1.1 (the "License"); you may not use this file
3
* except in compliance with the License. You may obtain a copy of
4
* the License at http://www.mozilla.org/NPL/
6
* Software distributed under the License is distributed on an "AS
7
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8
* implied. See the License for the specific language governing
9
* rights and limitations under the License.
11
* The Original Code is Mozilla Communicator client code, released March
14
* The Initial Developer of the Original Code is Netscape Communications
15
* Corporation. Portions created by Netscape are
16
* Copyright (C) 1998 Netscape Communications Corporation. All
23
File Name: 15.5.3.2-1.js
24
ECMA Section: 15.5.3.2 String.fromCharCode( char0, char1, ... )
25
Description: Return a string value containing as many characters
26
as the number of arguments. Each argument specifies
27
one character of the resulting string, with the first
28
argument specifying the first character, and so on,
29
from left to right. An argument is converted to a
30
character by applying the operation ToUint16 and
31
regarding the resulting 16bit integeras the Unicode
32
encoding of a character. If no arguments are supplied,
33
the result is the empty string.
35
This test covers Basic Latin (range U+0020 - U+007F)
37
Author: christine@netscape.com
41
var SECTION = "15.5.3.2-3";
42
var VERSION = "ECMA_1";
44
var TITLE = "String.fromCharCode()";
46
writeHeaderToLog( SECTION + " "+ TITLE);
48
var testcases = getTestCases();
51
function getTestCases() {
52
var array = new Array();
55
for ( CHARCODE = 0; CHARCODE < 256; CHARCODE++ ) {
56
array[item++] = new TestCase( SECTION,
57
"(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)",
59
(String.fromCharCode(CHARCODE)).charCodeAt(0)
62
for ( CHARCODE = 256; CHARCODE < 65536; CHARCODE+=333 ) {
63
array[item++] = new TestCase( SECTION,
64
"(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)",
66
(String.fromCharCode(CHARCODE)).charCodeAt(0)
69
for ( CHARCODE = 65535; CHARCODE < 65538; CHARCODE++ ) {
70
array[item++] = new TestCase( SECTION,
71
"(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)",
73
(String.fromCharCode(CHARCODE)).charCodeAt(0)
76
for ( CHARCODE = Math.pow(2,32)-1; CHARCODE < Math.pow(2,32)+1; CHARCODE++ ) {
77
array[item++] = new TestCase( SECTION,
78
"(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)",
80
(String.fromCharCode(CHARCODE)).charCodeAt(0)
83
for ( CHARCODE = 0; CHARCODE > -65536; CHARCODE-=3333 ) {
84
array[item++] = new TestCase( SECTION,
85
"(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)",
87
(String.fromCharCode(CHARCODE)).charCodeAt(0)
90
array[item++] = new TestCase( SECTION, "(String.fromCharCode(65535)).charCodeAt(0)", 65535, (String.fromCharCode(65535)).charCodeAt(0) );
91
array[item++] = new TestCase( SECTION, "(String.fromCharCode(65536)).charCodeAt(0)", 0, (String.fromCharCode(65536)).charCodeAt(0) );
92
array[item++] = new TestCase( SECTION, "(String.fromCharCode(65537)).charCodeAt(0)", 1, (String.fromCharCode(65537)).charCodeAt(0) );
96
function ToUint16( num ) {
98
if ( isNaN( num ) || num == 0 || num == Number.POSITIVE_INFINITY || num == Number.NEGATIVE_INFINITY ) {
102
var sign = ( num < 0 ) ? -1 : 1;
104
num = sign * Math.floor( Math.abs( num ) );
105
num = num % Math.pow(2,16);
106
num = ( num > -65536 && num < 0) ? 65536 + num : num;
111
for ( tc=0; tc < testcases.length; tc++ ) {
112
testcases[tc].passed = writeTestCaseResult(
113
testcases[tc].expect,
114
testcases[tc].actual,
115
testcases[tc].description +" = "+
116
testcases[tc].actual );
118
testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
121
return ( testcases );