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

Side by Side Diff: test/module_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, 3 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 unified diff | Download patch
« no previous file with comments | « test/main_test.ts ('k') | test/statement_test.ts » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /// <reference path="../typings/mocha/mocha.d.ts"/> 1 /// <reference path="../typings/mocha/mocha.d.ts"/>
2 import chai = require('chai'); 2 import chai = require('chai');
3 import main = require('../lib/main'); 3 import main = require('../lib/main');
4 import ModuleTranspiler from '../lib/module'; 4 import ModuleTranspiler from '../lib/module';
5 import {FacadeConverter} from '../lib/facade_converter'; 5 import {FacadeConverter, NameRewriter} from '../lib/facade_converter';
6 6
7 import {expectTranslate, expectErroneousCode, translateSources} from './test_sup port'; 7 import {expectTranslate, expectErroneousCode, translateSources} from './test_sup port';
8 8
9 describe('imports', () => { 9 describe('imports', () => {
10 it('translates import equals statements', () => { 10 it('translates import equals statements', () => {
11 expectTranslate('import x = require("y");').to.equal('import "package:y.dart " as x;'); 11 expectTranslate('import x = require("y");').to.equal('import "package:y.dart " as x;');
12 }); 12 });
13 it('translates import from statements', () => { 13 it('translates import from statements', () => {
14 expectTranslate('import {x,y} from "z";').to.equal('import "package:z.dart" show x, y;'); 14 expectTranslate('import {x,y} from "z";').to.equal('import "package:z.dart" show x, y;');
15 }); 15 });
16 it('translates import star', () => { 16 it('translates import star', () => {
17 expectTranslate('import * as foo from "z";').to.equal('import "package:z.dar t" as foo;'); 17 expectTranslate('import * as foo from "z";').to.equal('import "package:z.dar t" as foo;');
18 }); 18 });
19 it('allows import dart file from relative path', () => { 19 it('allows import dart file from relative path', () => {
20 expectTranslate('import x = require("./y")').to.equal('import "y.dart" as x; '); 20 expectTranslate('import x = require("./y")').to.equal('import "y.dart" as x; ');
21 expectTranslate('import {x} from "./y"').to.equal('import "y.dart" show x;') ; 21 expectTranslate('import {x} from "./y"').to.equal('import "y.dart" show x;') ;
22 expectTranslate('import {x} from "../y"').to.equal('import "../y.dart" show x;'); 22 expectTranslate('import {x} from "../y"').to.equal('import "../y.dart" show x;');
23 }); 23 });
24 it('handles ignored annotations in imports', () => {
25 expectTranslate('import {CONST, CONST_EXPR, IMPLEMENTS, ABSTRACT} from "x"') .to.equal('');
26 expectTranslate('import {x, IMPLEMENTS} from "./x"').to.equal('import "x.dar t" show x;');
27 });
28 it('fails for renamed imports', () => { 24 it('fails for renamed imports', () => {
29 expectErroneousCode('import {Foo as Bar} from "baz";') 25 expectErroneousCode('import {Foo as Bar} from "baz";')
30 .to.throw(/import\/export renames are unsupported in Dart/); 26 .to.throw(/import\/export renames are unsupported in Dart/);
31 }); 27 });
32 it('fails for empty import specs', 28 it('empty import spec generates safe Dart code',
33 () => { expectErroneousCode('import {} from "baz";').to.throw(/empty import list/); }); 29 () => { expectTranslate('import {} from "baz";').to.equal(''); });
34 }); 30 });
35 31
36 describe('exports', () => { 32 describe('exports', () => {
37 // Dart exports are implicit, everything non-private is exported by the librar y. 33 // Dart exports are implicit, everything non-private is exported by the librar y.
38 it('allows variable exports', 34 it('allows variable exports', () => {
39 () => { expectTranslate('export var x = 12;').to.equal('var x = 12;'); }); 35 expectTranslate('export var x = 12;').to.equal(`@JS()
40 it('allows class exports', 36 external get x;
41 () => { expectTranslate('export class X {}').to.equal('class X {}'); }); 37 @JS()
38 external set x(v);`);
39 });
40 it('allows class exports', () => {
41 expectTranslate('export class X {}').to.equal(`@JS()
42 class X {
43 // @Ignore
44 X.fakeConstructor$();
45 }`);
46 });
42 it('allows export declarations', 47 it('allows export declarations',
43 () => { expectTranslate('export * from "X";').to.equal('export "package:X.d art";'); }); 48 () => { expectTranslate('export * from "X";').to.equal('export "package:X.d art";'); });
44 it('allows export declarations', 49 it('allows export declarations',
45 () => { expectTranslate('export * from "./X";').to.equal('export "X.dart";' ); }); 50 () => { expectTranslate('export * from "./X";').to.equal('export "X.dart";' ); });
46 it('allows named export declarations', () => { 51 it('allows named export declarations', () => {
47 expectTranslate('export {a, b} from "X";').to.equal('export "package:X.dart" show a, b;'); 52 expectTranslate('export {a, b} from "X";').to.equal('export "package:X.dart" show a, b;');
48 }); 53 });
49 it('fails for renamed exports', () => { 54 it('fails for renamed exports', () => {
50 expectErroneousCode('export {Foo as Bar} from "baz";') 55 expectErroneousCode('export {Foo as Bar} from "baz";')
51 .to.throw(/import\/export renames are unsupported in Dart/); 56 .to.throw(/import\/export renames are unsupported in Dart/);
52 }); 57 });
53 it('fails for exports without URLs', () => { 58 it('fails for exports without URLs', () => {
54 expectErroneousCode('export {a as b};').to.throw('re-exports must have a mod ule URL'); 59 expectErroneousCode('export {a as b};').to.throw('re-exports must have a mod ule URL');
55 }); 60 });
56 it('fails for empty export specs', 61 it('fails for empty export specs',
57 () => { expectErroneousCode('export {} from "baz";').to.throw(/empty export list/); }); 62 () => { expectErroneousCode('export {} from "baz";').to.throw(/empty export list/); });
58 }); 63 });
59 64
60 describe('library name', () => { 65 describe('library name', () => {
61 let transpiler: main.Transpiler; 66 let transpiler: main.Transpiler;
62 let modTranspiler: ModuleTranspiler; 67 let modTranspiler: ModuleTranspiler;
63 beforeEach(() => { 68 beforeEach(() => {
64 transpiler = new main.Transpiler({failFast: true, generateLibraryName: true, basePath: '/a'}); 69 transpiler = new main.Transpiler({failFast: true, generateLibraryName: true, basePath: '/a'});
65 modTranspiler = new ModuleTranspiler(transpiler, new FacadeConverter(transpi ler), true); 70 modTranspiler = new ModuleTranspiler(
71 transpiler, new FacadeConverter(transpiler, '', new NameRewriter(), fals e), true);
66 }); 72 });
67 it('adds a library name', () => { 73 it('adds a library name', () => {
68 let results = translateSources( 74 let results = translateSources(
69 {'/a/b/c.ts': 'var x;'}, {failFast: true, generateLibraryName: true, bas ePath: '/a'}); 75 {'/a/b/c.ts': 'var x;'}, {failFast: true, generateLibraryName: true, bas ePath: '/a'});
70 chai.expect(results['/a/b/c.ts']).to.equal(`library b.c; 76 chai.expect(results['/a/b/c.ts']).to.equal(`@JS()
77 library b.c;
71 78
72 var x; 79 import "package:js/js.dart";
80
81 @JS()
82 external get x;
83 @JS()
84 external set x(v);
73 `); 85 `);
74 }); 86 });
75 it('leaves relative paths alone', 87 it('leaves relative paths alone',
76 () => { chai.expect(modTranspiler.getLibraryName('a/b')).to.equal('a.b'); } ); 88 () => { chai.expect(modTranspiler.getLibraryName('a/b')).to.equal('a.b'); } );
77 it('handles reserved words', () => { 89 it('handles reserved words', () => {
78 chai.expect(modTranspiler.getLibraryName('/a/for/in/do/x')).to.equal('_for._ in._do.x'); 90 chai.expect(modTranspiler.getLibraryName('/a/for/in/do/x')).to.equal('_for._ in._do.x');
79 }); 91 });
80 it('handles built-in and limited keywords', () => { 92 it('handles built-in and limited keywords', () => {
81 chai.expect(modTranspiler.getLibraryName('/a/as/if/sync/x')).to.equal('as._i f.sync.x'); 93 chai.expect(modTranspiler.getLibraryName('/a/as/if/sync/x')).to.equal('as._i f.sync.x');
82 }); 94 });
83 it('handles file extensions', () => { 95 it('handles file extensions', () => {
84 chai.expect(modTranspiler.getLibraryName('a/x.ts')).to.equal('a.x'); 96 chai.expect(modTranspiler.getLibraryName('a/x.ts')).to.equal('a.x');
85 chai.expect(modTranspiler.getLibraryName('a/x.js')).to.equal('a.x'); 97 chai.expect(modTranspiler.getLibraryName('a/x.js')).to.equal('a.x');
86 }); 98 });
87 it('handles non word characters', 99 it('handles non word characters',
88 () => { chai.expect(modTranspiler.getLibraryName('a/%x.ts')).to.equal('a._x '); }); 100 () => { chai.expect(modTranspiler.getLibraryName('a/%x.ts')).to.equal('a._x '); });
89 }); 101 });
OLDNEW
« no previous file with comments | « test/main_test.ts ('k') | test/statement_test.ts » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698