| Index: test/type_test.ts
|
| diff --git a/test/type_test.ts b/test/type_test.ts
|
| index 822f947fcf915e1f8a93f4d9e44e3fed74f82b38..bcdf62b2d222511457793cb61720f840c7d7ce6c 100644
|
| --- a/test/type_test.ts
|
| +++ b/test/type_test.ts
|
| @@ -8,6 +8,31 @@ external foo.Bar get x;
|
| @JS()
|
| external set x(foo.Bar v);`);
|
| });
|
| +
|
| + it('supports null types', () => {
|
| + expectTranslate('export function attr(name: string, value: null);').to.equal(`@JS()
|
| +external attr(String name, Null value);`);
|
| +
|
| + expectTranslate(`export function style(name: string, priority?: 'regular' | 'important');`)
|
| + .to.equal(`@JS()
|
| +external style(String name, [String /*'regular'|'important'*/ priority]);`);
|
| +
|
| + expectTranslate(`export function style(name: string, priority?: null | 'important');`)
|
| + .to.equal(`@JS()
|
| +external style(String name, [String /*Null|'important'*/ priority]);`);
|
| + expectTranslate('var foo: null;').to.equal(`@JS()
|
| +external Null get foo;
|
| +@JS()
|
| +external set foo(Null v);`);
|
| + });
|
| + it('supports this return type', () => {
|
| + expectTranslate('export interface Foo { bar() : this; }').to.equal(`@anonymous
|
| +@JS()
|
| +abstract class Foo {
|
| + external Foo bar();
|
| +}`);
|
| + });
|
| +
|
| it('comment type literals', () => {
|
| expectTranslate('var x: {x: string, y: number};').to.equal(`@JS()
|
| external dynamic /*{x: string, y: number}*/ get x;
|
| @@ -36,8 +61,8 @@ external set x(dynamic /*{a: number, [k: string]: number}*/ v);`);
|
| expectTranslate('import toString = require("./somewhere");')
|
| .to.equal('import "somewhere.dart" as toString;');
|
| });
|
| - it('should support union types', () => {
|
|
|
| + it('should support union types', () => {
|
| expectTranslate('function foo() : number | number[];').to.equal(`@JS()
|
| external dynamic /*num|List<num>*/ foo();`);
|
| expectTranslate('var x: number|List<string>;').to.equal(`@JS()
|
| @@ -47,6 +72,18 @@ external set x(dynamic /*num|List<String>*/ v);`);
|
| expectTranslate('function x(): number|List<{[k: string]: any}> {};').to.equal(`@JS()
|
| external dynamic /*num|List<JSMap of <String,dynamic>>*/ x();`);
|
| });
|
| +
|
| + it('should support parenthesized types', () => {
|
| + expectTranslate('function foo() : (number | number[]);').to.equal(`@JS()
|
| +external dynamic /*num|List<num>*/ foo();`);
|
| + expectTranslate('var x: (number|List<string>);').to.equal(`@JS()
|
| +external dynamic /*num|List<String>*/ get x;
|
| +@JS()
|
| +external set x(dynamic /*num|List<String>*/ v);`);
|
| + expectTranslate('function x(): number|(List<{[k: string]: any}>) {};').to.equal(`@JS()
|
| +external dynamic /*num|List<JSMap of <String,dynamic>>*/ x();`);
|
| + });
|
| +
|
| it('should support array types', () => {
|
| expectTranslate('var x: string[] = [];').to.equal(`@JS()
|
| external List<String> get x;
|
| @@ -94,15 +131,122 @@ class X extends Y<A, B> {
|
| X.fakeConstructor$() : super.fakeConstructor$();
|
| }`);
|
| });
|
| - it('should remove single <void> generic argument', () => {
|
| + it('should hanlde single <void> generic argument', () => {
|
| expectTranslate('var x: X<number>;').to.equal(`@JS()
|
| external X<num> get x;
|
| @JS()
|
| external set x(X<num> v);`);
|
| expectTranslate('class X extends Y<void> { }').to.equal(`@JS()
|
| -class X extends Y {
|
| +class X extends Y<Null> {
|
| // @Ignore
|
| X.fakeConstructor$() : super.fakeConstructor$();
|
| }`);
|
| });
|
| +
|
| + it('should replace void generic argument with Object', () => {
|
| + expectTranslate('class X extends Y<void, string> { }').to.equal(`@JS()
|
| +class X extends Y<Null, String> {
|
| + // @Ignore
|
| + X.fakeConstructor$() : super.fakeConstructor$();
|
| +}`);
|
| + expectTranslate('var z : Y<Null, string>;').to.equal(`@JS()
|
| +external Y<Null, String> get z;
|
| +@JS()
|
| +external set z(Y<Null, String> v);`);
|
| + expectTranslate('var z : Y<void, string, void>;').to.equal(`@JS()
|
| +external Y<Null, String, Null> get z;
|
| +@JS()
|
| +external set z(Y<Null, String, Null> v);`);
|
| +
|
| + });
|
| +
|
| + it('should create class for type alias literals', () => {
|
| + expectTranslate(`/**
|
| + * Event Parameters.
|
| + */
|
| +export type EventParameters = {
|
| + bubbles: boolean;
|
| + /**
|
| + * Is cancelable.
|
| + */
|
| + cancelable: boolean;
|
| +};
|
| +
|
| +export function dispatch(parameters: EventParameters): void;`)
|
| + .to.equal(`/// Event Parameters.
|
| +@anonymous
|
| +@JS()
|
| +abstract class EventParameters {
|
| + external bool get bubbles;
|
| + external set bubbles(bool v);
|
| +
|
| + /// Is cancelable.
|
| + external bool get cancelable;
|
| + external set cancelable(bool v);
|
| + external factory EventParameters({bool bubbles, bool cancelable});
|
| +}
|
| +
|
| +@JS()
|
| +external void dispatch(EventParameters parameters);`);
|
| +
|
| + expectTranslate(`/**
|
| + * Event Parameters.
|
| + */
|
| +export type EventParameters<T> = {
|
| + bubbles: T;
|
| + /**
|
| + * Is cancelable.
|
| + */
|
| + cancelable: T;
|
| +};
|
| +
|
| +export function dispatch(parameters: EventParameters<string>): void;`)
|
| + .to.equal(`/// Event Parameters.
|
| +@anonymous
|
| +@JS()
|
| +abstract class EventParameters<T> {
|
| + external T get bubbles;
|
| + external set bubbles(T v);
|
| +
|
| + /// Is cancelable.
|
| + external T get cancelable;
|
| + external set cancelable(T v);
|
| + external factory EventParameters({T bubbles, T cancelable});
|
| +}
|
| +
|
| +@JS()
|
| +external void dispatch(EventParameters<String> parameters);`);
|
| +
|
| + });
|
| +
|
| + it('should create typedef for type alias function literals', () => {
|
| + expectTranslate(`
|
| +export type ValueFn<A, B, T> = (this: T, a: A, b: B) => A;
|
| +
|
| +export type SimpleValueFn<A, B> = (a: A, b: B) => A;
|
| +
|
| +export function dispatch(callback: ValueFn<string, number, Element>): void;
|
| +export function dispatchSimple(callback: SimpleValueFn<string, number>): void;`)
|
| + .to.equal(`import "dart:html";
|
| +
|
| +typedef A ValueFn<A, B, T>(/*T this*/ A a, B b);
|
| +typedef A SimpleValueFn<A, B>(A a, B b);
|
| +@JS()
|
| +external void dispatch(ValueFn<String, num, Element> callback);
|
| +@JS()
|
| +external void dispatchSimple(SimpleValueFn<String, num> callback);`);
|
| + });
|
| +
|
| + it('should handle generic parameters on non dart compatible type aliases', () => {
|
| + expectTranslate(`
|
| + export type Triangle<G> = [G, G, G];
|
| + export type ListOfLists<G> = [G[]];
|
| +
|
| + export function triangles<T>(): Triangle<T>[];
|
| +`).to.equal(`/*export type Triangle<G> = [G, G, G];*/
|
| +/*export type ListOfLists<G> = [G[]];*/
|
| +@JS()
|
| +external List<List<dynamic/*=T*/ > /*Tuple of <T,T,T>*/ > triangles/*<T>*/();`);
|
| +
|
| + });
|
| });
|
|
|