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/ 5 * 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. 10 * 11 * The Original Code is Mozilla Communicator client code, released March 12 * 31, 1998. 13 * 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 17 * Rights Reserved. 18 * 19 * Contributor(s): 20 * 21 */ 22/** 23 Filename: concat.js 24 Description: 'This tests the new String object method: concat' 25 26 Author: NickLerissa 27 Date: Fri Feb 13 09:58:28 PST 1998 28*/ 29 30 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; 31 var VERSION = 'no version'; 32 startTest(); 33 var TITLE = 'String:concat'; 34 35 writeHeaderToLog('Executing script: concat.js'); 36 writeHeaderToLog( SECTION + " "+ TITLE); 37 38 var count = 0; 39 var testcases = new Array(); 40 41 42 var aString = new String("test string"); 43 var bString = new String(" another "); 44 45 testcases[count++] = new TestCase( SECTION, "aString.concat(' more')", "test string more", aString.concat(' more').toString()); 46 testcases[count++] = new TestCase( SECTION, "aString.concat(bString)", "test string another ", aString.concat(bString).toString()); 47 testcases[count++] = new TestCase( SECTION, "aString ", "test string", aString.toString()); 48 testcases[count++] = new TestCase( SECTION, "bString ", " another ", bString.toString()); 49 testcases[count++] = new TestCase( SECTION, "aString.concat(345) ", "test string345", aString.concat(345).toString()); 50 testcases[count++] = new TestCase( SECTION, "aString.concat(true) ", "test stringtrue", aString.concat(true).toString()); 51 testcases[count++] = new TestCase( SECTION, "aString.concat(null) ", "test stringnull", aString.concat(null).toString()); 52 /* 53 http://bugs.webkit.org/show_bug.cgi?id=11545#c3 54 According to ECMA 15.5.4.6, the argument of concat should send to ToString and 55 convert into a string value (not String object). So these arguments will be 56 convert into '' and '1,2,3' under ECMA-262v3, not the js1.2 expected '[]' and 57 '[1,2,3]' 58 */ 59 //testcases[count++] = new TestCase( SECTION, "aString.concat([]) ", "test string[]", aString.concat([]).toString()); 60 //testcases[count++] = new TestCase( SECTION, "aString.concat([1,2,3])", "test string[1, 2, 3]", aString.concat([1,2,3]).toString()); 61 62 testcases[count++] = new TestCase( SECTION, "'abcde'.concat(' more')", "abcde more", 'abcde'.concat(' more').toString()); 63 testcases[count++] = new TestCase( SECTION, "'abcde'.concat(bString)", "abcde another ", 'abcde'.concat(bString).toString()); 64 testcases[count++] = new TestCase( SECTION, "'abcde' ", "abcde", 'abcde'); 65 testcases[count++] = new TestCase( SECTION, "'abcde'.concat(345) ", "abcde345", 'abcde'.concat(345).toString()); 66 testcases[count++] = new TestCase( SECTION, "'abcde'.concat(true) ", "abcdetrue", 'abcde'.concat(true).toString()); 67 testcases[count++] = new TestCase( SECTION, "'abcde'.concat(null) ", "abcdenull", 'abcde'.concat(null).toString()); 68 /* 69 http://bugs.webkit.org/show_bug.cgi?id=11545#c3 70 According to ECMA 15.5.4.6, the argument of concat should send to ToString and 71 convert into a string value (not String object). So these arguments will be 72 convert into '' and '1,2,3' under ECMA-262v3, not the js1.2 expected '[]' and 73 '[1,2,3]' 74 */ 75 //testcases[count++] = new TestCase( SECTION, "'abcde'.concat([]) ", "abcde[]", 'abcde'.concat([]).toString()); 76 //testcases[count++] = new TestCase( SECTION, "'abcde'.concat([1,2,3])", "abcde[1, 2, 3]", 'abcde'.concat([1,2,3]).toString()); 77 78 //what should this do: 79 testcases[count++] = new TestCase( SECTION, "'abcde'.concat() ", "abcde", 'abcde'.concat().toString()); 80 81 function test() 82 { 83 for ( tc=0; tc < testcases.length; tc++ ) { 84 testcases[tc].passed = writeTestCaseResult( 85 testcases[tc].expect, 86 testcases[tc].actual, 87 testcases[tc].description +" = "+ 88 testcases[tc].actual ); 89 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; 90 } 91 stopTest(); 92 return ( testcases ); 93 } 94 95 test(); 96 97