| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = 'split-003.js'; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
var SECTION = "ecma_2/String/split-003.js"; |
| 35 |
var VERSION = "ECMA_2"; |
| 36 |
var TITLE = "String.prototype.split( regexp, [,limit] )"; |
| 37 |
|
| 38 |
startTest(); |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
AddSplitCases( "hello", new RegExp, "new RegExp", ["h","e","l","l","o"] ); |
| 47 |
|
| 48 |
AddSplitCases( "hello", /l/, "/l/", ["he","","o"] ); |
| 49 |
AddLimitedSplitCases( "hello", /l/, "/l/", 0, [] ); |
| 50 |
AddLimitedSplitCases( "hello", /l/, "/l/", 1, ["he"] ); |
| 51 |
AddLimitedSplitCases( "hello", /l/, "/l/", 2, ["he",""] ); |
| 52 |
AddLimitedSplitCases( "hello", /l/, "/l/", 3, ["he","","o"] ); |
| 53 |
AddLimitedSplitCases( "hello", /l/, "/l/", 4, ["he","","o"] ); |
| 54 |
AddLimitedSplitCases( "hello", /l/, "/l/", void 0, ["he","","o"] ); |
| 55 |
AddLimitedSplitCases( "hello", /l/, "/l/", "hi", [] ); |
| 56 |
AddLimitedSplitCases( "hello", /l/, "/l/", undefined, ["he","","o"] ); |
| 57 |
|
| 58 |
AddSplitCases( "hello", new RegExp, "new RegExp", ["h","e","l","l","o"] ); |
| 59 |
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 0, [] ); |
| 60 |
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 1, ["h"] ); |
| 61 |
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 2, ["h","e"] ); |
| 62 |
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 3, ["h","e","l"] ); |
| 63 |
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 4, ["h","e","l","l"] ); |
| 64 |
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", void 0, ["h","e","l","l","o"] ); |
| 65 |
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", "hi", [] ); |
| 66 |
AddLimitedSplitCases( "hello", new RegExp, "new RegExp", undefined, ["h","e","l","l","o"] ); |
| 67 |
|
| 68 |
test(); |
| 69 |
|
| 70 |
function AddSplitCases( string, separator, str_sep, split_array ) { |
| 71 |
|
| 72 |
AddTestCase( |
| 73 |
"( " + string + " ).split(" + str_sep +").constructor == Array", |
| 74 |
true, |
| 75 |
string.split(separator).constructor == Array ); |
| 76 |
|
| 77 |
|
| 78 |
AddTestCase( |
| 79 |
"( " + string + " ).split(" + str_sep +").length", |
| 80 |
split_array.length, |
| 81 |
string.split(separator).length ); |
| 82 |
|
| 83 |
|
| 84 |
var limit = (split_array.length > string.split(separator).length ) |
| 85 |
? split_array.length : string.split(separator).length; |
| 86 |
|
| 87 |
for ( var matches = 0; matches < split_array.length; matches++ ) { |
| 88 |
AddTestCase( |
| 89 |
"( " + string + " ).split(" + str_sep +")[" + matches +"]", |
| 90 |
split_array[matches], |
| 91 |
string.split( separator )[matches] ); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
function AddLimitedSplitCases( |
| 96 |
string, separator, str_sep, limit, split_array ) { |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
AddTestCase( |
| 101 |
"( " + string + " ).split(" + str_sep +", " + limit + |
| 102 |
" ).constructor == Array", |
| 103 |
true, |
| 104 |
string.split(separator, limit).constructor == Array ); |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
AddTestCase( |
| 109 |
"( " + string + " ).split(" + str_sep +", " + limit + " ).length", |
| 110 |
split_array.length, |
| 111 |
string.split(separator, limit).length ); |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
var slimit = (split_array.length > string.split(separator).length ) |
| 116 |
? split_array.length : string.split(separator, limit).length; |
| 117 |
|
| 118 |
for ( var matches = 0; matches < slimit; matches++ ) { |
| 119 |
AddTestCase( |
| 120 |
"( " + string + " ).split(" + str_sep +", " + limit + " )[" + matches +"]", |
| 121 |
split_array[matches], |
| 122 |
string.split( separator, limit )[matches] ); |
| 123 |
} |
| 124 |
} |