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

Side by Side Diff: test/module_test.ts

Issue 2416003003: Update package name, update and lock clang-format and tslint versions, and format all source files … (Closed)
Patch Set: Created 4 years, 2 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
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} 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('ignore import equals statements', 10 it('ignore import equals statements', () => {
11 () => { expectTranslate('import x = require("y");').to.equal('import "y.dar t" as x;'); }); 11 expectTranslate('import x = require("y");').to.equal('import "y.dart" as x;' );
12 it('ignore import from statements', 12 });
13 () => { expectTranslate('import {x,y} from "z";').to.equal(''); }); 13 it('ignore import from statements', () => {
14 it('ignore import star', () => { expectTranslate('import * as foo from "z";'). to.equal(''); }); 14 expectTranslate('import {x,y} from "z";').to.equal('');
15 it('ignore renamed imports', 15 });
16 () => { expectTranslate('import {Foo as Bar} from "baz";').to.equal(''); }) ; 16 it('ignore import star', () => {
17 it('empty import spec generates safe Dart code', 17 expectTranslate('import * as foo from "z";').to.equal('');
18 () => { expectTranslate('import {} from "baz";').to.equal(''); }); 18 });
19 it('ignore renamed imports', () => {
20 expectTranslate('import {Foo as Bar} from "baz";').to.equal('');
21 });
22 it('empty import spec generates safe Dart code', () => {
23 expectTranslate('import {} from "baz";').to.equal('');
24 });
19 }); 25 });
20 26
21 describe('exports', () => { 27 describe('exports', () => {
22 // Dart exports are implicit, everything non-private is exported by the librar y. 28 // Dart exports are implicit, everything non-private is exported by the librar y.
23 it('allows variable exports', () => { 29 it('allows variable exports', () => {
24 expectTranslate('export var x = 12;').to.equal(`@JS() 30 expectTranslate('export var x = 12;').to.equal(`@JS()
25 external get x; 31 external get x;
26 @JS() 32 @JS()
27 external set x(v);`); 33 external set x(v);`);
28 }); 34 });
29 it('allows class exports', () => { 35 it('allows class exports', () => {
30 expectTranslate('export class X {}').to.equal(`@JS() 36 expectTranslate('export class X {}').to.equal(`@JS()
31 class X { 37 class X {
32 // @Ignore 38 // @Ignore
33 X.fakeConstructor$(); 39 X.fakeConstructor$();
34 }`); 40 }`);
35 }); 41 });
36 it('allows export declarations', 42 it('allows export declarations', () => {
37 () => { expectTranslate('export * from "X";').to.equal('export "X.dart";'); }); 43 expectTranslate('export * from "X";').to.equal('export "X.dart";');
38 it('allows export declarations', 44 });
39 () => { expectTranslate('export * from "./X";').to.equal('export "X.dart";' ); }); 45 it('allows export declarations', () => {
40 it('allows named export declarations', 46 expectTranslate('export * from "./X";').to.equal('export "X.dart";');
41 () => { expectTranslate('export {a, b} from "X";').to.equal('export "X.dart " show a, b;'); }); 47 });
48 it('allows named export declarations', () => {
49 expectTranslate('export {a, b} from "X";').to.equal('export "X.dart" show a, b;');
50 });
42 it('ignores named export declarations', () => { 51 it('ignores named export declarations', () => {
43 expectTranslate(`declare module '../some_other_module' { 52 expectTranslate(`declare module '../some_other_module' {
44 interface Foo { } 53 interface Foo { }
45 }`) 54 }`)
46 .to.equal( 55 .to.equal(
47 '// Library augmentation not allowed by Dart. Ignoring augmentation of ../some_other_module'); 56 '// Library augmentation not allowed by Dart. Ignoring augmentation of ../some_other_module');
48 }); 57 });
49 58
50 it('fails for renamed exports', () => { 59 it('fails for renamed exports', () => {
51 expectErroneousCode('export {Foo as Bar} from "baz";') 60 expectErroneousCode('export {Foo as Bar} from "baz";')
52 .to.throw(/import\/export renames are unsupported in Dart/); 61 .to.throw(/import\/export renames are unsupported in Dart/);
53 }); 62 });
54 it('fails for exports without URLs', () => { 63 it('fails for exports without URLs', () => {
55 expectErroneousCode('export {a as b};').to.throw('re-exports must have a mod ule URL'); 64 expectErroneousCode('export {a as b};').to.throw('re-exports must have a mod ule URL');
56 }); 65 });
57 it('fails for empty export specs', 66 it('fails for empty export specs', () => {
58 () => { expectErroneousCode('export {} from "baz";').to.throw(/empty export list/); }); 67 expectErroneousCode('export {} from "baz";').to.throw(/empty export list/);
68 });
59 }); 69 });
60 70
61 describe('module name', () => { 71 describe('module name', () => {
62 let transpiler: main.Transpiler; 72 let transpiler: main.Transpiler;
63 let modTranspiler: ModuleTranspiler; 73 let modTranspiler: ModuleTranspiler;
64 beforeEach(() => { 74 beforeEach(() => {
65 transpiler = new main.Transpiler({failFast: true, moduleName: 'sample_module ', basePath: '/a'}); 75 transpiler = new main.Transpiler({failFast: true, moduleName: 'sample_module ', basePath: '/a'});
66 modTranspiler = 76 modTranspiler =
67 new ModuleTranspiler(transpiler, new FacadeConverter(transpiler, ''), 's ample_module'); 77 new ModuleTranspiler(transpiler, new FacadeConverter(transpiler, ''), 's ample_module');
68 }); 78 });
69 it('adds module name', () => { 79 it('adds module name', () => {
70 let results = translateSources( 80 let results = translateSources(
71 {'/a/b/c.ts': 'var x;'}, {failFast: true, moduleName: 'sample_module', b asePath: '/a'}); 81 {'/a/b/c.ts': 'var x;'}, {failFast: true, moduleName: 'sample_module', b asePath: '/a'});
72 chai.expect(results['/a/b/c.ts']).to.equal(`@JS("sample_module") 82 chai.expect(results['/a/b/c.ts']).to.equal(`@JS("sample_module")
73 library b.c; 83 library b.c;
74 84
75 import "package:js/js.dart"; 85 import "package:js/js.dart";
76 86
77 @JS() 87 @JS()
78 external get x; 88 external get x;
79 @JS() 89 @JS()
80 external set x(v); 90 external set x(v);
81 `); 91 `);
82 }); 92 });
83 it('leaves relative paths alone', 93 it('leaves relative paths alone', () => {
84 () => { chai.expect(modTranspiler.getLibraryName('a/b')).to.equal('a.b'); } ); 94 chai.expect(modTranspiler.getLibraryName('a/b')).to.equal('a.b');
95 });
85 it('handles reserved words', () => { 96 it('handles reserved words', () => {
86 chai.expect(modTranspiler.getLibraryName('/a/for/in/do/x')).to.equal('_for._ in._do.x'); 97 chai.expect(modTranspiler.getLibraryName('/a/for/in/do/x')).to.equal('_for._ in._do.x');
87 }); 98 });
88 it('handles built-in and limited keywords', () => { 99 it('handles built-in and limited keywords', () => {
89 chai.expect(modTranspiler.getLibraryName('/a/as/if/sync/x')).to.equal('as._i f.sync.x'); 100 chai.expect(modTranspiler.getLibraryName('/a/as/if/sync/x')).to.equal('as._i f.sync.x');
90 }); 101 });
91 it('handles file extensions', () => { 102 it('handles file extensions', () => {
92 chai.expect(modTranspiler.getLibraryName('a/x.ts')).to.equal('a.x'); 103 chai.expect(modTranspiler.getLibraryName('a/x.ts')).to.equal('a.x');
93 chai.expect(modTranspiler.getLibraryName('a/x.js')).to.equal('a.x'); 104 chai.expect(modTranspiler.getLibraryName('a/x.js')).to.equal('a.x');
94 }); 105 });
95 it('handles non word characters', 106 it('handles non word characters', () => {
96 () => { chai.expect(modTranspiler.getLibraryName('a/%x.ts')).to.equal('a._x '); }); 107 chai.expect(modTranspiler.getLibraryName('a/%x.ts')).to.equal('a._x');
108 });
97 }); 109 });
OLDNEW
« package.json ('K') | « test/main_test.ts ('k') | test/test_support.ts » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698