| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = 'match-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 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
var SECTION = "String/match-001.js"; |
| 40 |
var VERSION = "ECMA_2"; |
| 41 |
var TITLE = "String.prototype.match( regexp )"; |
| 42 |
|
| 43 |
startTest(); |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
AddRegExpCases( 3, "3", "1234567890", 1, 2, ["3"] ); |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
AddGlobalRegExpCases( /34/g, "/34/g", "343443444", 3, ["34", "34", "34"] ); |
| 55 |
AddGlobalRegExpCases( /\d{1}/g, "/d{1}/g", "123456abcde7890", 10, |
| 56 |
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] ); |
| 57 |
|
| 58 |
AddGlobalRegExpCases( /\d{2}/g, "/d{2}/g", "123456abcde7890", 5, |
| 59 |
["12", "34", "56", "78", "90"] ); |
| 60 |
|
| 61 |
AddGlobalRegExpCases( /\D{2}/g, "/d{2}/g", "123456abcde7890", 2, |
| 62 |
["ab", "cd"] ); |
| 63 |
|
| 64 |
test(); |
| 65 |
|
| 66 |
|
| 67 |
function AddRegExpCases( |
| 68 |
regexp, str_regexp, string, length, index, matches_array ) { |
| 69 |
|
| 70 |
AddTestCase( |
| 71 |
"( " + string + " ).match(" + str_regexp +").length", |
| 72 |
length, |
| 73 |
string.match(regexp).length ); |
| 74 |
|
| 75 |
AddTestCase( |
| 76 |
"( " + string + " ).match(" + str_regexp +").index", |
| 77 |
index, |
| 78 |
string.match(regexp).index ); |
| 79 |
|
| 80 |
AddTestCase( |
| 81 |
"( " + string + " ).match(" + str_regexp +").input", |
| 82 |
string, |
| 83 |
string.match(regexp).input ); |
| 84 |
|
| 85 |
for ( var matches = 0; matches < matches_array.length; matches++ ) { |
| 86 |
AddTestCase( |
| 87 |
"( " + string + " ).match(" + str_regexp +")[" + matches +"]", |
| 88 |
matches_array[matches], |
| 89 |
string.match(regexp)[matches] ); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
function AddGlobalRegExpCases( |
| 94 |
regexp, str_regexp, string, length, matches_array ) { |
| 95 |
|
| 96 |
AddTestCase( |
| 97 |
"( " + string + " ).match(" + str_regexp +").length", |
| 98 |
length, |
| 99 |
string.match(regexp).length ); |
| 100 |
|
| 101 |
for ( var matches = 0; matches < matches_array.length; matches++ ) { |
| 102 |
AddTestCase( |
| 103 |
"( " + string + " ).match(" + str_regexp +")[" + matches +"]", |
| 104 |
matches_array[matches], |
| 105 |
string.match(regexp)[matches] ); |
| 106 |
} |
| 107 |
} |