-
Notifications
You must be signed in to change notification settings - Fork 9
/
compatible.test.js
164 lines (147 loc) · 4.82 KB
/
compatible.test.js
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
import fs from 'fs'
import { LogicEngine, AsyncLogicEngine } from './index.js'
import traverseCopy from './utilities/traverseCopy.js'
const tests = JSON.parse(fs.readFileSync('./bench/compatible.json').toString())
const other = traverseCopy(tests, [], {
mutateKey: (i) => {
if (i === 'map') {
return 'mapYield'
}
if (i === 'reduce') {
return 'reduceYield'
}
if (i === 'filter') {
return 'filterYield'
}
if (i === 'every') {
return 'everyYield'
}
if (i === 'some') {
return 'someYield'
}
return i
}
})
// eslint-disable-next-line no-labels
inline: {
const logic = new LogicEngine()
const asyncLogic = new AsyncLogicEngine()
describe('All of the compatible tests', () => {
tests.forEach((testCase) => {
test(`${JSON.stringify(testCase[0])} ${JSON.stringify(
testCase[1]
)}`, () => {
expect(logic.run(testCase[0], testCase[1])).toStrictEqual(testCase[2])
})
test(`${JSON.stringify(testCase[0])} ${JSON.stringify(
testCase[1]
)} (async)`, async () => {
expect(await asyncLogic.run(testCase[0], testCase[1])).toStrictEqual(
testCase[2]
)
})
test(`${JSON.stringify(testCase[0])} ${JSON.stringify(
testCase[1]
)} (built)`, () => {
const f = logic.build(testCase[0])
expect(f(testCase[1])).toStrictEqual(testCase[2])
})
test(`${JSON.stringify(testCase[0])} ${JSON.stringify(
testCase[1]
)} (asyncBuilt)`, async () => {
const f = await asyncLogic.build(testCase[0])
expect(await f(testCase[1])).toStrictEqual(testCase[2])
})
})
})
describe('All of the compatible tests with yielded iterators', () => {
test('All of the compatible tests', () => {
other.forEach((test) => {
expect(logic.run(test[0], test[1])).toStrictEqual(test[2])
})
})
test('All of the compatible tests (async)', async () => {
for (let i = 0; i < other.length; i++) {
const test = other[i]
expect(await asyncLogic.run(test[0], test[1])).toStrictEqual(test[2])
}
})
test('All of the compatible tests (built)', () => {
for (let i = 0; i < other.length; i++) {
const test = other[i]
const f = logic.build(test[0])
// console.log(JSON.stringify(test[0]), JSON.stringify(test[1]))
expect(f(test[1])).toStrictEqual(test[2])
}
})
test('All of the compatible tests (asyncBuilt)', async () => {
for (let i = 0; i < other.length; i++) {
const test = other[i]
const f = await asyncLogic.build(test[0])
expect(await f(test[1])).toStrictEqual(test[2])
}
})
})
}
// eslint-disable-next-line no-labels
notInline: {
const logic = new LogicEngine()
const asyncLogic = new AsyncLogicEngine()
logic.disableInline = true
asyncLogic.disableInline = true
// using a loop to disable the inline compilation mechanism.
tests.forEach((testCase) => {
test(`${JSON.stringify(testCase[0])} ${JSON.stringify(
testCase[1]
)}`, () => {
expect(logic.run(testCase[0], testCase[1])).toStrictEqual(testCase[2])
})
test(`${JSON.stringify(testCase[0])} ${JSON.stringify(
testCase[1]
)} (async)`, async () => {
expect(await asyncLogic.run(testCase[0], testCase[1])).toStrictEqual(
testCase[2]
)
})
test(`${JSON.stringify(testCase[0])} ${JSON.stringify(
testCase[1]
)} (built)`, () => {
const f = logic.build(testCase[0])
expect(f(testCase[1])).toStrictEqual(testCase[2])
})
test(`${JSON.stringify(testCase[0])} ${JSON.stringify(
testCase[1]
)} (asyncBuilt)`, async () => {
const f = await asyncLogic.build(testCase[0])
expect(await f(testCase[1])).toStrictEqual(testCase[2])
})
})
describe('All of the compatible tests with yielded iterators', () => {
test('All of the compatible tests', () => {
other.forEach((test) => {
expect(logic.run(test[0], test[1])).toStrictEqual(test[2])
})
})
test('All of the compatible tests (async)', async () => {
for (let i = 0; i < other.length; i++) {
const test = other[i]
expect(await asyncLogic.run(test[0], test[1])).toStrictEqual(test[2])
}
})
test('All of the compatible tests (built)', () => {
for (let i = 0; i < other.length; i++) {
const test = other[i]
const f = logic.build(test[0])
// console.log(JSON.stringify(test[0]), JSON.stringify(test[1]))
expect(f(test[1])).toStrictEqual(test[2])
}
})
test('All of the compatible tests (asyncBuilt)', async () => {
for (let i = 0; i < other.length; i++) {
const test = other[i]
const f = await asyncLogic.build(test[0])
expect(await f(test[1])).toStrictEqual(test[2])
}
})
})
}