-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathinterface_method_test.ts
120 lines (114 loc) · 3.56 KB
/
interface_method_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
import merge from '../src/index';
import { expect } from 'chai';
import 'mocha';
describe('Merging interface methods', () => {
describe('should add the method from', () => {
const base = `interface a {
b(b:any):void;
}`,
patch = `interface a {
c(b:any):number;
}`;
it('the patch.', () => {
const result: String[] = merge(base, patch, false)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(
result.filter((res) =>
/\s*c\s*\(\s*b\s*:\s*any\s*\)\s*:\s*number\s*;/.test(res.toString()),
),
).length.to.be.greaterThan(
0,
'declaration should be present in interface a',
);
});
it('the patch with patchOverride.', () => {
const result: String[] = merge(base, patch, true)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(
result.filter((res) =>
/\s*c\s*\(\s*b\s*:\s*any\s*\)\s*:\s*number\s*;/.test(res.toString()),
),
).length.to.be.greaterThan(
0,
'declaration should be present in interface a',
);
});
});
describe('should add the method parameters from', () => {
const base = `interface a {
b(c:any):void;
}`,
patch = `interface a {
b(b:any):number;
}`;
it('the patch.', () => {
const result: String[] = merge(base, patch, false)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(
result.filter((res) =>
/\s*b\s*\(\s*c\s*:\s*any\s*,\s*b\s*:\s*any\s*\)\s*:\s*void\s*;/.test(
res.toString(),
),
),
).length.to.be.greaterThan(
0,
'both method parameters should be present, and should use base method type',
);
});
it('the patch with patchOverride.', () => {
const result: String[] = merge(base, patch, true)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(
result.filter((res) =>
/\s*b\s*\(\s*c\s*:\s*any\s*,\s*b\s*:\s*any\s*\)\s*:\s*number\s*;/.test(
res.toString(),
),
),
).length.to.be.greaterThan(
0,
'both method parameters should be present, and should use patch method type',
);
});
});
describe('should not change the method from', () => {
const base = `interface a {
b(c:any):void;
}`,
patch = `interface a {
b(c:any):number;
}`;
it('the base.', () => {
const result: String[] = merge(base, patch, false)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(
result.filter((res) =>
/\s*b\s*\(\s*c\s*:\s*any\s*\)\s*:\s*void\s*;/.test(res.toString()),
),
).length.to.be.greaterThan(0, 'base method should not change');
});
it('the patch with patchOverride.', () => {
const result: String[] = merge(base, patch, true)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(
result.filter((res) =>
/\s*b\s*\(\s*c\s*:\s*any\s*\)\s*:\s*number\s*;/.test(res.toString()),
),
).length.to.be.greaterThan(
0,
'only the base method type should be changed, using patch type',
);
});
});
});