Skip to content

Commit 551586c

Browse files
committed
feat(RegExpWrapper): implement a test method
1 parent 1dc8ba6 commit 551586c

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

modules/angular2/src/facade/lang.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

modules/angular2/src/facade/lang.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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

modules/angular2/test/facade/lang_spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff 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', () => {

0 commit comments

Comments
 (0)