| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = 'match-004.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 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
var SECTION = "String/match-004.js"; |
| 45 |
var VERSION = "ECMA_2"; |
| 46 |
var TITLE = "String.prototype.match( regexp )"; |
| 47 |
|
| 48 |
var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=345818"; |
| 49 |
|
| 50 |
startTest(); |
| 51 |
|
| 52 |
|
| 53 |
re = /0./; |
| 54 |
s = 10203040506070809000; |
| 55 |
|
| 56 |
Number.prototype.match = String.prototype.match; |
| 57 |
|
| 58 |
AddRegExpCases( re, |
| 59 |
"re = " + re , |
| 60 |
s, |
| 61 |
String(s), |
| 62 |
1, |
| 63 |
["02"]); |
| 64 |
|
| 65 |
|
| 66 |
re.lastIndex = 0; |
| 67 |
AddRegExpCases( re, |
| 68 |
"re = " + re +" [lastIndex is " + re.lastIndex+"]", |
| 69 |
s, |
| 70 |
String(s), |
| 71 |
1, |
| 72 |
["02"]); |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
test(); |
| 103 |
|
| 104 |
function AddRegExpCases( |
| 105 |
regexp, str_regexp, string, str_string, index, matches_array ) { |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
if ( regexp.exec(string) == null || matches_array == null ) { |
| 110 |
AddTestCase( |
| 111 |
string + ".match(" + regexp +")", |
| 112 |
matches_array, |
| 113 |
string.match(regexp) ); |
| 114 |
|
| 115 |
return; |
| 116 |
} |
| 117 |
|
| 118 |
AddTestCase( |
| 119 |
"( " + string + " ).match(" + str_regexp +").length", |
| 120 |
matches_array.length, |
| 121 |
string.match(regexp).length ); |
| 122 |
|
| 123 |
AddTestCase( |
| 124 |
"( " + string + " ).match(" + str_regexp +").index", |
| 125 |
index, |
| 126 |
string.match(regexp).index ); |
| 127 |
|
| 128 |
AddTestCase( |
| 129 |
"( " + string + " ).match(" + str_regexp +").input", |
| 130 |
str_string, |
| 131 |
string.match(regexp).input ); |
| 132 |
|
| 133 |
var limit = matches_array.length > string.match(regexp).length ? |
| 134 |
matches_array.length : |
| 135 |
string.match(regexp).length; |
| 136 |
|
| 137 |
for ( var matches = 0; matches < limit; matches++ ) { |
| 138 |
AddTestCase( |
| 139 |
"( " + string + " ).match(" + str_regexp +")[" + matches +"]", |
| 140 |
matches_array[matches], |
| 141 |
string.match(regexp)[matches] ); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
function AddGlobalRegExpCases( |
| 146 |
regexp, str_regexp, string, matches_array ) { |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
if ( regexp.exec(string) == null || matches_array == null ) { |
| 151 |
AddTestCase( |
| 152 |
regexp + ".exec(" + string +")", |
| 153 |
matches_array, |
| 154 |
regexp.exec(string) ); |
| 155 |
|
| 156 |
return; |
| 157 |
} |
| 158 |
|
| 159 |
AddTestCase( |
| 160 |
"( " + string + " ).match(" + str_regexp +").length", |
| 161 |
matches_array.length, |
| 162 |
string.match(regexp).length ); |
| 163 |
|
| 164 |
var limit = matches_array.length > string.match(regexp).length ? |
| 165 |
matches_array.length : |
| 166 |
string.match(regexp).length; |
| 167 |
|
| 168 |
for ( var matches = 0; matches < limit; matches++ ) { |
| 169 |
AddTestCase( |
| 170 |
"( " + string + " ).match(" + str_regexp +")[" + matches +"]", |
| 171 |
matches_array[matches], |
| 172 |
string.match(regexp)[matches] ); |
| 173 |
} |
| 174 |
} |