michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: 15.5.3.2-1.js michael@0: ECMA Section: 15.5.3.2 String.fromCharCode( char0, char1, ... ) michael@0: Description: Return a string value containing as many characters michael@0: as the number of arguments. Each argument specifies michael@0: one character of the resulting string, with the first michael@0: argument specifying the first character, and so on, michael@0: from left to right. An argument is converted to a michael@0: character by applying the operation ToUint16_t and michael@0: regarding the resulting 16bit integeras the Unicode michael@0: encoding of a character. If no arguments are supplied, michael@0: the result is the empty string. michael@0: michael@0: This test covers Basic Latin (range U+0020 - U+007F) michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 2 october 1997 michael@0: */ michael@0: michael@0: var SECTION = "15.5.3.2-3"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: var TITLE = "String.fromCharCode()"; michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: for ( CHARCODE = 0; CHARCODE < 256; CHARCODE++ ) { michael@0: new TestCase( SECTION, michael@0: "(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)", michael@0: ToUint16(CHARCODE), michael@0: (String.fromCharCode(CHARCODE)).charCodeAt(0) michael@0: ); michael@0: } michael@0: for ( CHARCODE = 256; CHARCODE < 65536; CHARCODE+=333 ) { michael@0: new TestCase( SECTION, michael@0: "(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)", michael@0: ToUint16(CHARCODE), michael@0: (String.fromCharCode(CHARCODE)).charCodeAt(0) michael@0: ); michael@0: } michael@0: for ( CHARCODE = 65535; CHARCODE < 65538; CHARCODE++ ) { michael@0: new TestCase( SECTION, michael@0: "(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)", michael@0: ToUint16(CHARCODE), michael@0: (String.fromCharCode(CHARCODE)).charCodeAt(0) michael@0: ); michael@0: } michael@0: for ( CHARCODE = Math.pow(2,32)-1; CHARCODE < Math.pow(2,32)+1; CHARCODE++ ) { michael@0: new TestCase( SECTION, michael@0: "(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)", michael@0: ToUint16(CHARCODE), michael@0: (String.fromCharCode(CHARCODE)).charCodeAt(0) michael@0: ); michael@0: } michael@0: for ( CHARCODE = 0; CHARCODE > -65536; CHARCODE-=3333 ) { michael@0: new TestCase( SECTION, michael@0: "(String.fromCharCode(" + CHARCODE +")).charCodeAt(0)", michael@0: ToUint16(CHARCODE), michael@0: (String.fromCharCode(CHARCODE)).charCodeAt(0) michael@0: ); michael@0: } michael@0: new TestCase( SECTION, "(String.fromCharCode(65535)).charCodeAt(0)", 65535, (String.fromCharCode(65535)).charCodeAt(0) ); michael@0: new TestCase( SECTION, "(String.fromCharCode(65536)).charCodeAt(0)", 0, (String.fromCharCode(65536)).charCodeAt(0) ); michael@0: new TestCase( SECTION, "(String.fromCharCode(65537)).charCodeAt(0)", 1, (String.fromCharCode(65537)).charCodeAt(0) ); michael@0: michael@0: test(); michael@0: michael@0: function ToUint16( num ) { michael@0: num = Number( num ); michael@0: if ( isNaN( num ) || num == 0 || num == Number.POSITIVE_INFINITY || num == Number.NEGATIVE_INFINITY ) { michael@0: return 0; michael@0: } michael@0: michael@0: var sign = ( num < 0 ) ? -1 : 1; michael@0: michael@0: num = sign * Math.floor( Math.abs( num ) ); michael@0: num = num % Math.pow(2,16); michael@0: num = ( num > -65536 && num < 0) ? 65536 + num : num; michael@0: return num; michael@0: } michael@0: