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
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/
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
15 * The Original Code is JavaScript Engine testing utilities.
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.
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.
36 * ***** END LICENSE BLOCK ***** */
38 gTestfile = 'split-001.js';
41 * File Name: String/split-001.js
42 * ECMA Section: 15.6.4.9
43 * Description: Based on ECMA 2 Draft 7 February 1999
45 * Author: christine@netscape.com
46 * Date: 19 February 1999
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.
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.
57 * The [,limit] argument to String.split is new, and not covered in any
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
66 var SECTION = "ecma_2/String/split-001.js";
67 var VERSION = "ECMA_2";
68 var TITLE = "String.prototype.split( regexp, [,limit] )";
72 // the separator is not supplied
73 // separator is undefined
74 // separator is an empty string
76 AddSplitCases( "splitme", "", "''", ["s", "p", "l", "i", "t", "m", "e"] );
77 AddSplitCases( "splitme", new RegExp(), "new RegExp()", ["s", "p", "l", "i", "t", "m", "e"] );
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
84 // this is not a String object
86 // limit is not a number
88 // limit is larger than 2^32-1
89 // limit is a negative number
93 function AddSplitCases( string, separator, str_sep, split_array ) {
95 // verify that the result of split is an object of type Array
97 "( " + string + " ).split(" + str_sep +").constructor == Array",
99 string.split(separator).constructor == Array );
101 // check the number of items in the array
103 "( " + string + " ).split(" + str_sep +").length",
105 string.split(separator).length );
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;
111 for ( var matches = 0; matches < split_array.length; matches++ ) {
113 "( " + string + " ).split(" + str_sep +")[" + matches +"]",
114 split_array[matches],
115 string.split( separator )[matches] );
119 function AddLimitedSplitCases(
120 string, separator, str_sep, limit, str_limit, split_array ) {
122 // verify that the result of split is an object of type Array
125 "( " + string + " ).split(" + str_sep +", " + str_limit +
126 " ).constructor == Array",
128 string.split(separator, limit).constructor == Array );
130 // check the length of the array
133 "( " + string + " ).split(" + str_sep +", " + str_limit + " ).length",
135 string.split(separator).length );
137 // check the value of each array item
139 for ( var matches = 0; matches < split_array.length; matches++ ) {
141 "( " + string + " ).split(" + str_sep +", " + str_limit + " )[" + matches +"]",
142 split_array[matches],
143 string.split( separator )[matches] );