1 |
/* |
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 "../../common/RTMath.h" |
16 |
#include "../ScriptVM.h" |
17 |
#include "../common.h" |
18 |
#include <sstream> |
19 |
#include <stdlib.h> |
20 |
#include <time.h> |
21 |
#include <assert.h> |
22 |
#include <functional> |
23 |
|
24 |
#ifndef TEST_ASSERT |
25 |
# define TEST_ASSERT assert |
26 |
#endif |
27 |
|
28 |
using namespace LinuxSampler; |
29 |
using namespace std; |
30 |
|
31 |
struct RunScriptOpt { |
32 |
String code; |
33 |
bool expectParseError; |
34 |
bool expectRuntimeError; |
35 |
bool expectNoExitResult; |
36 |
bool prohibitExitFunctionArguments; |
37 |
optional<vmint> expectIntExitResult; |
38 |
optional<bool> expectBoolExitResult; |
39 |
optional<vmfloat> expectRealExitResult; |
40 |
optional<String> expectStringExitResult; |
41 |
}; |
42 |
|
43 |
static void runScript(const RunScriptOpt& opt) { |
44 |
ScriptVM vm; |
45 |
vm.setAutoSuspendEnabled(false); |
46 |
if (!opt.prohibitExitFunctionArguments) |
47 |
vm.setExitResultEnabled(true); |
48 |
unique_ptr<VMParserContext> parserCtx( |
49 |
vm.loadScript(opt.code) |
50 |
); |
51 |
vector<ParserIssue> errors = parserCtx->errors(); |
52 |
if (opt.expectParseError) { |
53 |
TEST_ASSERT(!errors.empty()); |
54 |
return; |
55 |
} else { |
56 |
for (ParserIssue& err : errors) { |
57 |
err.dump(); |
58 |
} |
59 |
TEST_ASSERT(errors.empty()); |
60 |
} |
61 |
TEST_ASSERT(parserCtx->eventHandler(0)); |
62 |
unique_ptr<VMExecContext> execCtx( |
63 |
vm.createExecContext(&*parserCtx) |
64 |
); |
65 |
for (int i = 0; parserCtx->eventHandler(i); ++i) { |
66 |
VMEventHandler* handler = parserCtx->eventHandler(i); |
67 |
VMExecStatus_t result = vm.exec(&*parserCtx, &*execCtx, handler); |
68 |
if (opt.expectRuntimeError) { |
69 |
TEST_ASSERT(result & VM_EXEC_ERROR); |
70 |
} else { |
71 |
TEST_ASSERT(!(result & VM_EXEC_ERROR)); |
72 |
} |
73 |
if (opt.expectNoExitResult) { |
74 |
VMExpr* resExpr = execCtx->exitResult(); |
75 |
TEST_ASSERT(!resExpr); |
76 |
} |
77 |
if (opt.expectIntExitResult) { |
78 |
VMExpr* resExpr = execCtx->exitResult(); |
79 |
TEST_ASSERT(resExpr); |
80 |
TEST_ASSERT(resExpr->exprType() == INT_EXPR); |
81 |
TEST_ASSERT(resExpr->asInt()->evalInt() == *opt.expectIntExitResult); |
82 |
} |
83 |
if (opt.expectRealExitResult) { |
84 |
VMExpr* resExpr = execCtx->exitResult(); |
85 |
TEST_ASSERT(resExpr); |
86 |
TEST_ASSERT(resExpr->exprType() == REAL_EXPR); |
87 |
if (sizeof(vmfloat) == sizeof(float)) { |
88 |
TEST_ASSERT(RTMath::fEqual32(resExpr->asReal()->evalReal(), *opt.expectRealExitResult)); |
89 |
} else { |
90 |
TEST_ASSERT(RTMath::fEqual64(resExpr->asReal()->evalReal(), *opt.expectRealExitResult)); |
91 |
} |
92 |
} |
93 |
if (opt.expectBoolExitResult) { |
94 |
VMExpr* resExpr = execCtx->exitResult(); |
95 |
TEST_ASSERT(resExpr); |
96 |
TEST_ASSERT(resExpr->exprType() == INT_EXPR); |
97 |
TEST_ASSERT(bool(resExpr->asInt()->evalInt()) == *opt.expectBoolExitResult); |
98 |
} |
99 |
if (opt.expectStringExitResult) { |
100 |
VMExpr* resExpr = execCtx->exitResult(); |
101 |
TEST_ASSERT(resExpr); |
102 |
TEST_ASSERT(resExpr->exprType() == STRING_EXPR); |
103 |
TEST_ASSERT(resExpr->asString()->evalStr() == *opt.expectStringExitResult); |
104 |
} |
105 |
} |
106 |
} |
107 |
|
108 |
static void testBuiltInExitFunction() { |
109 |
#if !SILENT_TEST |
110 |
std::cout << "UNIT TEST: built-in exit() function\n"; |
111 |
#endif |
112 |
|
113 |
runScript({ |
114 |
.code = R"NKSP_CODE( |
115 |
on init |
116 |
end on |
117 |
)NKSP_CODE", |
118 |
.expectNoExitResult = true |
119 |
}); |
120 |
|
121 |
runScript({ |
122 |
.code = R"NKSP_CODE( |
123 |
on init |
124 |
exit |
125 |
end on |
126 |
)NKSP_CODE", |
127 |
.expectNoExitResult = true |
128 |
}); |
129 |
|
130 |
runScript({ |
131 |
.code = R"NKSP_CODE( |
132 |
on init |
133 |
exit() |
134 |
end on |
135 |
)NKSP_CODE", |
136 |
.expectNoExitResult = true |
137 |
}); |
138 |
|
139 |
// integer tests ... |
140 |
|
141 |
runScript({ |
142 |
.code = R"NKSP_CODE( |
143 |
on init |
144 |
exit(42) |
145 |
end on |
146 |
)NKSP_CODE", |
147 |
.expectIntExitResult = 42 |
148 |
}); |
149 |
|
150 |
runScript({ |
151 |
.code = R"NKSP_CODE( |
152 |
on init |
153 |
declare $foo := 1 |
154 |
if ($foo) |
155 |
exit(21) |
156 |
end if |
157 |
end on |
158 |
)NKSP_CODE", |
159 |
.expectIntExitResult = 21 |
160 |
}); |
161 |
|
162 |
runScript({ |
163 |
.code = R"NKSP_CODE( |
164 |
on init |
165 |
declare $foo := 0 |
166 |
if ($foo) |
167 |
exit(21) |
168 |
end if |
169 |
exit(99) |
170 |
end on |
171 |
)NKSP_CODE", |
172 |
.expectIntExitResult = 99 |
173 |
}); |
174 |
|
175 |
// string tests ... |
176 |
|
177 |
runScript({ |
178 |
.code = R"NKSP_CODE( |
179 |
on init |
180 |
exit("fourtytwo!") |
181 |
end on |
182 |
)NKSP_CODE", |
183 |
.expectStringExitResult = "fourtytwo!" |
184 |
}); |
185 |
|
186 |
// in production environment we prohibit the built-in exit() function to |
187 |
// accept any arguments |
188 |
runScript({ |
189 |
.code = R"NKSP_CODE( |
190 |
on init |
191 |
exit(42) |
192 |
end on |
193 |
)NKSP_CODE", |
194 |
.expectParseError = true, // see comment above why |
195 |
.prohibitExitFunctionArguments = true // simulate production environment |
196 |
}); |
197 |
|
198 |
// real number tests ... |
199 |
|
200 |
runScript({ |
201 |
.code = R"NKSP_CODE( |
202 |
on init |
203 |
exit(3.14) |
204 |
end on |
205 |
)NKSP_CODE", |
206 |
.expectRealExitResult = 3.14 |
207 |
}); |
208 |
|
209 |
runScript({ |
210 |
.code = R"NKSP_CODE( |
211 |
on init |
212 |
declare $foo := 1 |
213 |
if ($foo) |
214 |
exit(3.14) |
215 |
end if |
216 |
end on |
217 |
)NKSP_CODE", |
218 |
.expectRealExitResult = 3.14 |
219 |
}); |
220 |
|
221 |
runScript({ |
222 |
.code = R"NKSP_CODE( |
223 |
on init |
224 |
declare $foo := 0 |
225 |
if ($foo) |
226 |
exit(3.14) |
227 |
end if |
228 |
exit(6.9) |
229 |
end on |
230 |
)NKSP_CODE", |
231 |
.expectRealExitResult = 6.9 |
232 |
}); |
233 |
|
234 |
#if !SILENT_TEST |
235 |
std::cout << std::endl; |
236 |
#endif |
237 |
} |
238 |
|
239 |
static void testStringConcatOperator() { |
240 |
#if !SILENT_TEST |
241 |
std::cout << "UNIT TEST: string concatenation (&) operator\n"; |
242 |
#endif |
243 |
|
244 |
runScript({ |
245 |
.code = R"NKSP_CODE( |
246 |
on init |
247 |
declare @s := "foo" & " bar" |
248 |
exit(@s) |
249 |
end on |
250 |
)NKSP_CODE", |
251 |
.expectStringExitResult = "foo bar" |
252 |
}); |
253 |
|
254 |
runScript({ |
255 |
.code = R"NKSP_CODE( |
256 |
on init |
257 |
declare @s := "foo" & " bar" & " " & 123 |
258 |
exit(@s) |
259 |
end on |
260 |
)NKSP_CODE", |
261 |
.expectStringExitResult = "foo bar 123" |
262 |
}); |
263 |
|
264 |
runScript({ |
265 |
.code = R"NKSP_CODE( |
266 |
on init |
267 |
declare $i := 123 |
268 |
declare @s := "foo" & " bar" & " " & $i |
269 |
exit(@s) |
270 |
end on |
271 |
)NKSP_CODE", |
272 |
.expectStringExitResult = "foo bar 123" |
273 |
}); |
274 |
|
275 |
#if !SILENT_TEST |
276 |
std::cout << std::endl; |
277 |
#endif |
278 |
} |
279 |
|
280 |
static void testNegOperator() { |
281 |
#if !SILENT_TEST |
282 |
std::cout << "UNIT TEST: negate (-) operator\n"; |
283 |
#endif |
284 |
|
285 |
// integer tests ... |
286 |
|
287 |
runScript({ |
288 |
.code = R"NKSP_CODE( |
289 |
on init |
290 |
exit(-87) |
291 |
end on |
292 |
)NKSP_CODE", |
293 |
.expectIntExitResult = -87 |
294 |
}); |
295 |
|
296 |
runScript({ |
297 |
.code = R"NKSP_CODE( |
298 |
on init |
299 |
declare $foo := -87 |
300 |
exit(-$foo) |
301 |
end on |
302 |
)NKSP_CODE", |
303 |
.expectIntExitResult = 87 |
304 |
}); |
305 |
|
306 |
// real number tests ... |
307 |
|
308 |
runScript({ |
309 |
.code = R"NKSP_CODE( |
310 |
on init |
311 |
exit(-99.3) |
312 |
end on |
313 |
)NKSP_CODE", |
314 |
.expectRealExitResult = -99.3 |
315 |
}); |
316 |
|
317 |
runScript({ |
318 |
.code = R"NKSP_CODE( |
319 |
on init |
320 |
declare ~foo := -99.3 |
321 |
exit(-~foo) |
322 |
end on |
323 |
)NKSP_CODE", |
324 |
.expectRealExitResult = 99.3 |
325 |
}); |
326 |
|
327 |
#if !SILENT_TEST |
328 |
std::cout << std::endl; |
329 |
#endif |
330 |
} |
331 |
|
332 |
static void testPlusOperator() { |
333 |
#if !SILENT_TEST |
334 |
std::cout << "UNIT TEST: plus (+) operator\n"; |
335 |
#endif |
336 |
|
337 |
// integer tests ... |
338 |
|
339 |
runScript({ |
340 |
.code = R"NKSP_CODE( |
341 |
on init |
342 |
exit(4 + 3) |
343 |
end on |
344 |
)NKSP_CODE", |
345 |
.expectIntExitResult = 7 |
346 |
}); |
347 |
|
348 |
runScript({ |
349 |
.code = R"NKSP_CODE( |
350 |
on init |
351 |
exit(42 + 145) |
352 |
end on |
353 |
)NKSP_CODE", |
354 |
.expectIntExitResult = 187 |
355 |
}); |
356 |
|
357 |
runScript({ |
358 |
.code = R"NKSP_CODE( |
359 |
on init |
360 |
exit(-4 + 2) |
361 |
end on |
362 |
)NKSP_CODE", |
363 |
.expectIntExitResult = -2 |
364 |
}); |
365 |
|
366 |
// real number tests ... |
367 |
|
368 |
runScript({ |
369 |
.code = R"NKSP_CODE( |
370 |
on init |
371 |
exit(4.0 + 3.0) |
372 |
end on |
373 |
)NKSP_CODE", |
374 |
.expectRealExitResult = 7.0 |
375 |
}); |
376 |
|
377 |
runScript({ |
378 |
.code = R"NKSP_CODE( |
379 |
on init |
380 |
exit(42.3 + 145.2) |
381 |
end on |
382 |
)NKSP_CODE", |
383 |
.expectRealExitResult = 187.5 |
384 |
}); |
385 |
|
386 |
runScript({ |
387 |
.code = R"NKSP_CODE( |
388 |
on init |
389 |
exit(-4.0 + 2.2) |
390 |
end on |
391 |
)NKSP_CODE", |
392 |
.expectRealExitResult = -1.8 |
393 |
}); |
394 |
|
395 |
#if !SILENT_TEST |
396 |
std::cout << std::endl; |
397 |
#endif |
398 |
} |
399 |
|
400 |
static void testMinusOperator() { |
401 |
#if !SILENT_TEST |
402 |
std::cout << "UNIT TEST: minus (-) operator\n"; |
403 |
#endif |
404 |
|
405 |
// integer tests ... |
406 |
|
407 |
runScript({ |
408 |
.code = R"NKSP_CODE( |
409 |
on init |
410 |
exit(4 - 3) |
411 |
end on |
412 |
)NKSP_CODE", |
413 |
.expectIntExitResult = 1 |
414 |
}); |
415 |
|
416 |
runScript({ |
417 |
.code = R"NKSP_CODE( |
418 |
on init |
419 |
exit(139 - 74) |
420 |
end on |
421 |
)NKSP_CODE", |
422 |
.expectIntExitResult = 65 |
423 |
}); |
424 |
|
425 |
runScript({ |
426 |
.code = R"NKSP_CODE( |
427 |
on init |
428 |
exit(3 - 9) |
429 |
end on |
430 |
)NKSP_CODE", |
431 |
.expectIntExitResult = -6 |
432 |
}); |
433 |
|
434 |
runScript({ |
435 |
.code = R"NKSP_CODE( |
436 |
on init |
437 |
exit(-3 - 18) |
438 |
end on |
439 |
)NKSP_CODE", |
440 |
.expectIntExitResult = -21 |
441 |
}); |
442 |
|
443 |
// real number tests ... |
444 |
|
445 |
runScript({ |
446 |
.code = R"NKSP_CODE( |
447 |
on init |
448 |
exit(4.0 - 0.2) |
449 |
end on |
450 |
)NKSP_CODE", |
451 |
.expectRealExitResult = 3.8 |
452 |
}); |
453 |
|
454 |
runScript({ |
455 |
.code = R"NKSP_CODE( |
456 |
on init |
457 |
exit(3.1 - 9.65) |
458 |
end on |
459 |
)NKSP_CODE", |
460 |
.expectRealExitResult = -6.55 |
461 |
}); |
462 |
|
463 |
runScript({ |
464 |
.code = R"NKSP_CODE( |
465 |
on init |
466 |
exit(-3.0 - 18.1) |
467 |
end on |
468 |
)NKSP_CODE", |
469 |
.expectRealExitResult = -21.1 |
470 |
}); |
471 |
|
472 |
#if !SILENT_TEST |
473 |
std::cout << std::endl; |
474 |
#endif |
475 |
} |
476 |
|
477 |
static void testModuloOperator() { |
478 |
#if !SILENT_TEST |
479 |
std::cout << "UNIT TEST: modulo (mod) operator\n"; |
480 |
#endif |
481 |
|
482 |
// integer tests ... |
483 |
|
484 |
runScript({ |
485 |
.code = R"NKSP_CODE( |
486 |
on init |
487 |
exit(10 mod 8) |
488 |
end on |
489 |
)NKSP_CODE", |
490 |
.expectIntExitResult = 2 |
491 |
}); |
492 |
|
493 |
runScript({ |
494 |
.code = R"NKSP_CODE( |
495 |
on init |
496 |
declare $a := 10 |
497 |
declare $b := 8 |
498 |
exit($a mod $b) |
499 |
end on |
500 |
)NKSP_CODE", |
501 |
.expectIntExitResult = 2 |
502 |
}); |
503 |
|
504 |
// real number tests ... |
505 |
// (mod operator prohibits real numbers ATM) |
506 |
|
507 |
runScript({ |
508 |
.code = R"NKSP_CODE( |
509 |
on init |
510 |
exit(10.0 mod 8.0) |
511 |
end on |
512 |
)NKSP_CODE", |
513 |
.expectParseError = true // mod operator prohibits real numbers ATM |
514 |
}); |
515 |
|
516 |
runScript({ |
517 |
.code = R"NKSP_CODE( |
518 |
on init |
519 |
exit(10 mod 8.0) |
520 |
end on |
521 |
)NKSP_CODE", |
522 |
.expectParseError = true // mod operator prohibits real numbers ATM |
523 |
}); |
524 |
|
525 |
runScript({ |
526 |
.code = R"NKSP_CODE( |
527 |
on init |
528 |
exit(10.0 mod 8) |
529 |
end on |
530 |
)NKSP_CODE", |
531 |
.expectParseError = true // mod operator prohibits real numbers ATM |
532 |
}); |
533 |
|
534 |
runScript({ |
535 |
.code = R"NKSP_CODE( |
536 |
on init |
537 |
declare ~a := 10.0 |
538 |
declare ~b := 8.0 |
539 |
exit(~a mod ~b) |
540 |
end on |
541 |
)NKSP_CODE", |
542 |
.expectParseError = true // mod operator prohibits real numbers ATM |
543 |
}); |
544 |
|
545 |
#if !SILENT_TEST |
546 |
std::cout << std::endl; |
547 |
#endif |
548 |
} |
549 |
|
550 |
static void testMultiplyOperator() { |
551 |
#if !SILENT_TEST |
552 |
std::cout << "UNIT TEST: multiply (*) operator\n"; |
553 |
#endif |
554 |
|
555 |
// integer tests ... |
556 |
|
557 |
runScript({ |
558 |
.code = R"NKSP_CODE( |
559 |
on init |
560 |
exit(10 * 8) |
561 |
end on |
562 |
)NKSP_CODE", |
563 |
.expectIntExitResult = 80 |
564 |
}); |
565 |
|
566 |
runScript({ |
567 |
.code = R"NKSP_CODE( |
568 |
on init |
569 |
exit(-3 * -4) |
570 |
end on |
571 |
)NKSP_CODE", |
572 |
.expectIntExitResult = 12 |
573 |
}); |
574 |
|
575 |
runScript({ |
576 |
.code = R"NKSP_CODE( |
577 |
on init |
578 |
exit(-52 * 63) |
579 |
end on |
580 |
)NKSP_CODE", |
581 |
.expectIntExitResult = -3276 |
582 |
}); |
583 |
|
584 |
runScript({ |
585 |
.code = R"NKSP_CODE( |
586 |
on init |
587 |
exit(123 * -59) |
588 |
end on |
589 |
)NKSP_CODE", |
590 |
.expectIntExitResult = -7257 |
591 |
}); |
592 |
|
593 |
// real number tests ... |
594 |
|
595 |
runScript({ |
596 |
.code = R"NKSP_CODE( |
597 |
on init |
598 |
exit(10.2 * 8.4) |
599 |
end on |
600 |
)NKSP_CODE", |
601 |
.expectRealExitResult = 85.68 |
602 |
}); |
603 |
|
604 |
runScript({ |
605 |
.code = R"NKSP_CODE( |
606 |
on init |
607 |
exit(10.0 * -3.33) |
608 |
end on |
609 |
)NKSP_CODE", |
610 |
.expectRealExitResult = -33.3 |
611 |
}); |
612 |
|
613 |
runScript({ |
614 |
.code = R"NKSP_CODE( |
615 |
on init |
616 |
exit(-3.33 * 10.0) |
617 |
end on |
618 |
)NKSP_CODE", |
619 |
.expectRealExitResult = -33.3 |
620 |
}); |
621 |
|
622 |
runScript({ |
623 |
.code = R"NKSP_CODE( |
624 |
on init |
625 |
exit(-3.33 * -10.0) |
626 |
end on |
627 |
)NKSP_CODE", |
628 |
.expectRealExitResult = 33.3 |
629 |
}); |
630 |
|
631 |
// mixed type tests ... |
632 |
// (mixed int * real forbidden ATM) |
633 |
|
634 |
runScript({ |
635 |
.code = R"NKSP_CODE( |
636 |
on init |
637 |
exit(2 * 3.0) |
638 |
end on |
639 |
)NKSP_CODE", |
640 |
.expectParseError = true // mixed int * real forbidden ATM |
641 |
}); |
642 |
|
643 |
runScript({ |
644 |
.code = R"NKSP_CODE( |
645 |
on init |
646 |
exit(2.0 * 3) |
647 |
end on |
648 |
)NKSP_CODE", |
649 |
.expectParseError = true // mixed int * real forbidden ATM |
650 |
}); |
651 |
|
652 |
#if !SILENT_TEST |
653 |
std::cout << std::endl; |
654 |
#endif |
655 |
} |
656 |
|
657 |
static void testDivideOperator() { |
658 |
#if !SILENT_TEST |
659 |
std::cout << "UNIT TEST: divide (/) operator\n"; |
660 |
#endif |
661 |
|
662 |
// integer tests ... |
663 |
|
664 |
runScript({ |
665 |
.code = R"NKSP_CODE( |
666 |
on init |
667 |
exit(9 / 3) |
668 |
end on |
669 |
)NKSP_CODE", |
670 |
.expectIntExitResult = 3 |
671 |
}); |
672 |
|
673 |
runScript({ |
674 |
.code = R"NKSP_CODE( |
675 |
on init |
676 |
exit(-27 / 3) |
677 |
end on |
678 |
)NKSP_CODE", |
679 |
.expectIntExitResult = -9 |
680 |
}); |
681 |
|
682 |
runScript({ |
683 |
.code = R"NKSP_CODE( |
684 |
on init |
685 |
exit(35 / -5) |
686 |
end on |
687 |
)NKSP_CODE", |
688 |
.expectIntExitResult = -7 |
689 |
}); |
690 |
|
691 |
runScript({ |
692 |
.code = R"NKSP_CODE( |
693 |
on init |
694 |
exit(39 / -5) |
695 |
end on |
696 |
)NKSP_CODE", |
697 |
.expectIntExitResult = -7 |
698 |
}); |
699 |
|
700 |
// real number tests ... |
701 |
|
702 |
runScript({ |
703 |
.code = R"NKSP_CODE( |
704 |
on init |
705 |
exit(9.0 / 10.0) |
706 |
end on |
707 |
)NKSP_CODE", |
708 |
.expectRealExitResult = 0.9 |
709 |
}); |
710 |
|
711 |
runScript({ |
712 |
.code = R"NKSP_CODE( |
713 |
on init |
714 |
exit(-9.0 / 10.0) |
715 |
end on |
716 |
)NKSP_CODE", |
717 |
.expectRealExitResult = -0.9 |
718 |
}); |
719 |
|
720 |
runScript({ |
721 |
.code = R"NKSP_CODE( |
722 |
on init |
723 |
exit(9.0 / -10.0) |
724 |
end on |
725 |
)NKSP_CODE", |
726 |
.expectRealExitResult = -0.9 |
727 |
}); |
728 |
|
729 |
runScript({ |
730 |
.code = R"NKSP_CODE( |
731 |
on init |
732 |
exit(-9.0 / -10.0) |
733 |
end on |
734 |
)NKSP_CODE", |
735 |
.expectRealExitResult = 0.9 |
736 |
}); |
737 |
|
738 |
// mixed type tests ... |
739 |
// (mixed int / real forbidden ATM) |
740 |
|
741 |
runScript({ |
742 |
.code = R"NKSP_CODE( |
743 |
on init |
744 |
exit(9 / 10.0) |
745 |
end on |
746 |
)NKSP_CODE", |
747 |
.expectParseError = true // mixed int / real forbidden ATM |
748 |
}); |
749 |
|
750 |
runScript({ |
751 |
.code = R"NKSP_CODE( |
752 |
on init |
753 |
exit(9.0 / 10) |
754 |
end on |
755 |
)NKSP_CODE", |
756 |
.expectParseError = true // mixed int / real forbidden ATM |
757 |
}); |
758 |
|
759 |
#if !SILENT_TEST |
760 |
std::cout << std::endl; |
761 |
#endif |
762 |
} |
763 |
|
764 |
static void testSmallerThanOperator() { |
765 |
#if !SILENT_TEST |
766 |
std::cout << "UNIT TEST: smaller than (<) operator\n"; |
767 |
#endif |
768 |
|
769 |
// integer tests ... |
770 |
|
771 |
runScript({ |
772 |
.code = R"NKSP_CODE( |
773 |
on init |
774 |
exit(3 < 4) |
775 |
end on |
776 |
)NKSP_CODE", |
777 |
.expectBoolExitResult = true |
778 |
}); |
779 |
|
780 |
runScript({ |
781 |
.code = R"NKSP_CODE( |
782 |
on init |
783 |
exit(4 < 3) |
784 |
end on |
785 |
)NKSP_CODE", |
786 |
.expectBoolExitResult = false |
787 |
}); |
788 |
|
789 |
runScript({ |
790 |
.code = R"NKSP_CODE( |
791 |
on init |
792 |
exit(-4 < 3) |
793 |
end on |
794 |
)NKSP_CODE", |
795 |
.expectBoolExitResult = true |
796 |
}); |
797 |
|
798 |
runScript({ |
799 |
.code = R"NKSP_CODE( |
800 |
on init |
801 |
exit(3 < -4) |
802 |
end on |
803 |
)NKSP_CODE", |
804 |
.expectBoolExitResult = false |
805 |
}); |
806 |
|
807 |
runScript({ |
808 |
.code = R"NKSP_CODE( |
809 |
on init |
810 |
exit(123 < -45) |
811 |
end on |
812 |
)NKSP_CODE", |
813 |
.expectBoolExitResult = false |
814 |
}); |
815 |
|
816 |
runScript({ |
817 |
.code = R"NKSP_CODE( |
818 |
on init |
819 |
exit(-45 < 123) |
820 |
end on |
821 |
)NKSP_CODE", |
822 |
.expectBoolExitResult = true |
823 |
}); |
824 |
|
825 |
// real number tests ... |
826 |
|
827 |
runScript({ |
828 |
.code = R"NKSP_CODE( |
829 |
on init |
830 |
exit(3.0 < 4.0) |
831 |
end on |
832 |
)NKSP_CODE", |
833 |
.expectBoolExitResult = true |
834 |
}); |
835 |
|
836 |
runScript({ |
837 |
.code = R"NKSP_CODE( |
838 |
on init |
839 |
exit(4.0 < 3.0) |
840 |
end on |
841 |
)NKSP_CODE", |
842 |
.expectBoolExitResult = false |
843 |
}); |
844 |
|
845 |
runScript({ |
846 |
.code = R"NKSP_CODE( |
847 |
on init |
848 |
exit(1.2 < 1.23) |
849 |
end on |
850 |
)NKSP_CODE", |
851 |
.expectBoolExitResult = true |
852 |
}); |
853 |
|
854 |
runScript({ |
855 |
.code = R"NKSP_CODE( |
856 |
on init |
857 |
exit(1.23 < 1.2) |
858 |
end on |
859 |
)NKSP_CODE", |
860 |
.expectBoolExitResult = false |
861 |
}); |
862 |
|
863 |
runScript({ |
864 |
.code = R"NKSP_CODE( |
865 |
on init |
866 |
exit(-4.0 < 3.0) |
867 |
end on |
868 |
)NKSP_CODE", |
869 |
.expectBoolExitResult = true |
870 |
}); |
871 |
|
872 |
runScript({ |
873 |
.code = R"NKSP_CODE( |
874 |
on init |
875 |
exit(3.0 < -4.0) |
876 |
end on |
877 |
)NKSP_CODE", |
878 |
.expectBoolExitResult = false |
879 |
}); |
880 |
|
881 |
runScript({ |
882 |
.code = R"NKSP_CODE( |
883 |
on init |
884 |
exit(123.0 < -45.0) |
885 |
end on |
886 |
)NKSP_CODE", |
887 |
.expectBoolExitResult = false |
888 |
}); |
889 |
|
890 |
runScript({ |
891 |
.code = R"NKSP_CODE( |
892 |
on init |
893 |
exit(-45.0 < 123.0) |
894 |
end on |
895 |
)NKSP_CODE", |
896 |
.expectBoolExitResult = true |
897 |
}); |
898 |
|
899 |
// mixed type tests ... |
900 |
|
901 |
runScript({ |
902 |
.code = R"NKSP_CODE( |
903 |
on init |
904 |
exit(9 < 9.1) |
905 |
end on |
906 |
)NKSP_CODE", |
907 |
.expectBoolExitResult = true |
908 |
}); |
909 |
|
910 |
runScript({ |
911 |
.code = R"NKSP_CODE( |
912 |
on init |
913 |
exit(9.1 < 9) |
914 |
end on |
915 |
)NKSP_CODE", |
916 |
.expectBoolExitResult = false |
917 |
}); |
918 |
|
919 |
#if !SILENT_TEST |
920 |
std::cout << std::endl; |
921 |
#endif |
922 |
} |
923 |
|
924 |
static void testGreaterThanOperator() { |
925 |
#if !SILENT_TEST |
926 |
std::cout << "UNIT TEST: greater than (>) operator\n"; |
927 |
#endif |
928 |
|
929 |
// integer tests ... |
930 |
|
931 |
runScript({ |
932 |
.code = R"NKSP_CODE( |
933 |
on init |
934 |
exit(3 > 4) |
935 |
end on |
936 |
)NKSP_CODE", |
937 |
.expectBoolExitResult = false |
938 |
}); |
939 |
|
940 |
runScript({ |
941 |
.code = R"NKSP_CODE( |
942 |
on init |
943 |
exit(4 > 3) |
944 |
end on |
945 |
)NKSP_CODE", |
946 |
.expectBoolExitResult = true |
947 |
}); |
948 |
|
949 |
runScript({ |
950 |
.code = R"NKSP_CODE( |
951 |
on init |
952 |
exit(-4 > 3) |
953 |
end on |
954 |
)NKSP_CODE", |
955 |
.expectBoolExitResult = false |
956 |
}); |
957 |
|
958 |
runScript({ |
959 |
.code = R"NKSP_CODE( |
960 |
on init |
961 |
exit(3 > -4) |
962 |
end on |
963 |
)NKSP_CODE", |
964 |
.expectBoolExitResult = true |
965 |
}); |
966 |
|
967 |
runScript({ |
968 |
.code = R"NKSP_CODE( |
969 |
on init |
970 |
exit(123 > -45) |
971 |
end on |
972 |
)NKSP_CODE", |
973 |
.expectBoolExitResult = true |
974 |
}); |
975 |
|
976 |
runScript({ |
977 |
.code = R"NKSP_CODE( |
978 |
on init |
979 |
exit(-45 > 123) |
980 |
end on |
981 |
)NKSP_CODE", |
982 |
.expectBoolExitResult = false |
983 |
}); |
984 |
|
985 |
// real number tests ... |
986 |
|
987 |
runScript({ |
988 |
.code = R"NKSP_CODE( |
989 |
on init |
990 |
exit(3.0 > 4.0) |
991 |
end on |
992 |
)NKSP_CODE", |
993 |
.expectBoolExitResult = false |
994 |
}); |
995 |
|
996 |
runScript({ |
997 |
.code = R"NKSP_CODE( |
998 |
on init |
999 |
exit(4.0 > 3.0) |
1000 |
end on |
1001 |
)NKSP_CODE", |
1002 |
.expectBoolExitResult = true |
1003 |
}); |
1004 |
|
1005 |
runScript({ |
1006 |
.code = R"NKSP_CODE( |
1007 |
on init |
1008 |
exit(1.2 > 1.23) |
1009 |
end on |
1010 |
)NKSP_CODE", |
1011 |
.expectBoolExitResult = false |
1012 |
}); |
1013 |
|
1014 |
runScript({ |
1015 |
.code = R"NKSP_CODE( |
1016 |
on init |
1017 |
exit(1.23 > 1.2) |
1018 |
end on |
1019 |
)NKSP_CODE", |
1020 |
.expectBoolExitResult = true |
1021 |
}); |
1022 |
|
1023 |
runScript({ |
1024 |
.code = R"NKSP_CODE( |
1025 |
on init |
1026 |
exit(-4.0 > 3.0) |
1027 |
end on |
1028 |
)NKSP_CODE", |
1029 |
.expectBoolExitResult = false |
1030 |
}); |
1031 |
|
1032 |
runScript({ |
1033 |
.code = R"NKSP_CODE( |
1034 |
on init |
1035 |
exit(3.0 > -4.0) |
1036 |
end on |
1037 |
)NKSP_CODE", |
1038 |
.expectBoolExitResult = true |
1039 |
}); |
1040 |
|
1041 |
runScript({ |
1042 |
.code = R"NKSP_CODE( |
1043 |
on init |
1044 |
exit(123.0 > -45.0) |
1045 |
end on |
1046 |
)NKSP_CODE", |
1047 |
.expectBoolExitResult = true |
1048 |
}); |
1049 |
|
1050 |
runScript({ |
1051 |
.code = R"NKSP_CODE( |
1052 |
on init |
1053 |
exit(-45.0 > 123.0) |
1054 |
end on |
1055 |
)NKSP_CODE", |
1056 |
.expectBoolExitResult = false |
1057 |
}); |
1058 |
|
1059 |
// mixed type tests ... |
1060 |
|
1061 |
runScript({ |
1062 |
.code = R"NKSP_CODE( |
1063 |
on init |
1064 |
exit(9 > 9.1) |
1065 |
end on |
1066 |
)NKSP_CODE", |
1067 |
.expectBoolExitResult = false |
1068 |
}); |
1069 |
|
1070 |
runScript({ |
1071 |
.code = R"NKSP_CODE( |
1072 |
on init |
1073 |
exit(9.1 > 9) |
1074 |
end on |
1075 |
)NKSP_CODE", |
1076 |
.expectBoolExitResult = true |
1077 |
}); |
1078 |
|
1079 |
#if !SILENT_TEST |
1080 |
std::cout << std::endl; |
1081 |
#endif |
1082 |
} |
1083 |
|
1084 |
static void testSmallerOrEqualOperator() { |
1085 |
#if !SILENT_TEST |
1086 |
std::cout << "UNIT TEST: smaller-or-equal (<=) operator\n"; |
1087 |
#endif |
1088 |
|
1089 |
// integer tests ... |
1090 |
|
1091 |
runScript({ |
1092 |
.code = R"NKSP_CODE( |
1093 |
on init |
1094 |
exit(3 <= 3) |
1095 |
end on |
1096 |
)NKSP_CODE", |
1097 |
.expectBoolExitResult = true |
1098 |
}); |
1099 |
|
1100 |
runScript({ |
1101 |
.code = R"NKSP_CODE( |
1102 |
on init |
1103 |
exit(4 <= 4) |
1104 |
end on |
1105 |
)NKSP_CODE", |
1106 |
.expectBoolExitResult = true |
1107 |
}); |
1108 |
|
1109 |
runScript({ |
1110 |
.code = R"NKSP_CODE( |
1111 |
on init |
1112 |
exit(-23 <= -23) |
1113 |
end on |
1114 |
)NKSP_CODE", |
1115 |
.expectBoolExitResult = true |
1116 |
}); |
1117 |
|
1118 |
runScript({ |
1119 |
.code = R"NKSP_CODE( |
1120 |
on init |
1121 |
exit(23 <= -23) |
1122 |
end on |
1123 |
)NKSP_CODE", |
1124 |
.expectBoolExitResult = false |
1125 |
}); |
1126 |
|
1127 |
runScript({ |
1128 |
.code = R"NKSP_CODE( |
1129 |
on init |
1130 |
exit(3 <= 4) |
1131 |
end on |
1132 |
)NKSP_CODE", |
1133 |
.expectBoolExitResult = true |
1134 |
}); |
1135 |
|
1136 |
runScript({ |
1137 |
.code = R"NKSP_CODE( |
1138 |
on init |
1139 |
exit(4 <= 3) |
1140 |
end on |
1141 |
)NKSP_CODE", |
1142 |
.expectBoolExitResult = false |
1143 |
}); |
1144 |
|
1145 |
runScript({ |
1146 |
.code = R"NKSP_CODE( |
1147 |
on init |
1148 |
exit(-4 <= 3) |
1149 |
end on |
1150 |
)NKSP_CODE", |
1151 |
.expectBoolExitResult = true |
1152 |
}); |
1153 |
|
1154 |
runScript({ |
1155 |
.code = R"NKSP_CODE( |
1156 |
on init |
1157 |
exit(3 <= -4) |
1158 |
end on |
1159 |
)NKSP_CODE", |
1160 |
.expectBoolExitResult = false |
1161 |
}); |
1162 |
|
1163 |
runScript({ |
1164 |
.code = R"NKSP_CODE( |
1165 |
on init |
1166 |
exit(123 <= -45) |
1167 |
end on |
1168 |
)NKSP_CODE", |
1169 |
.expectBoolExitResult = false |
1170 |
}); |
1171 |
|
1172 |
runScript({ |
1173 |
.code = R"NKSP_CODE( |
1174 |
on init |
1175 |
exit(-45 <= 123) |
1176 |
end on |
1177 |
)NKSP_CODE", |
1178 |
.expectBoolExitResult = true |
1179 |
}); |
1180 |
|
1181 |
// real number tests ... |
1182 |
|
1183 |
runScript({ |
1184 |
.code = R"NKSP_CODE( |
1185 |
on init |
1186 |
exit(3.0 <= 3.0) |
1187 |
end on |
1188 |
)NKSP_CODE", |
1189 |
.expectBoolExitResult = true |
1190 |
}); |
1191 |
|
1192 |
runScript({ |
1193 |
.code = R"NKSP_CODE( |
1194 |
on init |
1195 |
exit(4.33 <= 4.33) |
1196 |
end on |
1197 |
)NKSP_CODE", |
1198 |
.expectBoolExitResult = true |
1199 |
}); |
1200 |
|
1201 |
runScript({ |
1202 |
.code = R"NKSP_CODE( |
1203 |
on init |
1204 |
exit(-23.1 <= -23.1) |
1205 |
end on |
1206 |
)NKSP_CODE", |
1207 |
.expectBoolExitResult = true |
1208 |
}); |
1209 |
|
1210 |
runScript({ |
1211 |
.code = R"NKSP_CODE( |
1212 |
on init |
1213 |
exit(23.3 <= -23.3) |
1214 |
end on |
1215 |
)NKSP_CODE", |
1216 |
.expectBoolExitResult = false |
1217 |
}); |
1218 |
|
1219 |
runScript({ |
1220 |
.code = R"NKSP_CODE( |
1221 |
on init |
1222 |
exit(3.0 <= 4.0) |
1223 |
end on |
1224 |
)NKSP_CODE", |
1225 |
.expectBoolExitResult = true |
1226 |
}); |
1227 |
|
1228 |
runScript({ |
1229 |
.code = R"NKSP_CODE( |
1230 |
on init |
1231 |
exit(4.0 <= 3.0) |
1232 |
end on |
1233 |
)NKSP_CODE", |
1234 |
.expectBoolExitResult = false |
1235 |
}); |
1236 |
|
1237 |
runScript({ |
1238 |
.code = R"NKSP_CODE( |
1239 |
on init |
1240 |
exit(-4.0 <= 3.0) |
1241 |
end on |
1242 |
)NKSP_CODE", |
1243 |
.expectBoolExitResult = true |
1244 |
}); |
1245 |
|
1246 |
runScript({ |
1247 |
.code = R"NKSP_CODE( |
1248 |
on init |
1249 |
exit(3.0 <= -4.0) |
1250 |
end on |
1251 |
)NKSP_CODE", |
1252 |
.expectBoolExitResult = false |
1253 |
}); |
1254 |
|
1255 |
runScript({ |
1256 |
.code = R"NKSP_CODE( |
1257 |
on init |
1258 |
exit(123.0 <= -45.0) |
1259 |
end on |
1260 |
)NKSP_CODE", |
1261 |
.expectBoolExitResult = false |
1262 |
}); |
1263 |
|
1264 |
runScript({ |
1265 |
.code = R"NKSP_CODE( |
1266 |
on init |
1267 |
exit(-45.0 <= 123.0) |
1268 |
end on |
1269 |
)NKSP_CODE", |
1270 |
.expectBoolExitResult = true |
1271 |
}); |
1272 |
|
1273 |
// mixed type tests ... |
1274 |
|
1275 |
runScript({ |
1276 |
.code = R"NKSP_CODE( |
1277 |
on init |
1278 |
exit(9 <= 9.1) |
1279 |
end on |
1280 |
)NKSP_CODE", |
1281 |
.expectBoolExitResult = true |
1282 |
}); |
1283 |
|
1284 |
runScript({ |
1285 |
.code = R"NKSP_CODE( |
1286 |
on init |
1287 |
exit(9.1 <= 9) |
1288 |
end on |
1289 |
)NKSP_CODE", |
1290 |
.expectBoolExitResult = false |
1291 |
}); |
1292 |
|
1293 |
runScript({ |
1294 |
.code = R"NKSP_CODE( |
1295 |
on init |
1296 |
exit(9 <= 9.0) |
1297 |
end on |
1298 |
)NKSP_CODE", |
1299 |
.expectBoolExitResult = true |
1300 |
}); |
1301 |
|
1302 |
runScript({ |
1303 |
.code = R"NKSP_CODE( |
1304 |
on init |
1305 |
exit(9.0 <= 9) |
1306 |
end on |
1307 |
)NKSP_CODE", |
1308 |
.expectBoolExitResult = true |
1309 |
}); |
1310 |
|
1311 |
#if !SILENT_TEST |
1312 |
std::cout << std::endl; |
1313 |
#endif |
1314 |
} |
1315 |
|
1316 |
static void testGreaterOrEqualOperator() { |
1317 |
#if !SILENT_TEST |
1318 |
std::cout << "UNIT TEST: greater-or-equal (>=) operator\n"; |
1319 |
#endif |
1320 |
|
1321 |
// integer tests ... |
1322 |
|
1323 |
runScript({ |
1324 |
.code = R"NKSP_CODE( |
1325 |
on init |
1326 |
exit(3 >= 3) |
1327 |
end on |
1328 |
)NKSP_CODE", |
1329 |
.expectBoolExitResult = true |
1330 |
}); |
1331 |
|
1332 |
runScript({ |
1333 |
.code = R"NKSP_CODE( |
1334 |
on init |
1335 |
exit(4 >= 4) |
1336 |
end on |
1337 |
)NKSP_CODE", |
1338 |
.expectBoolExitResult = true |
1339 |
}); |
1340 |
|
1341 |
runScript({ |
1342 |
.code = R"NKSP_CODE( |
1343 |
on init |
1344 |
exit(-23 >= -23) |
1345 |
end on |
1346 |
)NKSP_CODE", |
1347 |
.expectBoolExitResult = true |
1348 |
}); |
1349 |
|
1350 |
runScript({ |
1351 |
.code = R"NKSP_CODE( |
1352 |
on init |
1353 |
exit(23 >= -23) |
1354 |
end on |
1355 |
)NKSP_CODE", |
1356 |
.expectBoolExitResult = true |
1357 |
}); |
1358 |
|
1359 |
runScript({ |
1360 |
.code = R"NKSP_CODE( |
1361 |
on init |
1362 |
exit(3 >= 4) |
1363 |
end on |
1364 |
)NKSP_CODE", |
1365 |
.expectBoolExitResult = false |
1366 |
}); |
1367 |
|
1368 |
runScript({ |
1369 |
.code = R"NKSP_CODE( |
1370 |
on init |
1371 |
exit(4 >= 3) |
1372 |
end on |
1373 |
)NKSP_CODE", |
1374 |
.expectBoolExitResult = true |
1375 |
}); |
1376 |
|
1377 |
runScript({ |
1378 |
.code = R"NKSP_CODE( |
1379 |
on init |
1380 |
exit(-4 >= 3) |
1381 |
end on |
1382 |
)NKSP_CODE", |
1383 |
.expectBoolExitResult = false |
1384 |
}); |
1385 |
|
1386 |
runScript({ |
1387 |
.code = R"NKSP_CODE( |
1388 |
on init |
1389 |
exit(3 >= -4) |
1390 |
end on |
1391 |
)NKSP_CODE", |
1392 |
.expectBoolExitResult = true |
1393 |
}); |
1394 |
|
1395 |
runScript({ |
1396 |
.code = R"NKSP_CODE( |
1397 |
on init |
1398 |
exit(123 >= -45) |
1399 |
end on |
1400 |
)NKSP_CODE", |
1401 |
.expectBoolExitResult = true |
1402 |
}); |
1403 |
|
1404 |
runScript({ |
1405 |
.code = R"NKSP_CODE( |
1406 |
on init |
1407 |
exit(-45 >= 123) |
1408 |
end on |
1409 |
)NKSP_CODE", |
1410 |
.expectBoolExitResult = false |
1411 |
}); |
1412 |
|
1413 |
// real number tests ... |
1414 |
|
1415 |
runScript({ |
1416 |
.code = R"NKSP_CODE( |
1417 |
on init |
1418 |
exit(3.0 >= 3.0) |
1419 |
end on |
1420 |
)NKSP_CODE", |
1421 |
.expectBoolExitResult = true |
1422 |
}); |
1423 |
|
1424 |
runScript({ |
1425 |
.code = R"NKSP_CODE( |
1426 |
on init |
1427 |
exit(3.1 >= 3.1) |
1428 |
end on |
1429 |
)NKSP_CODE", |
1430 |
.expectBoolExitResult = true |
1431 |
}); |
1432 |
|
1433 |
runScript({ |
1434 |
.code = R"NKSP_CODE( |
1435 |
on init |
1436 |
exit(3.1 >= 3.0) |
1437 |
end on |
1438 |
)NKSP_CODE", |
1439 |
.expectBoolExitResult = true |
1440 |
}); |
1441 |
|
1442 |
runScript({ |
1443 |
.code = R"NKSP_CODE( |
1444 |
on init |
1445 |
exit(3.0 >= 3.1) |
1446 |
end on |
1447 |
)NKSP_CODE", |
1448 |
.expectBoolExitResult = false |
1449 |
}); |
1450 |
|
1451 |
runScript({ |
1452 |
.code = R"NKSP_CODE( |
1453 |
on init |
1454 |
exit(-23.33 >= -23.33) |
1455 |
end on |
1456 |
)NKSP_CODE", |
1457 |
.expectBoolExitResult = true |
1458 |
}); |
1459 |
|
1460 |
runScript({ |
1461 |
.code = R"NKSP_CODE( |
1462 |
on init |
1463 |
exit(23.0 >= -23.0) |
1464 |
end on |
1465 |
)NKSP_CODE", |
1466 |
.expectBoolExitResult = true |
1467 |
}); |
1468 |
|
1469 |
runScript({ |
1470 |
.code = R"NKSP_CODE( |
1471 |
on init |
1472 |
exit(3.0 >= 4.0) |
1473 |
end on |
1474 |
)NKSP_CODE", |
1475 |
.expectBoolExitResult = false |
1476 |
}); |
1477 |
|
1478 |
runScript({ |
1479 |
.code = R"NKSP_CODE( |
1480 |
on init |
1481 |
exit(4.0 >= 3.0) |
1482 |
end on |
1483 |
)NKSP_CODE", |
1484 |
.expectBoolExitResult = true |
1485 |
}); |
1486 |
|
1487 |
runScript({ |
1488 |
.code = R"NKSP_CODE( |
1489 |
on init |
1490 |
exit(-4.0 >= 3.0) |
1491 |
end on |
1492 |
)NKSP_CODE", |
1493 |
.expectBoolExitResult = false |
1494 |
}); |
1495 |
|
1496 |
runScript({ |
1497 |
.code = R"NKSP_CODE( |
1498 |
on init |
1499 |
exit(3.0 >= -4.0) |
1500 |
end on |
1501 |
)NKSP_CODE", |
1502 |
.expectBoolExitResult = true |
1503 |
}); |
1504 |
|
1505 |
runScript({ |
1506 |
.code = R"NKSP_CODE( |
1507 |
on init |
1508 |
exit(123.0 >= -45.0) |
1509 |
end on |
1510 |
)NKSP_CODE", |
1511 |
.expectBoolExitResult = true |
1512 |
}); |
1513 |
|
1514 |
runScript({ |
1515 |
.code = R"NKSP_CODE( |
1516 |
on init |
1517 |
exit(-45.0 >= 123.0) |
1518 |
end on |
1519 |
)NKSP_CODE", |
1520 |
.expectBoolExitResult = false |
1521 |
}); |
1522 |
|
1523 |
// mixed type tests ... |
1524 |
|
1525 |
runScript({ |
1526 |
.code = R"NKSP_CODE( |
1527 |
on init |
1528 |
exit(9 >= 9.1) |
1529 |
end on |
1530 |
)NKSP_CODE", |
1531 |
.expectBoolExitResult = false |
1532 |
}); |
1533 |
|
1534 |
runScript({ |
1535 |
.code = R"NKSP_CODE( |
1536 |
on init |
1537 |
exit(9.1 >= 9) |
1538 |
end on |
1539 |
)NKSP_CODE", |
1540 |
.expectBoolExitResult = true |
1541 |
}); |
1542 |
|
1543 |
runScript({ |
1544 |
.code = R"NKSP_CODE( |
1545 |
on init |
1546 |
exit(9 >= 9.0) |
1547 |
end on |
1548 |
)NKSP_CODE", |
1549 |
.expectBoolExitResult = true |
1550 |
}); |
1551 |
|
1552 |
runScript({ |
1553 |
.code = R"NKSP_CODE( |
1554 |
on init |
1555 |
exit(9.0 >= 9) |
1556 |
end on |
1557 |
)NKSP_CODE", |
1558 |
.expectBoolExitResult = true |
1559 |
}); |
1560 |
|
1561 |
#if !SILENT_TEST |
1562 |
std::cout << std::endl; |
1563 |
#endif |
1564 |
} |
1565 |
|
1566 |
static void testEqualOperator() { |
1567 |
#if !SILENT_TEST |
1568 |
std::cout << "UNIT TEST: equal (=) operator\n"; |
1569 |
#endif |
1570 |
|
1571 |
// integer tests ... |
1572 |
|
1573 |
runScript({ |
1574 |
.code = R"NKSP_CODE( |
1575 |
on init |
1576 |
exit(3 = 3) |
1577 |
end on |
1578 |
)NKSP_CODE", |
1579 |
.expectBoolExitResult = true |
1580 |
}); |
1581 |
|
1582 |
runScript({ |
1583 |
.code = R"NKSP_CODE( |
1584 |
on init |
1585 |
exit(4 = 4) |
1586 |
end on |
1587 |
)NKSP_CODE", |
1588 |
.expectBoolExitResult = true |
1589 |
}); |
1590 |
|
1591 |
runScript({ |
1592 |
.code = R"NKSP_CODE( |
1593 |
on init |
1594 |
exit(3 = 4) |
1595 |
end on |
1596 |
)NKSP_CODE", |
1597 |
.expectBoolExitResult = false |
1598 |
}); |
1599 |
|
1600 |
runScript({ |
1601 |
.code = R"NKSP_CODE( |
1602 |
on init |
1603 |
exit(23 = -23) |
1604 |
end on |
1605 |
)NKSP_CODE", |
1606 |
.expectBoolExitResult = false |
1607 |
}); |
1608 |
|
1609 |
// real number tests ... |
1610 |
|
1611 |
runScript({ |
1612 |
.code = R"NKSP_CODE( |
1613 |
on init |
1614 |
exit(3.0 = 3.0) |
1615 |
end on |
1616 |
)NKSP_CODE", |
1617 |
.expectBoolExitResult = true |
1618 |
}); |
1619 |
|
1620 |
runScript({ |
1621 |
.code = R"NKSP_CODE( |
1622 |
on init |
1623 |
exit(4.33 = 4.33) |
1624 |
end on |
1625 |
)NKSP_CODE", |
1626 |
.expectBoolExitResult = true |
1627 |
}); |
1628 |
|
1629 |
runScript({ |
1630 |
.code = R"NKSP_CODE( |
1631 |
on init |
1632 |
exit(4.31 = 4.35) |
1633 |
end on |
1634 |
)NKSP_CODE", |
1635 |
.expectBoolExitResult = false |
1636 |
}); |
1637 |
|
1638 |
runScript({ |
1639 |
.code = R"NKSP_CODE( |
1640 |
on init |
1641 |
exit(3.0 = 4.0) |
1642 |
end on |
1643 |
)NKSP_CODE", |
1644 |
.expectBoolExitResult = false |
1645 |
}); |
1646 |
|
1647 |
runScript({ |
1648 |
.code = R"NKSP_CODE( |
1649 |
on init |
1650 |
exit(23.0 = -23.0) |
1651 |
end on |
1652 |
)NKSP_CODE", |
1653 |
.expectBoolExitResult = false |
1654 |
}); |
1655 |
|
1656 |
// mixed type tests ... |
1657 |
|
1658 |
runScript({ |
1659 |
.code = R"NKSP_CODE( |
1660 |
on init |
1661 |
exit(23 = 23.0) |
1662 |
end on |
1663 |
)NKSP_CODE", |
1664 |
.expectBoolExitResult = true |
1665 |
}); |
1666 |
|
1667 |
runScript({ |
1668 |
.code = R"NKSP_CODE( |
1669 |
on init |
1670 |
exit(23.0 = 23) |
1671 |
end on |
1672 |
)NKSP_CODE", |
1673 |
.expectBoolExitResult = true |
1674 |
}); |
1675 |
|
1676 |
runScript({ |
1677 |
.code = R"NKSP_CODE( |
1678 |
on init |
1679 |
exit(23 = 23.1) |
1680 |
end on |
1681 |
)NKSP_CODE", |
1682 |
.expectBoolExitResult = false |
1683 |
}); |
1684 |
|
1685 |
runScript({ |
1686 |
.code = R"NKSP_CODE( |
1687 |
on init |
1688 |
exit(23.1 = 23) |
1689 |
end on |
1690 |
)NKSP_CODE", |
1691 |
.expectBoolExitResult = false |
1692 |
}); |
1693 |
|
1694 |
#if !SILENT_TEST |
1695 |
std::cout << std::endl; |
1696 |
#endif |
1697 |
} |
1698 |
|
1699 |
static void testUnequalOperator() { |
1700 |
#if !SILENT_TEST |
1701 |
std::cout << "UNIT TEST: unequal (#) operator\n"; |
1702 |
#endif |
1703 |
|
1704 |
// integer tests ... |
1705 |
|
1706 |
runScript({ |
1707 |
.code = R"NKSP_CODE( |
1708 |
on init |
1709 |
exit(3 # 3) |
1710 |
end on |
1711 |
)NKSP_CODE", |
1712 |
.expectBoolExitResult = false |
1713 |
}); |
1714 |
|
1715 |
runScript({ |
1716 |
.code = R"NKSP_CODE( |
1717 |
on init |
1718 |
exit(4 # 4) |
1719 |
end on |
1720 |
)NKSP_CODE", |
1721 |
.expectBoolExitResult = false |
1722 |
}); |
1723 |
|
1724 |
runScript({ |
1725 |
.code = R"NKSP_CODE( |
1726 |
on init |
1727 |
exit(3 # 4) |
1728 |
end on |
1729 |
)NKSP_CODE", |
1730 |
.expectBoolExitResult = true |
1731 |
}); |
1732 |
|
1733 |
runScript({ |
1734 |
.code = R"NKSP_CODE( |
1735 |
on init |
1736 |
exit(23 # -23) |
1737 |
end on |
1738 |
)NKSP_CODE", |
1739 |
.expectBoolExitResult = true |
1740 |
}); |
1741 |
|
1742 |
// real number tests ... |
1743 |
|
1744 |
runScript({ |
1745 |
.code = R"NKSP_CODE( |
1746 |
on init |
1747 |
exit(3.0 # 3.0) |
1748 |
end on |
1749 |
)NKSP_CODE", |
1750 |
.expectBoolExitResult = false |
1751 |
}); |
1752 |
|
1753 |
runScript({ |
1754 |
.code = R"NKSP_CODE( |
1755 |
on init |
1756 |
exit(3.14 # 3.14) |
1757 |
end on |
1758 |
)NKSP_CODE", |
1759 |
.expectBoolExitResult = false |
1760 |
}); |
1761 |
|
1762 |
runScript({ |
1763 |
.code = R"NKSP_CODE( |
1764 |
on init |
1765 |
exit(3.19 # 3.12) |
1766 |
end on |
1767 |
)NKSP_CODE", |
1768 |
.expectBoolExitResult = true |
1769 |
}); |
1770 |
|
1771 |
runScript({ |
1772 |
.code = R"NKSP_CODE( |
1773 |
on init |
1774 |
exit(23.0 # -23.0) |
1775 |
end on |
1776 |
)NKSP_CODE", |
1777 |
.expectBoolExitResult = true |
1778 |
}); |
1779 |
|
1780 |
// mixed type tests ... |
1781 |
|
1782 |
runScript({ |
1783 |
.code = R"NKSP_CODE( |
1784 |
on init |
1785 |
exit(3 # 3.0) |
1786 |
end on |
1787 |
)NKSP_CODE", |
1788 |
.expectBoolExitResult = false |
1789 |
}); |
1790 |
|
1791 |
runScript({ |
1792 |
.code = R"NKSP_CODE( |
1793 |
on init |
1794 |
exit(3.0 # 3) |
1795 |
end on |
1796 |
)NKSP_CODE", |
1797 |
.expectBoolExitResult = false |
1798 |
}); |
1799 |
|
1800 |
runScript({ |
1801 |
.code = R"NKSP_CODE( |
1802 |
on init |
1803 |
exit(3.1 # 3) |
1804 |
end on |
1805 |
)NKSP_CODE", |
1806 |
.expectBoolExitResult = true |
1807 |
}); |
1808 |
|
1809 |
runScript({ |
1810 |
.code = R"NKSP_CODE( |
1811 |
on init |
1812 |
exit(3 # 3.1) |
1813 |
end on |
1814 |
)NKSP_CODE", |
1815 |
.expectBoolExitResult = true |
1816 |
}); |
1817 |
|
1818 |
#if !SILENT_TEST |
1819 |
std::cout << std::endl; |
1820 |
#endif |
1821 |
} |
1822 |
|
1823 |
static void testLogicalAndOperator() { |
1824 |
#if !SILENT_TEST |
1825 |
std::cout << "UNIT TEST: logical and (and) operator\n"; |
1826 |
#endif |
1827 |
|
1828 |
// integer tests ... |
1829 |
|
1830 |
runScript({ |
1831 |
.code = R"NKSP_CODE( |
1832 |
on init |
1833 |
exit(1 and 1) |
1834 |
end on |
1835 |
)NKSP_CODE", |
1836 |
.expectBoolExitResult = true |
1837 |
}); |
1838 |
|
1839 |
runScript({ |
1840 |
.code = R"NKSP_CODE( |
1841 |
on init |
1842 |
exit(1 and 2) |
1843 |
end on |
1844 |
)NKSP_CODE", |
1845 |
.expectBoolExitResult = true |
1846 |
}); |
1847 |
|
1848 |
runScript({ |
1849 |
.code = R"NKSP_CODE( |
1850 |
on init |
1851 |
exit(1 and 3) |
1852 |
end on |
1853 |
)NKSP_CODE", |
1854 |
.expectBoolExitResult = true |
1855 |
}); |
1856 |
|
1857 |
runScript({ |
1858 |
.code = R"NKSP_CODE( |
1859 |
on init |
1860 |
exit(1 and 0) |
1861 |
end on |
1862 |
)NKSP_CODE", |
1863 |
.expectBoolExitResult = false |
1864 |
}); |
1865 |
|
1866 |
runScript({ |
1867 |
.code = R"NKSP_CODE( |
1868 |
on init |
1869 |
exit(0 and 1) |
1870 |
end on |
1871 |
)NKSP_CODE", |
1872 |
.expectBoolExitResult = false |
1873 |
}); |
1874 |
|
1875 |
runScript({ |
1876 |
.code = R"NKSP_CODE( |
1877 |
on init |
1878 |
exit(0 and 0) |
1879 |
end on |
1880 |
)NKSP_CODE", |
1881 |
.expectBoolExitResult = false |
1882 |
}); |
1883 |
|
1884 |
// real number tests ... |
1885 |
// (not allowed for this operator) |
1886 |
|
1887 |
runScript({ |
1888 |
.code = R"NKSP_CODE( |
1889 |
on init |
1890 |
exit(1.0 and 1.0) |
1891 |
end on |
1892 |
)NKSP_CODE", |
1893 |
.expectParseError = true // real numbers not allowed for this operator |
1894 |
}); |
1895 |
|
1896 |
// mixed type tests ... |
1897 |
// (not allowed for this operator) |
1898 |
|
1899 |
runScript({ |
1900 |
.code = R"NKSP_CODE( |
1901 |
on init |
1902 |
exit(1.0 and 1) |
1903 |
end on |
1904 |
)NKSP_CODE", |
1905 |
.expectParseError = true // real numbers not allowed for this operator |
1906 |
}); |
1907 |
|
1908 |
runScript({ |
1909 |
.code = R"NKSP_CODE( |
1910 |
on init |
1911 |
exit(1 and 1.0) |
1912 |
end on |
1913 |
)NKSP_CODE", |
1914 |
.expectParseError = true // real numbers not allowed for this operator |
1915 |
}); |
1916 |
|
1917 |
#if !SILENT_TEST |
1918 |
std::cout << std::endl; |
1919 |
#endif |
1920 |
} |
1921 |
|
1922 |
static void testLogicalOrOperator() { |
1923 |
#if !SILENT_TEST |
1924 |
std::cout << "UNIT TEST: logical or (or) operator\n"; |
1925 |
#endif |
1926 |
|
1927 |
// integer tests ... |
1928 |
|
1929 |
runScript({ |
1930 |
.code = R"NKSP_CODE( |
1931 |
on init |
1932 |
exit(1 or 1) |
1933 |
end on |
1934 |
)NKSP_CODE", |
1935 |
.expectBoolExitResult = true |
1936 |
}); |
1937 |
|
1938 |
runScript({ |
1939 |
.code = R"NKSP_CODE( |
1940 |
on init |
1941 |
exit(1 or 2) |
1942 |
end on |
1943 |
)NKSP_CODE", |
1944 |
.expectBoolExitResult = true |
1945 |
}); |
1946 |
|
1947 |
runScript({ |
1948 |
.code = R"NKSP_CODE( |
1949 |
on init |
1950 |
exit(1 or 3) |
1951 |
end on |
1952 |
)NKSP_CODE", |
1953 |
.expectBoolExitResult = true |
1954 |
}); |
1955 |
|
1956 |
runScript({ |
1957 |
.code = R"NKSP_CODE( |
1958 |
on init |
1959 |
exit(1 or 0) |
1960 |
end on |
1961 |
)NKSP_CODE", |
1962 |
.expectBoolExitResult = true |
1963 |
}); |
1964 |
|
1965 |
runScript({ |
1966 |
.code = R"NKSP_CODE( |
1967 |
on init |
1968 |
exit(0 or 1) |
1969 |
end on |
1970 |
)NKSP_CODE", |
1971 |
.expectBoolExitResult = true |
1972 |
}); |
1973 |
|
1974 |
runScript({ |
1975 |
.code = R"NKSP_CODE( |
1976 |
on init |
1977 |
exit(0 or 0) |
1978 |
end on |
1979 |
)NKSP_CODE", |
1980 |
.expectBoolExitResult = false |
1981 |
}); |
1982 |
|
1983 |
// real number tests ... |
1984 |
// (not allowed for this operator) |
1985 |
|
1986 |
runScript({ |
1987 |
.code = R"NKSP_CODE( |
1988 |
on init |
1989 |
exit(1.0 or 1.0) |
1990 |
end on |
1991 |
)NKSP_CODE", |
1992 |
.expectParseError = true // real numbers not allowed for this operator |
1993 |
}); |
1994 |
|
1995 |
// mixed type tests ... |
1996 |
// (not allowed for this operator) |
1997 |
|
1998 |
runScript({ |
1999 |
.code = R"NKSP_CODE( |
2000 |
on init |
2001 |
exit(1.0 or 1) |
2002 |
end on |
2003 |
)NKSP_CODE", |
2004 |
.expectParseError = true // real numbers not allowed for this operator |
2005 |
}); |
2006 |
|
2007 |
runScript({ |
2008 |
.code = R"NKSP_CODE( |
2009 |
on init |
2010 |
exit(1 or 1.0) |
2011 |
end on |
2012 |
)NKSP_CODE", |
2013 |
.expectParseError = true // real numbers not allowed for this operator |
2014 |
}); |
2015 |
|
2016 |
#if !SILENT_TEST |
2017 |
std::cout << std::endl; |
2018 |
#endif |
2019 |
} |
2020 |
|
2021 |
static void testLogicalNotOperator() { |
2022 |
#if !SILENT_TEST |
2023 |
std::cout << "UNIT TEST: logical not (not) operator\n"; |
2024 |
#endif |
2025 |
|
2026 |
// integer tests ... |
2027 |
|
2028 |
runScript({ |
2029 |
.code = R"NKSP_CODE( |
2030 |
on init |
2031 |
exit(not 1) |
2032 |
end on |
2033 |
)NKSP_CODE", |
2034 |
.expectBoolExitResult = false |
2035 |
}); |
2036 |
|
2037 |
runScript({ |
2038 |
.code = R"NKSP_CODE( |
2039 |
on init |
2040 |
exit(not 2) |
2041 |
end on |
2042 |
)NKSP_CODE", |
2043 |
.expectBoolExitResult = false |
2044 |
}); |
2045 |
|
2046 |
runScript({ |
2047 |
.code = R"NKSP_CODE( |
2048 |
on init |
2049 |
exit(not 0) |
2050 |
end on |
2051 |
)NKSP_CODE", |
2052 |
.expectBoolExitResult = true |
2053 |
}); |
2054 |
|
2055 |
// real number tests ... |
2056 |
// (not allowed for this operator) |
2057 |
|
2058 |
runScript({ |
2059 |
.code = R"NKSP_CODE( |
2060 |
on init |
2061 |
exit(not 1.0) |
2062 |
end on |
2063 |
)NKSP_CODE", |
2064 |
.expectParseError = true // real numbers not allowed for this operator |
2065 |
}); |
2066 |
|
2067 |
#if !SILENT_TEST |
2068 |
std::cout << std::endl; |
2069 |
#endif |
2070 |
} |
2071 |
|
2072 |
static void testBitwiseAndOperator() { |
2073 |
#if !SILENT_TEST |
2074 |
std::cout << "UNIT TEST: bitwise and (.and.) operator\n"; |
2075 |
#endif |
2076 |
|
2077 |
// integer tests ... |
2078 |
|
2079 |
runScript({ |
2080 |
.code = R"NKSP_CODE( |
2081 |
on init |
2082 |
exit(1 .and. 1) |
2083 |
end on |
2084 |
)NKSP_CODE", |
2085 |
.expectIntExitResult = 1 |
2086 |
}); |
2087 |
|
2088 |
runScript({ |
2089 |
.code = R"NKSP_CODE( |
2090 |
on init |
2091 |
exit(43 .and. 142) |
2092 |
end on |
2093 |
)NKSP_CODE", |
2094 |
.expectIntExitResult = 10 |
2095 |
}); |
2096 |
|
2097 |
// real number tests ... |
2098 |
// (not allowed for this operator) |
2099 |
|
2100 |
runScript({ |
2101 |
.code = R"NKSP_CODE( |
2102 |
on init |
2103 |
exit(1.0 .and. 1.0) |
2104 |
end on |
2105 |
)NKSP_CODE", |
2106 |
.expectParseError = true // real numbers not allowed for this operator |
2107 |
}); |
2108 |
|
2109 |
// mixed type tests ... |
2110 |
// (not allowed for this operator) |
2111 |
|
2112 |
runScript({ |
2113 |
.code = R"NKSP_CODE( |
2114 |
on init |
2115 |
exit(1.0 .and. 1) |
2116 |
end on |
2117 |
)NKSP_CODE", |
2118 |
.expectParseError = true // real numbers not allowed for this operator |
2119 |
}); |
2120 |
|
2121 |
runScript({ |
2122 |
.code = R"NKSP_CODE( |
2123 |
on init |
2124 |
exit(1 .and. 1.0) |
2125 |
end on |
2126 |
)NKSP_CODE", |
2127 |
.expectParseError = true // real numbers not allowed for this operator |
2128 |
}); |
2129 |
|
2130 |
#if !SILENT_TEST |
2131 |
std::cout << std::endl; |
2132 |
#endif |
2133 |
} |
2134 |
|
2135 |
static void testBitwiseOrOperator() { |
2136 |
#if !SILENT_TEST |
2137 |
std::cout << "UNIT TEST: bitwise or (.or.) operator\n"; |
2138 |
#endif |
2139 |
|
2140 |
// integer tests ... |
2141 |
|
2142 |
runScript({ |
2143 |
.code = R"NKSP_CODE( |
2144 |
on init |
2145 |
exit(1 .or. 1) |
2146 |
end on |
2147 |
)NKSP_CODE", |
2148 |
.expectIntExitResult = 1 |
2149 |
}); |
2150 |
|
2151 |
runScript({ |
2152 |
.code = R"NKSP_CODE( |
2153 |
on init |
2154 |
exit(0 .or. 0) |
2155 |
end on |
2156 |
)NKSP_CODE", |
2157 |
.expectIntExitResult = 0 |
2158 |
}); |
2159 |
|
2160 |
runScript({ |
2161 |
.code = R"NKSP_CODE( |
2162 |
on init |
2163 |
exit(43 .or. 142) |
2164 |
end on |
2165 |
)NKSP_CODE", |
2166 |
.expectIntExitResult = 175 |
2167 |
}); |
2168 |
|
2169 |
// real number tests ... |
2170 |
// (not allowed for this operator) |
2171 |
|
2172 |
runScript({ |
2173 |
.code = R"NKSP_CODE( |
2174 |
on init |
2175 |
exit(1.0 .or. 1.0) |
2176 |
end on |
2177 |
)NKSP_CODE", |
2178 |
.expectParseError = true // real numbers not allowed for this operator |
2179 |
}); |
2180 |
|
2181 |
// mixed type tests ... |
2182 |
// (not allowed for this operator) |
2183 |
|
2184 |
runScript({ |
2185 |
.code = R"NKSP_CODE( |
2186 |
on init |
2187 |
exit(1.0 .or. 1) |
2188 |
end on |
2189 |
)NKSP_CODE", |
2190 |
.expectParseError = true // real numbers not allowed for this operator |
2191 |
}); |
2192 |
|
2193 |
runScript({ |
2194 |
.code = R"NKSP_CODE( |
2195 |
on init |
2196 |
exit(1 .or. 1.0) |
2197 |
end on |
2198 |
)NKSP_CODE", |
2199 |
.expectParseError = true // real numbers not allowed for this operator |
2200 |
}); |
2201 |
|
2202 |
#if !SILENT_TEST |
2203 |
std::cout << std::endl; |
2204 |
#endif |
2205 |
} |
2206 |
|
2207 |
static void testBitwiseNotOperator() { |
2208 |
#if !SILENT_TEST |
2209 |
std::cout << "UNIT TEST: bitwise not (.not.) operator\n"; |
2210 |
#endif |
2211 |
|
2212 |
// integer tests ... |
2213 |
|
2214 |
runScript({ |
2215 |
.code = R"NKSP_CODE( |
2216 |
on init |
2217 |
exit(.not. -1) |
2218 |
end on |
2219 |
)NKSP_CODE", |
2220 |
.expectIntExitResult = 0 |
2221 |
}); |
2222 |
|
2223 |
runScript({ |
2224 |
.code = R"NKSP_CODE( |
2225 |
on init |
2226 |
exit(.not. 0) |
2227 |
end on |
2228 |
)NKSP_CODE", |
2229 |
.expectIntExitResult = -1 |
2230 |
}); |
2231 |
|
2232 |
runScript({ |
2233 |
.code = R"NKSP_CODE( |
2234 |
on init |
2235 |
exit(.not. 3) |
2236 |
end on |
2237 |
)NKSP_CODE", |
2238 |
.expectIntExitResult = ssize_t(size_t(-1) << 2) |
2239 |
}); |
2240 |
|
2241 |
// real number tests ... |
2242 |
// (not allowed for this operator) |
2243 |
|
2244 |
runScript({ |
2245 |
.code = R"NKSP_CODE( |
2246 |
on init |
2247 |
exit(.not. 1.0) |
2248 |
end on |
2249 |
)NKSP_CODE", |
2250 |
.expectParseError = true // real numbers not allowed for this operator |
2251 |
}); |
2252 |
|
2253 |
runScript({ |
2254 |
.code = R"NKSP_CODE( |
2255 |
on init |
2256 |
exit(.not. -1.0) |
2257 |
end on |
2258 |
)NKSP_CODE", |
2259 |
.expectParseError = true // real numbers not allowed for this operator |
2260 |
}); |
2261 |
|
2262 |
#if !SILENT_TEST |
2263 |
std::cout << std::endl; |
2264 |
#endif |
2265 |
} |
2266 |
|
2267 |
static void testPrecedenceOfOperators() { |
2268 |
#if !SILENT_TEST |
2269 |
std::cout << "UNIT TEST: precedence of operators\n"; |
2270 |
#endif |
2271 |
|
2272 |
// integer tests ... |
2273 |
|
2274 |
runScript({ |
2275 |
.code = R"NKSP_CODE( |
2276 |
on init |
2277 |
exit(3 + 4 * 2) |
2278 |
end on |
2279 |
)NKSP_CODE", |
2280 |
.expectIntExitResult = 11 |
2281 |
}); |
2282 |
|
2283 |
runScript({ |
2284 |
.code = R"NKSP_CODE( |
2285 |
on init |
2286 |
exit(4 * 2 + 3) |
2287 |
end on |
2288 |
)NKSP_CODE", |
2289 |
.expectIntExitResult = 11 |
2290 |
}); |
2291 |
|
2292 |
runScript({ |
2293 |
.code = R"NKSP_CODE( |
2294 |
on init |
2295 |
exit((3 + 4) * 2) |
2296 |
end on |
2297 |
)NKSP_CODE", |
2298 |
.expectIntExitResult = 14 |
2299 |
}); |
2300 |
|
2301 |
runScript({ |
2302 |
.code = R"NKSP_CODE( |
2303 |
on init |
2304 |
exit(4 * (2 + 3)) |
2305 |
end on |
2306 |
)NKSP_CODE", |
2307 |
.expectIntExitResult = 20 |
2308 |
}); |
2309 |
|
2310 |
// real number tests ... |
2311 |
|
2312 |
runScript({ |
2313 |
.code = R"NKSP_CODE( |
2314 |
on init |
2315 |
exit(3.2 + 4.0 * 2.0) |
2316 |
end on |
2317 |
)NKSP_CODE", |
2318 |
.expectRealExitResult = 11.2 |
2319 |
}); |
2320 |
|
2321 |
runScript({ |
2322 |
.code = R"NKSP_CODE( |
2323 |
on init |
2324 |
exit(4.0 * 2.0 + 3.2) |
2325 |
end on |
2326 |
)NKSP_CODE", |
2327 |
.expectRealExitResult = 11.2 |
2328 |
}); |
2329 |
|
2330 |
runScript({ |
2331 |
.code = R"NKSP_CODE( |
2332 |
on init |
2333 |
exit((3.2 + 4.0) * 2.0) |
2334 |
end on |
2335 |
)NKSP_CODE", |
2336 |
.expectRealExitResult = 14.4 |
2337 |
}); |
2338 |
|
2339 |
runScript({ |
2340 |
.code = R"NKSP_CODE( |
2341 |
on init |
2342 |
exit(4.0 * (2.0 + 3.2)) |
2343 |
end on |
2344 |
)NKSP_CODE", |
2345 |
.expectRealExitResult = 20.8 |
2346 |
}); |
2347 |
|
2348 |
#if !SILENT_TEST |
2349 |
std::cout << std::endl; |
2350 |
#endif |
2351 |
} |
2352 |
|
2353 |
static void testBuiltInMinFunction() { |
2354 |
#if !SILENT_TEST |
2355 |
std::cout << "UNIT TEST: built-in min() function\n"; |
2356 |
#endif |
2357 |
|
2358 |
runScript({ |
2359 |
.code = R"NKSP_CODE( |
2360 |
on init |
2361 |
declare $foo := min |
2362 |
end on |
2363 |
)NKSP_CODE", |
2364 |
.expectParseError = true // because min() function requires 2 arguments |
2365 |
}); |
2366 |
|
2367 |
runScript({ |
2368 |
.code = R"NKSP_CODE( |
2369 |
on init |
2370 |
declare $foo := min() |
2371 |
end on |
2372 |
)NKSP_CODE", |
2373 |
.expectParseError = true // because min() function requires 2 arguments |
2374 |
}); |
2375 |
|
2376 |
runScript({ |
2377 |
.code = R"NKSP_CODE( |
2378 |
on init |
2379 |
declare $foo := min(1) |
2380 |
end on |
2381 |
)NKSP_CODE", |
2382 |
.expectParseError = true // because min() function requires 2 arguments |
2383 |
}); |
2384 |
|
2385 |
// integer tests ... |
2386 |
|
2387 |
runScript({ |
2388 |
.code = R"NKSP_CODE( |
2389 |
on init |
2390 |
declare $foo := min(1,2) |
2391 |
exit($foo) |
2392 |
end on |
2393 |
)NKSP_CODE", |
2394 |
.expectIntExitResult = 1 |
2395 |
}); |
2396 |
|
2397 |
runScript({ |
2398 |
.code = R"NKSP_CODE( |
2399 |
on init |
2400 |
declare $foo := min(-30,4) |
2401 |
exit($foo) |
2402 |
end on |
2403 |
)NKSP_CODE", |
2404 |
.expectIntExitResult = -30 |
2405 |
}); |
2406 |
|
2407 |
// real number tests ... |
2408 |
|
2409 |
runScript({ |
2410 |
.code = R"NKSP_CODE( |
2411 |
on init |
2412 |
declare $foo := min(1.0, 2.0) |
2413 |
exit($foo) |
2414 |
end on |
2415 |
)NKSP_CODE", |
2416 |
.expectRealExitResult = 1.0 |
2417 |
}); |
2418 |
|
2419 |
runScript({ |
2420 |
.code = R"NKSP_CODE( |
2421 |
on init |
2422 |
declare $foo := min(-30.0, 4.0) |
2423 |
exit($foo) |
2424 |
end on |
2425 |
)NKSP_CODE", |
2426 |
.expectRealExitResult = -30.0 |
2427 |
}); |
2428 |
|
2429 |
runScript({ |
2430 |
.code = R"NKSP_CODE( |
2431 |
on init |
2432 |
declare $foo := min(1.1, 1.13) |
2433 |
exit($foo) |
2434 |
end on |
2435 |
)NKSP_CODE", |
2436 |
.expectRealExitResult = 1.1 |
2437 |
}); |
2438 |
|
2439 |
runScript({ |
2440 |
.code = R"NKSP_CODE( |
2441 |
on init |
2442 |
declare $foo := min(1.13, 1.1) |
2443 |
exit($foo) |
2444 |
end on |
2445 |
)NKSP_CODE", |
2446 |
.expectRealExitResult = 1.1 |
2447 |
}); |
2448 |
|
2449 |
// mixed type tests ... |
2450 |
|
2451 |
runScript({ |
2452 |
.code = R"NKSP_CODE( |
2453 |
on init |
2454 |
declare $foo := min(1, 1.16) |
2455 |
exit($foo) |
2456 |
end on |
2457 |
)NKSP_CODE", |
2458 |
.expectRealExitResult = 1.0 |
2459 |
}); |
2460 |
|
2461 |
runScript({ |
2462 |
.code = R"NKSP_CODE( |
2463 |
on init |
2464 |
declare $foo := min(-3.92, 9) |
2465 |
exit($foo) |
2466 |
end on |
2467 |
)NKSP_CODE", |
2468 |
.expectRealExitResult = -3.92 |
2469 |
}); |
2470 |
|
2471 |
#if !SILENT_TEST |
2472 |
std::cout << std::endl; |
2473 |
#endif |
2474 |
} |
2475 |
|
2476 |
static void testBuiltInMaxFunction() { |
2477 |
#if !SILENT_TEST |
2478 |
std::cout << "UNIT TEST: built-in max() function\n"; |
2479 |
#endif |
2480 |
|
2481 |
// integer tests ... |
2482 |
|
2483 |
runScript({ |
2484 |
.code = R"NKSP_CODE( |
2485 |
on init |
2486 |
declare $foo := max |
2487 |
end on |
2488 |
)NKSP_CODE", |
2489 |
.expectParseError = true // because max() function requires 2 arguments |
2490 |
}); |
2491 |
|
2492 |
runScript({ |
2493 |
.code = R"NKSP_CODE( |
2494 |
on init |
2495 |
declare $foo := max() |
2496 |
end on |
2497 |
)NKSP_CODE", |
2498 |
.expectParseError = true // because max() function requires 2 arguments |
2499 |
}); |
2500 |
|
2501 |
runScript({ |
2502 |
.code = R"NKSP_CODE( |
2503 |
on init |
2504 |
declare $foo := max(1) |
2505 |
end on |
2506 |
)NKSP_CODE", |
2507 |
.expectParseError = true // because max() function requires 2 arguments |
2508 |
}); |
2509 |
|
2510 |
runScript({ |
2511 |
.code = R"NKSP_CODE( |
2512 |
on init |
2513 |
declare $foo := max(1,2) |
2514 |
exit($foo) |
2515 |
end on |
2516 |
)NKSP_CODE", |
2517 |
.expectIntExitResult = 2 |
2518 |
}); |
2519 |
|
2520 |
runScript({ |
2521 |
.code = R"NKSP_CODE( |
2522 |
on init |
2523 |
declare $foo := max(-30,4) |
2524 |
exit($foo) |
2525 |
end on |
2526 |
)NKSP_CODE", |
2527 |
.expectIntExitResult = 4 |
2528 |
}); |
2529 |
|
2530 |
// real number tests ... |
2531 |
|
2532 |
runScript({ |
2533 |
.code = R"NKSP_CODE( |
2534 |
on init |
2535 |
declare $foo := max(1.0, 2.0) |
2536 |
exit($foo) |
2537 |
end on |
2538 |
)NKSP_CODE", |
2539 |
.expectRealExitResult = 2.0 |
2540 |
}); |
2541 |
|
2542 |
runScript({ |
2543 |
.code = R"NKSP_CODE( |
2544 |
on init |
2545 |
declare $foo := max(-30.0, 4.0) |
2546 |
exit($foo) |
2547 |
end on |
2548 |
)NKSP_CODE", |
2549 |
.expectRealExitResult = 4.0 |
2550 |
}); |
2551 |
|
2552 |
runScript({ |
2553 |
.code = R"NKSP_CODE( |
2554 |
on init |
2555 |
declare $foo := max(1.1, 1.13) |
2556 |
exit($foo) |
2557 |
end on |
2558 |
)NKSP_CODE", |
2559 |
.expectRealExitResult = 1.13 |
2560 |
}); |
2561 |
|
2562 |
runScript({ |
2563 |
.code = R"NKSP_CODE( |
2564 |
on init |
2565 |
declare $foo := max(1.13, 1.1) |
2566 |
exit($foo) |
2567 |
end on |
2568 |
)NKSP_CODE", |
2569 |
.expectRealExitResult = 1.13 |
2570 |
}); |
2571 |
|
2572 |
// mixed type tests ... |
2573 |
|
2574 |
runScript({ |
2575 |
.code = R"NKSP_CODE( |
2576 |
on init |
2577 |
declare $foo := max(1, 1.16) |
2578 |
exit($foo) |
2579 |
end on |
2580 |
)NKSP_CODE", |
2581 |
.expectRealExitResult = 1.16 |
2582 |
}); |
2583 |
|
2584 |
runScript({ |
2585 |
.code = R"NKSP_CODE( |
2586 |
on init |
2587 |
declare $foo := max(-3.92, 9) |
2588 |
exit($foo) |
2589 |
end on |
2590 |
)NKSP_CODE", |
2591 |
.expectRealExitResult = 9.0 |
2592 |
}); |
2593 |
|
2594 |
#if !SILENT_TEST |
2595 |
std::cout << std::endl; |
2596 |
#endif |
2597 |
} |
2598 |
|
2599 |
static void testBuiltInAbsFunction() { |
2600 |
#if !SILENT_TEST |
2601 |
std::cout << "UNIT TEST: built-in abs() function\n"; |
2602 |
#endif |
2603 |
|
2604 |
runScript({ |
2605 |
.code = R"NKSP_CODE( |
2606 |
on init |
2607 |
declare $foo := abs |
2608 |
end on |
2609 |
)NKSP_CODE", |
2610 |
.expectParseError = true // because abs() function requires 1 argument |
2611 |
}); |
2612 |
|
2613 |
runScript({ |
2614 |
.code = R"NKSP_CODE( |
2615 |
on init |
2616 |
declare $foo := abs() |
2617 |
end on |
2618 |
)NKSP_CODE", |
2619 |
.expectParseError = true // because abs() function requires 1 argument |
2620 |
}); |
2621 |
|
2622 |
// integer tests ... |
2623 |
|
2624 |
runScript({ |
2625 |
.code = R"NKSP_CODE( |
2626 |
on init |
2627 |
declare $foo := abs(23) |
2628 |
exit($foo) |
2629 |
end on |
2630 |
)NKSP_CODE", |
2631 |
.expectIntExitResult = 23 |
2632 |
}); |
2633 |
|
2634 |
runScript({ |
2635 |
.code = R"NKSP_CODE( |
2636 |
on init |
2637 |
declare $foo := abs(-23) |
2638 |
exit($foo) |
2639 |
end on |
2640 |
)NKSP_CODE", |
2641 |
.expectIntExitResult = 23 |
2642 |
}); |
2643 |
|
2644 |
// real number tests ... |
2645 |
|
2646 |
runScript({ |
2647 |
.code = R"NKSP_CODE( |
2648 |
on init |
2649 |
declare ~foo := abs(23.0) |
2650 |
exit(~foo) |
2651 |
end on |
2652 |
)NKSP_CODE", |
2653 |
.expectRealExitResult = 23.0 |
2654 |
}); |
2655 |
|
2656 |
runScript({ |
2657 |
.code = R"NKSP_CODE( |
2658 |
on init |
2659 |
declare ~foo := abs(23.11) |
2660 |
exit(~foo) |
2661 |
end on |
2662 |
)NKSP_CODE", |
2663 |
.expectRealExitResult = 23.11 |
2664 |
}); |
2665 |
|
2666 |
runScript({ |
2667 |
.code = R"NKSP_CODE( |
2668 |
on init |
2669 |
declare ~foo := abs(-23.11) |
2670 |
exit(~foo) |
2671 |
end on |
2672 |
)NKSP_CODE", |
2673 |
.expectRealExitResult = 23.11 |
2674 |
}); |
2675 |
|
2676 |
runScript({ |
2677 |
.code = R"NKSP_CODE( |
2678 |
on init |
2679 |
declare ~bar := -23.11 |
2680 |
declare ~foo := abs(~bar) |
2681 |
exit(~foo) |
2682 |
end on |
2683 |
)NKSP_CODE", |
2684 |
.expectRealExitResult = 23.11 |
2685 |
}); |
2686 |
|
2687 |
#if !SILENT_TEST |
2688 |
std::cout << std::endl; |
2689 |
#endif |
2690 |
} |
2691 |
|
2692 |
static void testBuiltInIncFunction() { |
2693 |
#if !SILENT_TEST |
2694 |
std::cout << "UNIT TEST: built-in inc() function\n"; |
2695 |
#endif |
2696 |
|
2697 |
runScript({ |
2698 |
.code = R"NKSP_CODE( |
2699 |
on init |
2700 |
declare $foo := 5 |
2701 |
inc($foo) |
2702 |
exit($foo) |
2703 |
end on |
2704 |
)NKSP_CODE", |
2705 |
.expectIntExitResult = 6 |
2706 |
}); |
2707 |
|
2708 |
runScript({ |
2709 |
.code = R"NKSP_CODE( |
2710 |
on init |
2711 |
declare $foo := 5 |
2712 |
inc($foo) |
2713 |
inc($foo) |
2714 |
inc($foo) |
2715 |
exit($foo) |
2716 |
end on |
2717 |
)NKSP_CODE", |
2718 |
.expectIntExitResult = 8 |
2719 |
}); |
2720 |
|
2721 |
runScript({ |
2722 |
.code = R"NKSP_CODE( |
2723 |
on init |
2724 |
declare $foo := 5 |
2725 |
inc($foo) |
2726 |
exit( inc($foo) ) |
2727 |
end on |
2728 |
)NKSP_CODE", |
2729 |
.expectIntExitResult = 7 |
2730 |
}); |
2731 |
|
2732 |
#if !SILENT_TEST |
2733 |
std::cout << std::endl; |
2734 |
#endif |
2735 |
} |
2736 |
|
2737 |
static void testBuiltInDecFunction() { |
2738 |
#if !SILENT_TEST |
2739 |
std::cout << "UNIT TEST: built-in dec() function\n"; |
2740 |
#endif |
2741 |
|
2742 |
runScript({ |
2743 |
.code = R"NKSP_CODE( |
2744 |
on init |
2745 |
declare $foo := 5 |
2746 |
dec($foo) |
2747 |
exit($foo) |
2748 |
end on |
2749 |
)NKSP_CODE", |
2750 |
.expectIntExitResult = 4 |
2751 |
}); |
2752 |
|
2753 |
runScript({ |
2754 |
.code = R"NKSP_CODE( |
2755 |
on init |
2756 |
declare $foo := 5 |
2757 |
dec($foo) |
2758 |
dec($foo) |
2759 |
dec($foo) |
2760 |
exit($foo) |
2761 |
end on |
2762 |
)NKSP_CODE", |
2763 |
.expectIntExitResult = 2 |
2764 |
}); |
2765 |
|
2766 |
runScript({ |
2767 |
.code = R"NKSP_CODE( |
2768 |
on init |
2769 |
declare $foo := 5 |
2770 |
dec($foo) |
2771 |
exit( dec($foo) ) |
2772 |
end on |
2773 |
)NKSP_CODE", |
2774 |
.expectIntExitResult = 3 |
2775 |
}); |
2776 |
|
2777 |
#if !SILENT_TEST |
2778 |
std::cout << std::endl; |
2779 |
#endif |
2780 |
} |
2781 |
|
2782 |
static void testBuiltInInRangeFunction() { |
2783 |
#if !SILENT_TEST |
2784 |
std::cout << "UNIT TEST: built-in in_range() function\n"; |
2785 |
#endif |
2786 |
|
2787 |
runScript({ |
2788 |
.code = R"NKSP_CODE( |
2789 |
on init |
2790 |
exit( in_range(1,4,9) ) |
2791 |
end on |
2792 |
)NKSP_CODE", |
2793 |
.expectBoolExitResult = false |
2794 |
}); |
2795 |
|
2796 |
runScript({ |
2797 |
.code = R"NKSP_CODE( |
2798 |
on init |
2799 |
exit( in_range(5,4,9) ) |
2800 |
end on |
2801 |
)NKSP_CODE", |
2802 |
.expectBoolExitResult = true |
2803 |
}); |
2804 |
|
2805 |
runScript({ |
2806 |
.code = R"NKSP_CODE( |
2807 |
on init |
2808 |
exit( in_range(9,4,9) ) |
2809 |
end on |
2810 |
)NKSP_CODE", |
2811 |
.expectBoolExitResult = true |
2812 |
}); |
2813 |
|
2814 |
runScript({ |
2815 |
.code = R"NKSP_CODE( |
2816 |
on init |
2817 |
exit( in_range(10,4,9) ) |
2818 |
end on |
2819 |
)NKSP_CODE", |
2820 |
.expectBoolExitResult = false |
2821 |
}); |
2822 |
|
2823 |
runScript({ |
2824 |
.code = R"NKSP_CODE( |
2825 |
on init |
2826 |
exit( in_range(-6,-5,5) ) |
2827 |
end on |
2828 |
)NKSP_CODE", |
2829 |
.expectBoolExitResult = false |
2830 |
}); |
2831 |
|
2832 |
runScript({ |
2833 |
.code = R"NKSP_CODE( |
2834 |
on init |
2835 |
exit( in_range(-5,-5,5) ) |
2836 |
end on |
2837 |
)NKSP_CODE", |
2838 |
.expectBoolExitResult = true |
2839 |
}); |
2840 |
|
2841 |
runScript({ |
2842 |
.code = R"NKSP_CODE( |
2843 |
on init |
2844 |
exit( in_range(0,-5,5) ) |
2845 |
end on |
2846 |
)NKSP_CODE", |
2847 |
.expectBoolExitResult = true |
2848 |
}); |
2849 |
|
2850 |
runScript({ |
2851 |
.code = R"NKSP_CODE( |
2852 |
on init |
2853 |
exit( in_range(5,-5,5) ) |
2854 |
end on |
2855 |
)NKSP_CODE", |
2856 |
.expectBoolExitResult = true |
2857 |
}); |
2858 |
|
2859 |
runScript({ |
2860 |
.code = R"NKSP_CODE( |
2861 |
on init |
2862 |
exit( in_range(6,-5,5) ) |
2863 |
end on |
2864 |
)NKSP_CODE", |
2865 |
.expectBoolExitResult = false |
2866 |
}); |
2867 |
|
2868 |
#if !SILENT_TEST |
2869 |
std::cout << std::endl; |
2870 |
#endif |
2871 |
} |
2872 |
|
2873 |
static void testBuiltInRandomFunction() { |
2874 |
#if !SILENT_TEST |
2875 |
std::cout << "UNIT TEST: built-in random() function\n"; |
2876 |
#endif |
2877 |
|
2878 |
for (int run = 0; run < 20; ++run) { |
2879 |
runScript({ |
2880 |
.code = R"NKSP_CODE( |
2881 |
on init |
2882 |
declare $foo := random(-5,5) |
2883 |
exit( in_range($foo,-5,5) ) |
2884 |
end on |
2885 |
)NKSP_CODE", |
2886 |
.expectBoolExitResult = true |
2887 |
}); |
2888 |
} |
2889 |
|
2890 |
#if !SILENT_TEST |
2891 |
std::cout << std::endl; |
2892 |
#endif |
2893 |
} |
2894 |
|
2895 |
static void testBuiltInShiftLeftFunction() { |
2896 |
#if !SILENT_TEST |
2897 |
std::cout << "UNIT TEST: built-in sh_left() function\n"; |
2898 |
#endif |
2899 |
|
2900 |
runScript({ |
2901 |
.code = R"NKSP_CODE( |
2902 |
on init |
2903 |
exit( sh_left(1,0) ) |
2904 |
end on |
2905 |
)NKSP_CODE", |
2906 |
.expectIntExitResult = 1 |
2907 |
}); |
2908 |
|
2909 |
runScript({ |
2910 |
.code = R"NKSP_CODE( |
2911 |
on init |
2912 |
exit( sh_left(1,1) ) |
2913 |
end on |
2914 |
)NKSP_CODE", |
2915 |
.expectIntExitResult = 2 |
2916 |
}); |
2917 |
|
2918 |
runScript({ |
2919 |
.code = R"NKSP_CODE( |
2920 |
on init |
2921 |
exit( sh_left(1,2) ) |
2922 |
end on |
2923 |
)NKSP_CODE", |
2924 |
.expectIntExitResult = 4 |
2925 |
}); |
2926 |
|
2927 |
runScript({ |
2928 |
.code = R"NKSP_CODE( |
2929 |
on init |
2930 |
exit( sh_left(1,3) ) |
2931 |
end on |
2932 |
)NKSP_CODE", |
2933 |
.expectIntExitResult = 8 |
2934 |
}); |
2935 |
|
2936 |
#if !SILENT_TEST |
2937 |
std::cout << std::endl; |
2938 |
#endif |
2939 |
} |
2940 |
|
2941 |
static void testBuiltInShiftRightFunction() { |
2942 |
#if !SILENT_TEST |
2943 |
std::cout << "UNIT TEST: built-in sh_right() function\n"; |
2944 |
#endif |
2945 |
|
2946 |
runScript({ |
2947 |
.code = R"NKSP_CODE( |
2948 |
on init |
2949 |
exit( sh_right(8,0) ) |
2950 |
end on |
2951 |
)NKSP_CODE", |
2952 |
.expectIntExitResult = 8 |
2953 |
}); |
2954 |
|
2955 |
runScript({ |
2956 |
.code = R"NKSP_CODE( |
2957 |
on init |
2958 |
exit( sh_right(8,1) ) |
2959 |
end on |
2960 |
)NKSP_CODE", |
2961 |
.expectIntExitResult = 4 |
2962 |
}); |
2963 |
|
2964 |
runScript({ |
2965 |
.code = R"NKSP_CODE( |
2966 |
on init |
2967 |
exit( sh_right(8,2) ) |
2968 |
end on |
2969 |
)NKSP_CODE", |
2970 |
.expectIntExitResult = 2 |
2971 |
}); |
2972 |
|
2973 |
runScript({ |
2974 |
.code = R"NKSP_CODE( |
2975 |
on init |
2976 |
exit( sh_right(8,3) ) |
2977 |
end on |
2978 |
)NKSP_CODE", |
2979 |
.expectIntExitResult = 1 |
2980 |
}); |
2981 |
|
2982 |
runScript({ |
2983 |
.code = R"NKSP_CODE( |
2984 |
on init |
2985 |
exit( sh_right(8,4) ) |
2986 |
end on |
2987 |
)NKSP_CODE", |
2988 |
.expectIntExitResult = 0 |
2989 |
}); |
2990 |
|
2991 |
#if !SILENT_TEST |
2992 |
std::cout << std::endl; |
2993 |
#endif |
2994 |
} |
2995 |
|
2996 |
static void testBuiltInIntToRealFunction() { |
2997 |
#if !SILENT_TEST |
2998 |
std::cout << "UNIT TEST: built-in int_to_real() function\n"; |
2999 |
#endif |
3000 |
|
3001 |
runScript({ |
3002 |
.code = R"NKSP_CODE( |
3003 |
on init |
3004 |
exit( int_to_real(8) ) |
3005 |
end on |
3006 |
)NKSP_CODE", |
3007 |
.expectRealExitResult = 8.0 |
3008 |
}); |
3009 |
|
3010 |
runScript({ |
3011 |
.code = R"NKSP_CODE( |
3012 |
on init |
3013 |
declare $foo := 23 |
3014 |
exit( int_to_real($foo) ) |
3015 |
end on |
3016 |
)NKSP_CODE", |
3017 |
.expectRealExitResult = 23.0 |
3018 |
}); |
3019 |
|
3020 |
#if !SILENT_TEST |
3021 |
std::cout << std::endl; |
3022 |
#endif |
3023 |
} |
3024 |
|
3025 |
static void testBuiltInRealFunction() { |
3026 |
#if !SILENT_TEST |
3027 |
std::cout << "UNIT TEST: built-in real() function\n"; |
3028 |
#endif |
3029 |
|
3030 |
runScript({ |
3031 |
.code = R"NKSP_CODE( |
3032 |
on init |
3033 |
exit( real(8) ) |
3034 |
end on |
3035 |
)NKSP_CODE", |
3036 |
.expectRealExitResult = 8.0 |
3037 |
}); |
3038 |
|
3039 |
runScript({ |
3040 |
.code = R"NKSP_CODE( |
3041 |
on init |
3042 |
declare $foo := 23 |
3043 |
exit( real($foo) ) |
3044 |
end on |
3045 |
)NKSP_CODE", |
3046 |
.expectRealExitResult = 23.0 |
3047 |
}); |
3048 |
|
3049 |
#if !SILENT_TEST |
3050 |
std::cout << std::endl; |
3051 |
#endif |
3052 |
} |
3053 |
|
3054 |
static void testBuiltInRealToIntFunction() { |
3055 |
#if !SILENT_TEST |
3056 |
std::cout << "UNIT TEST: built-in real_to_int() function\n"; |
3057 |
#endif |
3058 |
|
3059 |
runScript({ |
3060 |
.code = R"NKSP_CODE( |
3061 |
on init |
3062 |
exit( real_to_int(8.9) ) |
3063 |
end on |
3064 |
)NKSP_CODE", |
3065 |
.expectIntExitResult = 8 |
3066 |
}); |
3067 |
|
3068 |
runScript({ |
3069 |
.code = R"NKSP_CODE( |
3070 |
on init |
3071 |
declare ~foo := 8.9 |
3072 |
exit( real_to_int(~foo) ) |
3073 |
end on |
3074 |
)NKSP_CODE", |
3075 |
.expectIntExitResult = 8 |
3076 |
}); |
3077 |
|
3078 |
#if !SILENT_TEST |
3079 |
std::cout << std::endl; |
3080 |
#endif |
3081 |
} |
3082 |
|
3083 |
static void testBuiltInIntFunction() { |
3084 |
#if !SILENT_TEST |
3085 |
std::cout << "UNIT TEST: built-in int() function\n"; |
3086 |
#endif |
3087 |
|
3088 |
runScript({ |
3089 |
.code = R"NKSP_CODE( |
3090 |
on init |
3091 |
exit( int(8.9) ) |
3092 |
end on |
3093 |
)NKSP_CODE", |
3094 |
.expectIntExitResult = 8 |
3095 |
}); |
3096 |
|
3097 |
runScript({ |
3098 |
.code = R"NKSP_CODE( |
3099 |
on init |
3100 |
declare ~foo := 8.9 |
3101 |
exit( int(~foo) ) |
3102 |
end on |
3103 |
)NKSP_CODE", |
3104 |
.expectIntExitResult = 8 |
3105 |
}); |
3106 |
|
3107 |
#if !SILENT_TEST |
3108 |
std::cout << std::endl; |
3109 |
#endif |
3110 |
} |
3111 |
|
3112 |
static void testBuiltInArrayEqualFunction() { |
3113 |
#if !SILENT_TEST |
3114 |
std::cout << "UNIT TEST: built-in array_equal() function\n"; |
3115 |
#endif |
3116 |
|
3117 |
runScript({ |
3118 |
.code = R"NKSP_CODE( |
3119 |
on init |
3120 |
declare %foo[3] := ( 1, 2, 3 ) |
3121 |
declare %bar[3] := ( 1, 2, 3 ) |
3122 |
exit( array_equal(%foo, %bar) ) |
3123 |
end on |
3124 |
)NKSP_CODE", |
3125 |
.expectBoolExitResult = true |
3126 |
}); |
3127 |
|
3128 |
runScript({ |
3129 |
.code = R"NKSP_CODE( |
3130 |
on init |
3131 |
declare %foo[1] := ( 1 ) |
3132 |
declare %bar[1] := ( 1 ) |
3133 |
exit( array_equal(%foo, %bar) ) |
3134 |
end on |
3135 |
)NKSP_CODE", |
3136 |
.expectBoolExitResult = true |
3137 |
}); |
3138 |
|
3139 |
runScript({ |
3140 |
.code = R"NKSP_CODE( |
3141 |
on init |
3142 |
declare %foo[3] := ( 1, 2, 3 ) |
3143 |
declare %bar[3] := ( 0, 2, 3 ) |
3144 |
exit( array_equal(%foo, %bar) ) |
3145 |
end on |
3146 |
)NKSP_CODE", |
3147 |
.expectBoolExitResult = false |
3148 |
}); |
3149 |
|
3150 |
runScript({ |
3151 |
.code = R"NKSP_CODE( |
3152 |
on init |
3153 |
declare %foo[3] := ( 1, 2, 3 ) |
3154 |
declare %bar[3] := ( 3, 2, 1 ) |
3155 |
exit( array_equal(%foo, %bar) ) |
3156 |
end on |
3157 |
)NKSP_CODE", |
3158 |
.expectBoolExitResult = false |
3159 |
}); |
3160 |
|
3161 |
runScript({ |
3162 |
.code = R"NKSP_CODE( |
3163 |
on init |
3164 |
declare %foo[3] := ( 1, 2, 3 ) |
3165 |
declare %bar[2] := ( 1, 2 ) |
3166 |
exit( array_equal(%foo, %bar) ) |
3167 |
end on |
3168 |
)NKSP_CODE", |
3169 |
.expectBoolExitResult = false |
3170 |
}); |
3171 |
|
3172 |
#if !SILENT_TEST |
3173 |
std::cout << std::endl; |
3174 |
#endif |
3175 |
} |
3176 |
|
3177 |
static void testBuiltInSortFunction() { |
3178 |
#if !SILENT_TEST |
3179 |
std::cout << "UNIT TEST: built-in sort() function\n"; |
3180 |
#endif |
3181 |
|
3182 |
runScript({ |
3183 |
.code = R"NKSP_CODE( |
3184 |
on init |
3185 |
declare %input[3] := ( 19, 3, 6 ) |
3186 |
declare %expected[3] := ( 3, 6, 19 ) |
3187 |
sort(%input, 0) |
3188 |
exit( array_equal(%input, %expected) ) |
3189 |
end on |
3190 |
)NKSP_CODE", |
3191 |
.expectBoolExitResult = true |
3192 |
}); |
3193 |
|
3194 |
runScript({ |
3195 |
.code = R"NKSP_CODE( |
3196 |
on init |
3197 |
declare %input[3] := ( 19, 3, 6 ) |
3198 |
declare %expected[3] := ( 19, 6, 3 ) |
3199 |
sort(%input, 1) |
3200 |
exit( array_equal(%input, %expected) ) |
3201 |
end on |
3202 |
)NKSP_CODE", |
3203 |
.expectBoolExitResult = true |
3204 |
}); |
3205 |
|
3206 |
#if !SILENT_TEST |
3207 |
std::cout << std::endl; |
3208 |
#endif |
3209 |
} |
3210 |
|
3211 |
static void testBuiltInNumElementsFunction() { |
3212 |
#if !SILENT_TEST |
3213 |
std::cout << "UNIT TEST: built-in num_elements() function\n"; |
3214 |
#endif |
3215 |
|
3216 |
runScript({ |
3217 |
.code = R"NKSP_CODE( |
3218 |
on init |
3219 |
declare %foo[3] := ( 19, 3, 6 ) |
3220 |
exit( num_elements(%foo) ) |
3221 |
end on |
3222 |
)NKSP_CODE", |
3223 |
.expectIntExitResult = 3 |
3224 |
}); |
3225 |
|
3226 |
runScript({ |
3227 |
.code = R"NKSP_CODE( |
3228 |
on init |
3229 |
declare %foo[1] := ( 19 ) |
3230 |
exit( num_elements(%foo) ) |
3231 |
end on |
3232 |
)NKSP_CODE", |
3233 |
.expectIntExitResult = 1 |
3234 |
}); |
3235 |
|
3236 |
runScript({ |
3237 |
.code = R"NKSP_CODE( |
3238 |
on init |
3239 |
declare %foo[5] := ( 1, 2, 3, 4, 5 ) |
3240 |
exit( num_elements(%foo) ) |
3241 |
end on |
3242 |
)NKSP_CODE", |
3243 |
.expectIntExitResult = 5 |
3244 |
}); |
3245 |
|
3246 |
#if !SILENT_TEST |
3247 |
std::cout << std::endl; |
3248 |
#endif |
3249 |
} |
3250 |
|
3251 |
static void testBuiltInSearchFunction() { |
3252 |
#if !SILENT_TEST |
3253 |
std::cout << "UNIT TEST: built-in search() function\n"; |
3254 |
#endif |
3255 |
|
3256 |
runScript({ |
3257 |
.code = R"NKSP_CODE( |
3258 |
on init |
3259 |
declare %foo[3] := ( 19, 3, 6 ) |
3260 |
exit( search(%foo, 19) ) |
3261 |
end on |
3262 |
)NKSP_CODE", |
3263 |
.expectIntExitResult = 0 |
3264 |
}); |
3265 |
|
3266 |
runScript({ |
3267 |
.code = R"NKSP_CODE( |
3268 |
on init |
3269 |
declare %foo[3] := ( 19, 3, 6 ) |
3270 |
exit( search(%foo, 3) ) |
3271 |
end on |
3272 |
)NKSP_CODE", |
3273 |
.expectIntExitResult = 1 |
3274 |
}); |
3275 |
|
3276 |
runScript({ |
3277 |
.code = R"NKSP_CODE( |
3278 |
on init |
3279 |
declare %foo[3] := ( 19, 3, 6 ) |
3280 |
exit( search(%foo, 6) ) |
3281 |
end on |
3282 |
)NKSP_CODE", |
3283 |
.expectIntExitResult = 2 |
3284 |
}); |
3285 |
|
3286 |
runScript({ |
3287 |
.code = R"NKSP_CODE( |
3288 |
on init |
3289 |
declare %foo[3] := ( 19, 3, 6 ) |
3290 |
exit( search(%foo, 2) ) |
3291 |
end on |
3292 |
)NKSP_CODE", |
3293 |
.expectIntExitResult = -1 |
3294 |
}); |
3295 |
|
3296 |
#if !SILENT_TEST |
3297 |
std::cout << std::endl; |
3298 |
#endif |
3299 |
} |
3300 |
|
3301 |
static void testIfStatement() { |
3302 |
#if !SILENT_TEST |
3303 |
std::cout << "UNIT TEST: if statement\n"; |
3304 |
#endif |
3305 |
|
3306 |
runScript({ |
3307 |
.code = R"NKSP_CODE( |
3308 |
on init |
3309 |
declare $foo := 1 |
3310 |
if ($foo) |
3311 |
exit(42) |
3312 |
end if |
3313 |
end on |
3314 |
)NKSP_CODE", |
3315 |
.expectIntExitResult = 42 |
3316 |
}); |
3317 |
|
3318 |
runScript({ |
3319 |
.code = R"NKSP_CODE( |
3320 |
on init |
3321 |
declare $foo := 0 |
3322 |
if ($foo) |
3323 |
exit(42) |
3324 |
end if |
3325 |
exit(3) |
3326 |
end on |
3327 |
)NKSP_CODE", |
3328 |
.expectIntExitResult = 3 |
3329 |
}); |
3330 |
|
3331 |
runScript({ |
3332 |
.code = R"NKSP_CODE( |
3333 |
on init |
3334 |
declare $foo := 1 |
3335 |
if ($foo) |
3336 |
exit(42) |
3337 |
else |
3338 |
exit(3) |
3339 |
end if |
3340 |
end on |
3341 |
)NKSP_CODE", |
3342 |
.expectIntExitResult = 42 |
3343 |
}); |
3344 |
|
3345 |
runScript({ |
3346 |
.code = R"NKSP_CODE( |
3347 |
on init |
3348 |
declare $foo := 0 |
3349 |
if ($foo) |
3350 |
exit(42) |
3351 |
else |
3352 |
exit(3) |
3353 |
end if |
3354 |
end on |
3355 |
)NKSP_CODE", |
3356 |
.expectIntExitResult = 3 |
3357 |
}); |
3358 |
|
3359 |
#if !SILENT_TEST |
3360 |
std::cout << std::endl; |
3361 |
#endif |
3362 |
} |
3363 |
|
3364 |
static void testWhileStatement() { |
3365 |
#if !SILENT_TEST |
3366 |
std::cout << "UNIT TEST: while statement\n"; |
3367 |
#endif |
3368 |
|
3369 |
runScript({ |
3370 |
.code = R"NKSP_CODE( |
3371 |
on init |
3372 |
declare $foo := 100 |
3373 |
declare $i := 50 |
3374 |
while ($i) |
3375 |
$foo := $foo + 1 |
3376 |
$i := $i - 1 |
3377 |
end while |
3378 |
exit($foo) |
3379 |
end on |
3380 |
)NKSP_CODE", |
3381 |
.expectIntExitResult = 150 |
3382 |
}); |
3383 |
|
3384 |
#if !SILENT_TEST |
3385 |
std::cout << std::endl; |
3386 |
#endif |
3387 |
} |
3388 |
|
3389 |
#if !NO_MAIN |
3390 |
|
3391 |
int main() { |
3392 |
testBuiltInExitFunction(); |
3393 |
testStringConcatOperator(); |
3394 |
testNegOperator(); |
3395 |
testPlusOperator(); |
3396 |
testMinusOperator(); |
3397 |
testModuloOperator(); |
3398 |
testMultiplyOperator(); |
3399 |
testDivideOperator(); |
3400 |
testSmallerThanOperator(); |
3401 |
testGreaterThanOperator(); |
3402 |
testSmallerOrEqualOperator(); |
3403 |
testGreaterOrEqualOperator(); |
3404 |
testEqualOperator(); |
3405 |
testUnequalOperator(); |
3406 |
testLogicalAndOperator(); |
3407 |
testLogicalOrOperator(); |
3408 |
testLogicalNotOperator(); |
3409 |
testBitwiseAndOperator(); |
3410 |
testBitwiseOrOperator(); |
3411 |
testBitwiseNotOperator(); |
3412 |
testPrecedenceOfOperators(); |
3413 |
testBuiltInMinFunction(); |
3414 |
testBuiltInMaxFunction(); |
3415 |
testBuiltInAbsFunction(); |
3416 |
testBuiltInIncFunction(); |
3417 |
testBuiltInDecFunction(); |
3418 |
testBuiltInInRangeFunction(); |
3419 |
testBuiltInRandomFunction(); |
3420 |
testBuiltInShiftLeftFunction(); |
3421 |
testBuiltInShiftRightFunction(); |
3422 |
testBuiltInIntToRealFunction(); |
3423 |
testBuiltInRealFunction(); |
3424 |
testBuiltInRealToIntFunction(); |
3425 |
testBuiltInIntFunction(); |
3426 |
testBuiltInArrayEqualFunction(); |
3427 |
testBuiltInSortFunction(); |
3428 |
testBuiltInNumElementsFunction(); |
3429 |
testBuiltInSearchFunction(); |
3430 |
testIfStatement(); |
3431 |
testWhileStatement(); |
3432 |
std::cout << "\nAll tests passed successfully. :-)\n"; |
3433 |
return 0; |
3434 |
} |
3435 |
|
3436 |
#endif // !NO_MAIN |