From d27e5512c01bbd1c4eea94cb7c7f104097c6f4e5 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Fri, 22 May 2015 16:20:46 -0700 Subject: [PATCH] chore(reflection): tsfy tests --- .../test/reflection/reflector_common.dart | 19 +++++ .../test/reflection/reflector_common.ts | 24 ++++++ .../{reflector_spec.js => reflector_spec.ts} | 81 ++++++------------- 3 files changed, 69 insertions(+), 55 deletions(-) create mode 100644 modules/angular2/test/reflection/reflector_common.dart create mode 100644 modules/angular2/test/reflection/reflector_common.ts rename modules/angular2/test/reflection/{reflector_spec.js => reflector_spec.ts} (57%) diff --git a/modules/angular2/test/reflection/reflector_common.dart b/modules/angular2/test/reflection/reflector_common.dart new file mode 100644 index 0000000000..f077374c61 --- /dev/null +++ b/modules/angular2/test/reflection/reflector_common.dart @@ -0,0 +1,19 @@ +class ClassDecorator { + final dynamic value; + + const ClassDecorator(this.value); +} + +class ParamDecorator { + final dynamic value; + + const ParamDecorator(this.value); +} + +ClassDecorator classDecorator(value) { + return new ClassDecorator(value); +} + +ParamDecorator paramDecorator(value) { + return new ParamDecorator(value); +} \ No newline at end of file diff --git a/modules/angular2/test/reflection/reflector_common.ts b/modules/angular2/test/reflection/reflector_common.ts new file mode 100644 index 0000000000..c419d0fa1f --- /dev/null +++ b/modules/angular2/test/reflection/reflector_common.ts @@ -0,0 +1,24 @@ +import {makeDecorator, makeParamDecorator} from 'angular2/src/util/decorators'; + +export class ClassDecoratorImpl { + value; + + constructor(value) { this.value = value; } +} + +export class ParamDecoratorImpl { + value; + + constructor(value) { this.value = value; } +} + +export function classDecorator(value) { + return new ClassDecoratorImpl(value); +} + +export function paramDecorator(value) { + return new ParamDecoratorImpl(value); +} + +export var ClassDecorator = makeDecorator(ClassDecoratorImpl); +export var ParamDecorator = makeParamDecorator(ParamDecoratorImpl); \ No newline at end of file diff --git a/modules/angular2/test/reflection/reflector_spec.js b/modules/angular2/test/reflection/reflector_spec.ts similarity index 57% rename from modules/angular2/test/reflection/reflector_spec.js rename to modules/angular2/test/reflection/reflector_spec.ts index ec313bf0ed..7342d6e9d2 100644 --- a/modules/angular2/test/reflection/reflector_spec.js +++ b/modules/angular2/test/reflection/reflector_spec.ts @@ -1,47 +1,31 @@ import {describe, it, iit, ddescribe, expect, beforeEach} from 'angular2/test_lib'; import {Reflector} from 'angular2/src/reflection/reflection'; import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities'; -import {CONST} from 'angular2/src/facade/lang'; - -class Annotation { - value; - - @CONST() - constructor(value) { - this.value = value; - } -} +import {ClassDecorator, ParamDecorator, classDecorator, paramDecorator} from './reflector_common'; class AType { value; - constructor(value){ - this.value = value; - } + constructor(value) { this.value = value; } } -@Annotation('class') -class ClassWithAnnotations { +@ClassDecorator('class') +class ClassWithDecorators { a; b; - constructor(@Annotation("a") a:AType, @Annotation("b") b:AType) { + constructor(@ParamDecorator("a") a: AType, @ParamDecorator("b") b: AType) { this.a = a; this.b = b; } } -class ClassWithoutAnnotations { - constructor(a,b){} +class ClassWithoutDecorators { + constructor(a, b) {} } class TestObjWith11Args { - constructor(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) { - } -} - -@Annotation('func') -function testFunc(@Annotation("a") a:AType, @Annotation("b") b:AType) { + constructor(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) {} } class TestObj { @@ -53,18 +37,14 @@ class TestObj { this.b = b; } - identity(arg) { - return arg; - } + identity(arg) { return arg; } } export function main() { describe('Reflector', () => { var reflector; - beforeEach(() => { - reflector = new Reflector(new ReflectionCapabilities()); - }); + beforeEach(() => { reflector = new Reflector(new ReflectionCapabilities()); }); describe("factory", () => { it("should create a factory for the given type", () => { @@ -75,55 +55,46 @@ export function main() { }); it("should throw when more than 10 arguments", () => { - expect(() => reflector.factory(TestObjWith11Args)(1,2,3,4,5,6,7,8,9,10,11)).toThrowError(); + expect(() => reflector.factory(TestObjWith11Args)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)) + .toThrowError(); }); it("should return a registered factory if available", () => { - reflector.registerType(TestObj, {"factory" : () => "fake"}); + reflector.registerType(TestObj, {"factory": () => "fake"}); expect(reflector.factory(TestObj)()).toEqual("fake"); }); }); describe("parameters", () => { it("should return an array of parameters for a type", () => { - var p = reflector.parameters(ClassWithAnnotations); - expect(p).toEqual([[AType, new Annotation('a')], [AType, new Annotation('b')]]); - }); - - it("should return an array of parameters for a function", () => { - var p = reflector.parameters(testFunc); - expect(p).toEqual([[AType, new Annotation('a')], [AType, new Annotation('b')]]); + var p = reflector.parameters(ClassWithDecorators); + expect(p).toEqual([[AType, paramDecorator('a')], [AType, paramDecorator('b')]]); }); it("should work for a class without annotations", () => { - var p = reflector.parameters(ClassWithoutAnnotations); + var p = reflector.parameters(ClassWithoutDecorators); expect(p.length).toEqual(2); }); it("should return registered parameters if available", () => { - reflector.registerType(TestObj, {"parameters" : [1,2]}); - expect(reflector.parameters(TestObj)).toEqual([1,2]); + reflector.registerType(TestObj, {"parameters": [1, 2]}); + expect(reflector.parameters(TestObj)).toEqual([1, 2]); }); }); describe("annotations", () => { it("should return an array of annotations for a type", () => { - var p = reflector.annotations(ClassWithAnnotations); - expect(p).toEqual([new Annotation('class')]); - }); - - it("should return an array of annotations for a function", () => { - var p = reflector.annotations(testFunc); - expect(p).toEqual([new Annotation('func')]); + var p = reflector.annotations(ClassWithDecorators); + expect(p).toEqual([classDecorator('class')]); }); it("should return registered annotations if available", () => { - reflector.registerType(TestObj, {"annotations" : [1,2]}); - expect(reflector.annotations(TestObj)).toEqual([1,2]); + reflector.registerType(TestObj, {"annotations": [1, 2]}); + expect(reflector.annotations(TestObj)).toEqual([1, 2]); }); it("should work for a clas without annotations", () => { - var p = reflector.annotations(ClassWithoutAnnotations); + var p = reflector.annotations(ClassWithoutDecorators); expect(p).toEqual([]); }); }); @@ -135,7 +106,7 @@ export function main() { }); it("should return a registered getter if available", () => { - reflector.registerGetters({"abc" : (obj) => "fake"}); + reflector.registerGetters({"abc": (obj) => "fake"}); expect(reflector.getter("abc")("anything")).toEqual("fake"); }); }); @@ -150,7 +121,7 @@ export function main() { it("should return a registered setter if available", () => { var updateMe; - reflector.registerSetters({"abc" : (obj, value) => {updateMe = value;}}); + reflector.registerSetters({"abc": (obj, value) => { updateMe = value; }}); reflector.setter("abc")("anything", "fake"); expect(updateMe).toEqual("fake"); @@ -165,7 +136,7 @@ export function main() { }); it("should return a registered method if available", () => { - reflector.registerMethods({"abc" : (obj, args) => args}); + reflector.registerMethods({"abc": (obj, args) => args}); expect(reflector.method("abc")("anything", ["fake"])).toEqual(['fake']); }); });