Rename QDeclarative symbols to QQuick and QQml
[profile/ivi/qtdeclarative.git] / tests / auto / qml / parserstress / tests / ecma / Array / 15.4.4.3-1.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
18  * The Initial Developer of the Original Code is
19  * Netscape Communications Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 1998
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 gTestfile = '15.4.4.3-1.js';
40
41 /**
42    File Name:    15.4.4.3-1.js
43    ECMA Section: 15.4.4.3-1 Array.prototype.join()
44    Description:  The elements of this object are converted to strings and
45    these strings are then concatenated, separated by comma
46    characters. The result is the same as if the built-in join
47    method were invoiked for this object with no argument.
48    Author:       christine@netscape.com, pschwartau@netscape.com
49    Date:         07 October 1997
50    Modified:     14 July 2002
51    Reason:       See http://bugzilla.mozilla.org/show_bug.cgi?id=155285
52    ECMA-262 Ed.3  Section 15.4.4.5 Array.prototype.join()
53    Step 3: If |separator| is |undefined|, let |separator|
54    be the single-character string ","
55    *
56    */
57
58 var SECTION = "15.4.4.3-1";
59 var VERSION = "ECMA_1";
60 startTest();
61
62 writeHeaderToLog( SECTION + " Array.prototype.join()");
63
64 var ARR_PROTOTYPE = Array.prototype;
65
66 new TestCase( SECTION, "Array.prototype.join.length",           1,      Array.prototype.join.length );
67 new TestCase( SECTION, "delete Array.prototype.join.length",    false,  delete Array.prototype.join.length );
68 new TestCase( SECTION, "delete Array.prototype.join.length; Array.prototype.join.length",    1, eval("delete Array.prototype.join.length; Array.prototype.join.length") );
69
70 // case where array length is 0
71
72 new TestCase(   SECTION,
73                 "var TEST_ARRAY = new Array(); TEST_ARRAY.join()",
74                 "",
75                 eval("var TEST_ARRAY = new Array(); TEST_ARRAY.join()") );
76
77 // array length is 0, but spearator is specified
78
79 new TestCase(   SECTION,
80                 "var TEST_ARRAY = new Array(); TEST_ARRAY.join(' ')",
81                 "",
82                 eval("var TEST_ARRAY = new Array(); TEST_ARRAY.join(' ')") );
83
84 // length is greater than 0, separator is supplied
85 new TestCase(   SECTION,
86                 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('&')",
87                 "&&true&false&123&[object Object]&true",
88                 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('&')") );
89
90 // length is greater than 0, separator is empty string
91 new TestCase(   SECTION,
92                 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('')",
93                 "truefalse123[object Object]true",
94                 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('')") );
95
96 // length is greater than 0, separator is undefined
97 new TestCase(   SECTION,
98                 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join(void 0)",
99                 ",,true,false,123,[object Object],true",
100                 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join(void 0)") );
101
102 // length is greater than 0, separator is not supplied
103 new TestCase(   SECTION,
104                 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join()",
105                 ",,true,false,123,[object Object],true",
106                 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join()") );
107
108 // separator is a control character
109 new TestCase(   SECTION,
110                 "var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('\v')",
111                 decodeURIComponent("%0B%0Btrue%0Bfalse%0B123%0B[object Object]%0Btrue"),
112                 eval("var TEST_ARRAY = new Array(null, void 0, true, false, 123, new Object(), new Boolean(true) ); TEST_ARRAY.join('\v')") );
113
114 // length of array is 1
115 new TestCase(   SECTION,
116                 "var TEST_ARRAY = new Array(true) ); TEST_ARRAY.join('\v')",
117                 "true",
118                 eval("var TEST_ARRAY = new Array(true); TEST_ARRAY.join('\v')") );
119
120
121 SEPARATOR = "\t"
122   TEST_LENGTH = 100;
123 TEST_STRING = "";
124 ARGUMENTS = "";
125 TEST_RESULT = "";
126
127 for ( var index = 0; index < TEST_LENGTH; index++ ) {
128   ARGUMENTS   += index;
129   ARGUMENTS   += ( index == TEST_LENGTH -1 ) ? "" : ",";
130
131   TEST_RESULT += index;
132   TEST_RESULT += ( index == TEST_LENGTH -1 ) ? "" : SEPARATOR;
133 }
134
135 TEST_ARRAY = eval( "new Array( "+ARGUMENTS +")" );
136
137 new TestCase( SECTION,
138               "TEST_ARRAY.join("+SEPARATOR+")",  
139               TEST_RESULT,   
140               TEST_ARRAY.join( SEPARATOR ) );
141
142 new TestCase( SECTION,
143               "(new Array( Boolean(true), Boolean(false), null,  void 0, Number(1e+21), Number(1e-7))).join()",
144               "true,false,,,1e+21,1e-7",
145               (new Array( Boolean(true), Boolean(false), null,  void 0, Number(1e+21), Number(1e-7))).join() );
146
147 // this is not an Array object
148 new TestCase(   SECTION,
149                 "var OB = new Object_1('true,false,111,0.5,1.23e6,NaN,void 0,null'); OB.join(':')",
150                 "true:false:111:0.5:1230000:NaN::",
151                 eval("var OB = new Object_1('true,false,111,0.5,1.23e6,NaN,void 0,null'); OB.join(':')") );
152
153 test();
154
155 function Object_1( value ) {
156   this.array = value.split(",");
157   this.length = this.array.length;
158   for ( var i = 0; i < this.length; i++ ) {
159     this[i] = eval(this.array[i]);
160   }
161   this.join = Array.prototype.join;
162   this.getClass = Object.prototype.toString;
163 }