Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(517)

Unified Diff: test/type_test.ts

Issue 2225953002: Strip more unused features. (Closed) Base URL: git@github.com:dart-lang/js_facade_gen.git@master
Patch Set: Fix types Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/test_support.ts ('k') | tsconfig.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/type_test.ts
diff --git a/test/type_test.ts b/test/type_test.ts
index 7874c7d7e84fcad1b3b28b236e062bdbcff00272..822f947fcf915e1f8a93f4d9e44e3fed74f82b38 100644
--- a/test/type_test.ts
+++ b/test/type_test.ts
@@ -2,61 +2,107 @@
import {expectTranslate} from './test_support';
describe('types', () => {
- it('supports qualified names',
- () => { expectTranslate('var x: foo.Bar;').to.equal('foo.Bar x;'); });
- it('drops type literals',
- () => { expectTranslate('var x: {x: string, y: number};').to.equal('dynamic x;'); });
- it('translates string index signatures to dartisms', () => {
- expectTranslate('var x: {[k: string]: any[]};').to.equal('Map<String, List<dynamic>> x;');
- expectTranslate('var x: {[k: number]: number};').to.equal('Map<num, num> x;');
- });
- it('drops type literals with index signatures and other properties',
- () => { expectTranslate('var x: {a: number, [k: string]: number};').to.equal('dynamic x;'); });
- it('allows typecasts', () => { expectTranslate('<MyType>ref').to.equal('(ref as MyType);'); });
- it('translates typecasts to reified types on literals', () => {
- expectTranslate('let x = <string[]>[];').to.equal('var x = <String>[];');
- expectTranslate('let x = <{[k:string]: number}>{};').to.equal('var x = <String, num>{};');
+ it('supports qualified names', () => {
+ expectTranslate('var x: foo.Bar;').to.equal(`@JS()
+external foo.Bar get x;
+@JS()
+external set x(foo.Bar v);`);
+ });
+ it('comment type literals', () => {
+ expectTranslate('var x: {x: string, y: number};').to.equal(`@JS()
+external dynamic /*{x: string, y: number}*/ get x;
+@JS()
+external set x(dynamic /*{x: string, y: number}*/ v);`);
+ });
+ it('do not translates string index signatures to dartisms', () => {
+ // We wish these could be just Map<String, dynamic> but sadly can't support
+ // that yet.
+ expectTranslate('var x: {[k: string]: any[]};').to.equal(`@JS()
+external dynamic /*JSMap of <String,List<dynamic>>*/ get x;
+@JS()
+external set x(dynamic /*JSMap of <String,List<dynamic>>*/ v);`);
+ expectTranslate('var x: {[k: number]: number};').to.equal(`@JS()
+external dynamic /*JSMap of <num,num>*/ get x;
+@JS()
+external set x(dynamic /*JSMap of <num,num>*/ v);`);
+ });
+ it('drops type literals with index signatures and other properties', () => {
+ expectTranslate('var x: {a: number, [k: string]: number};').to.equal(`@JS()
+external dynamic /*{a: number, [k: string]: number}*/ get x;
+@JS()
+external set x(dynamic /*{a: number, [k: string]: number}*/ v);`);
});
it('does not mangle prototype names', () => {
expectTranslate('import toString = require("./somewhere");')
.to.equal('import "somewhere.dart" as toString;');
});
it('should support union types', () => {
- expectTranslate('var x: number|List<string> = 11;')
- .to.equal('dynamic /* num | List< String > */ x = 11;');
- expectTranslate('function x(): number|List<{[k: string]: any}> { return 11; }')
- .to.equal(
- 'dynamic /* num | List< Map < String , dynamic > > */ x() {\n' +
- ' return 11;\n' +
- '}');
- });
- it('should support array types',
- () => { expectTranslate('var x: string[] = [];').to.equal('List<String> x = [];'); });
- it('should support function types (by ignoring them)', () => {
- expectTranslate('var x: (a: string) => string;')
- .to.equal('dynamic /* (a: string) => string */ x;');
+
+ 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;
+@JS()
+external set x(List<String> v);`);
+ });
+ it('should support function types', () => {
+ expectTranslate('var x: (a: string) => string;').to.equal(`import "package:func/func.dart";
+
+@JS()
+external Func1<String, String> get x;
+@JS()
+external set x(Func1<String, String> v);`);
});
});
describe('type arguments', () => {
it('should support declaration', () => {
- expectTranslate('class X<A, B> { a: A; }').to.equal(`class X<A, B> {
- A a;
+ expectTranslate('class X<A, B> { a: A; }').to.equal(`@JS()
+class X<A, B> {
+ // @Ignore
+ X.fakeConstructor$();
+ external A get a;
+ external set a(A v);
}`);
});
it('should support nested extends', () => {
- expectTranslate('class X<A extends B<C>> { }').to.equal('class X<A extends B<C>> {}');
+ expectTranslate('class X<A extends B<C>> { }').to.equal(`@JS()
+class X<A extends B<C>> {
+ // @Ignore
+ X.fakeConstructor$();
+}`);
});
it('should multiple extends', () => {
- expectTranslate('class X<A extends A1, B extends B1> { }')
- .to.equal('class X<A extends A1, B extends B1> {}');
+ expectTranslate('class X<A extends A1, B extends B1> { }').to.equal(`@JS()
+class X<A extends A1, B extends B1> {
+ // @Ignore
+ X.fakeConstructor$();
+}`);
});
it('should support use', () => {
- expectTranslate('class X extends Y<A, B> { }').to.equal('class X extends Y<A, B> {}');
+ expectTranslate('class X extends Y<A, B> { }').to.equal(`@JS()
+class X extends Y<A, B> {
+ // @Ignore
+ X.fakeConstructor$() : super.fakeConstructor$();
+}`);
});
it('should remove single <void> generic argument', () => {
- expectTranslate('var x: X<number>;').to.equal('X<num> x;');
- expectTranslate('class X extends Y<void> { }').to.equal('class X extends Y {}');
- expectTranslate('var x = new Promise<void>();').to.equal('var x = new Promise();');
+ 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 {
+ // @Ignore
+ X.fakeConstructor$() : super.fakeConstructor$();
+}`);
});
});
« no previous file with comments | « test/test_support.ts ('k') | tsconfig.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698