2014-11-11 20:33:47 -05:00
|
|
|
import {describe, it, expect, iit} from 'test_lib/test_lib';
|
2014-11-07 18:20:06 -05:00
|
|
|
import {readFirstAnnotation} from './fixtures/annotations';
|
2015-02-02 19:25:34 -05:00
|
|
|
import {CONST} from 'facade/src/lang';
|
2014-09-25 17:30:10 -04:00
|
|
|
|
|
|
|
class Inject {}
|
|
|
|
class Bar {}
|
|
|
|
|
2014-11-07 18:20:06 -05:00
|
|
|
class Provide {
|
2014-11-22 00:19:23 -05:00
|
|
|
token;
|
|
|
|
|
2014-11-07 18:20:06 -05:00
|
|
|
@CONST()
|
|
|
|
constructor(token) {
|
|
|
|
this.token = token;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AnnotateMe {
|
2014-11-22 00:19:23 -05:00
|
|
|
maybe;
|
|
|
|
|
2014-11-07 18:20:06 -05:00
|
|
|
@CONST()
|
|
|
|
constructor({maybe = 'default'} = {}) {
|
|
|
|
this.maybe = maybe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-28 16:55:01 -04:00
|
|
|
@Provide('Foo')
|
2014-09-25 17:30:10 -04:00
|
|
|
class Foo {
|
|
|
|
@Inject
|
|
|
|
constructor() {}
|
|
|
|
}
|
|
|
|
|
2014-09-28 16:55:01 -04:00
|
|
|
@Provide(Foo)
|
2014-09-25 17:30:10 -04:00
|
|
|
function baz() {}
|
|
|
|
|
2014-11-07 18:20:06 -05:00
|
|
|
@AnnotateMe()
|
|
|
|
class A {}
|
|
|
|
|
|
|
|
@AnnotateMe({maybe: 'yes'})
|
|
|
|
class B {}
|
|
|
|
|
2014-11-11 20:33:47 -05:00
|
|
|
@AnnotateMe({maybe: {'a': 'b'}})
|
|
|
|
class SomeClassWithMapInAnnotation {}
|
|
|
|
|
|
|
|
@AnnotateMe({maybe: [23]})
|
|
|
|
class SomeClassWithListInAnnotation {}
|
|
|
|
|
|
|
|
@AnnotateMe({maybe: new Provide(0)})
|
|
|
|
class SomeClassWithConstObject {}
|
|
|
|
|
2014-09-25 17:30:10 -04:00
|
|
|
function annotatedParams(@Inject(Foo) f, @Inject(Bar) b) {}
|
|
|
|
|
2014-09-28 16:55:01 -04:00
|
|
|
export function main() {
|
|
|
|
describe('annotations', function() {
|
|
|
|
it('should work', function() {
|
|
|
|
// Assert `Foo` class has `Provide` annotation.
|
|
|
|
var clazz = readFirstAnnotation(Foo);
|
|
|
|
expect(clazz instanceof Provide).toBe(true);
|
|
|
|
});
|
2014-11-07 18:20:06 -05:00
|
|
|
|
|
|
|
it('should work with named arguments', function() {
|
|
|
|
expect(readFirstAnnotation(A).maybe).toBe('default');
|
|
|
|
expect(readFirstAnnotation(B).maybe).toBe('yes');
|
|
|
|
});
|
2014-11-11 20:33:47 -05:00
|
|
|
|
|
|
|
it('should work with maps in named arguments', () => {
|
|
|
|
expect(readFirstAnnotation(SomeClassWithMapInAnnotation).maybe).toEqual({'a': 'b'});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work with lists in named arguments', () => {
|
|
|
|
expect(readFirstAnnotation(SomeClassWithListInAnnotation).maybe).toEqual([23]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work with new instances in named arguments', () => {
|
|
|
|
expect(readFirstAnnotation(SomeClassWithConstObject).maybe).toEqual(new Provide(0));
|
|
|
|
});
|
2014-09-28 16:55:01 -04:00
|
|
|
});
|
2014-11-07 18:20:06 -05:00
|
|
|
}
|