-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmodules_and_namespaces.spec.ts
115 lines (107 loc) · 5.47 KB
/
modules_and_namespaces.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { Run } from '../src/compiler';
import { expect } from 'chai';
import { describe, it } from 'mocha';
describe('Modules', () => {
it('Module 1', () => expect('1\r\n').to.equals(new Run().test([
'module M { \
export class C { \
static Y() { return 2; } \
\
X() { return 1; } \
} \
} \
\
const c = new M.C(); \
console.log(c.X()); \
'])));
it('Module 2 - nested', () => expect('1\r\n').to.equals(new Run().test([
'module M1 { \
module M2 { \
export class C { \
static Y() { return 2; } \
\
X() { return 1; } \
} \
} \
} \
\
const c = new M1.M2.C(); \
console.log(c.X()); \
'])));
it('Module 3 - <module1>.<module2>', () => expect('1\r\n').to.equals(new Run().test([
'module M1.M2 { \
export class C { \
static Y() { return 2; } \
\
X() { return 1; } \
} \
} \
\
const c = new M1.M2.C(); \
console.log(c.X()); \
'])));
it('Module - export function', () => expect('Hi\r\n').to.equals(new Run().test([
'module M1.M2 { \
export function f() { \
console.log("Hi"); \
} \
} \
\
M1.M2.f(); \
'])));
it('Module - multi blocks', () => expect('1\r\n3\r\n').to.equals(new Run().test([
'module M { \
export class C { \
static Y() { return 2; } \
\
X() { return 1; } \
} \
} \
\
module M { \
export class C2 { \
static Y() { return 4; } \
\
X() { return 3; } \
} \
} \
\
const c = new M.C(); \
console.log(c.X()); \
const c2 = new M.C2(); \
console.log(c2.X()); \
'])));
it('Module - import only', () => expect('1\r\n3\r\n').to.equals(new Run().test([
'module M { \
export class C { \
static Y() { return 2; } \
\
X() { return 1; } \
} \
} \
\
module M { \
export class C2 { \
static Y() { return 4; } \
\
X() { return 3; } \
} \
} \
',
'import \'./test0\'; \
const c = new M.C(); \
console.log(c.X()); \
const c2 = new M.C2(); \
console.log(c2.X()); \
'])));
it('Module - static method call with param', () => expect(new Run().test([
'module M { \
export class C { \
static Y(name: string) { return name; }\
} \
} \
',
'import \'./test0\'; \
console.log(M.C.Y("test")); \
'])).to.equals('test\r\n'));
});