-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathinterface_field_test.ts
109 lines (101 loc) · 3.83 KB
/
interface_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
import merge from '../src/index';
import { expect } from 'chai';
import 'mocha';
describe('Merging interface fields', () => {
describe('should add the field from', () => {
const base = `interface a { private b; }`,
patch = `interface 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 interface 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 interface a',
);
});
});
describe('should use the modifier from', () => {
const base = `interface a { private b; }`,
patch = `interface 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 use the type from', () => {
const base = `interface a { private b: string; }`,
patch = `interface a { private b: number; }`;
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: string;')).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('private b: number;')).to.be.greaterThan(
0,
'b should have modifier from patch',
);
});
});
describe('should add the index signature from', () => {
const base = `interface a { [key: string]: any; }`,
patch = `interface a { [key: string]: string; }`;
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('[key: string]: any;')).to.be.greaterThan(
0,
'base index should be present in interface 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('[key: string]: string;')).to.be.greaterThan(
0,
'declaration should be present in interface a',
);
});
});
});