-
Notifications
You must be signed in to change notification settings - Fork 21
/
state_declaration.spec.ts
214 lines (138 loc) · 5.34 KB
/
state_declaration.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
/* eslint-disable max-len */
import * as jssm from '../jssm';
const sm = jssm.sm;
describe("doesn't throw", () => {
test('with no attributes', () =>
expect(() => { const _foo = sm`state c: {}; a -> b;`; })
.not.toThrow() );
test('with just whitespace', () =>
expect(() => { const _foo = sm`state c: { }; a -> b;`; })
.not.toThrow() );
test('with just node color', () =>
expect(() => { const _foo = sm`state c: { color: red; }; a -> b;`; })
.not.toThrow() );
});
describe('can read declaration', () => {
const mach0 = sm`state c: { }; a -> b;`,
mach1 = sm`state c: { color: red; }; a -> b;`,
mach2 = sm`state c: { color: red; shape: circle; }; a -> b;`;
test.todo('Incomplete test prototypes in state_declaration');
// const machT = sm`c: { color: red; }; d: { shape: circle; }; a -> b;`;
// const machP = sm`
// c: { shape: circle; color: red; };
// d: { shape: circle; color: red; };
// a -> b;
// `;
describe('of w/ nothing', () => {
const decls = mach0.state_declarations();
describe('through .state_declarations/0 w nothing', () => {
test('yielding map', () =>
expect( decls instanceof Map ).toBe(true) );
test('list having size 1', () =>
expect( decls.size ).toBe(1) );
test('props having length 0', () =>
expect( decls.get('c').declarations.length ).toBe(0) );
});
});
describe('of just w/ color', () => {
const decls = mach1.state_declarations();
describe('through .state_declarations/0 just state color', () => {
test('yielding map', () =>
expect(decls instanceof Map ).toBe(true) );
test('list having size 1', () =>
expect(decls.size).toBe(1) );
test('props having length 1', () =>
expect(decls.get('c').declarations.length ).toBe(1) );
// todo whargarbl check the actual members comeback
});
test('through .state_declaration/1', () =>
expect(mach1.state_declaration('c').declarations[0].value )
.toBe('#ff0000ff') );
});
describe('of w/ color, shape', () => {
test('through .state_declaration/1 red hex-8', () =>
expect(mach2.state_declaration('c').declarations[0].value )
.toBe('#ff0000ff') );
test('through .state_declaration/1 circle', () =>
expect(mach2.state_declaration('c').declarations[1].value )
.toBe('circle') );
test('through .state_declarations/0 size', () =>
expect(mach2.state_declarations().size )
.toBe(1) );
test.todo('Re-enable once state_declarations/0 exposes type 3');
test('through .state_declarations/0 declarations length', () =>
expect(mach2.state_declarations().get('c').declarations.length )
.toBe(2) );
});
test.todo('Not sure why these were commented out tbh');
/*
describe('of w/ color on c, shape on d', () => {
test('through .state_declaration/1', () =>
expect(machT.state_declaration('c') )
.toBe('left') );
test('through .state_declaration/1', () =>
expect(machT.state_declaration('d') )
.toBe('left') );
test('through .state_declarations/0', () =>
expect(machT.state_declarations() )
.toBe('left') );
});
describe('of w/ color, shape on each c and d', () => {
test('through .state_declaration/1', () =>
expect(machP.state_declaration('c') )
.toBe('left') );
test('through .state_declaration/1', () =>
expect(machP.state_declaration('d') )
.toBe('left') );
test('through .state_declarations/0', () =>
expect(machP.state_declarations() )
.toBe('left') );
});
*/
});
describe('error catchery', () => {
test('repeated declaration throws', () =>
expect( () => { const _mach1 = sm`state c: { color: red; }; state c: { color: red; }; a -> b;`; } ) // eslint-disable-line no-unused-vars
.toThrow()
);
describe('unknown state property', () => {
const prestate = {
"start_states":["b"],
"transitions":[{"from":"b","to":"c","kind":"legal","forced_only":false,"main_path":false}],
"state_declaration":[{"state":"a","declarations":[{"key":"urgle bergle","value":"circle"}]}]};
test('throws', () =>
expect( () => { const _m0 = new jssm.Machine(prestate as any); } )
.toThrow() );
});
test('transfer state properties throws on unknown key', () =>
expect( () => { jssm.transfer_state_properties({declarations: [{key: 'agsrhdtjfy', value: 'seven'}]} as any); } )
.toThrow()
);
test('Cannot declare the same state twice', () =>
expect( () => { const mach0 = sm`state c: { }; state c: { }; a -> b;`; } )
.toThrow()
);
test('Cannot generate an existing state', () =>
expect( () => {
const errM = sm`a->c;state c:{};`;
const errR = errM._new_state({name:'c'} as any);
} )
.toThrow()
);
test('Cannot generate an empty state name as string', () =>
expect( () => {
const errM = sm`state "":{};`;
} )
.toThrow()
);
describe('Cannot generate an empty state name as datastructure', () => {
const prestate = {
"start_states":["b"],
"transitions":[{"from":"b","to":"c","kind":"legal","forced_only":false,"main_path":false}],
"state_declaration":[{"state":""}]
};
test('throws', () =>
expect( () => { const _m0 = new jssm.Machine(prestate as any); } )
.toThrow() );
});
});