1
1
import fs from 'fs'
2
2
import { LogicEngine , AsyncLogicEngine } from './index.js'
3
+
3
4
const tests = [ ]
4
5
5
6
// get all json files from "suites" directory
@@ -20,141 +21,50 @@ function correction (x) {
20
21
return x
21
22
}
22
23
23
- // eslint-disable-next-line no-labels
24
- inline: {
25
- const logic = new LogicEngine ( undefined , { compatible : true } )
26
- const asyncLogic = new AsyncLogicEngine ( undefined , { compatible : true } )
27
- const logicWithoutOptimization = new LogicEngine ( undefined , { compatible : true } )
28
- const asyncLogicWithoutOptimization = new AsyncLogicEngine ( undefined , { compatible : true } )
24
+ const engines = [ ]
29
25
30
- describe ( 'All of the compatible tests' , ( ) => {
31
- tests . forEach ( ( testCase ) => {
32
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
33
- testCase [ 1 ]
34
- ) } `, ( ) => {
35
- expect ( correction ( logic . run ( testCase [ 0 ] , testCase [ 1 ] ) ) ) . toStrictEqual ( testCase [ 2 ] )
36
- } )
37
-
38
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
39
- testCase [ 1 ]
40
- ) } (async)`, async ( ) => {
41
- expect ( correction ( await asyncLogic . run ( testCase [ 0 ] , testCase [ 1 ] ) ) ) . toStrictEqual (
42
- testCase [ 2 ]
43
- )
44
- } )
45
-
46
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
47
- testCase [ 1 ]
48
- ) } (built)`, ( ) => {
49
- const f = logic . build ( testCase [ 0 ] )
50
- expect ( correction ( f ( testCase [ 1 ] ) ) ) . toStrictEqual ( testCase [ 2 ] )
51
- } )
52
-
53
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
54
- testCase [ 1 ]
55
- ) } (asyncBuilt)`, async ( ) => {
56
- const f = await asyncLogic . build ( testCase [ 0 ] )
57
- expect ( correction ( await f ( testCase [ 1 ] ) ) ) . toStrictEqual ( testCase [ 2 ] )
58
- } )
59
-
60
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
61
- testCase [ 1 ]
62
- ) } (noOptimization)`, ( ) => {
63
- expect ( correction ( logicWithoutOptimization . run ( testCase [ 0 ] , testCase [ 1 ] ) ) ) . toStrictEqual ( testCase [ 2 ] )
64
- } )
65
-
66
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
67
- testCase [ 1 ]
68
- ) } (asyncNoOptimization)`, async ( ) => {
69
- expect ( correction ( await asyncLogicWithoutOptimization . run ( testCase [ 0 ] , testCase [ 1 ] ) ) ) . toStrictEqual (
70
- testCase [ 2 ]
71
- )
72
- } )
26
+ for ( let i = 0 ; i < 8 ; i ++ ) {
27
+ let res = 'sync'
28
+ let engine = new LogicEngine ( undefined , { compatible : true } )
29
+ // sync / async
30
+ if ( i & 1 ) {
31
+ engine = new AsyncLogicEngine ( undefined , { compatible : true } )
32
+ res = 'async'
33
+ }
34
+ // inline / disabled
35
+ if ( i & 2 ) {
36
+ engine . disableInline = true
37
+ res += ' no-inline'
38
+ }
39
+ // optimized / not optimized
40
+ if ( i & 4 ) {
41
+ engine . disableInterpretedOptimization = true
42
+ res += ' no-optimized'
43
+ }
44
+ engines . push ( [ engine , res ] )
45
+ }
73
46
74
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
47
+ describe ( 'All of the compatible tests' , ( ) => {
48
+ for ( const testCase of tests ) {
49
+ for ( const engine of engines ) {
50
+ test ( `${ engine [ 1 ] } ${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
75
51
testCase [ 1 ]
76
- ) } (builtNoOptimization)`, ( ) => {
77
- const f = logicWithoutOptimization . build ( testCase [ 0 ] )
78
- expect ( correction ( f ( testCase [ 1 ] ) ) ) . toStrictEqual ( testCase [ 2 ] )
52
+ ) } `, async ( ) => {
53
+ let result = await engine [ 0 ] . run ( testCase [ 0 ] , testCase [ 1 ] )
54
+ if ( ( result || 0 ) . toNumber ) result = Number ( result )
55
+ if ( Array . isArray ( result ) ) result = result . map ( i => ( i || 0 ) . toNumber ? Number ( i ) : i )
56
+ expect ( correction ( result ) ) . toStrictEqual ( testCase [ 2 ] )
79
57
} )
80
58
81
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
59
+ test ( `${ engine [ 1 ] } ${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
82
60
testCase [ 1 ]
83
- ) } (asyncBuiltNoOptimization)`, async ( ) => {
84
- const f = await asyncLogicWithoutOptimization . build ( testCase [ 0 ] )
85
- expect ( correction ( await f ( testCase [ 1 ] ) ) ) . toStrictEqual ( testCase [ 2 ] )
61
+ ) } (built)`, async ( ) => {
62
+ const f = await engine [ 0 ] . build ( testCase [ 0 ] )
63
+ let result = await f ( testCase [ 1 ] )
64
+ if ( ( result || 0 ) . toNumber ) result = Number ( result )
65
+ if ( Array . isArray ( result ) ) result = result . map ( i => i . toNumber ? Number ( i ) : i )
66
+ expect ( correction ( result ) ) . toStrictEqual ( testCase [ 2 ] )
86
67
} )
87
- } )
88
- } )
89
- }
90
- // eslint-disable-next-line no-labels
91
- notInline: {
92
- const logic = new LogicEngine ( undefined , { compatible : true } )
93
- const asyncLogic = new AsyncLogicEngine ( undefined , { compatible : true } )
94
- const logicWithoutOptimization = new LogicEngine ( undefined , { compatible : true } )
95
- const asyncLogicWithoutOptimization = new AsyncLogicEngine ( undefined , { compatible : true } )
96
-
97
- logicWithoutOptimization . disableInline = true
98
- logic . disableInline = true
99
- asyncLogic . disableInline = true
100
- asyncLogicWithoutOptimization . disableInline = true
101
-
102
- // using a loop to disable the inline compilation mechanism.
103
- tests . forEach ( ( testCase ) => {
104
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
105
- testCase [ 1 ]
106
- ) } `, ( ) => {
107
- expect ( correction ( logic . run ( testCase [ 0 ] , testCase [ 1 ] ) ) ) . toStrictEqual ( testCase [ 2 ] )
108
- } )
109
-
110
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
111
- testCase [ 1 ]
112
- ) } (async)`, async ( ) => {
113
- expect ( correction ( await asyncLogic . run ( testCase [ 0 ] , testCase [ 1 ] ) ) ) . toStrictEqual (
114
- testCase [ 2 ]
115
- )
116
- } )
117
-
118
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
119
- testCase [ 1 ]
120
- ) } (built)`, ( ) => {
121
- const f = logic . build ( testCase [ 0 ] )
122
- expect ( correction ( f ( testCase [ 1 ] ) ) ) . toStrictEqual ( testCase [ 2 ] )
123
- } )
124
-
125
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
126
- testCase [ 1 ]
127
- ) } (asyncBuilt)`, async ( ) => {
128
- const f = await asyncLogic . build ( testCase [ 0 ] )
129
- expect ( correction ( await f ( testCase [ 1 ] ) ) ) . toStrictEqual ( testCase [ 2 ] )
130
- } )
131
-
132
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
133
- testCase [ 1 ]
134
- ) } (noOptimization)`, ( ) => {
135
- expect ( correction ( logicWithoutOptimization . run ( testCase [ 0 ] , testCase [ 1 ] ) ) ) . toStrictEqual ( testCase [ 2 ] )
136
- } )
137
-
138
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
139
- testCase [ 1 ]
140
- ) } (asyncNoOptimization)`, async ( ) => {
141
- expect ( correction ( await asyncLogicWithoutOptimization . run ( testCase [ 0 ] , testCase [ 1 ] ) ) ) . toStrictEqual (
142
- testCase [ 2 ]
143
- )
144
- } )
145
-
146
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
147
- testCase [ 1 ]
148
- ) } (builtNoOptimization)`, ( ) => {
149
- const f = logicWithoutOptimization . build ( testCase [ 0 ] )
150
- expect ( correction ( f ( testCase [ 1 ] ) ) ) . toStrictEqual ( testCase [ 2 ] )
151
- } )
152
-
153
- test ( `${ JSON . stringify ( testCase [ 0 ] ) } ${ JSON . stringify (
154
- testCase [ 1 ]
155
- ) } (asyncBuiltNoOptimization)`, async ( ) => {
156
- const f = await asyncLogicWithoutOptimization . build ( testCase [ 0 ] )
157
- expect ( correction ( await f ( testCase [ 1 ] ) ) ) . toStrictEqual ( testCase [ 2 ] )
158
- } )
159
- } )
160
- }
68
+ }
69
+ }
70
+ } )
0 commit comments