QML_RUNTIME_TESTING should be disabled by default.
[profile/ivi/qtdeclarative.git] / tests / auto / qml / parserstress / tests / ecma / String / 15.5.4.8-3.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.5.4.8-3.js';
40
41 /**
42    File Name:          15.5.4.8-3.js
43    ECMA Section:       15.5.4.8 String.prototype.split( separator )
44    Description:
45
46    Returns an Array object into which substrings of the result of converting
47    this object to a string have been stored. The substrings are determined by
48    searching from left to right for occurrences of the given separator; these
49    occurrences are not part of any substring in the returned array, but serve
50    to divide up this string value. The separator may be a string of any length.
51
52    As a special case, if the separator is the empty string, the string is split
53    up into individual characters; the length of the result array equals the
54    length of the string, and each substring contains one character.
55
56    If the separator is not supplied, then the result array contains just one
57    string, which is the string.
58
59    When the split method is called with one argument separator, the following steps are taken:
60
61    1.   Call ToString, giving it the this value as its argument.
62    2.   Create a new Array object of length 0 and call it A.
63    3.   If separator is not supplied, call the [[Put]] method of A with 0 and
64    Result(1) as arguments, and then return A.
65    4.   Call ToString(separator).
66    5.   Compute the number of characters in Result(1).
67    6.   Compute the number of characters in the string that is Result(4).
68    7.   Let p be 0.
69    8.   If Result(6) is zero (the separator string is empty), go to step 17.
70    9.   Compute the smallest possible integer k not smaller than p such that
71    k+Result(6) is not greater than Result(5), and for all nonnegative
72    integers j less than Result(6), the character at position k+j of
73    Result(1) is the same as the character at position j of Result(2);
74    but if there is no such integer k, then go to step 14.
75    10.   Compute a string value equal to the substring of Result(1), consisting
76    of the characters at positions p through k1, inclusive.
77    11.   Call the [[Put]] method of A with A.length and Result(10) as arguments.
78    12.   Let p be k+Result(6).
79    13.   Go to step 9.
80    14.   Compute a string value equal to the substring of Result(1), consisting
81    of the characters from position p to the end of Result(1).
82    15.   Call the [[Put]] method of A with A.length and Result(14) as arguments.
83    16.   Return A.
84    17.   If p equals Result(5), return A.
85    18.   Compute a string value equal to the substring of Result(1), consisting of
86    the single character at position p.
87    19.   Call the [[Put]] method of A with A.length and Result(18) as arguments.
88    20.   Increase p by 1.
89    21.   Go to step 17.
90
91    Note that the split function is intentionally generic; it does not require that its this value be a String
92    object. Therefore it can be transferred to other kinds of objects for use as a method.
93
94    Author:             christine@netscape.com
95    Date:               12 november 1997
96 */
97
98 var SECTION = "15.5.4.8-3";
99 var VERSION = "ECMA_1";
100 startTest();
101 var TITLE   = "String.prototype.split";
102
103 writeHeaderToLog( SECTION + " "+ TITLE);
104
105 var TEST_STRING = "";
106 var EXPECT = new Array();
107
108 // this.toString is the empty string.
109
110 new TestCase(   SECTION,
111                 "var s = new String(); s.split().length",
112                 1,
113                 eval("var s = new String(); s.split().length") );
114
115 new TestCase(   SECTION,
116                 "var s = new String(); s.split()[0]",
117                 "",
118                 eval("var s = new String(); s.split()[0]") );
119
120 // this.toString() is the empty string, separator is specified.
121
122 new TestCase(   SECTION,
123                 "var s = new String(); s.split('').length",
124                 0,
125                 eval("var s = new String(); s.split('').length") );
126
127 new TestCase(   SECTION,
128                 "var s = new String(); s.split(' ').length",
129                 1,
130                 eval("var s = new String(); s.split(' ').length") );
131
132 // this to string is " "
133 new TestCase(   SECTION,
134                 "var s = new String(' '); s.split().length",
135                 1,
136                 eval("var s = new String(' '); s.split().length") );
137
138 new TestCase(   SECTION,
139                 "var s = new String(' '); s.split()[0]",
140                 " ",
141                 eval("var s = new String(' '); s.split()[0]") );
142
143 new TestCase(   SECTION,
144                 "var s = new String(' '); s.split('').length",
145                 1,
146                 eval("var s = new String(' '); s.split('').length") );
147
148 new TestCase(   SECTION,
149                 "var s = new String(' '); s.split('')[0]",
150                 " ",
151                 eval("var s = new String(' '); s.split('')[0]") );
152
153 new TestCase(   SECTION,
154                 "var s = new String(' '); s.split(' ').length",
155                 2,
156                 eval("var s = new String(' '); s.split(' ').length") );
157
158 new TestCase(   SECTION,
159                 "var s = new String(' '); s.split(' ')[0]",
160                 "",
161                 eval("var s = new String(' '); s.split(' ')[0]") );
162
163 new TestCase(   SECTION,
164                 "\"\".split(\"\").length",
165                 0,
166                 ("".split("")).length );
167
168 new TestCase(   SECTION,
169                 "\"\".split(\"x\").length",
170                 1,
171                 ("".split("x")).length );
172
173 new TestCase(   SECTION,
174                 "\"\".split(\"x\")[0]",
175                 "",
176                 ("".split("x"))[0] );
177
178 test();
179
180 function Split( string, separator ) {
181   string = String( string );
182
183   var A = new Array();
184
185   if ( arguments.length < 2 ) {
186     A[0] = string;
187     return A;
188   }
189
190   separator = String( separator );
191
192   var str_len = String( string ).length;
193   var sep_len = String( separator ).length;
194
195   var p = 0;
196   var k = 0;
197
198   if ( sep_len == 0 ) {
199     for ( ; p < str_len; p++ ) {
200       A[A.length] = String( string.charAt(p) );
201     }
202   }
203   return A;
204 }