-
Notifications
You must be signed in to change notification settings - Fork 21
/
array_transitions.spec.ts
129 lines (67 loc) · 3.68 KB
/
array_transitions.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
/* eslint-disable max-len */
import * as jssm from '../jssm';
describe('Array basics', () => {
describe('array of one', () => {
const aLeft = [
{main_path: false,forced_only: false,"from":"a","to":"d","kind":"legal"}
];
test('[a]->d;', () => expect( jssm.compile(jssm.parse('[a]->d;')).transitions ).toEqual(aLeft) );
});
describe('array of one', () => {
const aLeft = [
{main_path: false,forced_only: false,"from":"a","to":"d","kind":"legal"}
];
test('[a]->d;', () => expect( jssm.compile(jssm.parse('[a]->d;')).transitions ).toEqual(aLeft) );
});
});
describe('Array sides', () => {
describe('array on left', () => {
const aLeft = [
{main_path: false,forced_only: false,"from":"a","to":"d","kind":"legal"},
{main_path: false,forced_only: false,"from":"b","to":"d","kind":"legal"},
{main_path: false,forced_only: false,"from":"c","to":"d","kind":"legal"}
];
test('[a b c]->d;', () => expect( jssm.compile(jssm.parse('[a b c]->d;')).transitions ).toEqual(aLeft) );
});
describe('array on right', () => {
const aRight = [
{main_path: false,forced_only: false,"from":"a","to":"b","kind":"legal"},
{main_path: false,forced_only: false,"from":"a","to":"c","kind":"legal"},
{main_path: false,forced_only: false,"from":"a","to":"d","kind":"legal"}
];
test('a->[b c d];', () => expect( jssm.compile(jssm.parse('a->[b c d];')).transitions ).toEqual(aRight) );
});
describe('array on both sides', () => {
const aBoth = [
{main_path: false,forced_only: false,"from":"a","to":"x","kind":"legal"},
{main_path: false,forced_only: false,"from":"a","to":"y","kind":"legal"},
{main_path: false,forced_only: false,"from":"a","to":"z","kind":"legal"},
{main_path: false,forced_only: false,"from":"b","to":"x","kind":"legal"},
{main_path: false,forced_only: false,"from":"b","to":"y","kind":"legal"},
{main_path: false,forced_only: false,"from":"b","to":"z","kind":"legal"},
{main_path: false,forced_only: false,"from":"c","to":"x","kind":"legal"},
{main_path: false,forced_only: false,"from":"c","to":"y","kind":"legal"},
{main_path: false,forced_only: false,"from":"c","to":"z","kind":"legal"}
];
test('[a b c]->[x y z];', () => expect( jssm.compile(jssm.parse('[a b c]->[x y z];')).transitions ).toEqual(aBoth) );
});
describe('array in middle', () => {
const aBoth = [
{main_path: false,forced_only: false,"from":"a","to":"x","kind":"legal"},
{main_path: false,forced_only: false,"from":"a","to":"y","kind":"legal"},
{main_path: false,forced_only: false,"from":"a","to":"z","kind":"legal"},
{main_path: false,forced_only: false,"from":"x","to":"b","kind":"legal"},
{main_path: false,forced_only: false,"from":"y","to":"b","kind":"legal"},
{main_path: false,forced_only: false,"from":"z","to":"b","kind":"legal"}
];
test('a->[x y z]->b;', () => expect( jssm.compile(jssm.parse('a->[x y z]->b;')).transitions ).toEqual(aBoth) );
});
});
describe('array of zero must throw', () => {
const aLeft = [];
test('On left []->d;', () => expect( () => jssm.compile( jssm.parse('[]->d;') ).transitions ).toThrow() );
test('On right d->[];', () => expect( () => jssm.compile( jssm.parse('d->[];') ).transitions ).toThrow() );
test('On both []->[];', () => expect( () => jssm.compile( jssm.parse('[]->[];') ).transitions ).toThrow() );
test('In middle d->[]->e;', () => expect( () => jssm.compile( jssm.parse('d->[]->e;') ).transitions ).toThrow() );
test('In loop d->[]->d;', () => expect( () => jssm.compile( jssm.parse('d->[]->d;') ).transitions ).toThrow() );
});