Skip to content

Commit

Permalink
refactor(tests): removed @implements
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Aug 26, 2015
1 parent 457eb5d commit 343dcfa
Show file tree
Hide file tree
Showing 43 changed files with 401 additions and 425 deletions.
6 changes: 0 additions & 6 deletions modules/angular1_router/lib/facades.es5
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ function CONST() {
});
}

function IMPLEMENTS(_) {
return (function(t) {
return t;
});
}

function CONST_EXPR(expr) {
return expr;
}
Expand Down
5 changes: 0 additions & 5 deletions modules/angular2/src/core/facade/lang.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ class ABSTRACT {
const ABSTRACT();
}

class IMPLEMENTS {
final interfaceClass;
const IMPLEMENTS(this.interfaceClass);
}

bool isPresent(obj) => obj != null;
bool isBlank(obj) => obj == null;
bool isString(obj) => obj is String;
Expand Down
7 changes: 0 additions & 7 deletions modules/angular2/src/core/facade/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ export function ABSTRACT(): ClassDecorator {
return (t) => t;
}

// Note: This is only a marker annotation needed for ts2dart.
// This is written so that is can be used as a Traceur annotation
// or a Typescript decorator.
export function IMPLEMENTS(_): ClassDecorator {
return (t) => t;
}

export function isPresent(obj: any): boolean {
return obj !== undefined && obj !== null;
}
Expand Down
8 changes: 3 additions & 5 deletions modules/angular2/src/http/backends/mock_backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import {ReadyStates} from '../enums';
import {Connection, ConnectionBackend} from '../interfaces';
import {ObservableWrapper, EventEmitter} from 'angular2/src/core/facade/async';
import {isPresent} from 'angular2/src/core/facade/lang';
import {IMPLEMENTS, BaseException} from 'angular2/src/core/facade/lang';
import {BaseException} from 'angular2/src/core/facade/lang';

/**
*
* Mock Connection to represent a {@link Connection} for tests.
*
**/
@IMPLEMENTS(Connection)
export class MockConnection {
export class MockConnection implements Connection {
// TODO Name `readyState` should change to be more generic, and states could be made to be more
// descriptive than XHR states.
/**
Expand Down Expand Up @@ -130,8 +129,7 @@ export class MockConnection {
* This method only exists in the mock implementation, not in real Backends.
**/
@Injectable()
@IMPLEMENTS(ConnectionBackend)
export class MockBackend {
export class MockBackend implements ConnectionBackend {
/**
* {@link EventEmitter}
* of {@link MockConnection} instances that have been created by this backend. Can be subscribed
Expand Down
28 changes: 8 additions & 20 deletions modules/angular2/src/mock/location_mock.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
import {SpyObject, proxy} from 'angular2/test_lib';

import {IMPLEMENTS} from 'angular2/src/core/facade/lang';
import {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async';
import {List, ListWrapper} from 'angular2/src/core/facade/collection';
import {Location} from 'angular2/src/router/location';


@proxy
@IMPLEMENTS(Location)
export class SpyLocation extends SpyObject {
urlChanges: List<string>;
_path: string;
_subject: EventEmitter;
_baseHref: string;

constructor() {
super();
this._path = '';
this.urlChanges = [];
this._subject = new EventEmitter();
this._baseHref = '';
}
export class SpyLocation implements Location {
urlChanges: List<string> = [];
_path: string = '';
_subject: EventEmitter = new EventEmitter();
_baseHref: string = '';

setInitialPath(url: string) { this._path = url; }

Expand Down Expand Up @@ -54,5 +40,7 @@ export class SpyLocation extends SpyObject {
ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn);
}

noSuchMethod(m: any) { super.noSuchMethod(m); }
// TODO: remove these once Location is an interface, and can be implemented cleanly
platformStrategy: any = null;
normalize(url: string): string { return null; }
}
53 changes: 24 additions & 29 deletions modules/angular2/src/router/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,69 +18,64 @@ export const APP_BASE_HREF: OpaqueToken = CONST_EXPR(new OpaqueToken('appBaseHre
*/
@Injectable()
export class Location {
private _subject: EventEmitter = new EventEmitter();
private _baseHref: string;
_subject: EventEmitter = new EventEmitter();
_baseHref: string;

constructor(public _platformStrategy: LocationStrategy,
constructor(public platformStrategy: LocationStrategy,
@Optional() @Inject(APP_BASE_HREF) href?: string) {
var browserBaseHref = isPresent(href) ? href : this._platformStrategy.getBaseHref();
var browserBaseHref = isPresent(href) ? href : this.platformStrategy.getBaseHref();

if (isBlank(browserBaseHref)) {
throw new BaseException(
`No base href set. Either provide a binding to "appBaseHrefToken" or add a base element.`);
}

this._baseHref = stripTrailingSlash(stripIndexHtml(browserBaseHref));
this._platformStrategy.onPopState((_) => this._onPopState(_));
this.platformStrategy.onPopState(
(_) => { ObservableWrapper.callNext(this._subject, {'url': this.path(), 'pop': true}); });
}

_onPopState(_): void {
ObservableWrapper.callNext(this._subject, {'url': this.path(), 'pop': true});
}

path(): string { return this.normalize(this._platformStrategy.path()); }
path(): string { return this.normalize(this.platformStrategy.path()); }

normalize(url: string): string {
return stripTrailingSlash(this._stripBaseHref(stripIndexHtml(url)));
return stripTrailingSlash(_stripBaseHref(this._baseHref, stripIndexHtml(url)));
}

normalizeAbsolutely(url: string): string {
if (!url.startsWith('/')) {
url = '/' + url;
}
return stripTrailingSlash(this._addBaseHref(url));
}

_stripBaseHref(url: string): string {
if (this._baseHref.length > 0 && url.startsWith(this._baseHref)) {
return url.substring(this._baseHref.length);
}
return url;
}

_addBaseHref(url: string): string {
if (!url.startsWith(this._baseHref)) {
return this._baseHref + url;
}
return url;
return stripTrailingSlash(_addBaseHref(this._baseHref, url));
}

go(url: string): void {
var finalUrl = this.normalizeAbsolutely(url);
this._platformStrategy.pushState(null, '', finalUrl);
this.platformStrategy.pushState(null, '', finalUrl);
}

forward(): void { this._platformStrategy.forward(); }
forward(): void { this.platformStrategy.forward(); }

back(): void { this._platformStrategy.back(); }
back(): void { this.platformStrategy.back(); }

subscribe(onNext: (value: any) => void, onThrow: (exception: any) => void = null,
onReturn: () => void = null): void {
ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn);
}
}

function _stripBaseHref(baseHref: string, url: string): string {
if (baseHref.length > 0 && url.startsWith(baseHref)) {
return url.substring(baseHref.length);
}
return url;
}

function _addBaseHref(baseHref: string, url: string): string {
if (!url.startsWith(baseHref)) {
return baseHref + url;
}
return url;
}

function stripIndexHtml(url: string): string {
if (/\/index.html$/g.test(url)) {
Expand Down
1 change: 0 additions & 1 deletion modules/angular2/src/router/path_recognizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
List,
ListWrapper
} from 'angular2/src/core/facade/collection';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang';

import {RouteHandler} from './route_handler';
import {Url, RootUrl, serializeParams} from './url_parser';
Expand Down
36 changes: 0 additions & 36 deletions modules/angular2/src/test_lib/spies.dart

This file was deleted.

28 changes: 0 additions & 28 deletions modules/angular2/src/test_lib/spies.ts

This file was deleted.

4 changes: 4 additions & 0 deletions modules/angular2/src/test_lib/test_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ class SpyObject extends gns.SpyObject {
SpyFunction spy(String funcName) =>
_spyFuncs.putIfAbsent(funcName, () => new SpyFunction(funcName));

void prop(String funcName, value) {
_spyFuncs.putIfAbsent("get:${funcName}", () => new SpyFunction(funcName)).andReturn(value);
}

static stub([object = null, config = null, overrides = null]) {
if (object is! SpyObject) {
overrides = config;
Expand Down
2 changes: 2 additions & 0 deletions modules/angular2/src/test_lib/test_lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ export class SpyObject {
return this[name];
}

prop(name, value) { this[name] = value; }

static stub(object = null, config = null, overrides = null) {
if (!(object instanceof SpyObject)) {
overrides = config;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import {
ddescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach,
SpyProtoChangeDetector
} from 'angular2/test_lib';
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';

import {SpyProtoChangeDetector} from '../spies';

import {
PreGeneratedChangeDetection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import {
ddescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach,
SpyIterableDifferFactory
} from 'angular2/test_lib';
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
import {SpyIterableDifferFactory} from '../../spies';
import {IterableDiffers} from 'angular2/src/core/change_detection/differs/iterable_differs';
import {Injector, bind} from 'angular2/di';

Expand Down
30 changes: 3 additions & 27 deletions modules/angular2/test/core/compiler/compiler_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,17 @@ import {
expect,
iit,
inject,
it,
SpyObject,
proxy
it
} from 'angular2/test_lib';

import {SpyRenderCompiler, SpyDirectiveResolver} from '../spies';
import {
List,
ListWrapper,
Map,
MapWrapper,
StringMapWrapper
} from 'angular2/src/core/facade/collection';
import {
IMPLEMENTS,
Type,
isBlank,
stringify,
isPresent,
isArray
} from 'angular2/src/core/facade/lang';
import {Type, isBlank, stringify, isPresent, isArray} from 'angular2/src/core/facade/lang';
import {PromiseCompleter, PromiseWrapper, Promise} from 'angular2/src/core/facade/async';

import {Compiler, CompilerCache} from 'angular2/src/core/compiler/compiler';
Expand Down Expand Up @@ -58,7 +49,6 @@ import {
RenderElementBinder
} from 'angular2/src/core/render/api';
// TODO(tbosch): Spys don't support named modules...
import {RenderCompiler} from 'angular2/src/core/render/api';
import {PipeBinding} from 'angular2/src/core/pipes/pipe_binding';


Expand Down Expand Up @@ -718,20 +708,6 @@ class DirectiveWithAttributes {
constructor(@Attribute('someAttr') someAttr: String) {}
}

@proxy
@IMPLEMENTS(RenderCompiler)
class SpyRenderCompiler extends SpyObject {
constructor() { super(RenderCompiler); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}

@proxy
@IMPLEMENTS(DirectiveResolver)
class SpyDirectiveResolver extends SpyObject {
constructor() { super(DirectiveResolver); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}

class FakeViewResolver extends ViewResolver {
_cmpViews: Map<Type, ViewMetadata> = new Map();

Expand Down
Loading

0 comments on commit 343dcfa

Please sign in to comment.