| OLD | NEW |
| 1 /// <reference path="../typings/mocha/mocha.d.ts"/> | 1 /// <reference path="../typings/mocha/mocha.d.ts"/> |
| 2 import {expectTranslate} from './test_support'; | 2 import {expectTranslate} from './test_support'; |
| 3 | 3 |
| 4 describe('types', () => { | 4 describe('types', () => { |
| 5 it('supports qualified names', | 5 it('supports qualified names', () => { |
| 6 () => { expectTranslate('var x: foo.Bar;').to.equal('foo.Bar x;'); }); | 6 expectTranslate('var x: foo.Bar;').to.equal(`@JS() |
| 7 it('drops type literals', | 7 external foo.Bar get x; |
| 8 () => { expectTranslate('var x: {x: string, y: number};').to.equal('dynamic
x;'); }); | 8 @JS() |
| 9 it('translates string index signatures to dartisms', () => { | 9 external set x(foo.Bar v);`); |
| 10 expectTranslate('var x: {[k: string]: any[]};').to.equal('Map<String, List<d
ynamic>> x;'); | |
| 11 expectTranslate('var x: {[k: number]: number};').to.equal('Map<num, num> x;'
); | |
| 12 }); | 10 }); |
| 13 it('drops type literals with index signatures and other properties', | 11 it('comment type literals', () => { |
| 14 () => { expectTranslate('var x: {a: number, [k: string]: number};').to.equa
l('dynamic x;'); }); | 12 expectTranslate('var x: {x: string, y: number};').to.equal(`@JS() |
| 15 it('allows typecasts', () => { expectTranslate('<MyType>ref').to.equal('(ref a
s MyType);'); }); | 13 external dynamic /*{x: string, y: number}*/ get x; |
| 16 it('translates typecasts to reified types on literals', () => { | 14 @JS() |
| 17 expectTranslate('let x = <string[]>[];').to.equal('var x = <String>[];'); | 15 external set x(dynamic /*{x: string, y: number}*/ v);`); |
| 18 expectTranslate('let x = <{[k:string]: number}>{};').to.equal('var x = <Stri
ng, num>{};'); | 16 }); |
| 17 it('do not translates string index signatures to dartisms', () => { |
| 18 // We wish these could be just Map<String, dynamic> but sadly can't support |
| 19 // that yet. |
| 20 expectTranslate('var x: {[k: string]: any[]};').to.equal(`@JS() |
| 21 external dynamic /*Map<String,List<dynamic>>*/ get x; |
| 22 @JS() |
| 23 external set x(dynamic /*Map<String,List<dynamic>>*/ v);`); |
| 24 expectTranslate('var x: {[k: number]: number};').to.equal(`@JS() |
| 25 external dynamic /*Map<num,num>*/ get x; |
| 26 @JS() |
| 27 external set x(dynamic /*Map<num,num>*/ v);`); |
| 28 }); |
| 29 it('drops type literals with index signatures and other properties', () => { |
| 30 expectTranslate('var x: {a: number, [k: string]: number};').to.equal(`@JS() |
| 31 external dynamic /*{a: number, [k: string]: number}*/ get x; |
| 32 @JS() |
| 33 external set x(dynamic /*{a: number, [k: string]: number}*/ v);`); |
| 19 }); | 34 }); |
| 20 it('does not mangle prototype names', () => { | 35 it('does not mangle prototype names', () => { |
| 21 expectTranslate('import toString = require("./somewhere");') | 36 expectTranslate('import toString = require("./somewhere");') |
| 22 .to.equal('import "somewhere.dart" as toString;'); | 37 .to.equal('import "somewhere.dart" as toString;'); |
| 23 }); | 38 }); |
| 24 it('should support union types', () => { | 39 it('should support union types', () => { |
| 25 expectTranslate('var x: number|List<string> = 11;') | 40 expectTranslate('var x: number|List<string>;').to.equal(`@JS() |
| 26 .to.equal('dynamic /* num | List< String > */ x = 11;'); | 41 external dynamic /*num|List<String>*/ get x; |
| 27 expectTranslate('function x(): number|List<{[k: string]: any}> { return 11;
}') | 42 @JS() |
| 28 .to.equal( | 43 external set x(dynamic /*num|List<String>*/ v);`); |
| 29 'dynamic /* num | List< Map < String , dynamic > > */ x() {\n' + | 44 expectTranslate('function x(): number|List<{[k: string]: any}> {};').to.equa
l(`@JS() |
| 30 ' return 11;\n' + | 45 external dynamic /*num|List<dynamic/*Map<String,dynamic>*/>*/ x();`); |
| 31 '}'); | |
| 32 }); | 46 }); |
| 33 it('should support array types', | 47 it('should support array types', () => { |
| 34 () => { expectTranslate('var x: string[] = [];').to.equal('List<String> x =
[];'); }); | 48 expectTranslate('var x: string[] = [];').to.equal(`@JS() |
| 35 it('should support function types (by ignoring them)', () => { | 49 external List<String> get x; |
| 36 expectTranslate('var x: (a: string) => string;') | 50 @JS() |
| 37 .to.equal('dynamic /* (a: string) => string */ x;'); | 51 external set x(List<String> v);`); |
| 52 }); |
| 53 it('should support function types', () => { |
| 54 expectTranslate('var x: (a: string) => string;').to.equal(`import "package:f
unc/func.dart"; |
| 55 |
| 56 @JS() |
| 57 external Func1<String, String> get x; |
| 58 @JS() |
| 59 external set x(Func1<String, String> v);`); |
| 38 }); | 60 }); |
| 39 }); | 61 }); |
| 40 | 62 |
| 41 describe('type arguments', () => { | 63 describe('type arguments', () => { |
| 42 it('should support declaration', () => { | 64 it('should support declaration', () => { |
| 43 expectTranslate('class X<A, B> { a: A; }').to.equal(`class X<A, B> { | 65 expectTranslate('class X<A, B> { a: A; }').to.equal(`@JS() |
| 44 A a; | 66 class X<A, B> { |
| 67 // @Ignore |
| 68 X.fakeConstructor$(); |
| 69 external A get a; |
| 70 external set a(A v); |
| 45 }`); | 71 }`); |
| 46 }); | 72 }); |
| 47 it('should support nested extends', () => { | 73 it('should support nested extends', () => { |
| 48 expectTranslate('class X<A extends B<C>> { }').to.equal('class X<A extends B
<C>> {}'); | 74 expectTranslate('class X<A extends B<C>> { }').to.equal(`@JS() |
| 75 class X<A extends B<C>> { |
| 76 // @Ignore |
| 77 X.fakeConstructor$(); |
| 78 }`); |
| 49 }); | 79 }); |
| 50 it('should multiple extends', () => { | 80 it('should multiple extends', () => { |
| 51 expectTranslate('class X<A extends A1, B extends B1> { }') | 81 expectTranslate('class X<A extends A1, B extends B1> { }').to.equal(`@JS() |
| 52 .to.equal('class X<A extends A1, B extends B1> {}'); | 82 class X<A extends A1, B extends B1> { |
| 83 // @Ignore |
| 84 X.fakeConstructor$(); |
| 85 }`); |
| 53 }); | 86 }); |
| 54 it('should support use', () => { | 87 it('should support use', () => { |
| 55 expectTranslate('class X extends Y<A, B> { }').to.equal('class X extends Y<A
, B> {}'); | 88 expectTranslate('class X extends Y<A, B> { }').to.equal(`@JS() |
| 89 class X extends Y<A, B> { |
| 90 // @Ignore |
| 91 X.fakeConstructor$() : super.fakeConstructor$(); |
| 92 }`); |
| 56 }); | 93 }); |
| 57 it('should remove single <void> generic argument', () => { | 94 it('should remove single <void> generic argument', () => { |
| 58 expectTranslate('var x: X<number>;').to.equal('X<num> x;'); | 95 expectTranslate('var x: X<number>;').to.equal(`@JS() |
| 59 expectTranslate('class X extends Y<void> { }').to.equal('class X extends Y {
}'); | 96 external X<num> get x; |
| 60 expectTranslate('var x = new Promise<void>();').to.equal('var x = new Promis
e();'); | 97 @JS() |
| 98 external set x(X<num> v);`); |
| 99 expectTranslate('class X extends Y<void> { }').to.equal(`@JS() |
| 100 class X extends Y { |
| 101 // @Ignore |
| 102 X.fakeConstructor$() : super.fakeConstructor$(); |
| 103 }`); |
| 61 }); | 104 }); |
| 62 }); | 105 }); |
| OLD | NEW |