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.
This commit is contained in:
Victor Berchet 2016-06-20 14:21:01 -07:00
parent fdf6bc18dd
commit c5c456120c
7 changed files with 23 additions and 42 deletions

View File

@ -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();
})}));
});

View File

@ -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() {
'<div simpleComponent needsService></div>',
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('<div needsService></div>', 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('<div needsTemplateRef></div>', 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',

View File

@ -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();
});
});
});
}

View File

@ -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';

View File

@ -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]}`));
}

View File

@ -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'; });

View File

@ -638,7 +638,6 @@ const CORE_TESTING = [
'beforeEach(fn:Function):void',
'beforeEachProviders(fn:() => Array<any>):void',
'clearPendingTimers():void',
'containsRegexp(input:string):RegExp',
'discardPeriodicTasks():void',
'fakeAsync(fn:Function):Function',
'fit(name:string, fn:Function, timeOut:number=null):void',