From 551586ced0bda68976c4149216aa06422f57f5b4 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 26 May 2015 13:34:11 +0200 Subject: [PATCH] feat(RegExpWrapper): implement a test method --- modules/angular2/src/facade/lang.dart | 3 +++ modules/angular2/src/facade/lang.ts | 3 ++- modules/angular2/test/facade/lang_spec.js | 9 ++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/angular2/src/facade/lang.dart b/modules/angular2/src/facade/lang.dart index 59f12ab607..3d3db10deb 100644 --- a/modules/angular2/src/facade/lang.dart +++ b/modules/angular2/src/facade/lang.dart @@ -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 matcher(RegExp regExp, String input) { return regExp.allMatches(input).iterator; } diff --git a/modules/angular2/src/facade/lang.ts b/modules/angular2/src/facade/lang.ts index bd2e1c34fd..4fcc90e7ae 100644 --- a/modules/angular2/src/facade/lang.ts +++ b/modules/angular2/src/facade/lang.ts @@ -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 { // 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 diff --git a/modules/angular2/test/facade/lang_spec.js b/modules/angular2/test/facade/lang_spec.js index e36fba2391..2da41d15a1 100644 --- a/modules/angular2/test/facade/lang_spec.js +++ b/modules/angular2/test/facade/lang_spec.js @@ -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', () => {