2014-09-28 16:55:01 -04:00
|
|
|
import {describe, it, expect} from 'test_lib/test_lib';
|
2014-11-07 18:20:06 -05:00
|
|
|
import {readFirstAnnotation} from './fixtures/annotations';
|
|
|
|
import {CONST} from 'facade/lang';
|
2014-09-25 17:30:10 -04:00
|
|
|
|
|
|
|
class Inject {}
|
|
|
|
class Bar {}
|
|
|
|
|
2014-11-07 18:20:06 -05:00
|
|
|
class Provide {
|
|
|
|
@CONST()
|
|
|
|
constructor(token) {
|
|
|
|
this.token = token;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AnnotateMe {
|
|
|
|
@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-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-09-28 16:55:01 -04:00
|
|
|
});
|
2014-11-07 18:20:06 -05:00
|
|
|
}
|