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 {
137
137
static Match firstMatch (RegExp regExp, String input) {
138
138
return regExp.firstMatch (input);
139
139
}
140
+ static bool test (RegExp regExp, String input) {
141
+ return regExp.hasMatch (input);
142
+ }
140
143
static Iterator <Match > matcher (RegExp regExp, String input) {
141
144
return regExp.allMatches (input).iterator;
142
145
}
Original file line number Diff line number Diff line change @@ -193,11 +193,12 @@ export class RegExpWrapper {
193
193
flags = flags . replace ( / g / g, '' ) ;
194
194
return new _global . RegExp ( regExpStr , flags + 'g' ) ;
195
195
}
196
- static firstMatch ( regExp , input ) {
196
+ static firstMatch ( regExp : RegExp , input : string ) : List < string > {
197
197
// Reset multimatch regex state
198
198
regExp . lastIndex = 0 ;
199
199
return regExp . exec ( input ) ;
200
200
}
201
+ static test ( regExp : RegExp , input : string ) : boolean { return regExp . test ( input ) ; }
201
202
static matcher ( regExp , input ) {
202
203
// Reset regex state for the case
203
204
// someone did not loop over all matches
Original file line number Diff line number Diff line change @@ -19,7 +19,14 @@ export function main() {
19
19
}
20
20
21
21
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
+ } ) ;
23
30
} ) ;
24
31
25
32
describe ( 'const' , ( ) => {
You can’t perform that action at this time.
0 commit comments