Skip to content

Commit c02208e

Browse files
committed
tests for array and calc executors
1 parent 93058b7 commit c02208e

3 files changed

Lines changed: 638 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsonscript-test-suite",
3-
"version": "0.1.3",
3+
"version": "0.2.0",
44
"description": "Tests for JSONScript interpreters",
55
"main": "lib/index.js",
66
"scripts": {

tests/array.json

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
[
2+
{
3+
"description": "array method map",
4+
"data": [
5+
"/resource/1",
6+
"/resource/2",
7+
"/resource/3"
8+
],
9+
"tests": [
10+
{
11+
"description": "map over array using function, $args is object",
12+
"script": {
13+
"$exec": "array",
14+
"$method": "map",
15+
"$args": {
16+
"data": { "$data": "" },
17+
"iterator": {
18+
"$func": {
19+
"$exec": "router1",
20+
"$method": "get",
21+
"$args": {
22+
"path": { "$data": "/path" }
23+
}
24+
},
25+
"$args": ["path"]
26+
}
27+
}
28+
},
29+
"result": [
30+
"you requested /resource/1 from router1",
31+
"you requested /resource/2 from router1",
32+
"you requested /resource/3 from router1"
33+
]
34+
},
35+
{
36+
"description": "map over array using function, $args is array",
37+
"script": {
38+
"$exec": "array",
39+
"$method": "map",
40+
"$args": [
41+
{ "$data": "" },
42+
{
43+
"$func": {
44+
"$exec": "router1",
45+
"$method": "get",
46+
"$args": {
47+
"path": { "$data": "/path" }
48+
}
49+
},
50+
"$args": ["path"]
51+
}
52+
]
53+
},
54+
"result": [
55+
"you requested /resource/1 from router1",
56+
"you requested /resource/2 from router1",
57+
"you requested /resource/3 from router1"
58+
]
59+
}
60+
]
61+
},
62+
{
63+
"description": "array method every",
64+
"data": [
65+
"/resource/1",
66+
"/resource/2",
67+
"/resource/3"
68+
],
69+
"tests": [
70+
{
71+
"description": "test every item of array using function, $args is object",
72+
"script": {
73+
"$exec": "array",
74+
"$method": "every",
75+
"$args": {
76+
"data": { "$data": "" },
77+
"iterator": {
78+
"$func": {
79+
"$exec": "calc",
80+
"$method": "equal",
81+
"$args": [
82+
{
83+
"$exec": "router1",
84+
"$method": "get",
85+
"$args": {
86+
"path": { "$data": "/path" }
87+
}
88+
},
89+
"you requested /resource/1 from router1"
90+
]
91+
},
92+
"$args": ["path"]
93+
}
94+
}
95+
},
96+
"result": false
97+
},
98+
{
99+
"description": "test every item of array using function, $args is array",
100+
"script": {
101+
"$exec": "array",
102+
"$method": "every",
103+
"$args": [
104+
{ "$data": "" },
105+
{
106+
"$func": {
107+
"$exec": "calc",
108+
"$method": "equal",
109+
"$args": [
110+
{
111+
"$exec": "router1",
112+
"$method": "get",
113+
"$args": {
114+
"path": { "$data": "/path" }
115+
}
116+
},
117+
"you requested /resource/1 from router1"
118+
]
119+
},
120+
"$args": ["path"]
121+
}
122+
]
123+
},
124+
"result": false
125+
}
126+
]
127+
},
128+
{
129+
"description": "array method some",
130+
"data": [
131+
"/resource/1",
132+
"/resource/2",
133+
"/resource/3"
134+
],
135+
"tests": [
136+
{
137+
"description": "test that some item passes using function, $args is object",
138+
"script": {
139+
"$exec": "array",
140+
"$method": "some",
141+
"$args": {
142+
"data": { "$data": "" },
143+
"iterator": {
144+
"$func": {
145+
"$exec": "calc",
146+
"$method": "equal",
147+
"$args": [
148+
{
149+
"$exec": "router1",
150+
"$method": "get",
151+
"$args": {
152+
"path": { "$data": "/path" }
153+
}
154+
},
155+
"you requested /resource/1 from router1"
156+
]
157+
},
158+
"$args": ["path"]
159+
}
160+
}
161+
},
162+
"result": true
163+
},
164+
{
165+
"description": "test that some item passes using function, $args is array",
166+
"script": {
167+
"$exec": "array",
168+
"$method": "some",
169+
"$args": [
170+
{ "$data": "" },
171+
{
172+
"$func": {
173+
"$exec": "calc",
174+
"$method": "equal",
175+
"$args": [
176+
{
177+
"$exec": "router1",
178+
"$method": "get",
179+
"$args": {
180+
"path": { "$data": "/path" }
181+
}
182+
},
183+
"you requested /resource/1 from router1"
184+
]
185+
},
186+
"$args": ["path"]
187+
}
188+
]
189+
},
190+
"result": true
191+
}
192+
]
193+
},
194+
{
195+
"description": "array method filter",
196+
"data": [
197+
"/resource/1",
198+
"/resource/2",
199+
"/resource/3"
200+
],
201+
"tests": [
202+
{
203+
"description": "filter items using function, $args is object",
204+
"script": {
205+
"$exec": "array",
206+
"$method": "filter",
207+
"$args": {
208+
"data": { "$data": "" },
209+
"iterator": {
210+
"$func": {
211+
"$exec": "calc",
212+
"$method": "equal",
213+
"$args": [
214+
{
215+
"$exec": "router1",
216+
"$method": "get",
217+
"$args": {
218+
"path": { "$data": "/path" }
219+
}
220+
},
221+
"you requested /resource/1 from router1"
222+
]
223+
},
224+
"$args": ["path"]
225+
}
226+
}
227+
},
228+
"result": [ "/resource/1" ]
229+
},
230+
{
231+
"description": "filter items using function, $args is array",
232+
"script": {
233+
"$exec": "array",
234+
"$method": "filter",
235+
"$args": [
236+
{ "$data": "" },
237+
{
238+
"$func": {
239+
"$exec": "calc",
240+
"$method": "equal",
241+
"$args": [
242+
{
243+
"$exec": "router1",
244+
"$method": "get",
245+
"$args": {
246+
"path": { "$data": "/path" }
247+
}
248+
},
249+
"you requested /resource/1 from router1"
250+
]
251+
},
252+
"$args": ["path"]
253+
}
254+
]
255+
},
256+
"result": [ "/resource/1" ]
257+
}
258+
]
259+
}
260+
]

0 commit comments

Comments
 (0)