]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma_2/String/split-003.js
2 * File Name: String/split-003.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-003.js";
28 var VERSION
= "ECMA_2";
29 var TITLE
= "String.prototype.split( regexp, [,limit] )";
33 // separartor is a regexp
34 // separator regexp value global setting is set
35 // string is an empty string
36 // if separator is an empty string, split each by character
39 AddSplitCases( "hello", new RegExp
, "new RegExp", ["h","e","l","l","o"] );
41 AddSplitCases( "hello", /l
/, "/l/", ["he","","o"] );
42 AddLimitedSplitCases( "hello", /l
/, "/l/", 0, [] );
43 AddLimitedSplitCases( "hello", /l
/, "/l/", 1, ["he"] );
44 AddLimitedSplitCases( "hello", /l
/, "/l/", 2, ["he",""] );
45 AddLimitedSplitCases( "hello", /l
/, "/l/", 3, ["he","","o"] );
46 AddLimitedSplitCases( "hello", /l
/, "/l/", 4, ["he","","o"] );
47 AddLimitedSplitCases( "hello", /l
/, "/l/", void 0, ["he","","o"] );
48 AddLimitedSplitCases( "hello", /l
/, "/l/", "hi", [] );
49 AddLimitedSplitCases( "hello", /l
/, "/l/", undefined, ["he","","o"] );
51 AddSplitCases( "hello", new RegExp
, "new RegExp", ["h","e","l","l","o"] );
52 AddLimitedSplitCases( "hello", new RegExp
, "new RegExp", 0, [] );
53 AddLimitedSplitCases( "hello", new RegExp
, "new RegExp", 1, ["h"] );
54 AddLimitedSplitCases( "hello", new RegExp
, "new RegExp", 2, ["h","e"] );
55 AddLimitedSplitCases( "hello", new RegExp
, "new RegExp", 3, ["h","e","l"] );
56 AddLimitedSplitCases( "hello", new RegExp
, "new RegExp", 4, ["h","e","l","l"] );
57 AddLimitedSplitCases( "hello", new RegExp
, "new RegExp", void 0, ["h","e","l","l","o"] );
58 AddLimitedSplitCases( "hello", new RegExp
, "new RegExp", "hi", [] );
59 AddLimitedSplitCases( "hello", new RegExp
, "new RegExp", undefined, ["h","e","l","l","o"] );
63 function AddSplitCases( string
, separator
, str_sep
, split_array
) {
64 // verify that the result of split is an object of type Array
66 "( " + string
+ " ).split(" + str_sep
+").constructor == Array",
68 string
.split(separator
).constructor == Array
);
70 // check the number of items in the array
72 "( " + string
+ " ).split(" + str_sep
+").length",
74 string
.split(separator
).length
);
76 // check the value of each array item
77 var limit
= (split_array
.length
> string
.split(separator
).length
)
78 ? split_array
.length : string
.split(separator
).length
;
80 for ( var matches
= 0; matches
< split_array
.length
; matches
++ ) {
82 "( " + string
+ " ).split(" + str_sep
+")[" + matches
+"]",
84 string
.split( separator
)[matches
] );
88 function AddLimitedSplitCases(
89 string
, separator
, str_sep
, limit
, split_array
) {
91 // verify that the result of split is an object of type Array
94 "( " + string
+ " ).split(" + str_sep
+", " + limit
+
95 " ).constructor == Array",
97 string
.split(separator
, limit
).constructor == Array
);
99 // check the length of the array
102 "( " + string
+ " ).split(" + str_sep
+", " + limit
+ " ).length",
104 string
.split(separator
, limit
).length
);
106 // check the value of each array item
108 var slimit
= (split_array
.length
> string
.split(separator
).length
)
109 ? split_array
.length : string
.split(separator
, limit
).length
;
111 for ( var matches
= 0; matches
< slimit
; matches
++ ) {
113 "( " + string
+ " ).split(" + str_sep
+", " + limit
+ " )[" + matches
+"]",
114 split_array
[matches
],
115 string
.split( separator
, limit
)[matches
] );