From c5c456120c4fe86ae8b65d90ded08394a176ad45 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 20 Jun 2016 14:21:01 -0700 Subject: [PATCH] refactor: delete containsRegexp() (there is escapeRegExp() in the lang facade) BREAKING CHANGES: `containsRegexp` is no more exported from `@angular/core/testing`. It should not have been part of the public API in the first place. --- .../core/test/linker/integration_spec.ts | 8 +++---- .../linker/view_injector_integration_spec.ts | 10 ++++----- .../core/test/testing_internal_spec.ts | 22 ++++--------------- modules/@angular/core/testing.ts | 1 - modules/@angular/core/testing/regexp.ts | 9 -------- modules/@angular/facade/test/lang_spec.ts | 14 +++++++++--- tools/public_api_guard/public_api_spec.ts | 1 - 7 files changed, 23 insertions(+), 42 deletions(-) delete mode 100644 modules/@angular/core/testing/regexp.ts diff --git a/modules/@angular/core/test/linker/integration_spec.ts b/modules/@angular/core/test/linker/integration_spec.ts index 15ba1ad857..c2d5bbc352 100644 --- a/modules/@angular/core/test/linker/integration_spec.ts +++ b/modules/@angular/core/test/linker/integration_spec.ts @@ -1,5 +1,5 @@ import {beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal'; -import {containsRegexp, fakeAsync, tick, clearPendingTimers} from '@angular/core/testing'; +import {fakeAsync, tick, clearPendingTimers} from '@angular/core/testing'; import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing'; import {AsyncTestCompleter} from '@angular/core/testing/testing_internal'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; @@ -1663,7 +1663,7 @@ function declareTests({useJit}: {useJit: boolean}) { .createAsync(MyComp) .then((fixture) => { - expect(() => fixture.detectChanges()).toThrowError(containsRegexp(`:0:5`)); + expect(() => fixture.detectChanges()).toThrowError(/:0:5/); async.done(); })})); @@ -1676,7 +1676,7 @@ function declareTests({useJit}: {useJit: boolean}) { .createAsync(MyComp) .then((fixture) => { - expect(() => fixture.detectChanges()).toThrowError(containsRegexp(`:0:5`)); + expect(() => fixture.detectChanges()).toThrowError(/:0:5/); async.done(); })})); @@ -1692,7 +1692,7 @@ function declareTests({useJit}: {useJit: boolean}) { .createAsync(MyComp) .then((fixture) => { - expect(() => fixture.detectChanges()).toThrowError(containsRegexp(`:0:11`)); + expect(() => fixture.detectChanges()).toThrowError(/:0:11/); async.done(); })})); }); diff --git a/modules/@angular/core/test/linker/view_injector_integration_spec.ts b/modules/@angular/core/test/linker/view_injector_integration_spec.ts index ce985fffaf..e90415f1a3 100644 --- a/modules/@angular/core/test/linker/view_injector_integration_spec.ts +++ b/modules/@angular/core/test/linker/view_injector_integration_spec.ts @@ -1,5 +1,5 @@ import {describe, ddescribe, it, iit, xit, xdescribe, expect, beforeEach, beforeEachProviders, inject,} from '@angular/core/testing/testing_internal'; -import {fakeAsync, flushMicrotasks, Log, tick, containsRegexp} from '@angular/core/testing'; +import {fakeAsync, flushMicrotasks, Log, tick} from '@angular/core/testing'; import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing'; import {isBlank} from '../../src/facade/lang'; import {Type, ViewContainerRef, TemplateRef, ElementRef, ChangeDetectorRef, ChangeDetectionStrategy, Directive, Component, DebugElement, forwardRef, Input, PipeTransform, Attribute, ViewMetadata, provide, Optional, Inject, Self, InjectMetadata, Pipe, Host, SkipSelfMetadata} from '@angular/core'; @@ -59,8 +59,6 @@ class SimpleDirective { class SimpleComponent { } -class SimpleService {} - @Directive({selector: '[someOtherDirective]'}) class SomeOtherDirective { } @@ -398,7 +396,7 @@ export function main() { '
', tcb.overrideViewProviders( SimpleComponent, [{provide: 'service', useValue: 'service'}]))) - .toThrowError(containsRegexp(`No provider for service!`)); + .toThrowError(/No provider for service!/); })); it('should instantiate directives that depend on providers of other directives', @@ -510,7 +508,7 @@ export function main() { it('should throw when a dependency cannot be resolved', fakeAsync(() => { expect(() => createComp('
', tcb)) - .toThrowError(containsRegexp(`No provider for service!`)); + .toThrowError(/No provider for service!/); })); it('should inject null when an optional dependency cannot be resolved', fakeAsync(() => { @@ -624,7 +622,7 @@ export function main() { it('should throw if there is no TemplateRef', fakeAsync(() => { expect(() => createComp('
', tcb)) - .toThrowError(containsRegexp(`No provider for TemplateRef!`)); + .toThrowError(/No provider for TemplateRef!/); })); it('should inject null if there is no TemplateRef when the dependency is optional', diff --git a/modules/@angular/core/test/testing_internal_spec.ts b/modules/@angular/core/test/testing_internal_spec.ts index da7fc51703..2286d6b0d4 100644 --- a/modules/@angular/core/test/testing_internal_spec.ts +++ b/modules/@angular/core/test/testing_internal_spec.ts @@ -1,14 +1,13 @@ import {SpyObject} from '@angular/core/testing/testing_internal'; import {MapWrapper} from '../../platform-browser/src/facade/collection'; -import {RegExpWrapper} from '../../router-deprecated/src/facade/lang'; -import {beforeEach, containsRegexp, ddescribe, describe, expect, iit, it, tick} from '../testing'; +import {beforeEach, ddescribe, describe, expect, iit, it, tick} from '../testing'; class TestObj { - prop: any /** TODO #9100 */; - constructor(prop: any /** TODO #9100 */) { this.prop = prop; } + prop: any; + constructor(prop: any) { this.prop = prop; } someFunc(): number { return -1; } - someComplexFunc(a: any /** TODO #9100 */) { return a; } + someComplexFunc(a: any) { return a; } } class SpyTestObj extends SpyObject { @@ -117,18 +116,5 @@ export function main() { }); }); - describe('containsRegexp', () => { - - it('should allow any prefix and suffix', () => { - expect(RegExpWrapper.firstMatch(containsRegexp('b'), 'abc')).toBeTruthy(); - expect(RegExpWrapper.firstMatch(containsRegexp('b'), 'adc')).toBeFalsy(); - }); - - it('should match various special characters', () => { - expect(RegExpWrapper.firstMatch(containsRegexp('a.b'), 'a.b')).toBeTruthy(); - expect(RegExpWrapper.firstMatch(containsRegexp('axb'), 'a.b')).toBeFalsy(); - }); - - }); }); } diff --git a/modules/@angular/core/testing.ts b/modules/@angular/core/testing.ts index cf0d1d9c37..8d11987557 100644 --- a/modules/@angular/core/testing.ts +++ b/modules/@angular/core/testing.ts @@ -2,7 +2,6 @@ export * from './testing/fake_async'; export * from './testing/lang_utils'; export * from './testing/logger'; export * from './testing/ng_zone_mock'; -export * from './testing/regexp'; export * from './testing/test_injector'; export * from './testing/testing'; export * from './testing/mock_application_ref'; diff --git a/modules/@angular/core/testing/regexp.ts b/modules/@angular/core/testing/regexp.ts deleted file mode 100644 index 90eae4fdd0..0000000000 --- a/modules/@angular/core/testing/regexp.ts +++ /dev/null @@ -1,9 +0,0 @@ -import {RegExpWrapper, StringWrapper} from '../src/facade/lang'; - -var _RE_SPECIAL_CHARS = - ['-', '[', ']', '/', '{', '}', '\\', '(', ')', '*', '+', '?', '.', '^', '$', '|']; -var _ESCAPE_RE = RegExpWrapper.create(`[\\${_RE_SPECIAL_CHARS.join('\\')}]`); -export function containsRegexp(input: string): RegExp { - return RegExpWrapper.create(StringWrapper.replaceAllMapped( - input, _ESCAPE_RE, (match: any /** TODO #9100 */) => `\\${match[0]}`)); -} diff --git a/modules/@angular/facade/test/lang_spec.ts b/modules/@angular/facade/test/lang_spec.ts index 902f2f5e23..ae85520e1f 100644 --- a/modules/@angular/facade/test/lang_spec.ts +++ b/modules/@angular/facade/test/lang_spec.ts @@ -1,5 +1,5 @@ import {beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing'; -import {NumberWrapper, RegExpMatcherWrapper, RegExpWrapper, StringWrapper, hasConstructor, isPresent, resolveEnumToken} from '../src/lang'; +import {NumberWrapper, RegExpMatcherWrapper, RegExpWrapper, StringWrapper, escapeRegExp, hasConstructor, isPresent, resolveEnumToken} from '../src/lang'; enum UsefulEnum { MyToken, @@ -14,7 +14,7 @@ export function main() { it('should expose the index for each match', () => { var re = /(!)/g; var matcher = RegExpWrapper.matcher(re, '0!23!567!!'); - var indexes: any[] /** TODO #9100 */ = []; + var indexes: number[] = []; var m: any /** TODO #9100 */; while (isPresent(m = RegExpMatcherWrapper.next(matcher))) { @@ -41,6 +41,14 @@ export function main() { RegExpWrapper.replaceAll(re, 'a1b2c', (match: any /** TODO #9100 */) => `!${match[1]}!`); expect(m).toEqual('a!1!b!2!c'); }); + + it('should escape regexp', () => { + expect(RegExpWrapper.firstMatch(new RegExp(escapeRegExp('b')), 'abc')).toBeTruthy(); + expect(RegExpWrapper.firstMatch(new RegExp(escapeRegExp('b')), 'adc')).toBeFalsy(); + expect(RegExpWrapper.firstMatch(new RegExp(escapeRegExp('a.b')), 'a.b')).toBeTruthy(); + expect(RegExpWrapper.firstMatch(new RegExp(escapeRegExp('axb')), 'a.b')).toBeFalsy(); + }); + }); describe('const', () => { @@ -73,7 +81,7 @@ export function main() { }); describe('String', () => { - var s: any /** TODO #9100 */; + var s: string; describe('slice', () => { beforeEach(() => { s = 'abcdefghij'; }); diff --git a/tools/public_api_guard/public_api_spec.ts b/tools/public_api_guard/public_api_spec.ts index 329d20d5f5..e30865d110 100644 --- a/tools/public_api_guard/public_api_spec.ts +++ b/tools/public_api_guard/public_api_spec.ts @@ -638,7 +638,6 @@ const CORE_TESTING = [ 'beforeEach(fn:Function):void', 'beforeEachProviders(fn:() => Array):void', 'clearPendingTimers():void', - 'containsRegexp(input:string):RegExp', 'discardPeriodicTasks():void', 'fakeAsync(fn:Function):Function', 'fit(name:string, fn:Function, timeOut:number=null):void',