2 * File Name: String/split-001.js
3 * ECMA Section: 15.6.4.9
4 * Description: Based on ECMA 2 Draft 7 February 1999
6 * Author: christine@netscape.com
7 * Date: 19 February 1999
11 * Since regular expressions have been part of JavaScript since 1.2, there
12 * are already tests for regular expressions in the js1_2/regexp folder.
14 * These new tests try to supplement the existing tests, and verify that
15 * our implementation of RegExp conforms to the ECMA specification, but
16 * does not try to be as exhaustive as in previous tests.
18 * The [,limit] argument to String.split is new, and not covered in any
21 * String.split cases are covered in ecma/String/15.5.4.8-*.js.
22 * String.split where separator is a RegExp are in
23 * js1_2/regexp/string_split.js
27 var SECTION = "ecma_2/String/split-001.js";
28 var VERSION = "ECMA_2";
29 var TITLE = "String.prototype.split( regexp, [,limit] )";
33 // the separator is not supplied
34 // separator is undefined
35 // separator is an empty string
37 AddSplitCases( "splitme", "", "''", ["s", "p", "l", "i", "t", "m", "e"] );
38 AddSplitCases( "splitme", new RegExp(), "new RegExp()", ["s", "p", "l", "i", "t", "m", "e"] );
40 // separartor is a regexp
41 // separator regexp value global setting is set
42 // string is an empty string
43 // if separator is an empty string, split each by character
45 // this is not a String object
47 // limit is not a number
49 // limit is larger than 2^32-1
50 // limit is a negative number
54 function AddSplitCases( string, separator, str_sep, split_array ) {
56 // verify that the result of split is an object of type Array
58 "( " + string + " ).split(" + str_sep +").constructor == Array",
60 string.split(separator).constructor == Array );
62 // check the number of items in the array
64 "( " + string + " ).split(" + str_sep +").length",
66 string.split(separator).length );
68 // check the value of each array item
69 var limit = (split_array.length > string.split(separator).length )
70 ? split_array.length : string.split(separator).length;
72 for ( var matches = 0; matches < split_array.length; matches++ ) {
74 "( " + string + " ).split(" + str_sep +")[" + matches +"]",
76 string.split( separator )[matches] );
80 function AddLimitedSplitCases(
81 string, separator, str_sep, limit, str_limit, split_array ) {
83 // verify that the result of split is an object of type Array
86 "( " + string + " ).split(" + str_sep +", " + str_limit +
87 " ).constructor == Array",
89 string.split(separator, limit).constructor == Array );
91 // check the length of the array
94 "( " + string + " ).split(" + str_sep +", " + str_limit + " ).length",
96 string.split(separator).length );
98 // check the value of each array item
100 for ( var matches = 0; matches < split_array.length; matches++ ) {
102 "( " + string + " ).split(" + str_sep +", " + str_limit + " )[" + matches +"]",
103 split_array[matches],
104 string.split( separator )[matches] );