| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = 'split-001.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-001.js"; |
| 35 |
var VERSION = "ECMA_2"; |
| 36 |
var TITLE = "String.prototype.split( regexp, [,limit] )"; |
| 37 |
|
| 38 |
startTest(); |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
AddSplitCases( "splitme", "", "''", ["s", "p", "l", "i", "t", "m", "e"] ); |
| 45 |
AddSplitCases( "splitme", new RegExp(), "new RegExp()", ["s", "p", "l", "i", "t", "m", "e"] ); |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
test(); |
| 60 |
|
| 61 |
function AddSplitCases( string, separator, str_sep, split_array ) { |
| 62 |
|
| 63 |
|
| 64 |
AddTestCase( |
| 65 |
"( " + string + " ).split(" + str_sep +").constructor == Array", |
| 66 |
true, |
| 67 |
string.split(separator).constructor == Array ); |
| 68 |
|
| 69 |
|
| 70 |
AddTestCase( |
| 71 |
"( " + string + " ).split(" + str_sep +").length", |
| 72 |
split_array.length, |
| 73 |
string.split(separator).length ); |
| 74 |
|
| 75 |
|
| 76 |
var limit = (split_array.length > string.split(separator).length ) |
| 77 |
? split_array.length : string.split(separator).length; |
| 78 |
|
| 79 |
for ( var matches = 0; matches < split_array.length; matches++ ) { |
| 80 |
AddTestCase( |
| 81 |
"( " + string + " ).split(" + str_sep +")[" + matches +"]", |
| 82 |
split_array[matches], |
| 83 |
string.split( separator )[matches] ); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
function AddLimitedSplitCases( |
| 88 |
string, separator, str_sep, limit, str_limit, split_array ) { |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
AddTestCase( |
| 93 |
"( " + string + " ).split(" + str_sep +", " + str_limit + |
| 94 |
" ).constructor == Array", |
| 95 |
true, |
| 96 |
string.split(separator, limit).constructor == Array ); |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
AddTestCase( |
| 101 |
"( " + string + " ).split(" + str_sep +", " + str_limit + " ).length", |
| 102 |
length, |
| 103 |
string.split(separator).length ); |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
for ( var matches = 0; matches < split_array.length; matches++ ) { |
| 108 |
AddTestCase( |
| 109 |
"( " + string + " ).split(" + str_sep +", " + str_limit + " )[" + matches +"]", |
| 110 |
split_array[matches], |
| 111 |
string.split( separator )[matches] ); |
| 112 |
} |
| 113 |
} |