File tree Expand file tree Collapse file tree 3 files changed +13
-2
lines changed Expand file tree Collapse file tree 3 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,9 @@ class RegExpWrapper {
137137 static Match firstMatch (RegExp regExp, String input) {
138138 return regExp.firstMatch (input);
139139 }
140+ static bool test (RegExp regExp, String input) {
141+ return regExp.hasMatch (input);
142+ }
140143 static Iterator <Match > matcher (RegExp regExp, String input) {
141144 return regExp.allMatches (input).iterator;
142145 }
Original file line number Diff line number Diff line change @@ -193,11 +193,12 @@ export class RegExpWrapper {
193193 flags = flags . replace ( / g / g, '' ) ;
194194 return new _global . RegExp ( regExpStr , flags + 'g' ) ;
195195 }
196- static firstMatch ( regExp , input ) {
196+ static firstMatch ( regExp : RegExp , input : string ) : List < string > {
197197 // Reset multimatch regex state
198198 regExp . lastIndex = 0 ;
199199 return regExp . exec ( input ) ;
200200 }
201+ static test ( regExp : RegExp , input : string ) : boolean { return regExp . test ( input ) ; }
201202 static matcher ( regExp , input ) {
202203 // Reset regex state for the case
203204 // someone did not loop over all matches
Original file line number Diff line number Diff line change @@ -19,7 +19,14 @@ export function main() {
1919 }
2020
2121 expect ( indexes ) . toEqual ( [ 1 , 4 , 8 , 9 ] ) ;
22- } )
22+ } ) ;
23+
24+ it ( 'should whether the regular expression has a match in the string' , ( ) => {
25+ var barRe = RegExpWrapper . create ( 'bar' ) ;
26+
27+ expect ( RegExpWrapper . test ( barRe , 'bar' ) ) . toEqual ( true ) ;
28+ expect ( RegExpWrapper . test ( barRe , 'foo' ) ) . toEqual ( false ) ;
29+ } ) ;
2330 } ) ;
2431
2532 describe ( 'const' , ( ) => {
You can’t perform that action at this time.
0 commit comments