2015-02-05 18:58:15 -05:00
|
|
|
import {ddescribe, describe, it, expect} from 'angular2/test_lib';
|
2014-10-01 10:29:45 -04:00
|
|
|
import {CONST} from './fixtures/annotations';
|
2014-09-28 16:55:01 -04:00
|
|
|
|
2014-09-25 17:30:10 -04:00
|
|
|
class Foo {
|
2014-11-22 00:19:23 -05:00
|
|
|
a;
|
|
|
|
b;
|
|
|
|
|
2014-09-25 17:30:10 -04:00
|
|
|
constructor(a, b) {
|
|
|
|
this.a = a;
|
|
|
|
this.b = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
sum() {
|
|
|
|
return this.a + this.b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-01 10:29:45 -04:00
|
|
|
class SubFoo extends Foo {
|
2014-11-22 00:19:23 -05:00
|
|
|
c;
|
|
|
|
|
2014-10-01 10:29:45 -04:00
|
|
|
constructor(a, b) {
|
|
|
|
this.c = 3;
|
|
|
|
super(a, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-02 14:21:11 -05:00
|
|
|
@CONST
|
|
|
|
class ConstClass {}
|
|
|
|
|
2014-10-01 10:29:45 -04:00
|
|
|
class Const {
|
2014-11-22 00:19:23 -05:00
|
|
|
a;
|
|
|
|
|
2014-10-01 10:29:45 -04:00
|
|
|
@CONST
|
|
|
|
constructor(a:number) {
|
|
|
|
this.a = a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SubConst extends Const {
|
2014-11-22 00:19:23 -05:00
|
|
|
b;
|
|
|
|
|
2014-10-01 10:29:45 -04:00
|
|
|
@CONST
|
|
|
|
constructor(a:number, b:number) {
|
|
|
|
super(a);
|
|
|
|
this.b = b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-16 16:10:21 -04:00
|
|
|
class HasGetters {
|
|
|
|
get getter():string {
|
|
|
|
return 'getter';
|
|
|
|
}
|
|
|
|
|
|
|
|
static get staticGetter():string {
|
|
|
|
return 'getter';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-07 12:31:51 -05:00
|
|
|
class WithFields {
|
|
|
|
name: string;
|
|
|
|
static id: number;
|
|
|
|
}
|
|
|
|
|
2014-09-28 16:55:01 -04:00
|
|
|
export function main() {
|
|
|
|
describe('classes', function() {
|
|
|
|
it('should work', function() {
|
|
|
|
var foo = new Foo(2, 3);
|
2014-09-25 17:30:10 -04:00
|
|
|
|
2014-09-28 16:55:01 -04:00
|
|
|
expect(foo.a).toBe(2);
|
|
|
|
expect(foo.b).toBe(3);
|
|
|
|
expect(foo.sum()).toBe(5);
|
|
|
|
});
|
2014-10-01 10:29:45 -04:00
|
|
|
|
|
|
|
it('@CONST should be transpiled to a const constructor', function() {
|
|
|
|
var subConst = new SubConst(1, 2);
|
|
|
|
expect(subConst.a).toBe(1);
|
|
|
|
expect(subConst.b).toBe(2);
|
|
|
|
});
|
|
|
|
|
2014-11-02 14:21:11 -05:00
|
|
|
it('@CONST on class without constructor should generate const constructor', function () {
|
|
|
|
var constClass = new ConstClass();
|
|
|
|
expect(constClass).not.toBe(null);
|
|
|
|
});
|
|
|
|
|
2014-10-01 10:29:45 -04:00
|
|
|
describe('inheritance', function() {
|
|
|
|
it('should support super call', function () {
|
|
|
|
var subFoo = new SubFoo(1, 2);
|
|
|
|
expect(subFoo.a).toBe(1);
|
|
|
|
expect(subFoo.b).toBe(2);
|
|
|
|
expect(subFoo.c).toBe(3);
|
|
|
|
});
|
|
|
|
});
|
2014-10-16 16:10:21 -04:00
|
|
|
|
|
|
|
describe("getters", function () {
|
|
|
|
it("should call instance getters", function () {
|
|
|
|
var obj = new HasGetters();
|
|
|
|
expect(obj.getter).toEqual('getter');
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should call static getters", function () {
|
|
|
|
expect(HasGetters.staticGetter).toEqual('getter');
|
|
|
|
});
|
|
|
|
});
|
2014-11-07 12:31:51 -05:00
|
|
|
|
|
|
|
describe('fields', function() {
|
|
|
|
it('should work', function() {
|
|
|
|
var obj = new WithFields();
|
|
|
|
obj.name = 'Vojta';
|
|
|
|
WithFields.id = 12;
|
|
|
|
});
|
|
|
|
});
|
2014-09-28 16:55:01 -04:00
|
|
|
});
|
2014-10-01 10:29:45 -04:00
|
|
|
|
2014-09-25 17:30:10 -04:00
|
|
|
}
|