-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathclass_test.ts
158 lines (147 loc) · 5.91 KB
/
class_test.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import merge from '../src/index';
import { expect } from 'chai';
import 'mocha';
describe('Merging class declarations', () => {
describe('handling inheritance', () => {
const base = `class a {}`,
patch = `class a extends b {}`;
it('should yield a valid class.', () => {
const result: String[] = merge(base, patch, false)
.split('\n')
.map((value) => value.trim())
.filter((value) => value.trim() != '');
const assembledResult: String = result.reduce(
(prev: String, current: String) => {
return prev.toString() + current.toString();
},
'',
);
expect(assembledResult).equal(
'class a extends b {}',
'Result is not valid',
);
});
it('should use the patch extension.', () => {
const result: String[] = merge(base, patch, false)
.split('\n')
.map((value) => value.trim())
.filter((value) => value.trim() != '');
expect(
result.filter((value) =>
/class\s*a\s*extends\s*b[^]*/.test(value.toString()),
).length,
).to.be.equal(1, 'extension from patch should not be applied');
});
it('should use the patch extension with patchOverride.', () => {
const result: String[] = merge(base, patch, true)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(
result.filter((value) =>
/class\s*a\s*extends\s*b[^]*/.test(value.toString()),
).length,
).to.be.equal(1, 'extension from patch should be applied');
});
});
describe('handling aliasing', () => {
const base = `class a {}`,
patch = `class a implements b {}`;
it('should use the patch implementations.', () => {
const result: String[] = merge(base, patch, false)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(
result.filter((value) =>
/class\s*a\s*implements\s*b[^]*/.test(value.toString()),
).length,
).to.be.equal(1, 'implementation from patch should not be applied');
});
it('should use the patch implementation with patchOverride.', () => {
const result: String[] = merge(base, patch, true)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(
result.filter((value) =>
/class\s*a\s*implements\s*b[^]*/.test(value.toString()),
).length,
).to.be.equal(1, 'implementation from patch should be applied');
});
});
describe('multiple class definitions', () => {
const base = `class a {}`,
patch = `class b {}`;
it('should be accumulated.', () => {
const result: String = merge(patch, base, false)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '')
.reduce((prev, curr) => prev.toString() + curr.toString(), '');
let regex = /\s*class\s+[ab]\s*\{\}\s*class\s+[ab].*/;
expect(regex.test(result.toString())).true;
});
it('should be accumulated with patchOverride (should not make a difference).', () => {
const result: String = merge(patch, base, false)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '')
.reduce((prev, curr) => prev.toString() + curr.toString(), '');
let regex = /\s*class\s+[ab]\s*\{\}\s*class\s+[ab].*/;
expect(regex.test(result.toString())).true;
});
});
describe('should accumulate implemented interfaces', () => {
const base = `class a implements b {}`,
patch = `class a implements b,c {}`;
it('by default should be accumulated.', () => {
const result: String[] = merge(base, patch, false)
.split('\n') // get each individual line
.map((value) => value.trim()) // trim all lines (no white spaces at the beginning and end of a line)
.filter((value) => value != ''); // remove empty lines
expect(
result.filter((value) =>
/class\s*a\s*implements\s*\w\s*,\s*\w.*/.test(value.toString()),
).length,
).to.be.equal(1, 'misformed class declaration');
});
it('should be accumulated with patchOverride (should not make a difference).', () => {
const result: String[] = merge(base, patch, true)
.split('\n') // get each individual line
.map((value) => value.trim()) // trim all lines (no white spaces at the beginning and end of a line)
.filter((value) => value != ''); // remove empty lines
expect(
result.filter((value) =>
/class\s*a\s*implements\s*\w\s*,\s*\w.*/.test(value.toString()),
).length,
).to.be.equal(1, 'misformed class declaration');
});
});
describe('should accumulate extended interfaces', () => {
const base = `class a extends b {}`,
patch = `class a extends b,c {}`;
it('by default should be accumulated.', () => {
const result: String[] = merge(base, patch, false)
.split('\n') // get each individual line
.map((value) => value.trim()) // trim all lines (no white spaces at the beginning and end of a line)
.filter((value) => value != ''); // remove empty lines
expect(
result.filter((value) =>
/class\s*a\s*extends\s*\w\s*,\s*\w.*/.test(value.toString()),
).length,
).to.be.equal(1, 'misformed class declaration');
});
it('should be accumulated with patchOverride (should not make a difference).', () => {
const result: String[] = merge(base, patch, true)
.split('\n') // get each individual line
.map((value) => value.trim()) // trim all lines (no white spaces at the beginning and end of a line)
.filter((value) => value != ''); // remove empty lines
expect(
result.filter((value) =>
/class\s*a\s*extends\s*\w\s*,\s*\w.*/.test(value.toString()),
).length,
).to.be.equal(1, 'misformed class declaration');
});
});
});