-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathclass_field_test.ts
160 lines (148 loc) · 5.71 KB
/
class_field_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
159
160
import merge from '../src/index';
import { expect } from 'chai';
import 'mocha';
describe('Merging class fields', () => {
describe('should add the field from', () => {
const base = `class a { private b; }`,
patch = `class a { private c; }`;
it('from the patch.', () => {
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.indexOf('private c;')).to.be.greaterThan(
0,
'declaration should be present in class a',
);
});
it('from the patch with patchOverride.', () => {
const result: String[] = merge(base, patch, true)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(result.indexOf('private c;')).to.be.greaterThan(
0,
'declaration should be present in class a',
);
});
});
describe('should use the value from', () => {
const base = `class a { private b = 1; }`,
patch = `class a { private b = 2; }`;
it('the base if variable is present in base and patch.', () => {
const result: String[] = merge(base, patch, false)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(
result.filter((res) => /private\s+b\s*=\s*1;/.test(res.toString())),
).length.is.greaterThan(0);
//expect(result.indexOf('private b = 1;')).to.be.greaterThan(0, 'b should have value from base');
});
it('the patch if variable is present in base and patch, and patchOverride is true.', () => {
const result: String[] = merge(base, patch, true)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(
result.filter((res) => /private\s+b\s*=\s*2;/.test(res.toString())),
).length.is.greaterThan(0, 'b should have value from patch');
});
});
describe('should use the modifier from', () => {
const base = `class a { private b; }`,
patch = `class a { public b; }`;
it('the base if variable is present in base and patch.', () => {
const result: String[] = merge(base, patch, false)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(result.indexOf('private b;')).to.be.greaterThan(
0,
'b should have modifier from base',
);
});
it('the patch if variable is present in base and patch, and patchOverride is true.', () => {
const result: String[] = merge(base, patch, true)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(result.indexOf('public b;')).to.be.greaterThan(
0,
'b should have modifier from patch',
);
});
});
describe('should add the optional token', () => {
const base = `class a { b?: string; }`,
patch = `class a { b: string; }`;
it('from the base.', () => {
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.indexOf('b?: string;')).to.be.greaterThan(
0,
'optional token should be present in class a',
);
});
it('from the patch with patchOverride.', () => {
const result: String[] = merge(base, patch, true)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(result.indexOf('b: string;')).to.be.greaterThan(
0,
'optional token should not be present in class a',
);
});
});
describe('should merge null types', () => {
const base = `class a { b: null; }`,
patch = `class a { b: null; }`;
it('from the base.', () => {
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.indexOf('b: null;')).to.be.greaterThan(
0,
'null token should be present in class a',
);
});
it('from the patch with patchOverride.', () => {
const result: String[] = merge(base, patch, true)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(result.indexOf('b: null;')).to.be.greaterThan(
0,
'null token should be present in class a',
);
});
});
describe('should merge undefined types', () => {
const base = `class a { b: undefined; }`,
patch = `class a { b: undefined; }`;
it('from the base.', () => {
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.indexOf('b: undefined;')).to.be.greaterThan(
0,
'undefined token should be present in class a',
);
});
it('from the patch with patchOverride.', () => {
const result: String[] = merge(base, patch, true)
.split('\n')
.map((value) => value.trim())
.filter((value) => value != '');
expect(result.indexOf('b: undefined;')).to.be.greaterThan(
0,
'undefined token should be present in class a',
);
});
});
});