-
Notifications
You must be signed in to change notification settings - Fork 7
/
TestCaseSSATest.spec.ts
226 lines (197 loc) · 6.81 KB
/
TestCaseSSATest.spec.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import { join } from 'path';
import { FileInfo, Import, Location, Feature, Document, TestCase, Tag, ReservedTags } from 'concordialang-types';
import { NodeTypes } from '../../modules/req/NodeTypes';
import { AugmentedSpec } from '../../modules/ast/AugmentedSpec';
import { TestCaseSSA } from '../../modules/semantic/TestCaseSSA';
/**
* @author Thiago Delgado Pinto
*/
describe( 'TestCaseSSATest', () => {
let analyzer: TestCaseSSA; // under test
const path = process.cwd();
let spec: AugmentedSpec;
let docA: Document;
let docB: Document;
let docC: Document;
let docD: Document;
let docE1: Document;
let docE2: Document;
let docF: Document;
let docG: Document;
beforeEach( () => {
analyzer = new TestCaseSSA();
/*
- C imports A, B, and E
- A and B have features
- E1 and E2 have no features
- D imports E1 and E2
- F has a feature and no imports
- G has a feature, no imports, and the tag references another feature
*/
spec = new AugmentedSpec( path );
docA = {
fileInfo: { path: join( path, "A.feature" ) } as FileInfo,
feature: {
name: "My feature A",
location: {}
} as Feature
};
docB = {
fileInfo: { path: join( path, "B.feature" ) } as FileInfo,
feature: {
name: "My feature B",
location: {}
} as Feature
};
docE1 = {
fileInfo: { path: join( path, "E1.feature" ) } as FileInfo
};
docE2 = {
fileInfo: { path: join( path, "E2.feature" ) } as FileInfo
};
docC = {
fileInfo: { path: join( path, "C.feature" ) } as FileInfo,
imports: [
{
value: "A.feature"
} as Import,
{
value: "B.feature"
} as Import,
{
value: "E1.feature"
} as Import
],
testCases: [
{
name: "My test case 1",
location: {},
tags: [
{
name: ReservedTags.FEATURE,
content: "My feature A",
nodeType: NodeTypes.TAG,
location: {
} as Location
} as Tag
]
} as TestCase
]
};
docD = {
fileInfo: { path: join( path, "D.feature" ) } as FileInfo,
imports: [
{
value: "E1.feature"
} as Import,
{
value: "E2.feature"
} as Import
],
testCases: [
{
name: "My test case 1",
location: {},
tags: [
{
name: ReservedTags.FEATURE,
content: "My feature A",
nodeType: NodeTypes.TAG,
location: {
} as Location
} as Tag
]
} as TestCase
]
};
docF = {
fileInfo: { path: join( path, "F.feature" ) } as FileInfo,
feature: {
name: "My feature F",
location: {}
} as Feature,
testCases: [
{
name: "My F test case 1",
location: {}
} as TestCase
]
};
docG = {
fileInfo: { path: join( path, "G.feature" ) } as FileInfo,
feature: {
name: "My feature G",
location: {},
} as Feature,
testCases: [
{
name: "My G test case 1",
location: {},
tags: [
{
name: ReservedTags.FEATURE,
content: "My feature A",
nodeType: NodeTypes.TAG,
location: {
} as Location
} as Tag
]
} as TestCase
]
};
spec.docs.push( docA, docB, docC, docD, docE1, docE2, docF, docG );
} );
afterEach( () => {
analyzer = null;
} );
it( 'criticizes the lack of a feature and an import', () => {
docC.imports = []; // empty
let errors: Error[] = [];
analyzer.analyzeDocument( spec, docC, errors );
expect( errors ).toHaveLength( 1 );
expect( errors[ 0 ].message ).toMatch( /import/ui );
} );
it( 'does not criticizes the lack of tags if its imports have a single feature', () => {
docC.testCases[ 0 ].tags = []; // empty
docC.imports.splice( 1 ); // remove the B, in order to have just one feature
let errors: Error[] = [];
analyzer.analyzeDocument( spec, docC, errors );
expect( errors ).toHaveLength( 0 );
} );
it( 'criticizes the lack of tags if its imports have more than one feature', () => {
docC.testCases[ 0 ].tags = []; // empty
let errors: Error[] = [];
analyzer.analyzeDocument( spec, docC, errors );
expect( errors ).toHaveLength( 1 );
expect( errors[ 0 ].message ).toMatch( /tag/ui );
} );
it( 'does not criticize the lack of feature if the file has a feature', () => {
let errors: Error[] = [];
analyzer.analyzeDocument( spec, docF, errors );
expect( errors ).toHaveLength( 0 );
} );
it( 'does not criticize a referenced feature that is the file\'s feature', () => {
docG.testCases[ 0 ].tags[ 0 ].content = docG.feature.name;
let errors: Error[] = [];
analyzer.analyzeDocument( spec, docG, errors );
expect( errors ).toHaveLength( 0 );
} );
it( 'criticizes a referenced feature not imported', () => {
let errors: Error[] = [];
analyzer.analyzeDocument( spec, docG, errors );
expect( errors ).toHaveLength( 1 );
expect( errors[ 0 ].message ).toMatch( /tag/ui );
} );
it( 'criticizes duplicated names', () => {
docF.testCases.push(
{
name: "My F test case 1",
location: {}
} as TestCase
);
let errors: Error[] = [];
analyzer.analyzeDocument( spec, docF, errors );
expect( errors ).toHaveLength( 1 );
expect( errors[ 0 ].message ).toMatch( /duplicated/ui );
} );
} );