OLD | NEW |
1 /// <reference path="../typings/chai/chai.d.ts"/> | 1 /// <reference path="../typings/chai/chai.d.ts"/> |
2 /// <reference path="../typings/mocha/mocha.d.ts"/> | 2 /// <reference path="../typings/mocha/mocha.d.ts"/> |
3 /// <reference path="../typings/source-map/source-map.d.ts"/> | 3 /// <reference path="../typings/source-map/source-map.d.ts"/> |
4 import chai = require('chai'); | 4 import chai = require('chai'); |
5 import main = require('../lib/main'); | 5 import main = require('../lib/main'); |
6 | 6 |
7 import {expectTranslate, expectErroneousCode} from './test_support'; | 7 import {expectTranslate} from './test_support'; |
8 | 8 |
9 describe('main transpiler functionality', () => { | 9 describe('main transpiler functionality', () => { |
10 describe('comments', () => { | 10 describe( |
11 it('keeps leading comments', () => { | 11 'comments', () => { |
12 expectTranslate(` | 12 it('keeps leading comments', |
13 function f() { | 13 () => { |
14 /* A */ a; | 14 expectTranslate(`/* A */ var a; |
15 /* B */ b; | 15 /* B */ var b;`).to.equal(`/* A */ |
16 }`).to.equal(`f() { | 16 @JS() |
17 /* A */ a; | 17 external get a; |
18 /* B */ b; | 18 @JS() |
| 19 external set a(v); |
| 20 /* B */ @JS() |
| 21 external get b; |
| 22 @JS() |
| 23 external set b(v);`); |
| 24 expectTranslate(`// A |
| 25 var a; |
| 26 // B |
| 27 var b;`).to.equal(`// A |
| 28 @JS() |
| 29 external get a; |
| 30 @JS() |
| 31 external set a(v); |
| 32 // B |
| 33 @JS() |
| 34 external get b; |
| 35 @JS() |
| 36 external set b(v);`); |
| 37 }); |
| 38 it('keeps ctor comments', () => { |
| 39 expectTranslate('/** A */ class A {\n /** ctor */ constructor() {}}').
to.equal(`/** A */ |
| 40 @JS() |
| 41 class A { |
| 42 // @Ignore |
| 43 A.fakeConstructor$(); |
| 44 /** ctor */ external factory A(); |
19 }`); | 45 }`); |
20 expectTranslate(`function f() { | 46 }); |
21 // A | 47 it('translates links to dart doc format', () => { |
22 a | 48 expectTranslate('/** {@link this/place} */ var a').to.equal(`/** [this
/place] */ |
23 // B | 49 @JS() |
24 b | 50 external get a; |
25 }`).to.equal(`f() { | 51 @JS() |
26 // A | 52 external set a(v);`); |
27 a; | 53 expectTranslate('/* {@link 1} {@link 2} */ var a').to.equal(`/* [1] [2
] */ |
28 // B | 54 @JS() |
29 b; | 55 external get a; |
30 }`); | 56 @JS() |
31 }); | 57 external set a(v);`); |
32 it('keeps ctor comments', () => { | 58 }); |
33 expectTranslate('/** A */ class A {\n /** ctor */ constructor() {}}').to.e
qual(`/** A */ | 59 it('removes @module doc tags', () => { |
34 class A { | 60 expectTranslate(`/** @module |
35 /** ctor */ A() {} | 61 * This is a module for doing X. |
36 }`); | 62 */`).to.equal(`/** |
37 }); | 63 * This is a module for doing X. |
38 it('translates links to dart doc format', () => { | 64 */`); |
39 expectTranslate('/** {@link this/place} */ a').to.equal('/** [this/place]
*/ a;'); | 65 }); |
40 expectTranslate('/* {@link 1} {@link 2} */ a').to.equal('/* [1] [2] */ a;'
); | 66 it('removes @description doc tags', () => { |
41 }); | 67 expectTranslate(`/** @description |
42 it('removes @module doc tags', () => { | 68 * This is a module for doing X. |
43 expectTranslate(`/** @module | 69 */`).to.equal(`/** |
44 * This is a module for doing X. | 70 * This is a module for doing X. |
45 */`).to.equal(`/** | 71 */`); |
46 * This is a module for doing X. | 72 }); |
47 */`); | 73 it('removes @depracted doc tags', () => { |
48 }); | 74 expectTranslate(`/** |
49 it('removes @description doc tags', () => { | 75 * Use SomethingElse instead. |
50 expectTranslate(`/** @description | 76 * @deprecated |
51 * This is a module for doing X. | 77 */`).to.equal(`/** |
52 */`).to.equal(`/** | 78 * Use SomethingElse instead. |
53 * This is a module for doing X. | 79 * |
54 */`); | 80 */`); |
55 }); | 81 }); |
56 it('removes @depracted doc tags', () => { | 82 it('removes @param doc tags', () => { |
57 expectTranslate(`/** | 83 expectTranslate(`/** |
58 * Use SomethingElse instead. | 84 * Method to do blah. |
59 * @deprecated | 85 * @param doc Document. |
60 */`).to.equal(`/** | 86 */`).to.equal(`/** |
61 * Use SomethingElse instead. | 87 * Method to do blah. |
62 * | 88 * |
63 */`); | 89 */`); |
64 }); | 90 }); |
65 it('removes @param doc tags', () => { | 91 it('removes @return doc tags', () => { |
66 expectTranslate(`/** | 92 expectTranslate(`/** |
67 * Method to do blah. | 93 * Method to do blah. |
68 * @param doc Document. | 94 * @return {String} |
69 */`).to.equal(`/** | 95 */`).to.equal(`/** |
70 * Method to do blah. | 96 * Method to do blah. |
71 * | 97 * |
72 */`); | 98 */`); |
73 }); | 99 }); |
74 it('removes @return doc tags', () => { | 100 it('removes @throws doc tags', () => { |
75 expectTranslate(`/** | 101 expectTranslate(`/** |
76 * Method to do blah. | 102 * Method to do blah. |
77 * @return {String} | 103 * @throws ArgumentException If arguments are wrong |
78 */`).to.equal(`/** | 104 */`).to.equal(`/** |
79 * Method to do blah. | 105 * Method to do blah. |
80 * | 106 * |
81 */`); | 107 */`); |
82 }); | 108 }); |
83 it('removes @throws doc tags', () => { | 109 }); |
84 expectTranslate(`/** | |
85 * Method to do blah. | |
86 * @throws ArgumentException If arguments are wrong | |
87 */`).to.equal(`/** | |
88 * Method to do blah. | |
89 * | |
90 */`); | |
91 }); | |
92 }); | |
93 | |
94 describe('errors', () => { | |
95 it('reports multiple errors', () => { | |
96 // Reports both the private field not having an underbar and protected bei
ng unsupported. | |
97 let errorLines = new RegExp( | |
98 'delete operator is unsupported\n' + | |
99 '.*void operator is unsupported'); | |
100 expectErroneousCode('delete x["y"]; void z;').to.throw(errorLines); | |
101 }); | |
102 it('reports relative paths in errors', () => { | |
103 chai.expect(() => expectTranslate({'/a/b/c.ts': 'delete x["y"];'}, {basePa
th: '/a'})) | |
104 .to.throw(/^b\/c.ts:1/); | |
105 }); | |
106 it('reports errors across multiple files', () => { | |
107 expectErroneousCode({'a.ts': 'delete x["y"];', 'b.ts': 'delete x["y"];'},
{ | |
108 failFast: false | |
109 }).to.throw(/^a\.ts.*\nb\.ts/); | |
110 }); | |
111 }); | |
112 | 110 |
113 describe('output paths', () => { | 111 describe('output paths', () => { |
114 it('writes within the path', () => { | 112 it('writes within the path', () => { |
115 let transpiler = new main.Transpiler({basePath: '/a'}); | 113 let transpiler = new main.Transpiler({basePath: '/a'}); |
116 chai.expect(transpiler.getOutputPath('/a/b/c.js', '/x')).to.equal('/x/b/c.
dart'); | 114 chai.expect(transpiler.getOutputPath('/a/b/c.js', '/x')).to.equal('/x/b/c.
dart'); |
117 chai.expect(transpiler.getOutputPath('b/c.js', '/x')).to.equal('/x/b/c.dar
t'); | 115 chai.expect(transpiler.getOutputPath('b/c.js', '/x')).to.equal('/x/b/c.dar
t'); |
118 chai.expect(transpiler.getOutputPath('b/c.js', 'x')).to.equal('x/b/c.dart'
); | 116 chai.expect(transpiler.getOutputPath('b/c.js', 'x')).to.equal('x/b/c.dart'
); |
119 chai.expect(() => transpiler.getOutputPath('/outside/b/c.js', '/x')) | 117 chai.expect(() => transpiler.getOutputPath('/outside/b/c.js', '/x')) |
120 .to.throw(/must be located under base/); | 118 .to.throw(/must be located under base/); |
121 }); | 119 }); |
122 it('defaults to writing to the same location', () => { | 120 it('defaults to writing to the same location', () => { |
123 let transpiler = new main.Transpiler({basePath: undefined}); | 121 let transpiler = new main.Transpiler({basePath: undefined}); |
124 chai.expect(transpiler.getOutputPath('/a/b/c.js', '/e')).to.equal('/a/b/c.
dart'); | 122 chai.expect(transpiler.getOutputPath('/a/b/c.js', '/e')).to.equal('/a/b/c.
dart'); |
125 chai.expect(transpiler.getOutputPath('b/c.js', '')).to.equal('b/c.dart'); | 123 chai.expect(transpiler.getOutputPath('b/c.js', '')).to.equal('b/c.dart'); |
126 }); | 124 }); |
127 it('translates .es6, .ts, and .js', () => { | 125 it('translates .es6, .ts, and .js', () => { |
128 let transpiler = new main.Transpiler({basePath: undefined}); | 126 let transpiler = new main.Transpiler({basePath: undefined}); |
129 ['a.js', 'a.ts', 'a.es6'].forEach( | 127 ['a.js', 'a.ts', 'a.es6'].forEach( |
130 (n) => { chai.expect(transpiler.getOutputPath(n, '')).to.equal('a.dart
'); }); | 128 (n) => { chai.expect(transpiler.getOutputPath(n, '')).to.equal('a.dart
'); }); |
131 }); | 129 }); |
132 }); | 130 }); |
133 }); | 131 }); |
OLD | NEW |