1 |
schoenebeck |
3551 |
/* |
2 |
|
|
* Copyright (c) 2019 Christian Schoenebeck |
3 |
|
|
* |
4 |
|
|
* http://www.linuxsampler.org |
5 |
|
|
* |
6 |
|
|
* This file is part of LinuxSampler and released under the same terms. |
7 |
|
|
* See README file for details. |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
// This file contains automated test cases against the NKSP real-time |
11 |
|
|
// instrument script engine. |
12 |
|
|
|
13 |
|
|
#include "../../common/global.h" |
14 |
|
|
#include "../../common/optional.h" |
15 |
|
|
#include "../ScriptVM.h" |
16 |
|
|
#include "../common.h" |
17 |
|
|
#include <sstream> |
18 |
|
|
#include <stdlib.h> |
19 |
|
|
#include <time.h> |
20 |
|
|
#include <assert.h> |
21 |
|
|
#include <functional> |
22 |
|
|
|
23 |
|
|
#ifndef TEST_ASSERT |
24 |
|
|
# define TEST_ASSERT assert |
25 |
|
|
#endif |
26 |
|
|
|
27 |
|
|
using namespace LinuxSampler; |
28 |
|
|
using namespace std; |
29 |
|
|
|
30 |
|
|
struct RunScriptOpt { |
31 |
|
|
String code; |
32 |
|
|
bool expectParseError; |
33 |
|
|
bool expectRuntimeError; |
34 |
|
|
bool expectNoExitResult; |
35 |
|
|
bool prohibitExitFunctionArguments; |
36 |
|
|
optional<int> expectIntExitResult; |
37 |
|
|
optional<bool> expectBoolExitResult; |
38 |
|
|
optional<String> expectStringExitResult; |
39 |
|
|
}; |
40 |
|
|
|
41 |
|
|
static void runScript(const RunScriptOpt& opt) { |
42 |
|
|
ScriptVM vm; |
43 |
|
|
vm.setAutoSuspendEnabled(false); |
44 |
|
|
if (!opt.prohibitExitFunctionArguments) |
45 |
|
|
vm.setExitResultEnabled(true); |
46 |
|
|
unique_ptr<VMParserContext> parserCtx( |
47 |
|
|
vm.loadScript(opt.code) |
48 |
|
|
); |
49 |
|
|
vector<ParserIssue> errors = parserCtx->errors(); |
50 |
|
|
if (opt.expectParseError) { |
51 |
|
|
TEST_ASSERT(!errors.empty()); |
52 |
|
|
return; |
53 |
|
|
} else { |
54 |
|
|
for (ParserIssue& err : errors) { |
55 |
|
|
err.dump(); |
56 |
|
|
} |
57 |
|
|
TEST_ASSERT(errors.empty()); |
58 |
|
|
} |
59 |
|
|
TEST_ASSERT(parserCtx->eventHandler(0)); |
60 |
|
|
unique_ptr<VMExecContext> execCtx( |
61 |
|
|
vm.createExecContext(&*parserCtx) |
62 |
|
|
); |
63 |
|
|
for (int i = 0; parserCtx->eventHandler(i); ++i) { |
64 |
|
|
VMEventHandler* handler = parserCtx->eventHandler(i); |
65 |
|
|
VMExecStatus_t result = vm.exec(&*parserCtx, &*execCtx, handler); |
66 |
|
|
if (opt.expectRuntimeError) { |
67 |
|
|
TEST_ASSERT(result & VM_EXEC_ERROR); |
68 |
|
|
} else { |
69 |
|
|
TEST_ASSERT(!(result & VM_EXEC_ERROR)); |
70 |
|
|
} |
71 |
|
|
if (opt.expectNoExitResult) { |
72 |
|
|
VMExpr* resExpr = execCtx->exitResult(); |
73 |
|
|
TEST_ASSERT(!resExpr); |
74 |
|
|
} |
75 |
|
|
if (opt.expectIntExitResult) { |
76 |
|
|
VMExpr* resExpr = execCtx->exitResult(); |
77 |
|
|
TEST_ASSERT(resExpr); |
78 |
|
|
TEST_ASSERT(resExpr->exprType() == INT_EXPR); |
79 |
|
|
TEST_ASSERT(resExpr->asInt()->evalInt() == *opt.expectIntExitResult); |
80 |
|
|
} |
81 |
|
|
if (opt.expectBoolExitResult) { |
82 |
|
|
VMExpr* resExpr = execCtx->exitResult(); |
83 |
|
|
TEST_ASSERT(resExpr); |
84 |
|
|
TEST_ASSERT(resExpr->exprType() == INT_EXPR); |
85 |
|
|
TEST_ASSERT(bool(resExpr->asInt()->evalInt()) == *opt.expectBoolExitResult); |
86 |
|
|
} |
87 |
|
|
if (opt.expectStringExitResult) { |
88 |
|
|
VMExpr* resExpr = execCtx->exitResult(); |
89 |
|
|
TEST_ASSERT(resExpr); |
90 |
|
|
TEST_ASSERT(resExpr->exprType() == STRING_EXPR); |
91 |
|
|
TEST_ASSERT(resExpr->asString()->evalStr() == *opt.expectStringExitResult); |
92 |
|
|
} |
93 |
|
|
} |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
static void testBuiltInExitFunction() { |
97 |
|
|
#if !SILENT_TEST |
98 |
|
|
std::cout << "UNIT TEST: built-in exit() function\n"; |
99 |
|
|
#endif |
100 |
|
|
|
101 |
|
|
runScript({ |
102 |
|
|
.code = R"NKSP_CODE( |
103 |
|
|
on init |
104 |
|
|
end on |
105 |
|
|
)NKSP_CODE", |
106 |
|
|
.expectNoExitResult = true |
107 |
|
|
}); |
108 |
|
|
|
109 |
|
|
runScript({ |
110 |
|
|
.code = R"NKSP_CODE( |
111 |
|
|
on init |
112 |
|
|
exit |
113 |
|
|
end on |
114 |
|
|
)NKSP_CODE", |
115 |
|
|
.expectNoExitResult = true |
116 |
|
|
}); |
117 |
|
|
|
118 |
|
|
runScript({ |
119 |
|
|
.code = R"NKSP_CODE( |
120 |
|
|
on init |
121 |
|
|
exit() |
122 |
|
|
end on |
123 |
|
|
)NKSP_CODE", |
124 |
|
|
.expectNoExitResult = true |
125 |
|
|
}); |
126 |
|
|
|
127 |
|
|
runScript({ |
128 |
|
|
.code = R"NKSP_CODE( |
129 |
|
|
on init |
130 |
|
|
exit(42) |
131 |
|
|
end on |
132 |
|
|
)NKSP_CODE", |
133 |
|
|
.expectIntExitResult = 42 |
134 |
|
|
}); |
135 |
|
|
|
136 |
|
|
runScript({ |
137 |
|
|
.code = R"NKSP_CODE( |
138 |
|
|
on init |
139 |
|
|
declare $foo := 1 |
140 |
|
|
if ($foo) |
141 |
|
|
exit(21) |
142 |
|
|
end if |
143 |
|
|
end on |
144 |
|
|
)NKSP_CODE", |
145 |
|
|
.expectIntExitResult = 21 |
146 |
|
|
}); |
147 |
|
|
|
148 |
|
|
runScript({ |
149 |
|
|
.code = R"NKSP_CODE( |
150 |
|
|
on init |
151 |
|
|
declare $foo := 0 |
152 |
|
|
if ($foo) |
153 |
|
|
exit(21) |
154 |
|
|
end if |
155 |
|
|
exit(99) |
156 |
|
|
end on |
157 |
|
|
)NKSP_CODE", |
158 |
|
|
.expectIntExitResult = 99 |
159 |
|
|
}); |
160 |
|
|
|
161 |
|
|
runScript({ |
162 |
|
|
.code = R"NKSP_CODE( |
163 |
|
|
on init |
164 |
|
|
exit("fourtytwo!") |
165 |
|
|
end on |
166 |
|
|
)NKSP_CODE", |
167 |
|
|
.expectStringExitResult = "fourtytwo!" |
168 |
|
|
}); |
169 |
|
|
|
170 |
|
|
// in production environment we prohibit the built-in exit() function to |
171 |
|
|
// accept any arguments |
172 |
|
|
runScript({ |
173 |
|
|
.code = R"NKSP_CODE( |
174 |
|
|
on init |
175 |
|
|
exit(42) |
176 |
|
|
end on |
177 |
|
|
)NKSP_CODE", |
178 |
|
|
.expectParseError = true, // see comment above why |
179 |
|
|
.prohibitExitFunctionArguments = true // simulate production environment |
180 |
|
|
}); |
181 |
|
|
|
182 |
|
|
#if !SILENT_TEST |
183 |
|
|
std::cout << std::endl; |
184 |
|
|
#endif |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
static void testStringConcatOperator() { |
188 |
|
|
#if !SILENT_TEST |
189 |
|
|
std::cout << "UNIT TEST: string concatenation (&) operator\n"; |
190 |
|
|
#endif |
191 |
|
|
|
192 |
|
|
runScript({ |
193 |
|
|
.code = R"NKSP_CODE( |
194 |
|
|
on init |
195 |
|
|
declare @s := "foo" & " bar" |
196 |
|
|
exit(@s) |
197 |
|
|
end on |
198 |
|
|
)NKSP_CODE", |
199 |
|
|
.expectStringExitResult = "foo bar" |
200 |
|
|
}); |
201 |
|
|
|
202 |
|
|
runScript({ |
203 |
|
|
.code = R"NKSP_CODE( |
204 |
|
|
on init |
205 |
|
|
declare @s := "foo" & " bar" & " " & 123 |
206 |
|
|
exit(@s) |
207 |
|
|
end on |
208 |
|
|
)NKSP_CODE", |
209 |
|
|
.expectStringExitResult = "foo bar 123" |
210 |
|
|
}); |
211 |
|
|
|
212 |
|
|
runScript({ |
213 |
|
|
.code = R"NKSP_CODE( |
214 |
|
|
on init |
215 |
|
|
declare $i := 123 |
216 |
|
|
declare @s := "foo" & " bar" & " " & $i |
217 |
|
|
exit(@s) |
218 |
|
|
end on |
219 |
|
|
)NKSP_CODE", |
220 |
|
|
.expectStringExitResult = "foo bar 123" |
221 |
|
|
}); |
222 |
|
|
|
223 |
|
|
#if !SILENT_TEST |
224 |
|
|
std::cout << std::endl; |
225 |
|
|
#endif |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
static void testPlusOperator() { |
229 |
|
|
#if !SILENT_TEST |
230 |
|
|
std::cout << "UNIT TEST: plus (+) operator\n"; |
231 |
|
|
#endif |
232 |
|
|
|
233 |
|
|
runScript({ |
234 |
|
|
.code = R"NKSP_CODE( |
235 |
|
|
on init |
236 |
|
|
exit(4 + 3) |
237 |
|
|
end on |
238 |
|
|
)NKSP_CODE", |
239 |
|
|
.expectIntExitResult = 7 |
240 |
|
|
}); |
241 |
|
|
|
242 |
|
|
runScript({ |
243 |
|
|
.code = R"NKSP_CODE( |
244 |
|
|
on init |
245 |
|
|
exit(42 + 145) |
246 |
|
|
end on |
247 |
|
|
)NKSP_CODE", |
248 |
|
|
.expectIntExitResult = 187 |
249 |
|
|
}); |
250 |
|
|
|
251 |
|
|
runScript({ |
252 |
|
|
.code = R"NKSP_CODE( |
253 |
|
|
on init |
254 |
|
|
exit(-4 + 2) |
255 |
|
|
end on |
256 |
|
|
)NKSP_CODE", |
257 |
|
|
.expectIntExitResult = -2 |
258 |
|
|
}); |
259 |
|
|
|
260 |
|
|
#if !SILENT_TEST |
261 |
|
|
std::cout << std::endl; |
262 |
|
|
#endif |
263 |
|
|
} |
264 |
|
|
|
265 |
|
|
static void testMinusOperator() { |
266 |
|
|
#if !SILENT_TEST |
267 |
|
|
std::cout << "UNIT TEST: minus (-) operator\n"; |
268 |
|
|
#endif |
269 |
|
|
|
270 |
|
|
runScript({ |
271 |
|
|
.code = R"NKSP_CODE( |
272 |
|
|
on init |
273 |
|
|
exit(4 - 3) |
274 |
|
|
end on |
275 |
|
|
)NKSP_CODE", |
276 |
|
|
.expectIntExitResult = 1 |
277 |
|
|
}); |
278 |
|
|
|
279 |
|
|
runScript({ |
280 |
|
|
.code = R"NKSP_CODE( |
281 |
|
|
on init |
282 |
|
|
exit(139 - 74) |
283 |
|
|
end on |
284 |
|
|
)NKSP_CODE", |
285 |
|
|
.expectIntExitResult = 65 |
286 |
|
|
}); |
287 |
|
|
|
288 |
|
|
runScript({ |
289 |
|
|
.code = R"NKSP_CODE( |
290 |
|
|
on init |
291 |
|
|
exit(3 - 9) |
292 |
|
|
end on |
293 |
|
|
)NKSP_CODE", |
294 |
|
|
.expectIntExitResult = -6 |
295 |
|
|
}); |
296 |
|
|
|
297 |
|
|
runScript({ |
298 |
|
|
.code = R"NKSP_CODE( |
299 |
|
|
on init |
300 |
|
|
exit(-3 - 18) |
301 |
|
|
end on |
302 |
|
|
)NKSP_CODE", |
303 |
|
|
.expectIntExitResult = -21 |
304 |
|
|
}); |
305 |
|
|
|
306 |
|
|
#if !SILENT_TEST |
307 |
|
|
std::cout << std::endl; |
308 |
|
|
#endif |
309 |
|
|
} |
310 |
|
|
|
311 |
|
|
static void testModuloOperator() { |
312 |
|
|
#if !SILENT_TEST |
313 |
|
|
std::cout << "UNIT TEST: modulo (mod) operator\n"; |
314 |
|
|
#endif |
315 |
|
|
|
316 |
|
|
runScript({ |
317 |
|
|
.code = R"NKSP_CODE( |
318 |
|
|
on init |
319 |
|
|
exit(10 mod 8) |
320 |
|
|
end on |
321 |
|
|
)NKSP_CODE", |
322 |
|
|
.expectIntExitResult = 2 |
323 |
|
|
}); |
324 |
|
|
|
325 |
|
|
#if !SILENT_TEST |
326 |
|
|
std::cout << std::endl; |
327 |
|
|
#endif |
328 |
|
|
} |
329 |
|
|
|
330 |
|
|
static void testMultiplyOperator() { |
331 |
|
|
#if !SILENT_TEST |
332 |
|
|
std::cout << "UNIT TEST: multiply (*) operator\n"; |
333 |
|
|
#endif |
334 |
|
|
|
335 |
|
|
runScript({ |
336 |
|
|
.code = R"NKSP_CODE( |
337 |
|
|
on init |
338 |
|
|
exit(10 * 8) |
339 |
|
|
end on |
340 |
|
|
)NKSP_CODE", |
341 |
|
|
.expectIntExitResult = 80 |
342 |
|
|
}); |
343 |
|
|
|
344 |
|
|
runScript({ |
345 |
|
|
.code = R"NKSP_CODE( |
346 |
|
|
on init |
347 |
|
|
exit(-3 * -4) |
348 |
|
|
end on |
349 |
|
|
)NKSP_CODE", |
350 |
|
|
.expectIntExitResult = 12 |
351 |
|
|
}); |
352 |
|
|
|
353 |
|
|
runScript({ |
354 |
|
|
.code = R"NKSP_CODE( |
355 |
|
|
on init |
356 |
|
|
exit(-52 * 63) |
357 |
|
|
end on |
358 |
|
|
)NKSP_CODE", |
359 |
|
|
.expectIntExitResult = -3276 |
360 |
|
|
}); |
361 |
|
|
|
362 |
|
|
runScript({ |
363 |
|
|
.code = R"NKSP_CODE( |
364 |
|
|
on init |
365 |
|
|
exit(123 * -59) |
366 |
|
|
end on |
367 |
|
|
)NKSP_CODE", |
368 |
|
|
.expectIntExitResult = -7257 |
369 |
|
|
}); |
370 |
|
|
|
371 |
|
|
#if !SILENT_TEST |
372 |
|
|
std::cout << std::endl; |
373 |
|
|
#endif |
374 |
|
|
} |
375 |
|
|
|
376 |
|
|
static void testDivideOperator() { |
377 |
|
|
#if !SILENT_TEST |
378 |
|
|
std::cout << "UNIT TEST: divide (/) operator\n"; |
379 |
|
|
#endif |
380 |
|
|
|
381 |
|
|
runScript({ |
382 |
|
|
.code = R"NKSP_CODE( |
383 |
|
|
on init |
384 |
|
|
exit(9 / 3) |
385 |
|
|
end on |
386 |
|
|
)NKSP_CODE", |
387 |
|
|
.expectIntExitResult = 3 |
388 |
|
|
}); |
389 |
|
|
|
390 |
|
|
runScript({ |
391 |
|
|
.code = R"NKSP_CODE( |
392 |
|
|
on init |
393 |
|
|
exit(-27 / 3) |
394 |
|
|
end on |
395 |
|
|
)NKSP_CODE", |
396 |
|
|
.expectIntExitResult = -9 |
397 |
|
|
}); |
398 |
|
|
|
399 |
|
|
runScript({ |
400 |
|
|
.code = R"NKSP_CODE( |
401 |
|
|
on init |
402 |
|
|
exit(35 / -5) |
403 |
|
|
end on |
404 |
|
|
)NKSP_CODE", |
405 |
|
|
.expectIntExitResult = -7 |
406 |
|
|
}); |
407 |
|
|
|
408 |
|
|
runScript({ |
409 |
|
|
.code = R"NKSP_CODE( |
410 |
|
|
on init |
411 |
|
|
exit(39 / -5) |
412 |
|
|
end on |
413 |
|
|
)NKSP_CODE", |
414 |
|
|
.expectIntExitResult = -7 |
415 |
|
|
}); |
416 |
|
|
|
417 |
|
|
#if !SILENT_TEST |
418 |
|
|
std::cout << std::endl; |
419 |
|
|
#endif |
420 |
|
|
} |
421 |
|
|
|
422 |
|
|
static void testSmallerThanOperator() { |
423 |
|
|
#if !SILENT_TEST |
424 |
|
|
std::cout << "UNIT TEST: smaller than (<) operator\n"; |
425 |
|
|
#endif |
426 |
|
|
|
427 |
|
|
runScript({ |
428 |
|
|
.code = R"NKSP_CODE( |
429 |
|
|
on init |
430 |
|
|
exit(3 < 4) |
431 |
|
|
end on |
432 |
|
|
)NKSP_CODE", |
433 |
|
|
.expectBoolExitResult = true |
434 |
|
|
}); |
435 |
|
|
|
436 |
|
|
runScript({ |
437 |
|
|
.code = R"NKSP_CODE( |
438 |
|
|
on init |
439 |
|
|
exit(4 < 3) |
440 |
|
|
end on |
441 |
|
|
)NKSP_CODE", |
442 |
|
|
.expectBoolExitResult = false |
443 |
|
|
}); |
444 |
|
|
|
445 |
|
|
runScript({ |
446 |
|
|
.code = R"NKSP_CODE( |
447 |
|
|
on init |
448 |
|
|
exit(-4 < 3) |
449 |
|
|
end on |
450 |
|
|
)NKSP_CODE", |
451 |
|
|
.expectBoolExitResult = true |
452 |
|
|
}); |
453 |
|
|
|
454 |
|
|
runScript({ |
455 |
|
|
.code = R"NKSP_CODE( |
456 |
|
|
on init |
457 |
|
|
exit(3 < -4) |
458 |
|
|
end on |
459 |
|
|
)NKSP_CODE", |
460 |
|
|
.expectBoolExitResult = false |
461 |
|
|
}); |
462 |
|
|
|
463 |
|
|
runScript({ |
464 |
|
|
.code = R"NKSP_CODE( |
465 |
|
|
on init |
466 |
|
|
exit(123 < -45) |
467 |
|
|
end on |
468 |
|
|
)NKSP_CODE", |
469 |
|
|
.expectBoolExitResult = false |
470 |
|
|
}); |
471 |
|
|
|
472 |
|
|
runScript({ |
473 |
|
|
.code = R"NKSP_CODE( |
474 |
|
|
on init |
475 |
|
|
exit(-45 < 123) |
476 |
|
|
end on |
477 |
|
|
)NKSP_CODE", |
478 |
|
|
.expectBoolExitResult = true |
479 |
|
|
}); |
480 |
|
|
|
481 |
|
|
#if !SILENT_TEST |
482 |
|
|
std::cout << std::endl; |
483 |
|
|
#endif |
484 |
|
|
} |
485 |
|
|
|
486 |
|
|
static void testGreaterThanOperator() { |
487 |
|
|
#if !SILENT_TEST |
488 |
|
|
std::cout << "UNIT TEST: greater than (>) operator\n"; |
489 |
|
|
#endif |
490 |
|
|
|
491 |
|
|
runScript({ |
492 |
|
|
.code = R"NKSP_CODE( |
493 |
|
|
on init |
494 |
|
|
exit(3 > 4) |
495 |
|
|
end on |
496 |
|
|
)NKSP_CODE", |
497 |
|
|
.expectBoolExitResult = false |
498 |
|
|
}); |
499 |
|
|
|
500 |
|
|
runScript({ |
501 |
|
|
.code = R"NKSP_CODE( |
502 |
|
|
on init |
503 |
|
|
exit(4 > 3) |
504 |
|
|
end on |
505 |
|
|
)NKSP_CODE", |
506 |
|
|
.expectBoolExitResult = true |
507 |
|
|
}); |
508 |
|
|
|
509 |
|
|
runScript({ |
510 |
|
|
.code = R"NKSP_CODE( |
511 |
|
|
on init |
512 |
|
|
exit(-4 > 3) |
513 |
|
|
end on |
514 |
|
|
)NKSP_CODE", |
515 |
|
|
.expectBoolExitResult = false |
516 |
|
|
}); |
517 |
|
|
|
518 |
|
|
runScript({ |
519 |
|
|
.code = R"NKSP_CODE( |
520 |
|
|
on init |
521 |
|
|
exit(3 > -4) |
522 |
|
|
end on |
523 |
|
|
)NKSP_CODE", |
524 |
|
|
.expectBoolExitResult = true |
525 |
|
|
}); |
526 |
|
|
|
527 |
|
|
runScript({ |
528 |
|
|
.code = R"NKSP_CODE( |
529 |
|
|
on init |
530 |
|
|
exit(123 > -45) |
531 |
|
|
end on |
532 |
|
|
)NKSP_CODE", |
533 |
|
|
.expectBoolExitResult = true |
534 |
|
|
}); |
535 |
|
|
|
536 |
|
|
runScript({ |
537 |
|
|
.code = R"NKSP_CODE( |
538 |
|
|
on init |
539 |
|
|
exit(-45 > 123) |
540 |
|
|
end on |
541 |
|
|
)NKSP_CODE", |
542 |
|
|
.expectBoolExitResult = false |
543 |
|
|
}); |
544 |
|
|
|
545 |
|
|
#if !SILENT_TEST |
546 |
|
|
std::cout << std::endl; |
547 |
|
|
#endif |
548 |
|
|
} |
549 |
|
|
|
550 |
|
|
static void testSmallerOrEqualOperator() { |
551 |
|
|
#if !SILENT_TEST |
552 |
|
|
std::cout << "UNIT TEST: smaller-or-equal (<=) operator\n"; |
553 |
|
|
#endif |
554 |
|
|
|
555 |
|
|
runScript({ |
556 |
|
|
.code = R"NKSP_CODE( |
557 |
|
|
on init |
558 |
|
|
exit(3 <= 3) |
559 |
|
|
end on |
560 |
|
|
)NKSP_CODE", |
561 |
|
|
.expectBoolExitResult = true |
562 |
|
|
}); |
563 |
|
|
|
564 |
|
|
runScript({ |
565 |
|
|
.code = R"NKSP_CODE( |
566 |
|
|
on init |
567 |
|
|
exit(4 <= 4) |
568 |
|
|
end on |
569 |
|
|
)NKSP_CODE", |
570 |
|
|
.expectBoolExitResult = true |
571 |
|
|
}); |
572 |
|
|
|
573 |
|
|
runScript({ |
574 |
|
|
.code = R"NKSP_CODE( |
575 |
|
|
on init |
576 |
|
|
exit(-23 <= -23) |
577 |
|
|
end on |
578 |
|
|
)NKSP_CODE", |
579 |
|
|
.expectBoolExitResult = true |
580 |
|
|
}); |
581 |
|
|
|
582 |
|
|
runScript({ |
583 |
|
|
.code = R"NKSP_CODE( |
584 |
|
|
on init |
585 |
|
|
exit(23 <= -23) |
586 |
|
|
end on |
587 |
|
|
)NKSP_CODE", |
588 |
|
|
.expectBoolExitResult = false |
589 |
|
|
}); |
590 |
|
|
|
591 |
|
|
runScript({ |
592 |
|
|
.code = R"NKSP_CODE( |
593 |
|
|
on init |
594 |
|
|
exit(3 <= 4) |
595 |
|
|
end on |
596 |
|
|
)NKSP_CODE", |
597 |
|
|
.expectBoolExitResult = true |
598 |
|
|
}); |
599 |
|
|
|
600 |
|
|
runScript({ |
601 |
|
|
.code = R"NKSP_CODE( |
602 |
|
|
on init |
603 |
|
|
exit(4 <= 3) |
604 |
|
|
end on |
605 |
|
|
)NKSP_CODE", |
606 |
|
|
.expectBoolExitResult = false |
607 |
|
|
}); |
608 |
|
|
|
609 |
|
|
runScript({ |
610 |
|
|
.code = R"NKSP_CODE( |
611 |
|
|
on init |
612 |
|
|
exit(-4 <= 3) |
613 |
|
|
end on |
614 |
|
|
)NKSP_CODE", |
615 |
|
|
.expectBoolExitResult = true |
616 |
|
|
}); |
617 |
|
|
|
618 |
|
|
runScript({ |
619 |
|
|
.code = R"NKSP_CODE( |
620 |
|
|
on init |
621 |
|
|
exit(3 <= -4) |
622 |
|
|
end on |
623 |
|
|
)NKSP_CODE", |
624 |
|
|
.expectBoolExitResult = false |
625 |
|
|
}); |
626 |
|
|
|
627 |
|
|
runScript({ |
628 |
|
|
.code = R"NKSP_CODE( |
629 |
|
|
on init |
630 |
|
|
exit(123 <= -45) |
631 |
|
|
end on |
632 |
|
|
)NKSP_CODE", |
633 |
|
|
.expectBoolExitResult = false |
634 |
|
|
}); |
635 |
|
|
|
636 |
|
|
runScript({ |
637 |
|
|
.code = R"NKSP_CODE( |
638 |
|
|
on init |
639 |
|
|
exit(-45 <= 123) |
640 |
|
|
end on |
641 |
|
|
)NKSP_CODE", |
642 |
|
|
.expectBoolExitResult = true |
643 |
|
|
}); |
644 |
|
|
|
645 |
|
|
#if !SILENT_TEST |
646 |
|
|
std::cout << std::endl; |
647 |
|
|
#endif |
648 |
|
|
} |
649 |
|
|
|
650 |
|
|
static void testGreaterOrEqualOperator() { |
651 |
|
|
#if !SILENT_TEST |
652 |
|
|
std::cout << "UNIT TEST: greater-or-equal (>=) operator\n"; |
653 |
|
|
#endif |
654 |
|
|
|
655 |
|
|
runScript({ |
656 |
|
|
.code = R"NKSP_CODE( |
657 |
|
|
on init |
658 |
|
|
exit(3 >= 3) |
659 |
|
|
end on |
660 |
|
|
)NKSP_CODE", |
661 |
|
|
.expectBoolExitResult = true |
662 |
|
|
}); |
663 |
|
|
|
664 |
|
|
runScript({ |
665 |
|
|
.code = R"NKSP_CODE( |
666 |
|
|
on init |
667 |
|
|
exit(4 >= 4) |
668 |
|
|
end on |
669 |
|
|
)NKSP_CODE", |
670 |
|
|
.expectBoolExitResult = true |
671 |
|
|
}); |
672 |
|
|
|
673 |
|
|
runScript({ |
674 |
|
|
.code = R"NKSP_CODE( |
675 |
|
|
on init |
676 |
|
|
exit(-23 >= -23) |
677 |
|
|
end on |
678 |
|
|
)NKSP_CODE", |
679 |
|
|
.expectBoolExitResult = true |
680 |
|
|
}); |
681 |
|
|
|
682 |
|
|
runScript({ |
683 |
|
|
.code = R"NKSP_CODE( |
684 |
|
|
on init |
685 |
|
|
exit(23 >= -23) |
686 |
|
|
end on |
687 |
|
|
)NKSP_CODE", |
688 |
|
|
.expectBoolExitResult = true |
689 |
|
|
}); |
690 |
|
|
|
691 |
|
|
runScript({ |
692 |
|
|
.code = R"NKSP_CODE( |
693 |
|
|
on init |
694 |
|
|
exit(3 >= 4) |
695 |
|
|
end on |
696 |
|
|
)NKSP_CODE", |
697 |
|
|
.expectBoolExitResult = false |
698 |
|
|
}); |
699 |
|
|
|
700 |
|
|
runScript({ |
701 |
|
|
.code = R"NKSP_CODE( |
702 |
|
|
on init |
703 |
|
|
exit(4 >= 3) |
704 |
|
|
end on |
705 |
|
|
)NKSP_CODE", |
706 |
|
|
.expectBoolExitResult = true |
707 |
|
|
}); |
708 |
|
|
|
709 |
|
|
runScript({ |
710 |
|
|
.code = R"NKSP_CODE( |
711 |
|
|
on init |
712 |
|
|
exit(-4 >= 3) |
713 |
|
|
end on |
714 |
|
|
)NKSP_CODE", |
715 |
|
|
.expectBoolExitResult = false |
716 |
|
|
}); |
717 |
|
|
|
718 |
|
|
runScript({ |
719 |
|
|
.code = R"NKSP_CODE( |
720 |
|
|
on init |
721 |
|
|
exit(3 >= -4) |
722 |
|
|
end on |
723 |
|
|
)NKSP_CODE", |
724 |
|
|
.expectBoolExitResult = true |
725 |
|
|
}); |
726 |
|
|
|
727 |
|
|
runScript({ |
728 |
|
|
.code = R"NKSP_CODE( |
729 |
|
|
on init |
730 |
|
|
exit(123 >= -45) |
731 |
|
|
end on |
732 |
|
|
)NKSP_CODE", |
733 |
|
|
.expectBoolExitResult = true |
734 |
|
|
}); |
735 |
|
|
|
736 |
|
|
runScript({ |
737 |
|
|
.code = R"NKSP_CODE( |
738 |
|
|
on init |
739 |
|
|
exit(-45 >= 123) |
740 |
|
|
end on |
741 |
|
|
)NKSP_CODE", |
742 |
|
|
.expectBoolExitResult = false |
743 |
|
|
}); |
744 |
|
|
|
745 |
|
|
#if !SILENT_TEST |
746 |
|
|
std::cout << std::endl; |
747 |
|
|
#endif |
748 |
|
|
} |
749 |
|
|
|
750 |
|
|
static void testEqualOperator() { |
751 |
|
|
#if !SILENT_TEST |
752 |
|
|
std::cout << "UNIT TEST: equal (=) operator\n"; |
753 |
|
|
#endif |
754 |
|
|
|
755 |
|
|
runScript({ |
756 |
|
|
.code = R"NKSP_CODE( |
757 |
|
|
on init |
758 |
|
|
exit(3 = 3) |
759 |
|
|
end on |
760 |
|
|
)NKSP_CODE", |
761 |
|
|
.expectBoolExitResult = true |
762 |
|
|
}); |
763 |
|
|
|
764 |
|
|
runScript({ |
765 |
|
|
.code = R"NKSP_CODE( |
766 |
|
|
on init |
767 |
|
|
exit(4 = 4) |
768 |
|
|
end on |
769 |
|
|
)NKSP_CODE", |
770 |
|
|
.expectBoolExitResult = true |
771 |
|
|
}); |
772 |
|
|
|
773 |
|
|
runScript({ |
774 |
|
|
.code = R"NKSP_CODE( |
775 |
|
|
on init |
776 |
|
|
exit(3 = 4) |
777 |
|
|
end on |
778 |
|
|
)NKSP_CODE", |
779 |
|
|
.expectBoolExitResult = false |
780 |
|
|
}); |
781 |
|
|
|
782 |
|
|
runScript({ |
783 |
|
|
.code = R"NKSP_CODE( |
784 |
|
|
on init |
785 |
|
|
exit(23 = -23) |
786 |
|
|
end on |
787 |
|
|
)NKSP_CODE", |
788 |
|
|
.expectBoolExitResult = false |
789 |
|
|
}); |
790 |
|
|
|
791 |
|
|
#if !SILENT_TEST |
792 |
|
|
std::cout << std::endl; |
793 |
|
|
#endif |
794 |
|
|
} |
795 |
|
|
|
796 |
|
|
static void testUnequalOperator() { |
797 |
|
|
#if !SILENT_TEST |
798 |
|
|
std::cout << "UNIT TEST: unequal (#) operator\n"; |
799 |
|
|
#endif |
800 |
|
|
|
801 |
|
|
runScript({ |
802 |
|
|
.code = R"NKSP_CODE( |
803 |
|
|
on init |
804 |
|
|
exit(3 # 3) |
805 |
|
|
end on |
806 |
|
|
)NKSP_CODE", |
807 |
|
|
.expectBoolExitResult = false |
808 |
|
|
}); |
809 |
|
|
|
810 |
|
|
runScript({ |
811 |
|
|
.code = R"NKSP_CODE( |
812 |
|
|
on init |
813 |
|
|
exit(4 # 4) |
814 |
|
|
end on |
815 |
|
|
)NKSP_CODE", |
816 |
|
|
.expectBoolExitResult = false |
817 |
|
|
}); |
818 |
|
|
|
819 |
|
|
runScript({ |
820 |
|
|
.code = R"NKSP_CODE( |
821 |
|
|
on init |
822 |
|
|
exit(3 # 4) |
823 |
|
|
end on |
824 |
|
|
)NKSP_CODE", |
825 |
|
|
.expectBoolExitResult = true |
826 |
|
|
}); |
827 |
|
|
|
828 |
|
|
runScript({ |
829 |
|
|
.code = R"NKSP_CODE( |
830 |
|
|
on init |
831 |
|
|
exit(23 # -23) |
832 |
|
|
end on |
833 |
|
|
)NKSP_CODE", |
834 |
|
|
.expectBoolExitResult = true |
835 |
|
|
}); |
836 |
|
|
|
837 |
|
|
#if !SILENT_TEST |
838 |
|
|
std::cout << std::endl; |
839 |
|
|
#endif |
840 |
|
|
} |
841 |
|
|
|
842 |
|
|
static void testLogicalAndOperator() { |
843 |
|
|
#if !SILENT_TEST |
844 |
|
|
std::cout << "UNIT TEST: logical and (and) operator\n"; |
845 |
|
|
#endif |
846 |
|
|
|
847 |
|
|
runScript({ |
848 |
|
|
.code = R"NKSP_CODE( |
849 |
|
|
on init |
850 |
|
|
exit(1 and 1) |
851 |
|
|
end on |
852 |
|
|
)NKSP_CODE", |
853 |
|
|
.expectBoolExitResult = true |
854 |
|
|
}); |
855 |
|
|
|
856 |
|
|
runScript({ |
857 |
|
|
.code = R"NKSP_CODE( |
858 |
|
|
on init |
859 |
|
|
exit(1 and 2) |
860 |
|
|
end on |
861 |
|
|
)NKSP_CODE", |
862 |
|
|
.expectBoolExitResult = true |
863 |
|
|
}); |
864 |
|
|
|
865 |
|
|
runScript({ |
866 |
|
|
.code = R"NKSP_CODE( |
867 |
|
|
on init |
868 |
|
|
exit(1 and 3) |
869 |
|
|
end on |
870 |
|
|
)NKSP_CODE", |
871 |
|
|
.expectBoolExitResult = true |
872 |
|
|
}); |
873 |
|
|
|
874 |
|
|
runScript({ |
875 |
|
|
.code = R"NKSP_CODE( |
876 |
|
|
on init |
877 |
|
|
exit(1 and 0) |
878 |
|
|
end on |
879 |
|
|
)NKSP_CODE", |
880 |
|
|
.expectBoolExitResult = false |
881 |
|
|
}); |
882 |
|
|
|
883 |
|
|
runScript({ |
884 |
|
|
.code = R"NKSP_CODE( |
885 |
|
|
on init |
886 |
|
|
exit(0 and 1) |
887 |
|
|
end on |
888 |
|
|
)NKSP_CODE", |
889 |
|
|
.expectBoolExitResult = false |
890 |
|
|
}); |
891 |
|
|
|
892 |
|
|
runScript({ |
893 |
|
|
.code = R"NKSP_CODE( |
894 |
|
|
on init |
895 |
|
|
exit(0 and 0) |
896 |
|
|
end on |
897 |
|
|
)NKSP_CODE", |
898 |
|
|
.expectBoolExitResult = false |
899 |
|
|
}); |
900 |
|
|
|
901 |
|
|
#if !SILENT_TEST |
902 |
|
|
std::cout << std::endl; |
903 |
|
|
#endif |
904 |
|
|
} |
905 |
|
|
|
906 |
|
|
static void testLogicalOrOperator() { |
907 |
|
|
#if !SILENT_TEST |
908 |
|
|
std::cout << "UNIT TEST: logical or (or) operator\n"; |
909 |
|
|
#endif |
910 |
|
|
|
911 |
|
|
runScript({ |
912 |
|
|
.code = R"NKSP_CODE( |
913 |
|
|
on init |
914 |
|
|
exit(1 or 1) |
915 |
|
|
end on |
916 |
|
|
)NKSP_CODE", |
917 |
|
|
.expectBoolExitResult = true |
918 |
|
|
}); |
919 |
|
|
|
920 |
|
|
runScript({ |
921 |
|
|
.code = R"NKSP_CODE( |
922 |
|
|
on init |
923 |
|
|
exit(1 or 2) |
924 |
|
|
end on |
925 |
|
|
)NKSP_CODE", |
926 |
|
|
.expectBoolExitResult = true |
927 |
|
|
}); |
928 |
|
|
|
929 |
|
|
runScript({ |
930 |
|
|
.code = R"NKSP_CODE( |
931 |
|
|
on init |
932 |
|
|
exit(1 or 3) |
933 |
|
|
end on |
934 |
|
|
)NKSP_CODE", |
935 |
|
|
.expectBoolExitResult = true |
936 |
|
|
}); |
937 |
|
|
|
938 |
|
|
runScript({ |
939 |
|
|
.code = R"NKSP_CODE( |
940 |
|
|
on init |
941 |
|
|
exit(1 or 0) |
942 |
|
|
end on |
943 |
|
|
)NKSP_CODE", |
944 |
|
|
.expectBoolExitResult = true |
945 |
|
|
}); |
946 |
|
|
|
947 |
|
|
runScript({ |
948 |
|
|
.code = R"NKSP_CODE( |
949 |
|
|
on init |
950 |
|
|
exit(0 or 1) |
951 |
|
|
end on |
952 |
|
|
)NKSP_CODE", |
953 |
|
|
.expectBoolExitResult = true |
954 |
|
|
}); |
955 |
|
|
|
956 |
|
|
runScript({ |
957 |
|
|
.code = R"NKSP_CODE( |
958 |
|
|
on init |
959 |
|
|
exit(0 or 0) |
960 |
|
|
end on |
961 |
|
|
)NKSP_CODE", |
962 |
|
|
.expectBoolExitResult = false |
963 |
|
|
}); |
964 |
|
|
|
965 |
|
|
#if !SILENT_TEST |
966 |
|
|
std::cout << std::endl; |
967 |
|
|
#endif |
968 |
|
|
} |
969 |
|
|
|
970 |
|
|
static void testLogicalNotOperator() { |
971 |
|
|
#if !SILENT_TEST |
972 |
|
|
std::cout << "UNIT TEST: logical not (not) operator\n"; |
973 |
|
|
#endif |
974 |
|
|
|
975 |
|
|
runScript({ |
976 |
|
|
.code = R"NKSP_CODE( |
977 |
|
|
on init |
978 |
|
|
exit(not 1) |
979 |
|
|
end on |
980 |
|
|
)NKSP_CODE", |
981 |
|
|
.expectBoolExitResult = false |
982 |
|
|
}); |
983 |
|
|
|
984 |
|
|
runScript({ |
985 |
|
|
.code = R"NKSP_CODE( |
986 |
|
|
on init |
987 |
|
|
exit(not 2) |
988 |
|
|
end on |
989 |
|
|
)NKSP_CODE", |
990 |
|
|
.expectBoolExitResult = false |
991 |
|
|
}); |
992 |
|
|
|
993 |
|
|
runScript({ |
994 |
|
|
.code = R"NKSP_CODE( |
995 |
|
|
on init |
996 |
|
|
exit(not 0) |
997 |
|
|
end on |
998 |
|
|
)NKSP_CODE", |
999 |
|
|
.expectBoolExitResult = true |
1000 |
|
|
}); |
1001 |
|
|
|
1002 |
|
|
#if !SILENT_TEST |
1003 |
|
|
std::cout << std::endl; |
1004 |
|
|
#endif |
1005 |
|
|
} |
1006 |
|
|
|
1007 |
|
|
static void testBitwiseAndOperator() { |
1008 |
|
|
#if !SILENT_TEST |
1009 |
|
|
std::cout << "UNIT TEST: bitwise and (.and.) operator\n"; |
1010 |
|
|
#endif |
1011 |
|
|
|
1012 |
|
|
runScript({ |
1013 |
|
|
.code = R"NKSP_CODE( |
1014 |
|
|
on init |
1015 |
|
|
exit(1 .and. 1) |
1016 |
|
|
end on |
1017 |
|
|
)NKSP_CODE", |
1018 |
|
|
.expectIntExitResult = 1 |
1019 |
|
|
}); |
1020 |
|
|
|
1021 |
|
|
runScript({ |
1022 |
|
|
.code = R"NKSP_CODE( |
1023 |
|
|
on init |
1024 |
|
|
exit(43 .and. 142) |
1025 |
|
|
end on |
1026 |
|
|
)NKSP_CODE", |
1027 |
|
|
.expectIntExitResult = 10 |
1028 |
|
|
}); |
1029 |
|
|
|
1030 |
|
|
#if !SILENT_TEST |
1031 |
|
|
std::cout << std::endl; |
1032 |
|
|
#endif |
1033 |
|
|
} |
1034 |
|
|
|
1035 |
|
|
static void testBitwiseOrOperator() { |
1036 |
|
|
#if !SILENT_TEST |
1037 |
|
|
std::cout << "UNIT TEST: bitwise or (.or.) operator\n"; |
1038 |
|
|
#endif |
1039 |
|
|
|
1040 |
|
|
runScript({ |
1041 |
|
|
.code = R"NKSP_CODE( |
1042 |
|
|
on init |
1043 |
|
|
exit(1 .or. 1) |
1044 |
|
|
end on |
1045 |
|
|
)NKSP_CODE", |
1046 |
|
|
.expectIntExitResult = 1 |
1047 |
|
|
}); |
1048 |
|
|
|
1049 |
|
|
runScript({ |
1050 |
|
|
.code = R"NKSP_CODE( |
1051 |
|
|
on init |
1052 |
|
|
exit(0 .or. 0) |
1053 |
|
|
end on |
1054 |
|
|
)NKSP_CODE", |
1055 |
|
|
.expectIntExitResult = 0 |
1056 |
|
|
}); |
1057 |
|
|
|
1058 |
|
|
runScript({ |
1059 |
|
|
.code = R"NKSP_CODE( |
1060 |
|
|
on init |
1061 |
|
|
exit(43 .or. 142) |
1062 |
|
|
end on |
1063 |
|
|
)NKSP_CODE", |
1064 |
|
|
.expectIntExitResult = 175 |
1065 |
|
|
}); |
1066 |
|
|
|
1067 |
|
|
#if !SILENT_TEST |
1068 |
|
|
std::cout << std::endl; |
1069 |
|
|
#endif |
1070 |
|
|
} |
1071 |
|
|
|
1072 |
|
|
static void testBitwiseNotOperator() { |
1073 |
|
|
#if !SILENT_TEST |
1074 |
|
|
std::cout << "UNIT TEST: bitwise not (.not.) operator\n"; |
1075 |
|
|
#endif |
1076 |
|
|
|
1077 |
|
|
runScript({ |
1078 |
|
|
.code = R"NKSP_CODE( |
1079 |
|
|
on init |
1080 |
|
|
exit(.not. -1) |
1081 |
|
|
end on |
1082 |
|
|
)NKSP_CODE", |
1083 |
|
|
.expectIntExitResult = 0 |
1084 |
|
|
}); |
1085 |
|
|
|
1086 |
|
|
runScript({ |
1087 |
|
|
.code = R"NKSP_CODE( |
1088 |
|
|
on init |
1089 |
|
|
exit(.not. 0) |
1090 |
|
|
end on |
1091 |
|
|
)NKSP_CODE", |
1092 |
|
|
.expectIntExitResult = -1 |
1093 |
|
|
}); |
1094 |
|
|
|
1095 |
|
|
runScript({ |
1096 |
|
|
.code = R"NKSP_CODE( |
1097 |
|
|
on init |
1098 |
|
|
exit(.not. 3) |
1099 |
|
|
end on |
1100 |
|
|
)NKSP_CODE", |
1101 |
|
|
.expectIntExitResult = ssize_t(size_t(-1) << 2) |
1102 |
|
|
}); |
1103 |
|
|
|
1104 |
|
|
#if !SILENT_TEST |
1105 |
|
|
std::cout << std::endl; |
1106 |
|
|
#endif |
1107 |
|
|
} |
1108 |
|
|
|
1109 |
|
|
static void testPrecedenceOfOperators() { |
1110 |
|
|
#if !SILENT_TEST |
1111 |
|
|
std::cout << "UNIT TEST: precedence of operators\n"; |
1112 |
|
|
#endif |
1113 |
|
|
|
1114 |
|
|
runScript({ |
1115 |
|
|
.code = R"NKSP_CODE( |
1116 |
|
|
on init |
1117 |
|
|
exit(3 + 4 * 2) |
1118 |
|
|
end on |
1119 |
|
|
)NKSP_CODE", |
1120 |
|
|
.expectIntExitResult = 11 |
1121 |
|
|
}); |
1122 |
|
|
|
1123 |
|
|
runScript({ |
1124 |
|
|
.code = R"NKSP_CODE( |
1125 |
|
|
on init |
1126 |
|
|
exit(4 * 2 + 3) |
1127 |
|
|
end on |
1128 |
|
|
)NKSP_CODE", |
1129 |
|
|
.expectIntExitResult = 11 |
1130 |
|
|
}); |
1131 |
|
|
|
1132 |
|
|
runScript({ |
1133 |
|
|
.code = R"NKSP_CODE( |
1134 |
|
|
on init |
1135 |
|
|
exit((3 + 4) * 2) |
1136 |
|
|
end on |
1137 |
|
|
)NKSP_CODE", |
1138 |
|
|
.expectIntExitResult = 14 |
1139 |
|
|
}); |
1140 |
|
|
|
1141 |
|
|
runScript({ |
1142 |
|
|
.code = R"NKSP_CODE( |
1143 |
|
|
on init |
1144 |
|
|
exit(4 * (2 + 3)) |
1145 |
|
|
end on |
1146 |
|
|
)NKSP_CODE", |
1147 |
|
|
.expectIntExitResult = 20 |
1148 |
|
|
}); |
1149 |
|
|
|
1150 |
|
|
#if !SILENT_TEST |
1151 |
|
|
std::cout << std::endl; |
1152 |
|
|
#endif |
1153 |
|
|
} |
1154 |
|
|
|
1155 |
|
|
static void testBuiltInMinFunction() { |
1156 |
|
|
#if !SILENT_TEST |
1157 |
|
|
std::cout << "UNIT TEST: built-in min() function\n"; |
1158 |
|
|
#endif |
1159 |
|
|
|
1160 |
|
|
runScript({ |
1161 |
|
|
.code = R"NKSP_CODE( |
1162 |
|
|
on init |
1163 |
|
|
declare $foo := min |
1164 |
|
|
end on |
1165 |
|
|
)NKSP_CODE", |
1166 |
|
|
.expectParseError = true // because min() function requires 2 arguments |
1167 |
|
|
}); |
1168 |
|
|
|
1169 |
|
|
runScript({ |
1170 |
|
|
.code = R"NKSP_CODE( |
1171 |
|
|
on init |
1172 |
|
|
declare $foo := min() |
1173 |
|
|
end on |
1174 |
|
|
)NKSP_CODE", |
1175 |
|
|
.expectParseError = true // because min() function requires 2 arguments |
1176 |
|
|
}); |
1177 |
|
|
|
1178 |
|
|
runScript({ |
1179 |
|
|
.code = R"NKSP_CODE( |
1180 |
|
|
on init |
1181 |
|
|
declare $foo := min(1) |
1182 |
|
|
end on |
1183 |
|
|
)NKSP_CODE", |
1184 |
|
|
.expectParseError = true // because min() function requires 2 arguments |
1185 |
|
|
}); |
1186 |
|
|
|
1187 |
|
|
runScript({ |
1188 |
|
|
.code = R"NKSP_CODE( |
1189 |
|
|
on init |
1190 |
|
|
declare $foo := min(1,2) |
1191 |
|
|
exit($foo) |
1192 |
|
|
end on |
1193 |
|
|
)NKSP_CODE", |
1194 |
|
|
.expectIntExitResult = 1 |
1195 |
|
|
}); |
1196 |
|
|
|
1197 |
|
|
runScript({ |
1198 |
|
|
.code = R"NKSP_CODE( |
1199 |
|
|
on init |
1200 |
|
|
declare $foo := min(-30,4) |
1201 |
|
|
exit($foo) |
1202 |
|
|
end on |
1203 |
|
|
)NKSP_CODE", |
1204 |
|
|
.expectIntExitResult = -30 |
1205 |
|
|
}); |
1206 |
|
|
|
1207 |
|
|
#if !SILENT_TEST |
1208 |
|
|
std::cout << std::endl; |
1209 |
|
|
#endif |
1210 |
|
|
} |
1211 |
|
|
|
1212 |
|
|
static void testBuiltInMaxFunction() { |
1213 |
|
|
#if !SILENT_TEST |
1214 |
|
|
std::cout << "UNIT TEST: built-in max() function\n"; |
1215 |
|
|
#endif |
1216 |
|
|
|
1217 |
|
|
runScript({ |
1218 |
|
|
.code = R"NKSP_CODE( |
1219 |
|
|
on init |
1220 |
|
|
declare $foo := max |
1221 |
|
|
end on |
1222 |
|
|
)NKSP_CODE", |
1223 |
|
|
.expectParseError = true // because max() function requires 2 arguments |
1224 |
|
|
}); |
1225 |
|
|
|
1226 |
|
|
runScript({ |
1227 |
|
|
.code = R"NKSP_CODE( |
1228 |
|
|
on init |
1229 |
|
|
declare $foo := max() |
1230 |
|
|
end on |
1231 |
|
|
)NKSP_CODE", |
1232 |
|
|
.expectParseError = true // because max() function requires 2 arguments |
1233 |
|
|
}); |
1234 |
|
|
|
1235 |
|
|
runScript({ |
1236 |
|
|
.code = R"NKSP_CODE( |
1237 |
|
|
on init |
1238 |
|
|
declare $foo := max(1) |
1239 |
|
|
end on |
1240 |
|
|
)NKSP_CODE", |
1241 |
|
|
.expectParseError = true // because max() function requires 2 arguments |
1242 |
|
|
}); |
1243 |
|
|
|
1244 |
|
|
runScript({ |
1245 |
|
|
.code = R"NKSP_CODE( |
1246 |
|
|
on init |
1247 |
|
|
declare $foo := max(1,2) |
1248 |
|
|
exit($foo) |
1249 |
|
|
end on |
1250 |
|
|
)NKSP_CODE", |
1251 |
|
|
.expectIntExitResult = 2 |
1252 |
|
|
}); |
1253 |
|
|
|
1254 |
|
|
runScript({ |
1255 |
|
|
.code = R"NKSP_CODE( |
1256 |
|
|
on init |
1257 |
|
|
declare $foo := max(-30,4) |
1258 |
|
|
exit($foo) |
1259 |
|
|
end on |
1260 |
|
|
)NKSP_CODE", |
1261 |
|
|
.expectIntExitResult = 4 |
1262 |
|
|
}); |
1263 |
|
|
|
1264 |
|
|
#if !SILENT_TEST |
1265 |
|
|
std::cout << std::endl; |
1266 |
|
|
#endif |
1267 |
|
|
} |
1268 |
|
|
|
1269 |
|
|
static void testBuiltInAbsFunction() { |
1270 |
|
|
#if !SILENT_TEST |
1271 |
|
|
std::cout << "UNIT TEST: built-in abs() function\n"; |
1272 |
|
|
#endif |
1273 |
|
|
|
1274 |
|
|
runScript({ |
1275 |
|
|
.code = R"NKSP_CODE( |
1276 |
|
|
on init |
1277 |
|
|
declare $foo := abs |
1278 |
|
|
end on |
1279 |
|
|
)NKSP_CODE", |
1280 |
|
|
.expectParseError = true // because abs() function requires 1 argument |
1281 |
|
|
}); |
1282 |
|
|
|
1283 |
|
|
runScript({ |
1284 |
|
|
.code = R"NKSP_CODE( |
1285 |
|
|
on init |
1286 |
|
|
declare $foo := abs() |
1287 |
|
|
end on |
1288 |
|
|
)NKSP_CODE", |
1289 |
|
|
.expectParseError = true // because abs() function requires 1 argument |
1290 |
|
|
}); |
1291 |
|
|
|
1292 |
|
|
runScript({ |
1293 |
|
|
.code = R"NKSP_CODE( |
1294 |
|
|
on init |
1295 |
|
|
declare $foo := abs(23) |
1296 |
|
|
exit($foo) |
1297 |
|
|
end on |
1298 |
|
|
)NKSP_CODE", |
1299 |
|
|
.expectIntExitResult = 23 |
1300 |
|
|
}); |
1301 |
|
|
|
1302 |
|
|
runScript({ |
1303 |
|
|
.code = R"NKSP_CODE( |
1304 |
|
|
on init |
1305 |
|
|
declare $foo := abs(-23) |
1306 |
|
|
exit($foo) |
1307 |
|
|
end on |
1308 |
|
|
)NKSP_CODE", |
1309 |
|
|
.expectIntExitResult = 23 |
1310 |
|
|
}); |
1311 |
|
|
|
1312 |
|
|
#if !SILENT_TEST |
1313 |
|
|
std::cout << std::endl; |
1314 |
|
|
#endif |
1315 |
|
|
} |
1316 |
|
|
|
1317 |
|
|
static void testBuiltInIncFunction() { |
1318 |
|
|
#if !SILENT_TEST |
1319 |
|
|
std::cout << "UNIT TEST: built-in inc() function\n"; |
1320 |
|
|
#endif |
1321 |
|
|
|
1322 |
|
|
runScript({ |
1323 |
|
|
.code = R"NKSP_CODE( |
1324 |
|
|
on init |
1325 |
|
|
declare $foo := 5 |
1326 |
|
|
inc($foo) |
1327 |
|
|
exit($foo) |
1328 |
|
|
end on |
1329 |
|
|
)NKSP_CODE", |
1330 |
|
|
.expectIntExitResult = 6 |
1331 |
|
|
}); |
1332 |
|
|
|
1333 |
|
|
runScript({ |
1334 |
|
|
.code = R"NKSP_CODE( |
1335 |
|
|
on init |
1336 |
|
|
declare $foo := 5 |
1337 |
|
|
inc($foo) |
1338 |
|
|
inc($foo) |
1339 |
|
|
inc($foo) |
1340 |
|
|
exit($foo) |
1341 |
|
|
end on |
1342 |
|
|
)NKSP_CODE", |
1343 |
|
|
.expectIntExitResult = 8 |
1344 |
|
|
}); |
1345 |
|
|
|
1346 |
|
|
runScript({ |
1347 |
|
|
.code = R"NKSP_CODE( |
1348 |
|
|
on init |
1349 |
|
|
declare $foo := 5 |
1350 |
|
|
inc($foo) |
1351 |
|
|
exit( inc($foo) ) |
1352 |
|
|
end on |
1353 |
|
|
)NKSP_CODE", |
1354 |
|
|
.expectIntExitResult = 7 |
1355 |
|
|
}); |
1356 |
|
|
|
1357 |
|
|
#if !SILENT_TEST |
1358 |
|
|
std::cout << std::endl; |
1359 |
|
|
#endif |
1360 |
|
|
} |
1361 |
|
|
|
1362 |
|
|
static void testBuiltInDecFunction() { |
1363 |
|
|
#if !SILENT_TEST |
1364 |
|
|
std::cout << "UNIT TEST: built-in dec() function\n"; |
1365 |
|
|
#endif |
1366 |
|
|
|
1367 |
|
|
runScript({ |
1368 |
|
|
.code = R"NKSP_CODE( |
1369 |
|
|
on init |
1370 |
|
|
declare $foo := 5 |
1371 |
|
|
dec($foo) |
1372 |
|
|
exit($foo) |
1373 |
|
|
end on |
1374 |
|
|
)NKSP_CODE", |
1375 |
|
|
.expectIntExitResult = 4 |
1376 |
|
|
}); |
1377 |
|
|
|
1378 |
|
|
runScript({ |
1379 |
|
|
.code = R"NKSP_CODE( |
1380 |
|
|
on init |
1381 |
|
|
declare $foo := 5 |
1382 |
|
|
dec($foo) |
1383 |
|
|
dec($foo) |
1384 |
|
|
dec($foo) |
1385 |
|
|
exit($foo) |
1386 |
|
|
end on |
1387 |
|
|
)NKSP_CODE", |
1388 |
|
|
.expectIntExitResult = 2 |
1389 |
|
|
}); |
1390 |
|
|
|
1391 |
|
|
runScript({ |
1392 |
|
|
.code = R"NKSP_CODE( |
1393 |
|
|
on init |
1394 |
|
|
declare $foo := 5 |
1395 |
|
|
dec($foo) |
1396 |
|
|
exit( dec($foo) ) |
1397 |
|
|
end on |
1398 |
|
|
)NKSP_CODE", |
1399 |
|
|
.expectIntExitResult = 3 |
1400 |
|
|
}); |
1401 |
|
|
|
1402 |
|
|
#if !SILENT_TEST |
1403 |
|
|
std::cout << std::endl; |
1404 |
|
|
#endif |
1405 |
|
|
} |
1406 |
|
|
|
1407 |
|
|
static void testBuiltInInRangeFunction() { |
1408 |
|
|
#if !SILENT_TEST |
1409 |
|
|
std::cout << "UNIT TEST: built-in in_range() function\n"; |
1410 |
|
|
#endif |
1411 |
|
|
|
1412 |
|
|
runScript({ |
1413 |
|
|
.code = R"NKSP_CODE( |
1414 |
|
|
on init |
1415 |
|
|
exit( in_range(1,4,9) ) |
1416 |
|
|
end on |
1417 |
|
|
)NKSP_CODE", |
1418 |
|
|
.expectBoolExitResult = false |
1419 |
|
|
}); |
1420 |
|
|
|
1421 |
|
|
runScript({ |
1422 |
|
|
.code = R"NKSP_CODE( |
1423 |
|
|
on init |
1424 |
|
|
exit( in_range(5,4,9) ) |
1425 |
|
|
end on |
1426 |
|
|
)NKSP_CODE", |
1427 |
|
|
.expectBoolExitResult = true |
1428 |
|
|
}); |
1429 |
|
|
|
1430 |
|
|
runScript({ |
1431 |
|
|
.code = R"NKSP_CODE( |
1432 |
|
|
on init |
1433 |
|
|
exit( in_range(9,4,9) ) |
1434 |
|
|
end on |
1435 |
|
|
)NKSP_CODE", |
1436 |
|
|
.expectBoolExitResult = true |
1437 |
|
|
}); |
1438 |
|
|
|
1439 |
|
|
runScript({ |
1440 |
|
|
.code = R"NKSP_CODE( |
1441 |
|
|
on init |
1442 |
|
|
exit( in_range(10,4,9) ) |
1443 |
|
|
end on |
1444 |
|
|
)NKSP_CODE", |
1445 |
|
|
.expectBoolExitResult = false |
1446 |
|
|
}); |
1447 |
|
|
|
1448 |
|
|
runScript({ |
1449 |
|
|
.code = R"NKSP_CODE( |
1450 |
|
|
on init |
1451 |
|
|
exit( in_range(-6,-5,5) ) |
1452 |
|
|
end on |
1453 |
|
|
)NKSP_CODE", |
1454 |
|
|
.expectBoolExitResult = false |
1455 |
|
|
}); |
1456 |
|
|
|
1457 |
|
|
runScript({ |
1458 |
|
|
.code = R"NKSP_CODE( |
1459 |
|
|
on init |
1460 |
|
|
exit( in_range(-5,-5,5) ) |
1461 |
|
|
end on |
1462 |
|
|
)NKSP_CODE", |
1463 |
|
|
.expectBoolExitResult = true |
1464 |
|
|
}); |
1465 |
|
|
|
1466 |
|
|
runScript({ |
1467 |
|
|
.code = R"NKSP_CODE( |
1468 |
|
|
on init |
1469 |
|
|
exit( in_range(0,-5,5) ) |
1470 |
|
|
end on |
1471 |
|
|
)NKSP_CODE", |
1472 |
|
|
.expectBoolExitResult = true |
1473 |
|
|
}); |
1474 |
|
|
|
1475 |
|
|
runScript({ |
1476 |
|
|
.code = R"NKSP_CODE( |
1477 |
|
|
on init |
1478 |
|
|
exit( in_range(5,-5,5) ) |
1479 |
|
|
end on |
1480 |
|
|
)NKSP_CODE", |
1481 |
|
|
.expectBoolExitResult = true |
1482 |
|
|
}); |
1483 |
|
|
|
1484 |
|
|
runScript({ |
1485 |
|
|
.code = R"NKSP_CODE( |
1486 |
|
|
on init |
1487 |
|
|
exit( in_range(6,-5,5) ) |
1488 |
|
|
end on |
1489 |
|
|
)NKSP_CODE", |
1490 |
|
|
.expectBoolExitResult = false |
1491 |
|
|
}); |
1492 |
|
|
|
1493 |
|
|
#if !SILENT_TEST |
1494 |
|
|
std::cout << std::endl; |
1495 |
|
|
#endif |
1496 |
|
|
} |
1497 |
|
|
|
1498 |
|
|
static void testBuiltInRandomFunction() { |
1499 |
|
|
#if !SILENT_TEST |
1500 |
|
|
std::cout << "UNIT TEST: built-in random() function\n"; |
1501 |
|
|
#endif |
1502 |
|
|
|
1503 |
|
|
for (int run = 0; run < 20; ++run) { |
1504 |
|
|
runScript({ |
1505 |
|
|
.code = R"NKSP_CODE( |
1506 |
|
|
on init |
1507 |
|
|
declare $foo := random(-5,5) |
1508 |
|
|
exit( in_range($foo,-5,5) ) |
1509 |
|
|
end on |
1510 |
|
|
)NKSP_CODE", |
1511 |
|
|
.expectBoolExitResult = true |
1512 |
|
|
}); |
1513 |
|
|
} |
1514 |
|
|
|
1515 |
|
|
#if !SILENT_TEST |
1516 |
|
|
std::cout << std::endl; |
1517 |
|
|
#endif |
1518 |
|
|
} |
1519 |
|
|
|
1520 |
|
|
static void testBuiltInShiftLeftFunction() { |
1521 |
|
|
#if !SILENT_TEST |
1522 |
|
|
std::cout << "UNIT TEST: built-in sh_left() function\n"; |
1523 |
|
|
#endif |
1524 |
|
|
|
1525 |
|
|
runScript({ |
1526 |
|
|
.code = R"NKSP_CODE( |
1527 |
|
|
on init |
1528 |
|
|
exit( sh_left(1,0) ) |
1529 |
|
|
end on |
1530 |
|
|
)NKSP_CODE", |
1531 |
|
|
.expectIntExitResult = 1 |
1532 |
|
|
}); |
1533 |
|
|
|
1534 |
|
|
runScript({ |
1535 |
|
|
.code = R"NKSP_CODE( |
1536 |
|
|
on init |
1537 |
|
|
exit( sh_left(1,1) ) |
1538 |
|
|
end on |
1539 |
|
|
)NKSP_CODE", |
1540 |
|
|
.expectIntExitResult = 2 |
1541 |
|
|
}); |
1542 |
|
|
|
1543 |
|
|
runScript({ |
1544 |
|
|
.code = R"NKSP_CODE( |
1545 |
|
|
on init |
1546 |
|
|
exit( sh_left(1,2) ) |
1547 |
|
|
end on |
1548 |
|
|
)NKSP_CODE", |
1549 |
|
|
.expectIntExitResult = 4 |
1550 |
|
|
}); |
1551 |
|
|
|
1552 |
|
|
runScript({ |
1553 |
|
|
.code = R"NKSP_CODE( |
1554 |
|
|
on init |
1555 |
|
|
exit( sh_left(1,3) ) |
1556 |
|
|
end on |
1557 |
|
|
)NKSP_CODE", |
1558 |
|
|
.expectIntExitResult = 8 |
1559 |
|
|
}); |
1560 |
|
|
|
1561 |
|
|
#if !SILENT_TEST |
1562 |
|
|
std::cout << std::endl; |
1563 |
|
|
#endif |
1564 |
|
|
} |
1565 |
|
|
|
1566 |
|
|
static void testBuiltInShiftRightFunction() { |
1567 |
|
|
#if !SILENT_TEST |
1568 |
|
|
std::cout << "UNIT TEST: built-in sh_right() function\n"; |
1569 |
|
|
#endif |
1570 |
|
|
|
1571 |
|
|
runScript({ |
1572 |
|
|
.code = R"NKSP_CODE( |
1573 |
|
|
on init |
1574 |
|
|
exit( sh_right(8,0) ) |
1575 |
|
|
end on |
1576 |
|
|
)NKSP_CODE", |
1577 |
|
|
.expectIntExitResult = 8 |
1578 |
|
|
}); |
1579 |
|
|
|
1580 |
|
|
runScript({ |
1581 |
|
|
.code = R"NKSP_CODE( |
1582 |
|
|
on init |
1583 |
|
|
exit( sh_right(8,1) ) |
1584 |
|
|
end on |
1585 |
|
|
)NKSP_CODE", |
1586 |
|
|
.expectIntExitResult = 4 |
1587 |
|
|
}); |
1588 |
|
|
|
1589 |
|
|
runScript({ |
1590 |
|
|
.code = R"NKSP_CODE( |
1591 |
|
|
on init |
1592 |
|
|
exit( sh_right(8,2) ) |
1593 |
|
|
end on |
1594 |
|
|
)NKSP_CODE", |
1595 |
|
|
.expectIntExitResult = 2 |
1596 |
|
|
}); |
1597 |
|
|
|
1598 |
|
|
runScript({ |
1599 |
|
|
.code = R"NKSP_CODE( |
1600 |
|
|
on init |
1601 |
|
|
exit( sh_right(8,3) ) |
1602 |
|
|
end on |
1603 |
|
|
)NKSP_CODE", |
1604 |
|
|
.expectIntExitResult = 1 |
1605 |
|
|
}); |
1606 |
|
|
|
1607 |
|
|
runScript({ |
1608 |
|
|
.code = R"NKSP_CODE( |
1609 |
|
|
on init |
1610 |
|
|
exit( sh_right(8,4) ) |
1611 |
|
|
end on |
1612 |
|
|
)NKSP_CODE", |
1613 |
|
|
.expectIntExitResult = 0 |
1614 |
|
|
}); |
1615 |
|
|
|
1616 |
|
|
#if !SILENT_TEST |
1617 |
|
|
std::cout << std::endl; |
1618 |
|
|
#endif |
1619 |
|
|
} |
1620 |
|
|
|
1621 |
|
|
static void testBuiltInArrayEqualFunction() { |
1622 |
|
|
#if !SILENT_TEST |
1623 |
|
|
std::cout << "UNIT TEST: built-in array_equal() function\n"; |
1624 |
|
|
#endif |
1625 |
|
|
|
1626 |
|
|
runScript({ |
1627 |
|
|
.code = R"NKSP_CODE( |
1628 |
|
|
on init |
1629 |
|
|
declare %foo[3] := ( 1, 2, 3 ) |
1630 |
|
|
declare %bar[3] := ( 1, 2, 3 ) |
1631 |
|
|
exit( array_equal(%foo, %bar) ) |
1632 |
|
|
end on |
1633 |
|
|
)NKSP_CODE", |
1634 |
|
|
.expectBoolExitResult = true |
1635 |
|
|
}); |
1636 |
|
|
|
1637 |
|
|
runScript({ |
1638 |
|
|
.code = R"NKSP_CODE( |
1639 |
|
|
on init |
1640 |
|
|
declare %foo[1] := ( 1 ) |
1641 |
|
|
declare %bar[1] := ( 1 ) |
1642 |
|
|
exit( array_equal(%foo, %bar) ) |
1643 |
|
|
end on |
1644 |
|
|
)NKSP_CODE", |
1645 |
|
|
.expectBoolExitResult = true |
1646 |
|
|
}); |
1647 |
|
|
|
1648 |
|
|
runScript({ |
1649 |
|
|
.code = R"NKSP_CODE( |
1650 |
|
|
on init |
1651 |
|
|
declare %foo[3] := ( 1, 2, 3 ) |
1652 |
|
|
declare %bar[3] := ( 0, 2, 3 ) |
1653 |
|
|
exit( array_equal(%foo, %bar) ) |
1654 |
|
|
end on |
1655 |
|
|
)NKSP_CODE", |
1656 |
|
|
.expectBoolExitResult = false |
1657 |
|
|
}); |
1658 |
|
|
|
1659 |
|
|
runScript({ |
1660 |
|
|
.code = R"NKSP_CODE( |
1661 |
|
|
on init |
1662 |
|
|
declare %foo[3] := ( 1, 2, 3 ) |
1663 |
|
|
declare %bar[3] := ( 3, 2, 1 ) |
1664 |
|
|
exit( array_equal(%foo, %bar) ) |
1665 |
|
|
end on |
1666 |
|
|
)NKSP_CODE", |
1667 |
|
|
.expectBoolExitResult = false |
1668 |
|
|
}); |
1669 |
|
|
|
1670 |
|
|
runScript({ |
1671 |
|
|
.code = R"NKSP_CODE( |
1672 |
|
|
on init |
1673 |
|
|
declare %foo[3] := ( 1, 2, 3 ) |
1674 |
|
|
declare %bar[2] := ( 1, 2 ) |
1675 |
|
|
exit( array_equal(%foo, %bar) ) |
1676 |
|
|
end on |
1677 |
|
|
)NKSP_CODE", |
1678 |
|
|
.expectBoolExitResult = false |
1679 |
|
|
}); |
1680 |
|
|
|
1681 |
|
|
#if !SILENT_TEST |
1682 |
|
|
std::cout << std::endl; |
1683 |
|
|
#endif |
1684 |
|
|
} |
1685 |
|
|
|
1686 |
|
|
static void testBuiltInSortFunction() { |
1687 |
|
|
#if !SILENT_TEST |
1688 |
|
|
std::cout << "UNIT TEST: built-in sort() function\n"; |
1689 |
|
|
#endif |
1690 |
|
|
|
1691 |
|
|
runScript({ |
1692 |
|
|
.code = R"NKSP_CODE( |
1693 |
|
|
on init |
1694 |
|
|
declare %input[3] := ( 19, 3, 6 ) |
1695 |
|
|
declare %expected[3] := ( 3, 6, 19 ) |
1696 |
|
|
sort(%input, 0) |
1697 |
|
|
exit( array_equal(%input, %expected) ) |
1698 |
|
|
end on |
1699 |
|
|
)NKSP_CODE", |
1700 |
|
|
.expectBoolExitResult = true |
1701 |
|
|
}); |
1702 |
|
|
|
1703 |
|
|
runScript({ |
1704 |
|
|
.code = R"NKSP_CODE( |
1705 |
|
|
on init |
1706 |
|
|
declare %input[3] := ( 19, 3, 6 ) |
1707 |
|
|
declare %expected[3] := ( 19, 6, 3 ) |
1708 |
|
|
sort(%input, 1) |
1709 |
|
|
exit( array_equal(%input, %expected) ) |
1710 |
|
|
end on |
1711 |
|
|
)NKSP_CODE", |
1712 |
|
|
.expectBoolExitResult = true |
1713 |
|
|
}); |
1714 |
|
|
|
1715 |
|
|
#if !SILENT_TEST |
1716 |
|
|
std::cout << std::endl; |
1717 |
|
|
#endif |
1718 |
|
|
} |
1719 |
|
|
|
1720 |
|
|
static void testBuiltInNumElementsFunction() { |
1721 |
|
|
#if !SILENT_TEST |
1722 |
|
|
std::cout << "UNIT TEST: built-in num_elements() function\n"; |
1723 |
|
|
#endif |
1724 |
|
|
|
1725 |
|
|
runScript({ |
1726 |
|
|
.code = R"NKSP_CODE( |
1727 |
|
|
on init |
1728 |
|
|
declare %foo[3] := ( 19, 3, 6 ) |
1729 |
|
|
exit( num_elements(%foo) ) |
1730 |
|
|
end on |
1731 |
|
|
)NKSP_CODE", |
1732 |
|
|
.expectIntExitResult = 3 |
1733 |
|
|
}); |
1734 |
|
|
|
1735 |
|
|
runScript({ |
1736 |
|
|
.code = R"NKSP_CODE( |
1737 |
|
|
on init |
1738 |
|
|
declare %foo[1] := ( 19 ) |
1739 |
|
|
exit( num_elements(%foo) ) |
1740 |
|
|
end on |
1741 |
|
|
)NKSP_CODE", |
1742 |
|
|
.expectIntExitResult = 1 |
1743 |
|
|
}); |
1744 |
|
|
|
1745 |
|
|
runScript({ |
1746 |
|
|
.code = R"NKSP_CODE( |
1747 |
|
|
on init |
1748 |
|
|
declare %foo[5] := ( 1, 2, 3, 4, 5 ) |
1749 |
|
|
exit( num_elements(%foo) ) |
1750 |
|
|
end on |
1751 |
|
|
)NKSP_CODE", |
1752 |
|
|
.expectIntExitResult = 5 |
1753 |
|
|
}); |
1754 |
|
|
|
1755 |
|
|
#if !SILENT_TEST |
1756 |
|
|
std::cout << std::endl; |
1757 |
|
|
#endif |
1758 |
|
|
} |
1759 |
|
|
|
1760 |
|
|
static void testBuiltInSearchFunction() { |
1761 |
|
|
#if !SILENT_TEST |
1762 |
|
|
std::cout << "UNIT TEST: built-in search() function\n"; |
1763 |
|
|
#endif |
1764 |
|
|
|
1765 |
|
|
runScript({ |
1766 |
|
|
.code = R"NKSP_CODE( |
1767 |
|
|
on init |
1768 |
|
|
declare %foo[3] := ( 19, 3, 6 ) |
1769 |
|
|
exit( search(%foo, 19) ) |
1770 |
|
|
end on |
1771 |
|
|
)NKSP_CODE", |
1772 |
|
|
.expectIntExitResult = 0 |
1773 |
|
|
}); |
1774 |
|
|
|
1775 |
|
|
runScript({ |
1776 |
|
|
.code = R"NKSP_CODE( |
1777 |
|
|
on init |
1778 |
|
|
declare %foo[3] := ( 19, 3, 6 ) |
1779 |
|
|
exit( search(%foo, 3) ) |
1780 |
|
|
end on |
1781 |
|
|
)NKSP_CODE", |
1782 |
|
|
.expectIntExitResult = 1 |
1783 |
|
|
}); |
1784 |
|
|
|
1785 |
|
|
runScript({ |
1786 |
|
|
.code = R"NKSP_CODE( |
1787 |
|
|
on init |
1788 |
|
|
declare %foo[3] := ( 19, 3, 6 ) |
1789 |
|
|
exit( search(%foo, 6) ) |
1790 |
|
|
end on |
1791 |
|
|
)NKSP_CODE", |
1792 |
|
|
.expectIntExitResult = 2 |
1793 |
|
|
}); |
1794 |
|
|
|
1795 |
|
|
runScript({ |
1796 |
|
|
.code = R"NKSP_CODE( |
1797 |
|
|
on init |
1798 |
|
|
declare %foo[3] := ( 19, 3, 6 ) |
1799 |
|
|
exit( search(%foo, 2) ) |
1800 |
|
|
end on |
1801 |
|
|
)NKSP_CODE", |
1802 |
|
|
.expectIntExitResult = -1 |
1803 |
|
|
}); |
1804 |
|
|
|
1805 |
|
|
#if !SILENT_TEST |
1806 |
|
|
std::cout << std::endl; |
1807 |
|
|
#endif |
1808 |
|
|
} |
1809 |
|
|
|
1810 |
|
|
static void testIfStatement() { |
1811 |
|
|
#if !SILENT_TEST |
1812 |
|
|
std::cout << "UNIT TEST: if statement\n"; |
1813 |
|
|
#endif |
1814 |
|
|
|
1815 |
|
|
runScript({ |
1816 |
|
|
.code = R"NKSP_CODE( |
1817 |
|
|
on init |
1818 |
|
|
declare $foo := 1 |
1819 |
|
|
if ($foo) |
1820 |
|
|
exit(42) |
1821 |
|
|
end if |
1822 |
|
|
end on |
1823 |
|
|
)NKSP_CODE", |
1824 |
|
|
.expectIntExitResult = 42 |
1825 |
|
|
}); |
1826 |
|
|
|
1827 |
|
|
runScript({ |
1828 |
|
|
.code = R"NKSP_CODE( |
1829 |
|
|
on init |
1830 |
|
|
declare $foo := 0 |
1831 |
|
|
if ($foo) |
1832 |
|
|
exit(42) |
1833 |
|
|
end if |
1834 |
|
|
exit(3) |
1835 |
|
|
end on |
1836 |
|
|
)NKSP_CODE", |
1837 |
|
|
.expectIntExitResult = 3 |
1838 |
|
|
}); |
1839 |
|
|
|
1840 |
|
|
runScript({ |
1841 |
|
|
.code = R"NKSP_CODE( |
1842 |
|
|
on init |
1843 |
|
|
declare $foo := 1 |
1844 |
|
|
if ($foo) |
1845 |
|
|
exit(42) |
1846 |
|
|
else |
1847 |
|
|
exit(3) |
1848 |
|
|
end if |
1849 |
|
|
end on |
1850 |
|
|
)NKSP_CODE", |
1851 |
|
|
.expectIntExitResult = 42 |
1852 |
|
|
}); |
1853 |
|
|
|
1854 |
|
|
runScript({ |
1855 |
|
|
.code = R"NKSP_CODE( |
1856 |
|
|
on init |
1857 |
|
|
declare $foo := 0 |
1858 |
|
|
if ($foo) |
1859 |
|
|
exit(42) |
1860 |
|
|
else |
1861 |
|
|
exit(3) |
1862 |
|
|
end if |
1863 |
|
|
end on |
1864 |
|
|
)NKSP_CODE", |
1865 |
|
|
.expectIntExitResult = 3 |
1866 |
|
|
}); |
1867 |
|
|
|
1868 |
|
|
#if !SILENT_TEST |
1869 |
|
|
std::cout << std::endl; |
1870 |
|
|
#endif |
1871 |
|
|
} |
1872 |
|
|
|
1873 |
|
|
static void testWhileStatement() { |
1874 |
|
|
#if !SILENT_TEST |
1875 |
|
|
std::cout << "UNIT TEST: while statement\n"; |
1876 |
|
|
#endif |
1877 |
|
|
|
1878 |
|
|
runScript({ |
1879 |
|
|
.code = R"NKSP_CODE( |
1880 |
|
|
on init |
1881 |
|
|
declare $foo := 100 |
1882 |
|
|
declare $i := 50 |
1883 |
|
|
while ($i) |
1884 |
|
|
$foo := $foo + 1 |
1885 |
|
|
$i := $i - 1 |
1886 |
|
|
end while |
1887 |
|
|
exit($foo) |
1888 |
|
|
end on |
1889 |
|
|
)NKSP_CODE", |
1890 |
|
|
.expectIntExitResult = 150 |
1891 |
|
|
}); |
1892 |
|
|
|
1893 |
|
|
#if !SILENT_TEST |
1894 |
|
|
std::cout << std::endl; |
1895 |
|
|
#endif |
1896 |
|
|
} |
1897 |
|
|
|
1898 |
|
|
#if !NO_MAIN |
1899 |
|
|
|
1900 |
|
|
int main() { |
1901 |
|
|
testBuiltInExitFunction(); |
1902 |
|
|
testStringConcatOperator(); |
1903 |
|
|
testPlusOperator(); |
1904 |
|
|
testMinusOperator(); |
1905 |
|
|
testModuloOperator(); |
1906 |
|
|
testMultiplyOperator(); |
1907 |
|
|
testDivideOperator(); |
1908 |
|
|
testSmallerThanOperator(); |
1909 |
|
|
testGreaterThanOperator(); |
1910 |
|
|
testSmallerOrEqualOperator(); |
1911 |
|
|
testGreaterOrEqualOperator(); |
1912 |
|
|
testEqualOperator(); |
1913 |
|
|
testUnequalOperator(); |
1914 |
|
|
testLogicalAndOperator(); |
1915 |
|
|
testLogicalOrOperator(); |
1916 |
|
|
testLogicalNotOperator(); |
1917 |
|
|
testBitwiseAndOperator(); |
1918 |
|
|
testBitwiseOrOperator(); |
1919 |
|
|
testBitwiseNotOperator(); |
1920 |
|
|
testPrecedenceOfOperators(); |
1921 |
|
|
testBuiltInMinFunction(); |
1922 |
|
|
testBuiltInMaxFunction(); |
1923 |
|
|
testBuiltInAbsFunction(); |
1924 |
|
|
testBuiltInIncFunction(); |
1925 |
|
|
testBuiltInDecFunction(); |
1926 |
|
|
testBuiltInInRangeFunction(); |
1927 |
|
|
testBuiltInRandomFunction(); |
1928 |
|
|
testBuiltInShiftLeftFunction(); |
1929 |
|
|
testBuiltInShiftRightFunction(); |
1930 |
|
|
testBuiltInArrayEqualFunction(); |
1931 |
|
|
testBuiltInSortFunction(); |
1932 |
|
|
testBuiltInNumElementsFunction(); |
1933 |
|
|
testBuiltInSearchFunction(); |
1934 |
|
|
testIfStatement(); |
1935 |
|
|
testWhileStatement(); |
1936 |
|
|
std::cout << "\nAll tests passed successfully. :-)\n"; |
1937 |
|
|
return 0; |
1938 |
|
|
} |
1939 |
|
|
|
1940 |
|
|
#endif // !NO_MAIN |