feat(RegExpWrapper): implement a test method
This commit is contained in:
parent
1dc8ba6920
commit
551586ced0
|
@ -137,6 +137,9 @@ class RegExpWrapper {
|
|||
static Match firstMatch(RegExp regExp, String input) {
|
||||
return regExp.firstMatch(input);
|
||||
}
|
||||
static bool test(RegExp regExp, String input) {
|
||||
return regExp.hasMatch(input);
|
||||
}
|
||||
static Iterator<Match> matcher(RegExp regExp, String input) {
|
||||
return regExp.allMatches(input).iterator;
|
||||
}
|
||||
|
|
|
@ -193,11 +193,12 @@ export class RegExpWrapper {
|
|||
flags = flags.replace(/g/g, '');
|
||||
return new _global.RegExp(regExpStr, flags + 'g');
|
||||
}
|
||||
static firstMatch(regExp, input) {
|
||||
static firstMatch(regExp: RegExp, input: string): List<string> {
|
||||
// Reset multimatch regex state
|
||||
regExp.lastIndex = 0;
|
||||
return regExp.exec(input);
|
||||
}
|
||||
static test(regExp: RegExp, input: string): boolean { return regExp.test(input); }
|
||||
static matcher(regExp, input) {
|
||||
// Reset regex state for the case
|
||||
// someone did not loop over all matches
|
||||
|
|
|
@ -19,7 +19,14 @@ export function main() {
|
|||
}
|
||||
|
||||
expect(indexes).toEqual([1, 4, 8, 9]);
|
||||
})
|
||||
});
|
||||
|
||||
it('should whether the regular expression has a match in the string', () => {
|
||||
var barRe = RegExpWrapper.create('bar');
|
||||
|
||||
expect(RegExpWrapper.test(barRe, 'bar')).toEqual(true);
|
||||
expect(RegExpWrapper.test(barRe, 'foo')).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('const', () => {
|
||||
|
|
Loading…
Reference in New Issue