Rename QDeclarative symbols to QQuick and QQml
[profile/ivi/qtdeclarative.git] / tests / auto / qml / parserstress / tests / ecma_2 / String / split-001.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 JavaScript Engine testing utilities.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communication Corporation.
19  * Portions created by the Initial Developer are Copyright (C) 1998
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37
38 gTestfile = 'split-001.js';
39
40 /**
41  *  File Name:          String/split-001.js
42  *  ECMA Section:       15.6.4.9
43  *  Description:        Based on ECMA 2 Draft 7 February 1999
44  *
45  *  Author:             christine@netscape.com
46  *  Date:               19 February 1999
47  */
48
49 /*
50  * Since regular expressions have been part of JavaScript since 1.2, there
51  * are already tests for regular expressions in the js1_2/regexp folder.
52  *
53  * These new tests try to supplement the existing tests, and verify that
54  * our implementation of RegExp conforms to the ECMA specification, but
55  * does not try to be as exhaustive as in previous tests.
56  *
57  * The [,limit] argument to String.split is new, and not covered in any
58  * existing tests.
59  *
60  * String.split cases are covered in ecma/String/15.5.4.8-*.js.
61  * String.split where separator is a RegExp are in
62  * js1_2/regexp/string_split.js
63  *
64  */
65
66 var SECTION = "ecma_2/String/split-001.js";
67 var VERSION = "ECMA_2";
68 var TITLE   = "String.prototype.split( regexp, [,limit] )";
69
70 startTest();
71
72 // the separator is not supplied
73 // separator is undefined
74 // separator is an empty string
75
76 AddSplitCases( "splitme", "", "''", ["s", "p", "l", "i", "t", "m", "e"] );
77 AddSplitCases( "splitme", new RegExp(), "new RegExp()", ["s", "p", "l", "i", "t", "m", "e"] );
78
79 // separartor is a regexp
80 // separator regexp value global setting is set
81 // string is an empty string
82 // if separator is an empty string, split each by character
83
84 // this is not a String object
85
86 // limit is not a number
87 // limit is undefined
88 // limit is larger than 2^32-1
89 // limit is a negative number
90
91 test();
92
93 function AddSplitCases( string, separator, str_sep, split_array ) {
94
95   // verify that the result of split is an object of type Array
96   AddTestCase(
97     "( " + string  + " ).split(" + str_sep +").constructor == Array",
98     true,
99     string.split(separator).constructor == Array );
100
101   // check the number of items in the array
102   AddTestCase(
103     "( " + string  + " ).split(" + str_sep +").length",
104     split_array.length,
105     string.split(separator).length );
106
107   // check the value of each array item
108   var limit = (split_array.length > string.split(separator).length )
109     ? split_array.length : string.split(separator).length;
110
111   for ( var matches = 0; matches < split_array.length; matches++ ) {
112     AddTestCase(
113       "( " + string + " ).split(" + str_sep +")[" + matches +"]",
114       split_array[matches],
115       string.split( separator )[matches] );
116   }
117 }
118
119 function AddLimitedSplitCases(
120   string, separator, str_sep, limit, str_limit, split_array ) {
121
122   // verify that the result of split is an object of type Array
123
124   AddTestCase(
125     "( " + string  + " ).split(" + str_sep +", " + str_limit +
126     " ).constructor == Array",
127     true,
128     string.split(separator, limit).constructor == Array );
129
130   // check the length of the array
131
132   AddTestCase(
133     "( " + string + " ).split(" + str_sep  +", " + str_limit + " ).length",
134     length,
135     string.split(separator).length );
136
137   // check the value of each array item
138
139   for ( var matches = 0; matches < split_array.length; matches++ ) {
140     AddTestCase(
141       "( " + string + " ).split(" + str_sep +", " + str_limit + " )[" + matches +"]",
142       split_array[matches],
143       string.split( separator )[matches] );
144   }
145 }