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 |
| 21 /// B |
| 22 @JS() |
| 23 external get b; |
| 24 @JS() |
| 25 external set b(v);`); |
| 26 expectTranslate(`// A |
| 27 var a; |
| 28 /// B |
| 29 var b;`).to.equal(`/// A |
| 30 @JS() |
| 31 external get a; |
| 32 @JS() |
| 33 external set a(v); |
| 34 |
| 35 /// B |
| 36 @JS() |
| 37 external get b; |
| 38 @JS() |
| 39 external set b(v);`); |
| 40 }); |
| 41 it('keeps ctor comments', () => { |
| 42 expectTranslate('/** A */ class A {\n /** ctor */ constructor() {}}').
to.equal(`/// A |
| 43 @JS() |
| 44 class A { |
| 45 // @Ignore |
| 46 A.fakeConstructor$(); |
| 47 |
| 48 /// ctor |
| 49 external factory A(); |
19 }`); | 50 }`); |
20 expectTranslate(`function f() { | 51 }); |
21 // A | 52 it('translates links to dart doc format', () => { |
22 a | 53 expectTranslate('/** {@link this/place} */ var a').to.equal(`/// [this
/place] |
23 // B | 54 @JS() |
24 b | 55 external get a; |
25 }`).to.equal(`f() { | 56 @JS() |
26 // A | 57 external set a(v);`); |
27 a; | 58 expectTranslate('/* {@link 1} {@link 2} */ var a').to.equal(`/// [1] [
2] |
28 // B | 59 @JS() |
29 b; | 60 external get a; |
| 61 @JS() |
| 62 external set a(v);`); |
| 63 }); |
| 64 it('removes @module doc tags', () => { |
| 65 expectTranslate(`/** @module |
| 66 * This is a module for doing X. |
| 67 */`).to.equal(`/// This is a module for doing X.`); |
| 68 }); |
| 69 it('removes @description doc tags', () => { |
| 70 expectTranslate(`/** @description |
| 71 * This is a module for doing X. |
| 72 */`).to.equal(`/// This is a module for doing X.`); |
| 73 }); |
| 74 it('removes @depracted doc tags', () => { |
| 75 expectTranslate(`/** |
| 76 * Use SomethingElse instead. |
| 77 * @deprecated |
| 78 */`).to.equal(`/// Use SomethingElse instead.`); |
| 79 }); |
| 80 it('removes @param doc tags', () => { |
| 81 expectTranslate(`/** |
| 82 * Method to do blah. |
| 83 * @param doc Document. |
| 84 */`).to.equal(`/// Method to do blah.`); |
| 85 }); |
| 86 it('removes @return doc tags', () => { |
| 87 expectTranslate(`/** |
| 88 * Method to do blah. |
| 89 * @return {String} |
| 90 */`).to.equal(`/// Method to do blah.`); |
| 91 }); |
| 92 it('removes @throws doc tags', () => { |
| 93 expectTranslate(`/** |
| 94 * Method to do blah. |
| 95 * @throws ArgumentException If arguments are wrong |
| 96 */`).to.equal(`/// Method to do blah.`); |
| 97 }); |
| 98 it('multiple line comment', () => { |
| 99 expectTranslate(`/** |
| 100 * Method to do blah. |
| 101 * Bla bla bla. |
| 102 * Foo bar. |
| 103 */`).to.equal(`/// Method to do blah. |
| 104 /// Bla bla bla. |
| 105 /// Foo bar.`); |
| 106 }); |
| 107 it('multiple line comment', () => { |
| 108 expectTranslate(`class Foo { |
| 109 /** |
| 110 * Method to do blah. |
| 111 * Bla bla bla. |
| 112 * Foo bar. |
| 113 */ |
| 114 bar(); |
| 115 }`).to.equal(`@JS() |
| 116 class Foo { |
| 117 // @Ignore |
| 118 Foo.fakeConstructor$(); |
| 119 |
| 120 /// Method to do blah. |
| 121 /// Bla bla bla. |
| 122 /// Foo bar. |
| 123 external bar(); |
30 }`); | 124 }`); |
31 }); | 125 |
32 it('keeps ctor comments', () => { | 126 expectTranslate(`class Foo { |
33 expectTranslate('/** A */ class A {\n /** ctor */ constructor() {}}').to.e
qual(`/** A */ | 127 // Baz. |
34 class A { | 128 // Bla bla bla. |
35 /** ctor */ A() {} | 129 // Foo bar. |
| 130 |
| 131 // Bla. |
| 132 bar(); |
| 133 }`).to.equal(`@JS() |
| 134 class Foo { |
| 135 // @Ignore |
| 136 Foo.fakeConstructor$(); |
| 137 |
| 138 /// Baz. |
| 139 /// Bla bla bla. |
| 140 /// Foo bar. |
| 141 |
| 142 /// Bla. |
| 143 external bar(); |
36 }`); | 144 }`); |
37 }); | |
38 it('translates links to dart doc format', () => { | |
39 expectTranslate('/** {@link this/place} */ a').to.equal('/** [this/place]
*/ a;'); | |
40 expectTranslate('/* {@link 1} {@link 2} */ a').to.equal('/* [1] [2] */ a;'
); | |
41 }); | |
42 it('removes @module doc tags', () => { | |
43 expectTranslate(`/** @module | |
44 * This is a module for doing X. | |
45 */`).to.equal(`/** | |
46 * This is a module for doing X. | |
47 */`); | |
48 }); | |
49 it('removes @description doc tags', () => { | |
50 expectTranslate(`/** @description | |
51 * This is a module for doing X. | |
52 */`).to.equal(`/** | |
53 * This is a module for doing X. | |
54 */`); | |
55 }); | |
56 it('removes @depracted doc tags', () => { | |
57 expectTranslate(`/** | |
58 * Use SomethingElse instead. | |
59 * @deprecated | |
60 */`).to.equal(`/** | |
61 * Use SomethingElse instead. | |
62 * | |
63 */`); | |
64 }); | |
65 it('removes @param doc tags', () => { | |
66 expectTranslate(`/** | |
67 * Method to do blah. | |
68 * @param doc Document. | |
69 */`).to.equal(`/** | |
70 * Method to do blah. | |
71 * | |
72 */`); | |
73 }); | |
74 it('removes @return doc tags', () => { | |
75 expectTranslate(`/** | |
76 * Method to do blah. | |
77 * @return {String} | |
78 */`).to.equal(`/** | |
79 * Method to do blah. | |
80 * | |
81 */`); | |
82 }); | |
83 it('removes @throws doc tags', () => { | |
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 | 145 |
94 describe('errors', () => { | 146 }); |
95 it('reports multiple errors', () => { | 147 }); |
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 | 148 |
113 describe('output paths', () => { | 149 describe('output paths', () => { |
114 it('writes within the path', () => { | 150 it('writes within the path', () => { |
115 let transpiler = new main.Transpiler({basePath: '/a'}); | 151 let transpiler = new main.Transpiler({basePath: '/a'}); |
116 chai.expect(transpiler.getOutputPath('/a/b/c.js', '/x')).to.equal('/x/b/c.
dart'); | 152 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'); | 153 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'
); | 154 chai.expect(transpiler.getOutputPath('b/c.js', 'x')).to.equal('x/b/c.dart'
); |
119 chai.expect(() => transpiler.getOutputPath('/outside/b/c.js', '/x')) | 155 chai.expect(() => transpiler.getOutputPath('/outside/b/c.js', '/x')) |
120 .to.throw(/must be located under base/); | 156 .to.throw(/must be located under base/); |
121 }); | 157 }); |
122 it('defaults to writing to the same location', () => { | 158 it('defaults to writing to the same location', () => { |
123 let transpiler = new main.Transpiler({basePath: undefined}); | 159 let transpiler = new main.Transpiler({basePath: undefined}); |
124 chai.expect(transpiler.getOutputPath('/a/b/c.js', '/e')).to.equal('/a/b/c.
dart'); | 160 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'); | 161 chai.expect(transpiler.getOutputPath('b/c.js', '')).to.equal('b/c.dart'); |
126 }); | 162 }); |
127 it('translates .es6, .ts, and .js', () => { | 163 it('translates .es6, .ts, and .js', () => { |
128 let transpiler = new main.Transpiler({basePath: undefined}); | 164 let transpiler = new main.Transpiler({basePath: undefined}); |
129 ['a.js', 'a.ts', 'a.es6'].forEach( | 165 ['a.js', 'a.ts', 'a.es6'].forEach( |
130 (n) => { chai.expect(transpiler.getOutputPath(n, '')).to.equal('a.dart
'); }); | 166 (n) => { chai.expect(transpiler.getOutputPath(n, '')).to.equal('a.dart
'); }); |
131 }); | 167 }); |
132 }); | 168 }); |
133 }); | 169 }); |
OLD | NEW |