-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathinterface_test.ts
112 lines (106 loc) · 4.18 KB
/
interface_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
import merge from '../src/index';
import { expect } from 'chai';
import 'mocha';
describe('Merging interface declarations', () => {
describe('handling inheritance', () => {
const base = `interface a {}`,
patch = `interface a extends b {}`;
it('should yield a valid interface.', () => {
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(
'interface 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) =>
/interface\s*a\s*extends\s*\w\s*/.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) =>
/interface a extends b[^]*/.test(value.toString()),
).length,
).to.be.equal(1, 'extension from patch should be applied');
});
it('should keep the base extension.', () => {
const result: String[] = merge(patch, base, false)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(
result.filter((value) =>
/interface\s*a\s*extends\s*\w\s*/.test(value.toString()),
).length,
).to.be.equal(1, 'extension from base should be kept');
});
});
describe('multiple interface definitions', () => {
const base = `interface a {}`,
patch = `interface 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*interface\s+[ab]\s*\{\}\s*interface\s+[ab].*/;
expect(regex.test(result.toString())).true;
});
it('should be accumulated with patchOverride (should not make any 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*interface\s+[ab]\s*\{\}\s*interface\s+[ab].*/;
expect(regex.test(result.toString())).true;
});
});
describe('should accumulate extended interfaces', () => {
const base = `interface a extends b {}`,
patch = `interface 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) =>
/interface\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 any 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) =>
/interface\s*a\s*extends\s*\w\s*,\s*\w.*/.test(value.toString()),
).length,
).to.be.equal(1, 'misformed class declaration');
});
});
});