OLD | NEW |
| (Empty) |
1 /// <reference path="../typings/mocha/mocha.d.ts"/> | |
2 import {expectTranslate} from './test_support'; | |
3 | |
4 describe('statements', () => { | |
5 it('translates switch', () => { | |
6 expectTranslate('switch(x) { case 1: break; case 2: break; default: break; }
') | |
7 .to.equal(`switch (x) { | |
8 case 1: | |
9 break; | |
10 case 2: | |
11 break; | |
12 default: | |
13 break; | |
14 }`); | |
15 }); | |
16 it('translates for loops', () => { | |
17 expectTranslate('for (1; 2; 3) { 4 }').to.equal(`for (1; 2; 3) { | |
18 4; | |
19 }`); | |
20 expectTranslate('for (var x = 1; 2; 3) { 4 }').to.equal(`for (var x = 1; 2;
3) { | |
21 4; | |
22 }`); | |
23 expectTranslate('for (var x, y = 1; 2; 3) { 4 }').to.equal(`for (var x, y =
1; 2; 3) { | |
24 4; | |
25 }`); | |
26 expectTranslate('for (var x = 0, y = 1; 2; 3) { 4 }').to.equal(`for (var x =
0, y = 1; 2; 3) { | |
27 4; | |
28 }`); | |
29 }); | |
30 it('translates for-in loops', () => { | |
31 expectTranslate('for (var x in 1) { 2 }').to.equal(`for (var x in 1) { | |
32 2; | |
33 }`); | |
34 expectTranslate('for (x in 1) { 2 }').to.equal(`for (x in 1) { | |
35 2; | |
36 }`); | |
37 }); | |
38 it('translates for-of loops', () => { | |
39 expectTranslate('for (var x of 1) { 2 }').to.equal(`for (var x in 1) { | |
40 2; | |
41 }`); | |
42 expectTranslate('for (x of 1) { 2 }').to.equal(`for (x in 1) { | |
43 2; | |
44 }`); | |
45 }); | |
46 it('translates while loops', () => { | |
47 expectTranslate('while (1) { 2 }').to.equal(`while (1) { | |
48 2; | |
49 }`); | |
50 expectTranslate('do 1; while (2);').to.equal('do 1; while (2);'); | |
51 }); | |
52 it('translates if/then/else', () => { | |
53 expectTranslate('if (x) { 1 }').to.equal(`if (x) { | |
54 1; | |
55 }`); | |
56 expectTranslate('if (x) { 1 } else { 2 }').to.equal(`if (x) { | |
57 1; | |
58 } else { | |
59 2; | |
60 }`); | |
61 expectTranslate('if (x) 1;').to.equal('if (x) 1;'); | |
62 expectTranslate('if (x) 1; else 2;').to.equal(`if (x) | |
63 1; | |
64 else | |
65 2;`); | |
66 }); | |
67 it('translates try/catch', () => { | |
68 expectTranslate('try {} catch(e) {} finally {}') | |
69 .to.equal('try {} catch (e, e_stack) {} finally {}'); | |
70 expectTranslate('try {} catch(e: MyException) {}') | |
71 .to.equal('try {} on MyException catch (e, e_stack) {}'); | |
72 }); | |
73 it('translates throw', | |
74 () => { expectTranslate('throw new Error("oops")').to.equal('throw new Erro
r("oops");'); }); | |
75 it('translates empty statements', () => { expectTranslate(';').to.equal(';');
}); | |
76 it('translates break & continue', () => { | |
77 expectTranslate(`while (true) { | |
78 break; | |
79 }`).to.equal(`while (true) { | |
80 break; | |
81 }`); | |
82 expectTranslate(`while (true) { | |
83 continue; | |
84 }`).to.equal(`while (true) { | |
85 continue; | |
86 }`); | |
87 expectTranslate(`while (true) { | |
88 break foo; | |
89 }`).to.equal(`while (true) { | |
90 break foo; | |
91 }`); | |
92 }); | |
93 it('rewrites catch block to preserve stack trace', () => { | |
94 expectTranslate(`try {} catch (e) { | |
95 console.log(e, e.stack); | |
96 }`).to.equal(`try {} catch (e, e_stack) { | |
97 console.log(e, e_stack); | |
98 }`); | |
99 }); | |
100 it('rewrites rethrow to preserve stack trace', () => { | |
101 expectTranslate('try {} catch (ex) { throw ex; }').to.equal(`try {} catch (e
x, ex_stack) { | |
102 rethrow; | |
103 }`); | |
104 }); | |
105 }); | |
OLD | NEW |