/[svn]/linuxsampler/trunk/src/scriptvm/tests/NKSPCoreLangTest.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/scriptvm/tests/NKSPCoreLangTest.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3804 - (show annotations) (download)
Thu Aug 6 12:15:02 2020 UTC (8 days, 8 hours ago) by schoenebeck
File size: 231644 byte(s)
NKSP: Fixed built-in exit() function to behave as return statement.

* VM API: Introduced new signal STMT_RETURN_SIGNALLED.

* NKSP exit() function: signal STMT_RETURN_SIGNALLED instead of
  STMT_ABORT_SIGNALLED.

* NKSP AST: Introduced common base class 'Subroutine' for 'EventHandler'
  and for new 'UserFunction' class.

* NKSP parser: Use 'UserFunction' class instead of 'Statements' class
  for user declared NKSP functions.

* ScriptVM: Handle new STMT_RETURN_SIGNALLED signal by unwinding the
  stack to previous, calling subroutine.

* NKSP tests: Added test cases for exit() acting as return statement.

* Bumped version (2.1.1.svn62).

1 /*
2 * Copyright (c) 2019 - 2020 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 #define TEST_VERIFY(...) \
29 if (!(__VA_ARGS__)) { \
30 fprintf(stderr, "\n[ERROR]: The following NKSP test has failed:\n%s\n", \
31 opt.code.c_str()); \
32 fprintf(stderr, "Violated expectation for this failure was: " #__VA_ARGS__ "\n\n"); \
33 fprintf(stderr, "The overall expectations for this failed NKSP test were:\n\n"); \
34 printExpectations(opt); \
35 fprintf(stderr, "\n"); \
36 } \
37 TEST_ASSERT(__VA_ARGS__); \
38
39 #define TEST_PRINT_BOOL_EXPECTATION(e) \
40 printf(#e ": %s\n", (opt.e) ? "Yes" : "No"); \
41
42 #define TEST_PRINT_BOOL_EXPECTATION_OR(e,alt) \
43 printf(#e ": %s", (opt.e || opt.alt) ? "Yes" : "No"); \
44 if (!opt.e && opt.alt) { \
45 printf(" (implied by " #alt ")"); \
46 } \
47 printf("\n"); \
48
49 #define TEST_PRINT_BOOL_EXPECTATION_OR2(e,alt1,alt2) \
50 printf(#e ": %s", (opt.e || opt.alt1 || opt.alt2) ? "Yes" : "No"); \
51 if (!opt.e) { \
52 if (opt.alt1 && opt.alt2) { \
53 printf(" (implied by " #alt1 " and " #alt2 ")"); \
54 } else if (opt.alt1) { \
55 printf(" (implied by " #alt1 ")"); \
56 } else if (opt.alt2) { \
57 printf(" (implied by " #alt2 ")"); \
58 } \
59 } \
60 printf("\n"); \
61
62 #define TEST_PRINT_OPTIONAL_EXPECTATION(e) \
63 printf(#e ": %s\n", \
64 (opt.e) ? std::to_string(*opt.e).c_str() : "Not expected"); \
65
66 #define TEST_PRINT_OPTIONAL_STRING_EXPECTATION(e) \
67 printf(#e ": %s\n", \
68 (opt.e) ? ("'" + *opt.e + "'").c_str() : "Not expected"); \
69
70 #define TEST_PRINT_VECTOR_EXPECTATION(e) \
71 if (opt.e.empty()) { \
72 printf(#e ": Not expected\n"); \
73 } else { \
74 for (size_t i = 0; i < opt.e.size(); ++i) { \
75 printf(#e ": %s\n", std::to_string(opt.e[i]).c_str()); \
76 if (i < opt.e.size() - 1) printf(", "); \
77 } \
78 } \
79
80 using namespace LinuxSampler;
81 using namespace std;
82
83 struct RunScriptOpt {
84 String code;
85 bool expectParseError;
86 bool expectParseWarning;
87 bool expectRuntimeError;
88 bool expectNoExitResult;
89 bool expectExitResultIsInt;
90 bool expectExitResultIsReal;
91 bool prohibitExitFunctionArguments;
92 optional<vmint> expectIntExitResult;
93 optional<bool> expectBoolExitResult;
94 optional<vmfloat> expectRealExitResult;
95 optional<String> expectStringExitResult;
96 vector<MetricPrefix_t> expectExitResultUnitPrefix;
97 optional<StdUnit_t> expectExitResultUnit;
98 optional<bool> expectExitResultFinal;
99 };
100
101 static void printExpectations(RunScriptOpt opt) {
102 TEST_PRINT_BOOL_EXPECTATION(expectParseError);
103 TEST_PRINT_BOOL_EXPECTATION(expectParseWarning);
104 TEST_PRINT_BOOL_EXPECTATION(expectRuntimeError);
105 TEST_PRINT_BOOL_EXPECTATION(expectNoExitResult);
106 TEST_PRINT_BOOL_EXPECTATION_OR2(expectExitResultIsInt, /* Or: */ expectIntExitResult, expectBoolExitResult);
107 TEST_PRINT_BOOL_EXPECTATION_OR(expectExitResultIsReal, /* Or: */ expectRealExitResult);
108 TEST_PRINT_BOOL_EXPECTATION(prohibitExitFunctionArguments);
109 TEST_PRINT_OPTIONAL_EXPECTATION(expectIntExitResult);
110 TEST_PRINT_OPTIONAL_EXPECTATION(expectBoolExitResult);
111 TEST_PRINT_OPTIONAL_EXPECTATION(expectRealExitResult);
112 TEST_PRINT_OPTIONAL_STRING_EXPECTATION(expectStringExitResult);
113 TEST_PRINT_VECTOR_EXPECTATION(expectExitResultUnitPrefix);
114 TEST_PRINT_OPTIONAL_EXPECTATION(expectExitResultUnit);
115 TEST_PRINT_OPTIONAL_EXPECTATION(expectExitResultFinal);
116 }
117
118 static void runScript(const RunScriptOpt& opt) {
119 ScriptVM vm;
120 vm.setAutoSuspendEnabled(false);
121 if (!opt.prohibitExitFunctionArguments)
122 vm.setExitResultEnabled(true);
123 unique_ptr<VMParserContext> parserCtx(
124 vm.loadScript(opt.code)
125 );
126 vector<ParserIssue> errors = parserCtx->errors();
127 vector<ParserIssue> warnings = parserCtx->warnings();
128 if (opt.expectParseError) {
129 TEST_VERIFY(!errors.empty());
130 return;
131 } else {
132 for (ParserIssue& err : errors) {
133 err.dump();
134 }
135 TEST_VERIFY(errors.empty());
136 }
137 if (opt.expectParseWarning) {
138 TEST_VERIFY(!warnings.empty());
139 } else {
140 for (ParserIssue& wrn : warnings) {
141 wrn.dump();
142 }
143 }
144 TEST_VERIFY(parserCtx->eventHandler(0));
145 unique_ptr<VMExecContext> execCtx(
146 vm.createExecContext(&*parserCtx)
147 );
148 for (int i = 0; parserCtx->eventHandler(i); ++i) {
149 VMEventHandler* handler = parserCtx->eventHandler(i);
150 VMExecStatus_t result = vm.exec(&*parserCtx, &*execCtx, handler);
151 if (opt.expectRuntimeError) {
152 TEST_VERIFY(result & VM_EXEC_ERROR);
153 } else {
154 TEST_VERIFY(!(result & VM_EXEC_ERROR));
155 }
156 if (opt.expectNoExitResult) {
157 VMExpr* resExpr = execCtx->exitResult();
158 TEST_VERIFY(!resExpr);
159 }
160 if (opt.expectExitResultIsInt) {
161 VMExpr* resExpr = execCtx->exitResult();
162 TEST_VERIFY(resExpr);
163 TEST_VERIFY(resExpr->exprType() == INT_EXPR);
164 }
165 if (opt.expectExitResultIsReal) {
166 VMExpr* resExpr = execCtx->exitResult();
167 TEST_VERIFY(resExpr);
168 TEST_VERIFY(resExpr->exprType() == REAL_EXPR);
169 }
170 if (opt.expectIntExitResult) {
171 VMExpr* resExpr = execCtx->exitResult();
172 TEST_VERIFY(resExpr);
173 TEST_VERIFY(resExpr->exprType() == INT_EXPR);
174 TEST_VERIFY(resExpr->asInt()->evalInt() == *opt.expectIntExitResult);
175 }
176 if (opt.expectRealExitResult) {
177 VMExpr* resExpr = execCtx->exitResult();
178 TEST_VERIFY(resExpr);
179 TEST_VERIFY(resExpr->exprType() == REAL_EXPR);
180 if (sizeof(vmfloat) == sizeof(float)) {
181 TEST_VERIFY(RTMath::fEqual32(resExpr->asReal()->evalReal(), *opt.expectRealExitResult));
182 } else {
183 TEST_VERIFY(RTMath::fEqual64(resExpr->asReal()->evalReal(), *opt.expectRealExitResult));
184 }
185 }
186 if (opt.expectBoolExitResult) {
187 VMExpr* resExpr = execCtx->exitResult();
188 TEST_VERIFY(resExpr);
189 TEST_VERIFY(resExpr->exprType() == INT_EXPR);
190 TEST_VERIFY(bool(resExpr->asInt()->evalInt()) == *opt.expectBoolExitResult);
191 }
192 if (opt.expectStringExitResult) {
193 VMExpr* resExpr = execCtx->exitResult();
194 TEST_VERIFY(resExpr);
195 TEST_VERIFY(resExpr->exprType() == STRING_EXPR);
196 TEST_VERIFY(resExpr->asString()->evalStr() == *opt.expectStringExitResult);
197 }
198 if (opt.expectExitResultUnit) {
199 VMExpr* resExpr = execCtx->exitResult();
200 TEST_VERIFY(resExpr);
201 VMNumberExpr* numberExpr = resExpr->asNumber();
202 TEST_VERIFY(numberExpr);
203 TEST_VERIFY(numberExpr->unitType() == *opt.expectExitResultUnit);
204 }
205 if (!opt.expectExitResultUnitPrefix.empty()) {
206 VMExpr* resExpr = execCtx->exitResult();
207 TEST_VERIFY(resExpr);
208 VMNumberExpr* numberExpr = resExpr->asNumber();
209 TEST_VERIFY(numberExpr);
210 auto prefixes = opt.expectExitResultUnitPrefix;
211 if (*prefixes.rbegin() != VM_NO_PREFIX)
212 prefixes.push_back(VM_NO_PREFIX); // VM_NO_PREFIX termination required by unitFactr() call
213 vmfloat expectedFactor = VMUnit::unitFactor(&prefixes[0]);
214 vmfloat actualFactor = numberExpr->unitFactor();
215 if (sizeof(vmfloat) == sizeof(float)) {
216 TEST_VERIFY(RTMath::fEqual32(expectedFactor, actualFactor));
217 } else {
218 TEST_VERIFY(RTMath::fEqual64(expectedFactor, actualFactor));
219 }
220 }
221 if (opt.expectExitResultFinal) {
222 VMExpr* resExpr = execCtx->exitResult();
223 TEST_VERIFY(resExpr);
224 VMNumberExpr* numberExpr = resExpr->asNumber();
225 TEST_VERIFY(numberExpr);
226 TEST_VERIFY(numberExpr->isFinal() == *opt.expectExitResultFinal);
227 }
228 }
229 }
230
231 static void testBuiltInExitFunction() {
232 #if !SILENT_TEST
233 std::cout << "UNIT TEST: built-in exit() function\n";
234 #endif
235
236 runScript({
237 .code = R"NKSP_CODE(
238 on init
239 end on
240 )NKSP_CODE",
241 .expectNoExitResult = true
242 });
243
244 runScript({
245 .code = R"NKSP_CODE(
246 on init
247 exit
248 end on
249 )NKSP_CODE",
250 .expectNoExitResult = true
251 });
252
253 runScript({
254 .code = R"NKSP_CODE(
255 on init
256 exit()
257 end on
258 )NKSP_CODE",
259 .expectNoExitResult = true
260 });
261
262 // integer tests ...
263
264 runScript({
265 .code = R"NKSP_CODE(
266 on init
267 exit(42)
268 end on
269 )NKSP_CODE",
270 .expectIntExitResult = 42
271 });
272
273 runScript({
274 .code = R"NKSP_CODE(
275 on init
276 declare $foo := 1
277 if ($foo)
278 exit(21)
279 end if
280 end on
281 )NKSP_CODE",
282 .expectIntExitResult = 21
283 });
284
285 runScript({
286 .code = R"NKSP_CODE(
287 on init
288 declare $foo := 0
289 if ($foo)
290 exit(21)
291 end if
292 exit(99)
293 end on
294 )NKSP_CODE",
295 .expectIntExitResult = 99
296 });
297
298 // string tests ...
299
300 runScript({
301 .code = R"NKSP_CODE(
302 on init
303 exit("fourtytwo!")
304 end on
305 )NKSP_CODE",
306 .expectStringExitResult = "fourtytwo!"
307 });
308
309 // in production environment we prohibit the built-in exit() function to
310 // accept any arguments
311 runScript({
312 .code = R"NKSP_CODE(
313 on init
314 exit(42)
315 end on
316 )NKSP_CODE",
317 .expectParseError = true, // see comment above why
318 .prohibitExitFunctionArguments = true // simulate production environment
319 });
320
321 // real number tests ...
322
323 runScript({
324 .code = R"NKSP_CODE(
325 on init
326 exit(3.14)
327 end on
328 )NKSP_CODE",
329 .expectRealExitResult = 3.14
330 });
331
332 runScript({
333 .code = R"NKSP_CODE(
334 on init
335 declare $foo := 1
336 if ($foo)
337 exit(3.14)
338 end if
339 end on
340 )NKSP_CODE",
341 .expectRealExitResult = 3.14
342 });
343
344 runScript({
345 .code = R"NKSP_CODE(
346 on init
347 declare $foo := 0
348 if ($foo)
349 exit(3.14)
350 end if
351 exit(6.9)
352 end on
353 )NKSP_CODE",
354 .expectRealExitResult = 6.9
355 });
356
357 // int array tests ...
358
359 runScript({
360 .code = R"NKSP_CODE(
361 on init
362 declare %foo[3]
363 %foo[0] := 21
364 exit(%foo[0])
365 end on
366 )NKSP_CODE",
367 .expectIntExitResult = 21
368 });
369
370 runScript({
371 .code = R"NKSP_CODE(
372 on init
373 declare %foo[3] := ( 12, 23, 34 )
374 exit(%foo[0])
375 end on
376 )NKSP_CODE",
377 .expectIntExitResult = 12
378 });
379
380 runScript({
381 .code = R"NKSP_CODE(
382 on init
383 declare %foo[3] := ( 12, 23, 34 )
384 exit(%foo[1])
385 end on
386 )NKSP_CODE",
387 .expectIntExitResult = 23
388 });
389
390 runScript({
391 .code = R"NKSP_CODE(
392 on init
393 declare %foo[3] := ( 12, 23, 34 )
394 exit(%foo[2])
395 end on
396 )NKSP_CODE",
397 .expectIntExitResult = 34
398 });
399
400 runScript({ // make sure array is entirely initialized with zeroes
401 .code = R"NKSP_CODE(
402 on init
403 declare $i
404 declare $result
405 declare %foo[100]
406 while ($i < 100)
407 $result := $result .or. %foo[$i]
408 inc($i)
409 end while
410 exit($result)
411 end on
412 )NKSP_CODE",
413 .expectIntExitResult = 0
414 });
415
416 // real array tests ...
417
418 runScript({
419 .code = R"NKSP_CODE(
420 on init
421 declare ?foo[3]
422 ?foo[0] := 34.9
423 exit(?foo[0])
424 end on
425 )NKSP_CODE",
426 .expectRealExitResult = 34.9
427 });
428
429 runScript({
430 .code = R"NKSP_CODE(
431 on init
432 declare ?foo[3] := ( 0.3, 23.5, 900.1 )
433 exit(?foo[0])
434 end on
435 )NKSP_CODE",
436 .expectRealExitResult = 0.3
437 });
438
439 runScript({
440 .code = R"NKSP_CODE(
441 on init
442 declare ?foo[3] := ( 0.3, 23.5, 900.1 )
443 exit(?foo[1])
444 end on
445 )NKSP_CODE",
446 .expectRealExitResult = 23.5
447 });
448
449 runScript({
450 .code = R"NKSP_CODE(
451 on init
452 declare ?foo[3] := ( 0.3, 23.5, 900.1 )
453 exit(?foo[2])
454 end on
455 )NKSP_CODE",
456 .expectRealExitResult = 900.1
457 });
458
459 runScript({ // make sure array is entirely initialized with zeroes
460 .code = R"NKSP_CODE(
461 on init
462 declare $i
463 declare ?foo[100]
464 while ($i < 100)
465 if (?foo[$i] # 0.0)
466 exit(-1) { test failed }
467 end if
468 inc($i)
469 end while
470 exit(0) { test succeeded }
471 end on
472 )NKSP_CODE",
473 .expectIntExitResult = 0
474 });
475
476 // std unit tests ...
477
478 runScript({
479 .code = R"NKSP_CODE(
480 on init
481 exit(42s)
482 end on
483 )NKSP_CODE",
484 .expectIntExitResult = 42,
485 .expectExitResultUnit = VM_SECOND
486 });
487
488 runScript({
489 .code = R"NKSP_CODE(
490 on init
491 exit(42Hz)
492 end on
493 )NKSP_CODE",
494 .expectIntExitResult = 42,
495 .expectExitResultUnit = VM_HERTZ
496 });
497
498 runScript({
499 .code = R"NKSP_CODE(
500 on init
501 exit(42B)
502 end on
503 )NKSP_CODE",
504 .expectIntExitResult = 42,
505 .expectExitResultUnit = VM_BEL
506 });
507
508 runScript({
509 .code = R"NKSP_CODE(
510 on init
511 exit(42us)
512 end on
513 )NKSP_CODE",
514 .expectIntExitResult = 42,
515 .expectExitResultUnitPrefix = { VM_MICRO },
516 .expectExitResultUnit = VM_SECOND
517 });
518
519 runScript({
520 .code = R"NKSP_CODE(
521 on init
522 exit(42ms)
523 end on
524 )NKSP_CODE",
525 .expectIntExitResult = 42,
526 .expectExitResultUnitPrefix = { VM_MILLI },
527 .expectExitResultUnit = VM_SECOND
528 });
529
530 runScript({
531 .code = R"NKSP_CODE(
532 on init
533 exit(42cs)
534 end on
535 )NKSP_CODE",
536 .expectIntExitResult = 42,
537 .expectExitResultUnitPrefix = { VM_CENTI },
538 .expectExitResultUnit = VM_SECOND
539 });
540
541 runScript({
542 .code = R"NKSP_CODE(
543 on init
544 exit(42ds)
545 end on
546 )NKSP_CODE",
547 .expectIntExitResult = 42,
548 .expectExitResultUnitPrefix = { VM_DECI },
549 .expectExitResultUnit = VM_SECOND
550 });
551
552 runScript({
553 .code = R"NKSP_CODE(
554 on init
555 exit(42das)
556 end on
557 )NKSP_CODE",
558 .expectIntExitResult = 42,
559 .expectExitResultUnitPrefix = { VM_DECA },
560 .expectExitResultUnit = VM_SECOND
561 });
562
563 runScript({
564 .code = R"NKSP_CODE(
565 on init
566 exit(42hs)
567 end on
568 )NKSP_CODE",
569 .expectIntExitResult = 42,
570 .expectExitResultUnitPrefix = { VM_HECTO },
571 .expectExitResultUnit = VM_SECOND
572 });
573
574 runScript({
575 .code = R"NKSP_CODE(
576 on init
577 exit(42ks)
578 end on
579 )NKSP_CODE",
580 .expectIntExitResult = 42,
581 .expectExitResultUnitPrefix = { VM_KILO },
582 .expectExitResultUnit = VM_SECOND
583 });
584
585 runScript({
586 .code = R"NKSP_CODE(
587 on init
588 exit(42s)
589 end on
590 )NKSP_CODE",
591 .expectIntExitResult = 42,
592 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
593 .expectExitResultUnit = VM_SECOND
594 });
595
596 runScript({
597 .code = R"NKSP_CODE(
598 on init
599 exit(42uHz)
600 end on
601 )NKSP_CODE",
602 .expectIntExitResult = 42,
603 .expectExitResultUnitPrefix = { VM_MICRO },
604 .expectExitResultUnit = VM_HERTZ
605 });
606
607 runScript({
608 .code = R"NKSP_CODE(
609 on init
610 exit(42mHz)
611 end on
612 )NKSP_CODE",
613 .expectIntExitResult = 42,
614 .expectExitResultUnitPrefix = { VM_MILLI },
615 .expectExitResultUnit = VM_HERTZ
616 });
617
618 runScript({
619 .code = R"NKSP_CODE(
620 on init
621 exit(42cHz)
622 end on
623 )NKSP_CODE",
624 .expectIntExitResult = 42,
625 .expectExitResultUnitPrefix = { VM_CENTI },
626 .expectExitResultUnit = VM_HERTZ
627 });
628
629 runScript({
630 .code = R"NKSP_CODE(
631 on init
632 exit(42dHz)
633 end on
634 )NKSP_CODE",
635 .expectIntExitResult = 42,
636 .expectExitResultUnitPrefix = { VM_DECI },
637 .expectExitResultUnit = VM_HERTZ
638 });
639
640 runScript({
641 .code = R"NKSP_CODE(
642 on init
643 exit(42daHz)
644 end on
645 )NKSP_CODE",
646 .expectIntExitResult = 42,
647 .expectExitResultUnitPrefix = { VM_DECA },
648 .expectExitResultUnit = VM_HERTZ
649 });
650
651 runScript({
652 .code = R"NKSP_CODE(
653 on init
654 exit(42hHz)
655 end on
656 )NKSP_CODE",
657 .expectIntExitResult = 42,
658 .expectExitResultUnitPrefix = { VM_HECTO },
659 .expectExitResultUnit = VM_HERTZ
660 });
661
662 runScript({
663 .code = R"NKSP_CODE(
664 on init
665 exit(42kHz)
666 end on
667 )NKSP_CODE",
668 .expectIntExitResult = 42,
669 .expectExitResultUnitPrefix = { VM_KILO },
670 .expectExitResultUnit = VM_HERTZ
671 });
672
673 runScript({
674 .code = R"NKSP_CODE(
675 on init
676 exit(42Hz)
677 end on
678 )NKSP_CODE",
679 .expectIntExitResult = 42,
680 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
681 .expectExitResultUnit = VM_HERTZ
682 });
683
684 runScript({
685 .code = R"NKSP_CODE(
686 on init
687 exit(42uB)
688 end on
689 )NKSP_CODE",
690 .expectIntExitResult = 42,
691 .expectExitResultUnitPrefix = { VM_MICRO },
692 .expectExitResultUnit = VM_BEL
693 });
694
695 runScript({
696 .code = R"NKSP_CODE(
697 on init
698 exit(42mB)
699 end on
700 )NKSP_CODE",
701 .expectIntExitResult = 42,
702 .expectExitResultUnitPrefix = { VM_MILLI },
703 .expectExitResultUnit = VM_BEL
704 });
705
706 runScript({
707 .code = R"NKSP_CODE(
708 on init
709 exit(42cB)
710 end on
711 )NKSP_CODE",
712 .expectIntExitResult = 42,
713 .expectExitResultUnitPrefix = { VM_CENTI },
714 .expectExitResultUnit = VM_BEL
715 });
716
717 runScript({
718 .code = R"NKSP_CODE(
719 on init
720 exit(42dB)
721 end on
722 )NKSP_CODE",
723 .expectIntExitResult = 42,
724 .expectExitResultUnitPrefix = { VM_DECI },
725 .expectExitResultUnit = VM_BEL
726 });
727
728 runScript({
729 .code = R"NKSP_CODE(
730 on init
731 exit(42daB)
732 end on
733 )NKSP_CODE",
734 .expectIntExitResult = 42,
735 .expectExitResultUnitPrefix = { VM_DECA },
736 .expectExitResultUnit = VM_BEL
737 });
738
739 runScript({
740 .code = R"NKSP_CODE(
741 on init
742 exit(42hB)
743 end on
744 )NKSP_CODE",
745 .expectIntExitResult = 42,
746 .expectExitResultUnitPrefix = { VM_HECTO },
747 .expectExitResultUnit = VM_BEL
748 });
749
750 runScript({
751 .code = R"NKSP_CODE(
752 on init
753 exit(42kB)
754 end on
755 )NKSP_CODE",
756 .expectIntExitResult = 42,
757 .expectExitResultUnitPrefix = { VM_KILO },
758 .expectExitResultUnit = VM_BEL
759 });
760
761 runScript({
762 .code = R"NKSP_CODE(
763 on init
764 exit(42B)
765 end on
766 )NKSP_CODE",
767 .expectIntExitResult = 42,
768 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
769 .expectExitResultUnit = VM_BEL
770 });
771
772 runScript({
773 .code = R"NKSP_CODE(
774 on init
775 exit(42udB)
776 end on
777 )NKSP_CODE",
778 .expectIntExitResult = 42,
779 .expectExitResultUnitPrefix = { VM_MICRO, VM_DECI },
780 .expectExitResultUnit = VM_BEL
781 });
782
783 runScript({
784 .code = R"NKSP_CODE(
785 on init
786 exit(42mdB)
787 end on
788 )NKSP_CODE",
789 .expectIntExitResult = 42,
790 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
791 .expectExitResultUnit = VM_BEL
792 });
793
794 runScript({
795 .code = R"NKSP_CODE(
796 on init
797 exit(42cdB)
798 end on
799 )NKSP_CODE",
800 .expectIntExitResult = 42,
801 .expectExitResultUnitPrefix = { VM_CENTI, VM_DECI },
802 .expectExitResultUnit = VM_BEL
803 });
804
805 runScript({
806 .code = R"NKSP_CODE(
807 on init
808 exit(42ddB)
809 end on
810 )NKSP_CODE",
811 .expectIntExitResult = 42,
812 .expectExitResultUnitPrefix = { VM_DECI, VM_DECI },
813 .expectExitResultUnit = VM_BEL
814 });
815
816 runScript({
817 .code = R"NKSP_CODE(
818 on init
819 exit(42dadB)
820 end on
821 )NKSP_CODE",
822 .expectIntExitResult = 42,
823 .expectExitResultUnitPrefix = { VM_DECA, VM_DECI },
824 .expectExitResultUnit = VM_BEL
825 });
826
827 runScript({
828 .code = R"NKSP_CODE(
829 on init
830 exit(42hdB)
831 end on
832 )NKSP_CODE",
833 .expectIntExitResult = 42,
834 .expectExitResultUnitPrefix = { VM_HECTO, VM_DECI },
835 .expectExitResultUnit = VM_BEL
836 });
837
838 runScript({
839 .code = R"NKSP_CODE(
840 on init
841 exit(42kdB)
842 end on
843 )NKSP_CODE",
844 .expectIntExitResult = 42,
845 .expectExitResultUnitPrefix = { VM_KILO, VM_DECI },
846 .expectExitResultUnit = VM_BEL
847 });
848
849 runScript({
850 .code = R"NKSP_CODE(
851 on init
852 declare $foo := 42mdB
853 exit($foo)
854 end on
855 )NKSP_CODE",
856 .expectIntExitResult = 42,
857 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
858 .expectExitResultUnit = VM_BEL
859 });
860
861 runScript({
862 .code = R"NKSP_CODE(
863 on init
864 exit(3.14s)
865 end on
866 )NKSP_CODE",
867 .expectRealExitResult = 3.14,
868 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
869 .expectExitResultUnit = VM_SECOND
870 });
871
872 runScript({
873 .code = R"NKSP_CODE(
874 on init
875 exit(3.14us)
876 end on
877 )NKSP_CODE",
878 .expectRealExitResult = 3.14,
879 .expectExitResultUnitPrefix = { VM_MICRO },
880 .expectExitResultUnit = VM_SECOND
881 });
882
883 runScript({
884 .code = R"NKSP_CODE(
885 on init
886 exit(3.14ms)
887 end on
888 )NKSP_CODE",
889 .expectRealExitResult = 3.14,
890 .expectExitResultUnitPrefix = { VM_MILLI },
891 .expectExitResultUnit = VM_SECOND
892 });
893
894 runScript({
895 .code = R"NKSP_CODE(
896 on init
897 exit(-0.1B)
898 end on
899 )NKSP_CODE",
900 .expectRealExitResult = -0.1,
901 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
902 .expectExitResultUnit = VM_BEL
903 });
904
905 runScript({
906 .code = R"NKSP_CODE(
907 on init
908 exit(-0.1dB)
909 end on
910 )NKSP_CODE",
911 .expectRealExitResult = -0.1,
912 .expectExitResultUnitPrefix = { VM_DECI },
913 .expectExitResultUnit = VM_BEL
914 });
915
916 runScript({
917 .code = R"NKSP_CODE(
918 on init
919 exit(-0.1mdB)
920 end on
921 )NKSP_CODE",
922 .expectRealExitResult = -0.1,
923 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
924 .expectExitResultUnit = VM_BEL
925 });
926
927 runScript({
928 .code = R"NKSP_CODE(
929 on init
930 declare ~foo := -0.1mdB
931 exit(~foo)
932 end on
933 )NKSP_CODE",
934 .expectRealExitResult = -0.1,
935 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
936 .expectExitResultUnit = VM_BEL
937 });
938
939 runScript({
940 .code = R"NKSP_CODE(
941 on init
942 declare ~foo := 0.0dB
943 ~foo := -0.1mdB
944 exit(~foo)
945 end on
946 )NKSP_CODE",
947 .expectRealExitResult = -0.1,
948 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
949 .expectExitResultUnit = VM_BEL
950 });
951
952 runScript({
953 .code = R"NKSP_CODE(
954 on init
955 declare ~foo := 0.0dB
956 ~foo := -0.1Hz
957 exit(~foo)
958 end on
959 )NKSP_CODE",
960 .expectParseError = true // assigning different unit type to a variable is not allowed
961 });
962
963 // 'final' ('!') operator tests ...
964
965 runScript({
966 .code = R"NKSP_CODE(
967 on init
968 exit(!42)
969 end on
970 )NKSP_CODE",
971 .expectIntExitResult = 42,
972 .expectExitResultFinal = true
973 });
974
975 runScript({
976 .code = R"NKSP_CODE(
977 on init
978 exit(42)
979 end on
980 )NKSP_CODE",
981 .expectIntExitResult = 42,
982 .expectExitResultFinal = false
983 });
984
985 runScript({
986 .code = R"NKSP_CODE(
987 on init
988 declare $foo := !42
989 exit($foo)
990 end on
991 )NKSP_CODE",
992 .expectIntExitResult = 42,
993 .expectExitResultFinal = true
994 });
995
996 runScript({
997 .code = R"NKSP_CODE(
998 on init
999 declare $foo := 42
1000 exit($foo)
1001 end on
1002 )NKSP_CODE",
1003 .expectIntExitResult = 42,
1004 .expectExitResultFinal = false
1005 });
1006
1007 runScript({
1008 .code = R"NKSP_CODE(
1009 on init
1010 declare ~foo := !3.14
1011 exit(~foo)
1012 end on
1013 )NKSP_CODE",
1014 .expectRealExitResult = 3.14,
1015 .expectExitResultFinal = true
1016 });
1017
1018 runScript({
1019 .code = R"NKSP_CODE(
1020 on init
1021 declare ~foo := 3.14
1022 exit(~foo)
1023 end on
1024 )NKSP_CODE",
1025 .expectRealExitResult = 3.14,
1026 .expectExitResultFinal = false
1027 });
1028
1029 runScript({
1030 .code = R"NKSP_CODE(
1031 on init
1032 declare ~foo := !3.14mdB
1033 exit(~foo)
1034 end on
1035 )NKSP_CODE",
1036 .expectRealExitResult = 3.14,
1037 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
1038 .expectExitResultUnit = VM_BEL,
1039 .expectExitResultFinal = true
1040 });
1041
1042 runScript({
1043 .code = R"NKSP_CODE(
1044 on init
1045 declare ~foo := !0.0mdB
1046 ~foo := !3.14mdB
1047 exit(~foo)
1048 end on
1049 )NKSP_CODE",
1050 .expectRealExitResult = 3.14,
1051 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
1052 .expectExitResultUnit = VM_BEL,
1053 .expectExitResultFinal = true
1054 });
1055
1056 runScript({
1057 .code = R"NKSP_CODE(
1058 on init
1059 declare ~foo := !0.0mdB
1060 ~foo := 3.14mdB
1061 exit(~foo)
1062 end on
1063 )NKSP_CODE",
1064 .expectParseError = true // assigning non-final to a final variable not allowed
1065 });
1066
1067 runScript({
1068 .code = R"NKSP_CODE(
1069 on init
1070 declare ~foo := 0.0mdB
1071 ~foo := !3.14mdB
1072 exit(~foo)
1073 end on
1074 )NKSP_CODE",
1075 .expectParseError = true // assigning final to a non-final variable not allowed
1076 });
1077
1078 // exit() acting as return statement ...
1079
1080 runScript({
1081 .code = R"NKSP_CODE(
1082 function doFoo
1083 exit(2) { just return from this user function, i.e. don't stop init handler }
1084 end function
1085
1086 on init
1087 call doFoo
1088 exit(3)
1089 end on
1090 )NKSP_CODE",
1091 .expectIntExitResult = 3
1092 });
1093
1094 runScript({
1095 .code = R"NKSP_CODE(
1096 function doFoo1
1097 exit(2) { just return from this user function, i.e. don't stop init handler }
1098 end function
1099
1100 function doFoo2
1101 call doFoo1
1102 exit(3) { just return from this user function, i.e. don't stop init handler }
1103 end function
1104
1105 on init
1106 call doFoo2
1107 exit(4)
1108 end on
1109 )NKSP_CODE",
1110 .expectIntExitResult = 4
1111 });
1112
1113 runScript({
1114 .code = R"NKSP_CODE(
1115 function doFoo
1116 exit(2) { just return from this user function, i.e. don't stop init handler }
1117 end function
1118
1119 on init
1120 call doFoo
1121 exit(3)
1122 { dead code ... }
1123 call doFoo
1124 exit(4)
1125 end on
1126 )NKSP_CODE",
1127 .expectIntExitResult = 3
1128 });
1129
1130 runScript({
1131 .code = R"NKSP_CODE(
1132 function doFoo
1133 exit(2) { just return from this user function, i.e. don't stop init handler }
1134 end function
1135
1136 on init
1137 call doFoo
1138 exit(3)
1139 { dead code ... }
1140 call doFoo
1141 end on
1142 )NKSP_CODE",
1143 .expectIntExitResult = 3
1144 });
1145
1146 #if !SILENT_TEST
1147 std::cout << std::endl;
1148 #endif
1149 }
1150
1151 static void testStringConcatOperator() {
1152 #if !SILENT_TEST
1153 std::cout << "UNIT TEST: string concatenation (&) operator\n";
1154 #endif
1155
1156 // strings only tests ...
1157
1158 runScript({
1159 .code = R"NKSP_CODE(
1160 on init
1161 declare @s := "foo" & " bar"
1162 exit(@s)
1163 end on
1164 )NKSP_CODE",
1165 .expectStringExitResult = "foo bar"
1166 });
1167
1168 // integer tests ...
1169
1170 runScript({
1171 .code = R"NKSP_CODE(
1172 on init
1173 declare @s := "foo" & " bar" & " " & 123
1174 exit(@s)
1175 end on
1176 )NKSP_CODE",
1177 .expectStringExitResult = "foo bar 123"
1178 });
1179
1180 runScript({
1181 .code = R"NKSP_CODE(
1182 on init
1183 declare $i := 123
1184 declare @s := "foo" & " bar" & " " & $i
1185 exit(@s)
1186 end on
1187 )NKSP_CODE",
1188 .expectStringExitResult = "foo bar 123"
1189 });
1190
1191 // real number tests ...
1192
1193 runScript({
1194 .code = R"NKSP_CODE(
1195 on init
1196 declare @s := "foo" & " bar" & " " & 1.23
1197 exit(@s)
1198 end on
1199 )NKSP_CODE",
1200 .expectStringExitResult = "foo bar 1.23"
1201 });
1202
1203 runScript({
1204 .code = R"NKSP_CODE(
1205 on init
1206 declare ~r := 3.14
1207 declare @s := "foo" & " bar" & " " & ~r
1208 exit(@s)
1209 end on
1210 )NKSP_CODE",
1211 .expectStringExitResult = "foo bar 3.14"
1212 });
1213
1214 // std unit tests ...
1215
1216 runScript({
1217 .code = R"NKSP_CODE(
1218 on init
1219 declare $i := 500Hz
1220 declare @s := "foo" & " bar" & " " & $i
1221 exit(@s)
1222 end on
1223 )NKSP_CODE",
1224 .expectStringExitResult = "foo bar 500Hz"
1225 });
1226
1227 runScript({
1228 .code = R"NKSP_CODE(
1229 on init
1230 declare ~r := 3.14s
1231 declare @s := "foo" & " bar" & " " & ~r
1232 exit(@s)
1233 end on
1234 )NKSP_CODE",
1235 .expectStringExitResult = "foo bar 3.14s"
1236 });
1237
1238 runScript({
1239 .code = R"NKSP_CODE(
1240 on init
1241 declare ~r := -22.3mdB
1242 declare @s := "foo" & " bar" & " " & ~r
1243 exit(@s)
1244 end on
1245 )NKSP_CODE",
1246 .expectStringExitResult = "foo bar -22.3mdB"
1247 });
1248
1249 runScript({
1250 .code = R"NKSP_CODE(
1251 on init
1252 declare $i := 20us
1253 declare @s := "foo" & " bar" & " " & $i
1254 exit(@s)
1255 end on
1256 )NKSP_CODE",
1257 .expectStringExitResult = "foo bar 20us"
1258 });
1259
1260 runScript({
1261 .code = R"NKSP_CODE(
1262 on init
1263 declare $i := 20kHz
1264 declare @s := "foo" & " bar" & " " & $i
1265 exit(@s)
1266 end on
1267 )NKSP_CODE",
1268 .expectStringExitResult = "foo bar 20kHz"
1269 });
1270
1271 runScript({
1272 .code = R"NKSP_CODE(
1273 on init
1274 declare $i := -6dB
1275 declare @s := "foo" & " bar" & " " & $i
1276 exit(@s)
1277 end on
1278 )NKSP_CODE",
1279 .expectStringExitResult = "foo bar -6dB"
1280 });
1281
1282 runScript({
1283 .code = R"NKSP_CODE(
1284 on init
1285 declare $i := 1us * 1d
1286 declare @s := "foo" & " bar" & " " & $i
1287 exit(@s)
1288 end on
1289 )NKSP_CODE",
1290 .expectStringExitResult = "foo bar 1*10^-7s"
1291 });
1292
1293 runScript({
1294 .code = R"NKSP_CODE(
1295 on init
1296 declare ~r := 12.4mc
1297 declare @s := "foo" & " bar" & " " & ~r
1298 exit(@s)
1299 end on
1300 )NKSP_CODE",
1301 .expectStringExitResult = "foo bar 12.4mc"
1302 });
1303
1304 #if !SILENT_TEST
1305 std::cout << std::endl;
1306 #endif
1307 }
1308
1309 static void testNegOperator() {
1310 #if !SILENT_TEST
1311 std::cout << "UNIT TEST: negate (-) operator\n";
1312 #endif
1313
1314 // integer tests ...
1315
1316 runScript({
1317 .code = R"NKSP_CODE(
1318 on init
1319 exit(-87)
1320 end on
1321 )NKSP_CODE",
1322 .expectIntExitResult = -87
1323 });
1324
1325 runScript({
1326 .code = R"NKSP_CODE(
1327 on init
1328 declare $foo := -87
1329 exit(-$foo)
1330 end on
1331 )NKSP_CODE",
1332 .expectIntExitResult = 87
1333 });
1334
1335 // real number tests ...
1336
1337 runScript({
1338 .code = R"NKSP_CODE(
1339 on init
1340 exit(-99.3)
1341 end on
1342 )NKSP_CODE",
1343 .expectRealExitResult = -99.3
1344 });
1345
1346 runScript({
1347 .code = R"NKSP_CODE(
1348 on init
1349 declare ~foo := -99.3
1350 exit(-~foo)
1351 end on
1352 )NKSP_CODE",
1353 .expectRealExitResult = 99.3
1354 });
1355
1356 // std unit tests
1357
1358 runScript({
1359 .code = R"NKSP_CODE(
1360 on init
1361 declare $foo := -87mdB
1362 exit(-$foo)
1363 end on
1364 )NKSP_CODE",
1365 .expectIntExitResult = 87,
1366 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
1367 .expectExitResultUnit = VM_BEL
1368 });
1369
1370 // 'final' ('!') operator tests ...
1371
1372 runScript({
1373 .code = R"NKSP_CODE(
1374 on init
1375 declare $foo := !-87
1376 exit(-$foo)
1377 end on
1378 )NKSP_CODE",
1379 .expectIntExitResult = 87,
1380 .expectExitResultFinal = true
1381 });
1382
1383 runScript({
1384 .code = R"NKSP_CODE(
1385 on init
1386 declare $foo := -87
1387 exit(-$foo)
1388 end on
1389 )NKSP_CODE",
1390 .expectIntExitResult = 87,
1391 .expectExitResultFinal = false
1392 });
1393
1394 //TODO: the following are unary '+' operator tests which should be moved to their own function (lazy me).
1395
1396 runScript({
1397 .code = R"NKSP_CODE(
1398 on init
1399 exit(+54)
1400 end on
1401 )NKSP_CODE",
1402 .expectIntExitResult = 54
1403 });
1404
1405 runScript({
1406 .code = R"NKSP_CODE(
1407 on init
1408 declare $foo := +54
1409 exit( $foo )
1410 end on
1411 )NKSP_CODE",
1412 .expectIntExitResult = 54
1413 });
1414
1415 runScript({
1416 .code = R"NKSP_CODE(
1417 on init
1418 exit(+0.45)
1419 end on
1420 )NKSP_CODE",
1421 .expectRealExitResult = 0.45
1422 });
1423
1424 runScript({
1425 .code = R"NKSP_CODE(
1426 on init
1427 declare ~foo := +0.29
1428 exit( ~foo )
1429 end on
1430 )NKSP_CODE",
1431 .expectRealExitResult = 0.29
1432 });
1433
1434 #if !SILENT_TEST
1435 std::cout << std::endl;
1436 #endif
1437 }
1438
1439 static void testPlusOperator() {
1440 #if !SILENT_TEST
1441 std::cout << "UNIT TEST: plus (+) operator\n";
1442 #endif
1443
1444 // integer tests ...
1445
1446 runScript({
1447 .code = R"NKSP_CODE(
1448 on init
1449 exit(4 + 3)
1450 end on
1451 )NKSP_CODE",
1452 .expectIntExitResult = 7
1453 });
1454
1455 runScript({
1456 .code = R"NKSP_CODE(
1457 on init
1458 exit(42 + 145)
1459 end on
1460 )NKSP_CODE",
1461 .expectIntExitResult = 187
1462 });
1463
1464 runScript({
1465 .code = R"NKSP_CODE(
1466 on init
1467 exit(-4 + 2)
1468 end on
1469 )NKSP_CODE",
1470 .expectIntExitResult = -2
1471 });
1472
1473 // real number tests ...
1474
1475 runScript({
1476 .code = R"NKSP_CODE(
1477 on init
1478 exit(4.0 + 3.0)
1479 end on
1480 )NKSP_CODE",
1481 .expectRealExitResult = 7.0
1482 });
1483
1484 runScript({
1485 .code = R"NKSP_CODE(
1486 on init
1487 exit(42.3 + 145.2)
1488 end on
1489 )NKSP_CODE",
1490 .expectRealExitResult = 187.5
1491 });
1492
1493 runScript({
1494 .code = R"NKSP_CODE(
1495 on init
1496 exit(-4.0 + 2.2)
1497 end on
1498 )NKSP_CODE",
1499 .expectRealExitResult = -1.8
1500 });
1501
1502 // std unit tests ...
1503
1504 runScript({
1505 .code = R"NKSP_CODE(
1506 on init
1507 exit(42ms + 145ms)
1508 end on
1509 )NKSP_CODE",
1510 .expectIntExitResult = 187,
1511 .expectExitResultUnitPrefix = { VM_MILLI },
1512 .expectExitResultUnit = VM_SECOND
1513 });
1514
1515 runScript({
1516 .code = R"NKSP_CODE(
1517 on init
1518 exit(1s + 145ms)
1519 end on
1520 )NKSP_CODE",
1521 .expectIntExitResult = 1145,
1522 .expectExitResultUnitPrefix = { VM_MILLI },
1523 .expectExitResultUnit = VM_SECOND
1524 });
1525
1526 runScript({
1527 .code = R"NKSP_CODE(
1528 on init
1529 exit(42ms + 145)
1530 end on
1531 )NKSP_CODE",
1532 .expectParseError = true // units must match for + operator
1533 });
1534
1535 runScript({
1536 .code = R"NKSP_CODE(
1537 on init
1538 exit(42 + 145ms)
1539 end on
1540 )NKSP_CODE",
1541 .expectParseError = true // units must match for + operator
1542 });
1543
1544 runScript({
1545 .code = R"NKSP_CODE(
1546 on init
1547 exit(42Hz + 145s)
1548 end on
1549 )NKSP_CODE",
1550 .expectParseError = true // units must match for + operator
1551 });
1552
1553 runScript({
1554 .code = R"NKSP_CODE(
1555 on init
1556 exit(42.1ms + 145.3ms)
1557 end on
1558 )NKSP_CODE",
1559 .expectRealExitResult = 187.4,
1560 .expectExitResultUnitPrefix = { VM_MILLI },
1561 .expectExitResultUnit = VM_SECOND
1562 });
1563
1564 runScript({
1565 .code = R"NKSP_CODE(
1566 on init
1567 exit(1.1s + 145.0ms)
1568 end on
1569 )NKSP_CODE",
1570 .expectRealExitResult = 1245.0,
1571 .expectExitResultUnitPrefix = { VM_MILLI },
1572 .expectExitResultUnit = VM_SECOND
1573 });
1574
1575 runScript({
1576 .code = R"NKSP_CODE(
1577 on init
1578 exit(42.1ms + 145.3)
1579 end on
1580 )NKSP_CODE",
1581 .expectParseError = true // units must match for + operator
1582 });
1583
1584 runScript({
1585 .code = R"NKSP_CODE(
1586 on init
1587 exit(42.0 + 145.0ms)
1588 end on
1589 )NKSP_CODE",
1590 .expectParseError = true // units must match for + operator
1591 });
1592
1593 runScript({
1594 .code = R"NKSP_CODE(
1595 on init
1596 exit(42.0Hz + 145.0s)
1597 end on
1598 )NKSP_CODE",
1599 .expectParseError = true // units must match for + operator
1600 });
1601
1602 // 'final' ('!') operator tests ...
1603
1604 runScript({
1605 .code = R"NKSP_CODE(
1606 on init
1607 exit(!4 + !3)
1608 end on
1609 )NKSP_CODE",
1610 .expectIntExitResult = 7,
1611 .expectExitResultFinal = true
1612 });
1613
1614 runScript({
1615 .code = R"NKSP_CODE(
1616 on init
1617 exit(4 + 3)
1618 end on
1619 )NKSP_CODE",
1620 .expectIntExitResult = 7,
1621 .expectExitResultFinal = false
1622 });
1623
1624 runScript({
1625 .code = R"NKSP_CODE(
1626 on init
1627 exit(!4.1 + !3.3)
1628 end on
1629 )NKSP_CODE",
1630 .expectRealExitResult = 7.4,
1631 .expectExitResultFinal = true
1632 });
1633
1634 runScript({
1635 .code = R"NKSP_CODE(
1636 on init
1637 exit(4.1 + 3.3)
1638 end on
1639 )NKSP_CODE",
1640 .expectRealExitResult = 7.4,
1641 .expectExitResultFinal = false
1642 });
1643
1644 #if !SILENT_TEST
1645 std::cout << std::endl;
1646 #endif
1647 }
1648
1649 static void testMinusOperator() {
1650 #if !SILENT_TEST
1651 std::cout << "UNIT TEST: minus (-) operator\n";
1652 #endif
1653
1654 // integer tests ...
1655
1656 runScript({
1657 .code = R"NKSP_CODE(
1658 on init
1659 exit(4 - 3)
1660 end on
1661 )NKSP_CODE",
1662 .expectIntExitResult = 1
1663 });
1664
1665 runScript({
1666 .code = R"NKSP_CODE(
1667 on init
1668 exit(139 - 74)
1669 end on
1670 )NKSP_CODE",
1671 .expectIntExitResult = 65
1672 });
1673
1674 runScript({
1675 .code = R"NKSP_CODE(
1676 on init
1677 exit(3 - 9)
1678 end on
1679 )NKSP_CODE",
1680 .expectIntExitResult = -6
1681 });
1682
1683 runScript({
1684 .code = R"NKSP_CODE(
1685 on init
1686 exit(-3 - 18)
1687 end on
1688 )NKSP_CODE",
1689 .expectIntExitResult = -21
1690 });
1691
1692 // real number tests ...
1693
1694 runScript({
1695 .code = R"NKSP_CODE(
1696 on init
1697 exit(4.0 - 0.2)
1698 end on
1699 )NKSP_CODE",
1700 .expectRealExitResult = 3.8
1701 });
1702
1703 runScript({
1704 .code = R"NKSP_CODE(
1705 on init
1706 exit(3.1 - 9.65)
1707 end on
1708 )NKSP_CODE",
1709 .expectRealExitResult = -6.55
1710 });
1711
1712 runScript({
1713 .code = R"NKSP_CODE(
1714 on init
1715 exit(-3.0 - 18.1)
1716 end on
1717 )NKSP_CODE",
1718 .expectRealExitResult = -21.1
1719 });
1720
1721 // std unit tests ...
1722
1723 runScript({
1724 .code = R"NKSP_CODE(
1725 on init
1726 exit(1000ms - 145ms)
1727 end on
1728 )NKSP_CODE",
1729 .expectIntExitResult = 855,
1730 .expectExitResultUnitPrefix = { VM_MILLI },
1731 .expectExitResultUnit = VM_SECOND
1732 });
1733
1734 runScript({
1735 .code = R"NKSP_CODE(
1736 on init
1737 exit(1s - 145ms)
1738 end on
1739 )NKSP_CODE",
1740 .expectIntExitResult = 855,
1741 .expectExitResultUnitPrefix = { VM_MILLI },
1742 .expectExitResultUnit = VM_SECOND
1743 });
1744
1745 runScript({
1746 .code = R"NKSP_CODE(
1747 on init
1748 exit(1s - 145)
1749 end on
1750 )NKSP_CODE",
1751 .expectParseError = true // units must match for - operator
1752 });
1753
1754 runScript({
1755 .code = R"NKSP_CODE(
1756 on init
1757 exit(1 - 145s)
1758 end on
1759 )NKSP_CODE",
1760 .expectParseError = true // units must match for - operator
1761 });
1762
1763 runScript({
1764 .code = R"NKSP_CODE(
1765 on init
1766 exit(1ms - 145mB)
1767 end on
1768 )NKSP_CODE",
1769 .expectParseError = true // units must match for - operator
1770 });
1771
1772 runScript({
1773 .code = R"NKSP_CODE(
1774 on init
1775 exit(1.0ms - 0.1ms)
1776 end on
1777 )NKSP_CODE",
1778 .expectRealExitResult = 0.9,
1779 .expectExitResultUnitPrefix = { VM_MILLI },
1780 .expectExitResultUnit = VM_SECOND
1781 });
1782
1783 runScript({
1784 .code = R"NKSP_CODE(
1785 on init
1786 exit(1.1s - 106.0ms)
1787 end on
1788 )NKSP_CODE",
1789 .expectRealExitResult = 994.0,
1790 .expectExitResultUnitPrefix = { VM_MILLI },
1791 .expectExitResultUnit = VM_SECOND
1792 });
1793
1794 runScript({
1795 .code = R"NKSP_CODE(
1796 on init
1797 exit(1100.0ms - 0.106s)
1798 end on
1799 )NKSP_CODE",
1800 .expectRealExitResult = 994.0,
1801 .expectExitResultUnitPrefix = { VM_MILLI },
1802 .expectExitResultUnit = VM_SECOND
1803 });
1804
1805 runScript({
1806 .code = R"NKSP_CODE(
1807 on init
1808 exit(1.0s - 145.0)
1809 end on
1810 )NKSP_CODE",
1811 .expectParseError = true // units must match for - operator
1812 });
1813
1814 runScript({
1815 .code = R"NKSP_CODE(
1816 on init
1817 exit(1.0 - 145.0s)
1818 end on
1819 )NKSP_CODE",
1820 .expectParseError = true // units must match for - operator
1821 });
1822
1823 runScript({
1824 .code = R"NKSP_CODE(
1825 on init
1826 exit(1.0ms - 145.0mB)
1827 end on
1828 )NKSP_CODE",
1829 .expectParseError = true // units must match for - operator
1830 });
1831
1832 // 'final' ('!') operator tests ...
1833
1834 runScript({
1835 .code = R"NKSP_CODE(
1836 on init
1837 exit(!5 - !3)
1838 end on
1839 )NKSP_CODE",
1840 .expectIntExitResult = 2,
1841 .expectExitResultFinal = true
1842 });
1843
1844 runScript({
1845 .code = R"NKSP_CODE(
1846 on init
1847 exit(5 - 3)
1848 end on
1849 )NKSP_CODE",
1850 .expectIntExitResult = 2,
1851 .expectExitResultFinal = false
1852 });
1853
1854 runScript({
1855 .code = R"NKSP_CODE(
1856 on init
1857 exit(!5.9 - !3.3)
1858 end on
1859 )NKSP_CODE",
1860 .expectRealExitResult = 2.6,
1861 .expectExitResultFinal = true
1862 });
1863
1864 runScript({
1865 .code = R"NKSP_CODE(
1866 on init
1867 exit(5.9 - 3.3)
1868 end on
1869 )NKSP_CODE",
1870 .expectRealExitResult = 2.6,
1871 .expectExitResultFinal = false
1872 });
1873
1874 #if !SILENT_TEST
1875 std::cout << std::endl;
1876 #endif
1877 }
1878
1879 static void testModuloOperator() {
1880 #if !SILENT_TEST
1881 std::cout << "UNIT TEST: modulo (mod) operator\n";
1882 #endif
1883
1884 // integer tests ...
1885
1886 runScript({
1887 .code = R"NKSP_CODE(
1888 on init
1889 exit(10 mod 8)
1890 end on
1891 )NKSP_CODE",
1892 .expectIntExitResult = 2
1893 });
1894
1895 runScript({
1896 .code = R"NKSP_CODE(
1897 on init
1898 declare $a := 10
1899 declare $b := 8
1900 exit($a mod $b)
1901 end on
1902 )NKSP_CODE",
1903 .expectIntExitResult = 2
1904 });
1905
1906 // real number tests ...
1907 // (mod operator prohibits real numbers ATM)
1908
1909 runScript({
1910 .code = R"NKSP_CODE(
1911 on init
1912 exit(10.0 mod 8.0)
1913 end on
1914 )NKSP_CODE",
1915 .expectParseError = true // mod operator prohibits real numbers ATM
1916 });
1917
1918 runScript({
1919 .code = R"NKSP_CODE(
1920 on init
1921 exit(10 mod 8.0)
1922 end on
1923 )NKSP_CODE",
1924 .expectParseError = true // mod operator prohibits real numbers ATM
1925 });
1926
1927 runScript({
1928 .code = R"NKSP_CODE(
1929 on init
1930 exit(10.0 mod 8)
1931 end on
1932 )NKSP_CODE",
1933 .expectParseError = true // mod operator prohibits real numbers ATM
1934 });
1935
1936 runScript({
1937 .code = R"NKSP_CODE(
1938 on init
1939 declare ~a := 10.0
1940 declare ~b := 8.0
1941 exit(~a mod ~b)
1942 end on
1943 )NKSP_CODE",
1944 .expectParseError = true // mod operator prohibits real numbers ATM
1945 });
1946
1947 // std unit tests ...
1948
1949 runScript({
1950 .code = R"NKSP_CODE(
1951 on init
1952 exit(10s mod 8)
1953 end on
1954 )NKSP_CODE",
1955 .expectParseError = true // mod operator prohibits std units ATM
1956 });
1957
1958 runScript({
1959 .code = R"NKSP_CODE(
1960 on init
1961 exit(10 mod 8s)
1962 end on
1963 )NKSP_CODE",
1964 .expectParseError = true // mod operator prohibits std units ATM
1965 });
1966
1967 runScript({
1968 .code = R"NKSP_CODE(
1969 on init
1970 exit(10s mod 8s)
1971 end on
1972 )NKSP_CODE",
1973 .expectParseError = true // mod operator prohibits std units ATM
1974 });
1975
1976 // 'final' ('!') operator tests ...
1977
1978 runScript({
1979 .code = R"NKSP_CODE(
1980 on init
1981 exit(!10 mod !8)
1982 end on
1983 )NKSP_CODE",
1984 .expectIntExitResult = 2,
1985 .expectExitResultFinal = true
1986 });
1987
1988 runScript({
1989 .code = R"NKSP_CODE(
1990 on init
1991 exit(10 mod 8)
1992 end on
1993 )NKSP_CODE",
1994 .expectIntExitResult = 2,
1995 .expectExitResultFinal = false
1996 });
1997
1998 #if !SILENT_TEST
1999 std::cout << std::endl;
2000 #endif
2001 }
2002
2003 static void testMultiplyOperator() {
2004 #if !SILENT_TEST
2005 std::cout << "UNIT TEST: multiply (*) operator\n";
2006 #endif
2007
2008 // integer tests ...
2009
2010 runScript({
2011 .code = R"NKSP_CODE(
2012 on init
2013 exit(10 * 8)
2014 end on
2015 )NKSP_CODE",
2016 .expectIntExitResult = 80
2017 });
2018
2019 runScript({
2020 .code = R"NKSP_CODE(
2021 on init
2022 exit(-3 * -4)
2023 end on
2024 )NKSP_CODE",
2025 .expectIntExitResult = 12
2026 });
2027
2028 runScript({
2029 .code = R"NKSP_CODE(
2030 on init
2031 exit(-52 * 63)
2032 end on
2033 )NKSP_CODE",
2034 .expectIntExitResult = -3276
2035 });
2036
2037 runScript({
2038 .code = R"NKSP_CODE(
2039 on init
2040 exit(123 * -59)
2041 end on
2042 )NKSP_CODE",
2043 .expectIntExitResult = -7257
2044 });
2045
2046 // real number tests ...
2047
2048 runScript({
2049 .code = R"NKSP_CODE(
2050 on init
2051 exit(10.2 * 8.4)
2052 end on
2053 )NKSP_CODE",
2054 .expectRealExitResult = 85.68
2055 });
2056
2057 runScript({
2058 .code = R"NKSP_CODE(
2059 on init
2060 exit(10.0 * -3.33)
2061 end on
2062 )NKSP_CODE",
2063 .expectRealExitResult = -33.3
2064 });
2065
2066 runScript({
2067 .code = R"NKSP_CODE(
2068 on init
2069 exit(-3.33 * 10.0)
2070 end on
2071 )NKSP_CODE",
2072 .expectRealExitResult = -33.3
2073 });
2074
2075 runScript({
2076 .code = R"NKSP_CODE(
2077 on init
2078 exit(-3.33 * -10.0)
2079 end on
2080 )NKSP_CODE",
2081 .expectRealExitResult = 33.3
2082 });
2083
2084 // mixed type tests ...
2085 // (mixed int * real forbidden ATM)
2086
2087 runScript({
2088 .code = R"NKSP_CODE(
2089 on init
2090 exit(2 * 3.0)
2091 end on
2092 )NKSP_CODE",
2093 .expectParseError = true // mixed int * real forbidden ATM
2094 });
2095
2096 runScript({
2097 .code = R"NKSP_CODE(
2098 on init
2099 exit(2.0 * 3)
2100 end on
2101 )NKSP_CODE",
2102 .expectParseError = true // mixed int * real forbidden ATM
2103 });
2104
2105 // std unit tests ...
2106
2107 runScript({
2108 .code = R"NKSP_CODE(
2109 on init
2110 exit(10ms * 8)
2111 end on
2112 )NKSP_CODE",
2113 .expectIntExitResult = 80,
2114 .expectExitResultUnitPrefix = { VM_MILLI },
2115 .expectExitResultUnit = VM_SECOND
2116 });
2117
2118 runScript({
2119 .code = R"NKSP_CODE(
2120 on init
2121 exit(10 * 8ms)
2122 end on
2123 )NKSP_CODE",
2124 .expectIntExitResult = 80,
2125 .expectExitResultUnitPrefix = { VM_MILLI },
2126 .expectExitResultUnit = VM_SECOND
2127 });
2128
2129 runScript({
2130 .code = R"NKSP_CODE(
2131 on init
2132 exit(10s * 8s)
2133 end on
2134 )NKSP_CODE",
2135 .expectParseError = true // units on both sides not allowed for * ATM
2136 });
2137
2138 runScript({
2139 .code = R"NKSP_CODE(
2140 on init
2141 exit(10cs * 8d)
2142 end on
2143 )NKSP_CODE",
2144 .expectIntExitResult = 80,
2145 .expectExitResultUnitPrefix = { VM_MILLI },
2146 .expectExitResultUnit = VM_SECOND
2147 });
2148
2149 runScript({
2150 .code = R"NKSP_CODE(
2151 on init
2152 exit(10m * 8ms)
2153 end on
2154 )NKSP_CODE",
2155 .expectIntExitResult = 80,
2156 .expectExitResultUnitPrefix = { VM_MICRO },
2157 .expectExitResultUnit = VM_SECOND
2158 });
2159
2160 runScript({
2161 .code = R"NKSP_CODE(
2162 on init
2163 exit(10ms * 8k)
2164 end on
2165 )NKSP_CODE",
2166 .expectIntExitResult = 80,
2167 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
2168 .expectExitResultUnit = VM_SECOND
2169 });
2170
2171 runScript({
2172 .code = R"NKSP_CODE(
2173 on init
2174 exit(10.1ms * 8.0)
2175 end on
2176 )NKSP_CODE",
2177 .expectRealExitResult = 80.8,
2178 .expectExitResultUnitPrefix = { VM_MILLI },
2179 .expectExitResultUnit = VM_SECOND
2180 });
2181
2182 runScript({
2183 .code = R"NKSP_CODE(
2184 on init
2185 exit(10.1 * 8.0ms)
2186 end on
2187 )NKSP_CODE",
2188 .expectRealExitResult = 80.8,
2189 .expectExitResultUnitPrefix = { VM_MILLI },
2190 .expectExitResultUnit = VM_SECOND
2191 });
2192
2193 runScript({
2194 .code = R"NKSP_CODE(
2195 on init
2196 exit(10.0s * 8.0s)
2197 end on
2198 )NKSP_CODE",
2199 .expectParseError = true // units on both sides not allowed for * ATM
2200 });
2201
2202 runScript({
2203 .code = R"NKSP_CODE(
2204 on init
2205 exit(10.1ds * 8.0c)
2206 end on
2207 )NKSP_CODE",
2208 .expectRealExitResult = 80.8,
2209 .expectExitResultUnitPrefix = { VM_MILLI },
2210 .expectExitResultUnit = VM_SECOND
2211 });
2212
2213 runScript({
2214 .code = R"NKSP_CODE(
2215 on init
2216 exit(10.1m * 8.0ms)
2217 end on
2218 )NKSP_CODE",
2219 .expectRealExitResult = 80.8,
2220 .expectExitResultUnitPrefix = { VM_MICRO },
2221 .expectExitResultUnit = VM_SECOND
2222 });
2223
2224 runScript({
2225 .code = R"NKSP_CODE(
2226 on init
2227 exit(10.1m * 8.0ks)
2228 end on
2229 )NKSP_CODE",
2230 .expectRealExitResult = 80.8,
2231 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
2232 .expectExitResultUnit = VM_SECOND
2233 });
2234
2235 runScript({
2236 .code = R"NKSP_CODE(
2237 on init
2238 declare ~foo := 1.0 { neutral }
2239 declare $bar := 7000ms
2240 exit(~foo * real($bar))
2241 end on
2242 )NKSP_CODE",
2243 .expectRealExitResult = 7000.0,
2244 .expectExitResultUnitPrefix = { VM_MILLI },
2245 .expectExitResultUnit = VM_SECOND
2246 });
2247
2248 runScript({
2249 .code = R"NKSP_CODE(
2250 on init
2251 declare $foo := 1 { neutral }
2252 declare $bar := 7000ms
2253 exit(real($foo) * real($bar))
2254 end on
2255 )NKSP_CODE",
2256 .expectRealExitResult = 7000.0,
2257 .expectExitResultUnitPrefix = { VM_MILLI },
2258 .expectExitResultUnit = VM_SECOND
2259 });
2260
2261 // 'final' ('!') operator tests ...
2262
2263 runScript({
2264 .code = R"NKSP_CODE(
2265 on init
2266 exit(!10 * !8)
2267 end on
2268 )NKSP_CODE",
2269 .expectIntExitResult = 80,
2270 .expectExitResultFinal = true
2271 });
2272
2273 runScript({
2274 .code = R"NKSP_CODE(
2275 on init
2276 exit(10 * 8)
2277 end on
2278 )NKSP_CODE",
2279 .expectIntExitResult = 80,
2280 .expectExitResultFinal = false
2281 });
2282
2283 runScript({
2284 .code = R"NKSP_CODE(
2285 on init
2286 exit(!10 * 8)
2287 end on
2288 )NKSP_CODE",
2289 .expectIntExitResult = 80,
2290 .expectExitResultFinal = true,
2291 .expectParseWarning = true // since final only on one side, result will be final though
2292 });
2293
2294 runScript({
2295 .code = R"NKSP_CODE(
2296 on init
2297 exit(10 * !8)
2298 end on
2299 )NKSP_CODE",
2300 .expectIntExitResult = 80,
2301 .expectExitResultFinal = true,
2302 .expectParseWarning = true // since final only on one side, result will be final though
2303 });
2304
2305 runScript({
2306 .code = R"NKSP_CODE(
2307 on init
2308 exit(!10.1 * !8.0)
2309 end on
2310 )NKSP_CODE",
2311 .expectRealExitResult = 80.8,
2312 .expectExitResultFinal = true
2313 });
2314
2315 runScript({
2316 .code = R"NKSP_CODE(
2317 on init
2318 exit(10.1 * 8.0)
2319 end on
2320 )NKSP_CODE",
2321 .expectRealExitResult = 80.8,
2322 .expectExitResultFinal = false
2323 });
2324
2325 runScript({
2326 .code = R"NKSP_CODE(
2327 on init
2328 exit(!10.1 * 8.0)
2329 end on
2330 )NKSP_CODE",
2331 .expectRealExitResult = 80.8,
2332 .expectExitResultFinal = true,
2333 .expectParseWarning = true // since final only on one side, result will be final though
2334 });
2335
2336 runScript({
2337 .code = R"NKSP_CODE(
2338 on init
2339 exit(10.1 * !8.0)
2340 end on
2341 )NKSP_CODE",
2342 .expectRealExitResult = 80.8,
2343 .expectExitResultFinal = true,
2344 .expectParseWarning = true // since final only on one side, result will be final though
2345 });
2346
2347 #if !SILENT_TEST
2348 std::cout << std::endl;
2349 #endif
2350 }
2351
2352 static void testDivideOperator() {
2353 #if !SILENT_TEST
2354 std::cout << "UNIT TEST: divide (/) operator\n";
2355 #endif
2356
2357 // integer tests ...
2358
2359 runScript({
2360 .code = R"NKSP_CODE(
2361 on init
2362 exit(9 / 3)
2363 end on
2364 )NKSP_CODE",
2365 .expectIntExitResult = 3
2366 });
2367
2368 runScript({
2369 .code = R"NKSP_CODE(
2370 on init
2371 exit(-27 / 3)
2372 end on
2373 )NKSP_CODE",
2374 .expectIntExitResult = -9
2375 });
2376
2377 runScript({
2378 .code = R"NKSP_CODE(
2379 on init
2380 exit(35 / -5)
2381 end on
2382 )NKSP_CODE",
2383 .expectIntExitResult = -7
2384 });
2385
2386 runScript({
2387 .code = R"NKSP_CODE(
2388 on init
2389 exit(39 / -5)
2390 end on
2391 )NKSP_CODE",
2392 .expectIntExitResult = -7
2393 });
2394
2395 // real number tests ...
2396
2397 runScript({
2398 .code = R"NKSP_CODE(
2399 on init
2400 exit(9.0 / 10.0)
2401 end on
2402 )NKSP_CODE",
2403 .expectRealExitResult = 0.9
2404 });
2405
2406 runScript({
2407 .code = R"NKSP_CODE(
2408 on init
2409 exit(-9.0 / 10.0)
2410 end on
2411 )NKSP_CODE",
2412 .expectRealExitResult = -0.9
2413 });
2414
2415 runScript({
2416 .code = R"NKSP_CODE(
2417 on init
2418 exit(9.0 / -10.0)
2419 end on
2420 )NKSP_CODE",
2421 .expectRealExitResult = -0.9
2422 });
2423
2424 runScript({
2425 .code = R"NKSP_CODE(
2426 on init
2427 exit(-9.0 / -10.0)
2428 end on
2429 )NKSP_CODE",
2430 .expectRealExitResult = 0.9
2431 });
2432
2433 // mixed type tests ...
2434 // (mixed int / real forbidden ATM)
2435
2436 runScript({
2437 .code = R"NKSP_CODE(
2438 on init
2439 exit(9 / 10.0)
2440 end on
2441 )NKSP_CODE",
2442 .expectParseError = true // mixed int / real forbidden ATM
2443 });
2444
2445 runScript({
2446 .code = R"NKSP_CODE(
2447 on init
2448 exit(9.0 / 10)
2449 end on
2450 )NKSP_CODE",
2451 .expectParseError = true // mixed int / real forbidden ATM
2452 });
2453
2454 // std unit tests ...
2455
2456 runScript({
2457 .code = R"NKSP_CODE(
2458 on init
2459 exit(-27us / 3)
2460 end on
2461 )NKSP_CODE",
2462 .expectIntExitResult = -9,
2463 .expectExitResultUnitPrefix = { VM_MICRO },
2464 .expectExitResultUnit = VM_SECOND
2465 });
2466
2467 runScript({
2468 .code = R"NKSP_CODE(
2469 on init
2470 exit(-27mdB / 3mdB)
2471 end on
2472 )NKSP_CODE",
2473 .expectIntExitResult = -9,
2474 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
2475 .expectExitResultUnit = VM_NO_UNIT
2476 });
2477
2478 runScript({
2479 .code = R"NKSP_CODE(
2480 on init
2481 exit(-27s / 3m)
2482 end on
2483 )NKSP_CODE",
2484 .expectIntExitResult = -9,
2485 .expectExitResultUnitPrefix = { VM_KILO },
2486 .expectExitResultUnit = VM_SECOND
2487 });
2488
2489 runScript({
2490 .code = R"NKSP_CODE(
2491 on init
2492 exit(-27us / 3m)
2493 end on
2494 )NKSP_CODE",
2495 .expectIntExitResult = -9,
2496 .expectExitResultUnitPrefix = { VM_MILLI },
2497 .expectExitResultUnit = VM_SECOND
2498 });
2499
2500 runScript({
2501 .code = R"NKSP_CODE(
2502 on init
2503 exit(-27 / 3s)
2504 end on
2505 )NKSP_CODE",
2506 .expectParseError = true // illegal unit type arrangement for divisions
2507 });
2508
2509 runScript({
2510 .code = R"NKSP_CODE(
2511 on init
2512 exit(-27s / 3Hz)
2513 end on
2514 )NKSP_CODE",
2515 .expectParseError = true // unit types are not matching
2516 });
2517
2518 runScript({
2519 .code = R"NKSP_CODE(
2520 on init
2521 declare $foo := 1000000
2522 declare $bar := 7000ms
2523 exit(real($foo) / 1000000.0 * real($bar))
2524 end on
2525 )NKSP_CODE",
2526 .expectRealExitResult = 7000.0,
2527 .expectExitResultUnitPrefix = { VM_MILLI },
2528 .expectExitResultUnit = VM_SECOND
2529 });
2530
2531 // 'final' ('!') operator tests ...
2532
2533 runScript({
2534 .code = R"NKSP_CODE(
2535 on init
2536 exit(!-27 / !3)
2537 end on
2538 )NKSP_CODE",
2539 .expectIntExitResult = -9,
2540 .expectExitResultFinal = true
2541 });
2542
2543 runScript({
2544 .code = R"NKSP_CODE(
2545 on init
2546 exit(-27 / 3)
2547 end on
2548 )NKSP_CODE",
2549 .expectIntExitResult = -9,
2550 .expectExitResultFinal = false
2551 });
2552
2553 runScript({
2554 .code = R"NKSP_CODE(
2555 on init
2556 exit(!-27 / 3)
2557 end on
2558 )NKSP_CODE",
2559 .expectIntExitResult = -9,
2560 .expectExitResultFinal = true,
2561 .expectParseWarning = true // final only on one side, result will be final though
2562 });
2563
2564 runScript({
2565 .code = R"NKSP_CODE(
2566 on init
2567 exit(-27 / !3)
2568 end on
2569 )NKSP_CODE",
2570 .expectIntExitResult = -9,
2571 .expectExitResultFinal = true,
2572 .expectParseWarning = true // final only on one side, result will be final though
2573 });
2574
2575 #if !SILENT_TEST
2576 std::cout << std::endl;
2577 #endif
2578 }
2579
2580 static void testSmallerThanOperator() {
2581 #if !SILENT_TEST
2582 std::cout << "UNIT TEST: smaller than (<) operator\n";
2583 #endif
2584
2585 // integer tests ...
2586
2587 runScript({
2588 .code = R"NKSP_CODE(
2589 on init
2590 exit(3 < 4)
2591 end on
2592 )NKSP_CODE",
2593 .expectBoolExitResult = true
2594 });
2595
2596 runScript({
2597 .code = R"NKSP_CODE(
2598 on init
2599 exit(4 < 3)
2600 end on
2601 )NKSP_CODE",
2602 .expectBoolExitResult = false
2603 });
2604
2605 runScript({
2606 .code = R"NKSP_CODE(
2607 on init
2608 exit(-4 < 3)
2609 end on
2610 )NKSP_CODE",
2611 .expectBoolExitResult = true
2612 });
2613
2614 runScript({
2615 .code = R"NKSP_CODE(
2616 on init
2617 exit(3 < -4)
2618 end on
2619 )NKSP_CODE",
2620 .expectBoolExitResult = false
2621 });
2622
2623 runScript({
2624 .code = R"NKSP_CODE(
2625 on init
2626 exit(123 < -45)
2627 end on
2628 )NKSP_CODE",
2629 .expectBoolExitResult = false
2630 });
2631
2632 runScript({
2633 .code = R"NKSP_CODE(
2634 on init
2635 exit(-45 < 123)
2636 end on
2637 )NKSP_CODE",
2638 .expectBoolExitResult = true
2639 });
2640
2641 // real number tests ...
2642
2643 runScript({
2644 .code = R"NKSP_CODE(
2645 on init
2646 exit(3.0 < 4.0)
2647 end on
2648 )NKSP_CODE",
2649 .expectBoolExitResult = true
2650 });
2651
2652 runScript({
2653 .code = R"NKSP_CODE(
2654 on init
2655 exit(4.0 < 3.0)
2656 end on
2657 )NKSP_CODE",
2658 .expectBoolExitResult = false
2659 });
2660
2661 runScript({
2662 .code = R"NKSP_CODE(
2663 on init
2664 exit(1.2 < 1.23)
2665 end on
2666 )NKSP_CODE",
2667 .expectBoolExitResult = true
2668 });
2669
2670 runScript({
2671 .code = R"NKSP_CODE(
2672 on init
2673 exit(1.23 < 1.2)
2674 end on
2675 )NKSP_CODE",
2676 .expectBoolExitResult = false
2677 });
2678
2679 runScript({
2680 .code = R"NKSP_CODE(
2681 on init
2682 exit(-4.0 < 3.0)
2683 end on
2684 )NKSP_CODE",
2685 .expectBoolExitResult = true
2686 });
2687
2688 runScript({
2689 .code = R"NKSP_CODE(
2690 on init
2691 exit(3.0 < -4.0)
2692 end on
2693 )NKSP_CODE",
2694 .expectBoolExitResult = false
2695 });
2696
2697 runScript({
2698 .code = R"NKSP_CODE(
2699 on init
2700 exit(123.0 < -45.0)
2701 end on
2702 )NKSP_CODE",
2703 .expectBoolExitResult = false
2704 });
2705
2706 runScript({
2707 .code = R"NKSP_CODE(
2708 on init
2709 exit(-45.0 < 123.0)
2710 end on
2711 )NKSP_CODE",
2712 .expectBoolExitResult = true
2713 });
2714
2715 // mixed type tests ...
2716
2717 runScript({
2718 .code = R"NKSP_CODE(
2719 on init
2720 exit(9 < 9.1)
2721 end on
2722 )NKSP_CODE",
2723 .expectBoolExitResult = true
2724 });
2725
2726 runScript({
2727 .code = R"NKSP_CODE(
2728 on init
2729 exit(9.1 < 9)
2730 end on
2731 )NKSP_CODE",
2732 .expectBoolExitResult = false
2733 });
2734
2735 // std unit tests ...
2736
2737 runScript({
2738 .code = R"NKSP_CODE(
2739 on init
2740 exit(13ms < 14ms)
2741 end on
2742 )NKSP_CODE",
2743 .expectBoolExitResult = true
2744 });
2745
2746 runScript({
2747 .code = R"NKSP_CODE(
2748 on init
2749 exit(14ms < 13ms)
2750 end on
2751 )NKSP_CODE",
2752 .expectBoolExitResult = false
2753 });
2754
2755 runScript({
2756 .code = R"NKSP_CODE(
2757 on init
2758 exit(1s < 990ms)
2759 end on
2760 )NKSP_CODE",
2761 .expectBoolExitResult = false
2762 });
2763
2764 runScript({
2765 .code = R"NKSP_CODE(
2766 on init
2767 exit(990ms < 1s)
2768 end on
2769 )NKSP_CODE",
2770 .expectBoolExitResult = true
2771 });
2772
2773 runScript({
2774 .code = R"NKSP_CODE(
2775 on init
2776 exit(1000ms < 1s)
2777 end on
2778 )NKSP_CODE",
2779 .expectBoolExitResult = false
2780 });
2781
2782 runScript({
2783 .code = R"NKSP_CODE(
2784 on init
2785 exit(1s < 1000ms)
2786 end on
2787 )NKSP_CODE",
2788 .expectBoolExitResult = false
2789 });
2790
2791 runScript({
2792 .code = R"NKSP_CODE(
2793 on init
2794 exit(1s < 1)
2795 end on
2796 )NKSP_CODE",
2797 .expectParseError = true // units on both sides must match
2798 });
2799
2800 runScript({
2801 .code = R"NKSP_CODE(
2802 on init
2803 exit(1 < 1s)
2804 end on
2805 )NKSP_CODE",
2806 .expectParseError = true // units on both sides must match
2807 });
2808
2809 runScript({
2810 .code = R"NKSP_CODE(
2811 on init
2812 exit(1Hz < 1B)
2813 end on
2814 )NKSP_CODE",
2815 .expectParseError = true // units on both sides must match
2816 });
2817
2818 runScript({
2819 .code = R"NKSP_CODE(
2820 on init
2821 exit(13.0ms < 13.1ms)
2822 end on
2823 )NKSP_CODE",
2824 .expectBoolExitResult = true
2825 });
2826
2827 runScript({
2828 .code = R"NKSP_CODE(
2829 on init
2830 exit(13.1ms < 13.0ms)
2831 end on
2832 )NKSP_CODE",
2833 .expectBoolExitResult = false
2834 });
2835
2836 runScript({
2837 .code = R"NKSP_CODE(
2838 on init
2839 exit(0.9s < 600.0ms)
2840 end on
2841 )NKSP_CODE",
2842 .expectBoolExitResult = false
2843 });
2844
2845 runScript({
2846 .code = R"NKSP_CODE(
2847 on init
2848 exit(600.0ms < 0.9s)
2849 end on
2850 )NKSP_CODE",
2851 .expectBoolExitResult = true
2852 });
2853
2854 runScript({
2855 .code = R"NKSP_CODE(
2856 on init
2857 exit(5.1kHz < 5100.0Hz)
2858 end on
2859 )NKSP_CODE",
2860 .expectBoolExitResult = false
2861 });
2862
2863 runScript({
2864 .code = R"NKSP_CODE(
2865 on init
2866 exit(5100.0Hz < 5.1kHz)
2867 end on
2868 )NKSP_CODE",
2869 .expectBoolExitResult = false
2870 });
2871
2872 runScript({
2873 .code = R"NKSP_CODE(
2874 on init
2875 exit(1.0Hz < 1.1)
2876 end on
2877 )NKSP_CODE",
2878 .expectParseError = true // units on both sides must match
2879 });
2880
2881 runScript({
2882 .code = R"NKSP_CODE(
2883 on init
2884 exit(1.2 < 1.34mdB)
2885 end on
2886 )NKSP_CODE",
2887 .expectParseError = true // units on both sides must match
2888 });
2889
2890 runScript({
2891 .code = R"NKSP_CODE(
2892 on init
2893 exit(9.23us < 3.14kHz)
2894 end on
2895 )NKSP_CODE",
2896 .expectParseError = true // units on both sides must match
2897 });
2898
2899 // 'final' ('!') operator tests ...
2900 // (should always yield in false for relation operators)
2901
2902 runScript({
2903 .code = R"NKSP_CODE(
2904 on init
2905 exit(!-4 < !3)
2906 end on
2907 )NKSP_CODE",
2908 .expectBoolExitResult = true,
2909 .expectExitResultFinal = false
2910 });
2911
2912 runScript({
2913 .code = R"NKSP_CODE(
2914 on init
2915 exit(-4 < 3)
2916 end on
2917 )NKSP_CODE",
2918 .expectBoolExitResult = true,
2919 .expectExitResultFinal = false
2920 });
2921
2922 #if !SILENT_TEST
2923 std::cout << std::endl;
2924 #endif
2925 }
2926
2927 static void testGreaterThanOperator() {
2928 #if !SILENT_TEST
2929 std::cout << "UNIT TEST: greater than (>) operator\n";
2930 #endif
2931
2932 // integer tests ...
2933
2934 runScript({
2935 .code = R"NKSP_CODE(
2936 on init
2937 exit(3 > 4)
2938 end on
2939 )NKSP_CODE",
2940 .expectBoolExitResult = false
2941 });
2942
2943 runScript({
2944 .code = R"NKSP_CODE(
2945 on init
2946 exit(4 > 3)
2947 end on
2948 )NKSP_CODE",
2949 .expectBoolExitResult = true
2950 });
2951
2952 runScript({
2953 .code = R"NKSP_CODE(
2954 on init
2955 exit(-4 > 3)
2956 end on
2957 )NKSP_CODE",
2958 .expectBoolExitResult = false
2959 });
2960
2961 runScript({
2962 .code = R"NKSP_CODE(
2963 on init
2964 exit(3 > -4)
2965 end on
2966 )NKSP_CODE",
2967 .expectBoolExitResult = true
2968 });
2969
2970 runScript({
2971 .code = R"NKSP_CODE(
2972 on init
2973 exit(123 > -45)
2974 end on
2975 )NKSP_CODE",
2976 .expectBoolExitResult = true
2977 });
2978
2979 runScript({
2980 .code = R"NKSP_CODE(
2981 on init
2982 exit(-45 > 123)
2983 end on
2984 )NKSP_CODE",
2985 .expectBoolExitResult = false
2986 });
2987
2988 // real number tests ...
2989
2990 runScript({
2991 .code = R"NKSP_CODE(
2992 on init
2993 exit(3.0 > 4.0)
2994 end on
2995 )NKSP_CODE",
2996 .expectBoolExitResult = false
2997 });
2998
2999 runScript({
3000 .code = R"NKSP_CODE(
3001 on init
3002 exit(4.0 > 3.0)
3003 end on
3004 )NKSP_CODE",
3005 .expectBoolExitResult = true
3006 });
3007
3008 runScript({
3009 .code = R"NKSP_CODE(
3010 on init
3011 exit(1.2 > 1.23)
3012 end on
3013 )NKSP_CODE",
3014 .expectBoolExitResult = false
3015 });
3016
3017 runScript({
3018 .code = R"NKSP_CODE(
3019 on init
3020 exit(1.23 > 1.2)
3021 end on
3022 )NKSP_CODE",
3023 .expectBoolExitResult = true
3024 });
3025
3026 runScript({
3027 .code = R"NKSP_CODE(
3028 on init
3029 exit(-4.0 > 3.0)
3030 end on
3031 )NKSP_CODE",
3032 .expectBoolExitResult = false
3033 });
3034
3035 runScript({
3036 .code = R"NKSP_CODE(
3037 on init
3038 exit(3.0 > -4.0)
3039 end on
3040 )NKSP_CODE",
3041 .expectBoolExitResult = true
3042 });
3043
3044 runScript({
3045 .code = R"NKSP_CODE(
3046 on init
3047 exit(123.0 > -45.0)
3048 end on
3049 )NKSP_CODE",
3050 .expectBoolExitResult = true
3051 });
3052
3053 runScript({
3054 .code = R"NKSP_CODE(
3055 on init
3056 exit(-45.0 > 123.0)
3057 end on
3058 )NKSP_CODE",
3059 .expectBoolExitResult = false
3060 });
3061
3062 // mixed type tests ...
3063
3064 runScript({
3065 .code = R"NKSP_CODE(
3066 on init
3067 exit(9 > 9.1)
3068 end on
3069 )NKSP_CODE",
3070 .expectBoolExitResult = false
3071 });
3072
3073 runScript({
3074 .code = R"NKSP_CODE(
3075 on init
3076 exit(9.1 > 9)
3077 end on
3078 )NKSP_CODE",
3079 .expectBoolExitResult = true
3080 });
3081
3082 // std unit tests ...
3083
3084 runScript({
3085 .code = R"NKSP_CODE(
3086 on init
3087 exit(13ms > 14ms)
3088 end on
3089 )NKSP_CODE",
3090 .expectBoolExitResult = false
3091 });
3092
3093 runScript({
3094 .code = R"NKSP_CODE(
3095 on init
3096 exit(14ms > 13ms)
3097 end on
3098 )NKSP_CODE",
3099 .expectBoolExitResult = true
3100 });
3101
3102 runScript({
3103 .code = R"NKSP_CODE(
3104 on init
3105 exit(1s > 990ms)
3106 end on
3107 )NKSP_CODE",
3108 .expectBoolExitResult = true
3109 });
3110
3111 runScript({
3112 .code = R"NKSP_CODE(
3113 on init
3114 exit(990ms > 1s)
3115 end on
3116 )NKSP_CODE",
3117 .expectBoolExitResult = false
3118 });
3119
3120 runScript({
3121 .code = R"NKSP_CODE(
3122 on init
3123 exit(1000ms > 1s)
3124 end on
3125 )NKSP_CODE",
3126 .expectBoolExitResult = false
3127 });
3128
3129 runScript({
3130 .code = R"NKSP_CODE(
3131 on init
3132 exit(1s > 1000ms)
3133 end on
3134 )NKSP_CODE",
3135 .expectBoolExitResult = false
3136 });
3137
3138 runScript({
3139 .code = R"NKSP_CODE(
3140 on init
3141 exit(1s > 1)
3142 end on
3143 )NKSP_CODE",
3144 .expectParseError = true // units on both sides must match
3145 });
3146
3147 runScript({
3148 .code = R"NKSP_CODE(
3149 on init
3150 exit(1 > 1s)
3151 end on
3152 )NKSP_CODE",
3153 .expectParseError = true // units on both sides must match
3154 });
3155
3156 runScript({
3157 .code = R"NKSP_CODE(
3158 on init
3159 exit(1Hz > 1B)
3160 end on
3161 )NKSP_CODE",
3162 .expectParseError = true // units on both sides must match
3163 });
3164
3165 runScript({
3166 .code = R"NKSP_CODE(
3167 on init
3168 exit(13.0ms > 13.1ms)
3169 end on
3170 )NKSP_CODE",
3171 .expectBoolExitResult = false
3172 });
3173
3174 runScript({
3175 .code = R"NKSP_CODE(
3176 on init
3177 exit(13.1ms > 13.0ms)
3178 end on
3179 )NKSP_CODE",
3180 .expectBoolExitResult = true
3181 });
3182
3183 runScript({
3184 .code = R"NKSP_CODE(
3185 on init
3186 exit(0.9s > 600.0ms)
3187 end on
3188 )NKSP_CODE",
3189 .expectBoolExitResult = true
3190 });
3191
3192 runScript({
3193 .code = R"NKSP_CODE(
3194 on init
3195 exit(600.0ms > 0.9s)
3196 end on
3197 )NKSP_CODE",
3198 .expectBoolExitResult = false
3199 });
3200
3201 runScript({
3202 .code = R"NKSP_CODE(
3203 on init
3204 exit(5.1kHz > 5100.0Hz)
3205 end on
3206 )NKSP_CODE",
3207 .expectBoolExitResult = false
3208 });
3209
3210 runScript({
3211 .code = R"NKSP_CODE(
3212 on init
3213 exit(5100.0Hz > 5.1kHz)
3214 end on
3215 )NKSP_CODE",
3216 .expectBoolExitResult = false
3217 });
3218
3219 runScript({
3220 .code = R"NKSP_CODE(
3221 on init
3222 exit(1.0Hz > 1.1)
3223 end on
3224 )NKSP_CODE",
3225 .expectParseError = true // units on both sides must match
3226 });
3227
3228 runScript({
3229 .code = R"NKSP_CODE(
3230 on init
3231 exit(1.2 > 1.34mdB)
3232 end on
3233 )NKSP_CODE",
3234 .expectParseError = true // units on both sides must match
3235 });
3236
3237 runScript({
3238 .code = R"NKSP_CODE(
3239 on init
3240 exit(9.23us > 3.14kHz)
3241 end on
3242 )NKSP_CODE",
3243 .expectParseError = true // units on both sides must match
3244 });
3245
3246 // 'final' ('!') operator tests ...
3247 // (should always yield in false for relation operators)
3248
3249 runScript({
3250 .code = R"NKSP_CODE(
3251 on init
3252 exit(!-4 > !3)
3253 end on
3254 )NKSP_CODE",
3255 .expectBoolExitResult = false,
3256 .expectExitResultFinal = false
3257 });
3258
3259 runScript({
3260 .code = R"NKSP_CODE(
3261 on init
3262 exit(-4 > 3)
3263 end on
3264 )NKSP_CODE",
3265 .expectBoolExitResult = false,
3266 .expectExitResultFinal = false
3267 });
3268
3269 #if !SILENT_TEST
3270 std::cout << std::endl;
3271 #endif
3272 }
3273
3274 static void testSmallerOrEqualOperator() {
3275 #if !SILENT_TEST
3276 std::cout << "UNIT TEST: smaller-or-equal (<=) operator\n";
3277 #endif
3278
3279 // integer tests ...
3280
3281 runScript({
3282 .code = R"NKSP_CODE(
3283 on init
3284 exit(3 <= 3)
3285 end on
3286 )NKSP_CODE",
3287 .expectBoolExitResult = true
3288 });
3289
3290 runScript({
3291 .code = R"NKSP_CODE(
3292 on init
3293 exit(4 <= 4)
3294 end on
3295 )NKSP_CODE",
3296 .expectBoolExitResult = true
3297 });
3298
3299 runScript({
3300 .code = R"NKSP_CODE(
3301 on init
3302 exit(-23 <= -23)
3303 end on
3304 )NKSP_CODE",
3305 .expectBoolExitResult = true
3306 });
3307
3308 runScript({
3309 .code = R"NKSP_CODE(
3310 on init
3311 exit(23 <= -23)
3312 end on
3313 )NKSP_CODE",
3314 .expectBoolExitResult = false
3315 });
3316
3317 runScript({
3318 .code = R"NKSP_CODE(
3319 on init
3320 exit(3 <= 4)
3321 end on
3322 )NKSP_CODE",
3323 .expectBoolExitResult = true
3324 });
3325
3326 runScript({
3327 .code = R"NKSP_CODE(
3328 on init
3329 exit(4 <= 3)
3330 end on
3331 )NKSP_CODE",
3332 .expectBoolExitResult = false
3333 });
3334
3335 runScript({
3336 .code = R"NKSP_CODE(
3337 on init
3338 exit(-4 <= 3)
3339 end on
3340 )NKSP_CODE",
3341 .expectBoolExitResult = true
3342 });
3343
3344 runScript({
3345 .code = R"NKSP_CODE(
3346 on init
3347 exit(3 <= -4)
3348 end on
3349 )NKSP_CODE",
3350 .expectBoolExitResult = false
3351 });
3352
3353 runScript({
3354 .code = R"NKSP_CODE(
3355 on init
3356 exit(123 <= -45)
3357 end on
3358 )NKSP_CODE",
3359 .expectBoolExitResult = false
3360 });
3361
3362 runScript({
3363 .code = R"NKSP_CODE(
3364 on init
3365 exit(-45 <= 123)
3366 end on
3367 )NKSP_CODE",
3368 .expectBoolExitResult = true
3369 });
3370
3371 // real number tests ...
3372
3373 runScript({
3374 .code = R"NKSP_CODE(
3375 on init
3376 exit(3.0 <= 3.0)
3377 end on
3378 )NKSP_CODE",
3379 .expectBoolExitResult = true
3380 });
3381
3382 runScript({
3383 .code = R"NKSP_CODE(
3384 on init
3385 exit(4.33 <= 4.33)
3386 end on
3387 )NKSP_CODE",
3388 .expectBoolExitResult = true
3389 });
3390
3391 runScript({
3392 .code = R"NKSP_CODE(
3393 on init
3394 exit(-23.1 <= -23.1)
3395 end on
3396 )NKSP_CODE",
3397 .expectBoolExitResult = true
3398 });
3399
3400 runScript({
3401 .code = R"NKSP_CODE(
3402 on init
3403 exit(23.3 <= -23.3)
3404 end on
3405 )NKSP_CODE",
3406 .expectBoolExitResult = false
3407 });
3408
3409 runScript({
3410 .code = R"NKSP_CODE(
3411 on init
3412 exit(3.0 <= 4.0)
3413 end on
3414 )NKSP_CODE",
3415 .expectBoolExitResult = true
3416 });
3417
3418 runScript({
3419 .code = R"NKSP_CODE(
3420 on init
3421 exit(4.0 <= 3.0)
3422 end on
3423 )NKSP_CODE",
3424 .expectBoolExitResult = false
3425 });
3426
3427 runScript({
3428 .code = R"NKSP_CODE(
3429 on init
3430 exit(-4.0 <= 3.0)
3431 end on
3432 )NKSP_CODE",
3433 .expectBoolExitResult = true
3434 });
3435
3436 runScript({
3437 .code = R"NKSP_CODE(
3438 on init
3439 exit(3.0 <= -4.0)
3440 end on
3441 )NKSP_CODE",
3442 .expectBoolExitResult = false
3443 });
3444
3445 runScript({
3446 .code = R"NKSP_CODE(
3447 on init
3448 exit(123.0 <= -45.0)
3449 end on
3450 )NKSP_CODE",
3451 .expectBoolExitResult = false
3452 });
3453
3454 runScript({
3455 .code = R"NKSP_CODE(
3456 on init
3457 exit(-45.0 <= 123.0)
3458 end on
3459 )NKSP_CODE",
3460 .expectBoolExitResult = true
3461 });
3462
3463 // mixed type tests ...
3464
3465 runScript({
3466 .code = R"NKSP_CODE(
3467 on init
3468 exit(9 <= 9.1)
3469 end on
3470 )NKSP_CODE",
3471 .expectBoolExitResult = true
3472 });
3473
3474 runScript({
3475 .code = R"NKSP_CODE(
3476 on init
3477 exit(9.1 <= 9)
3478 end on
3479 )NKSP_CODE",
3480 .expectBoolExitResult = false
3481 });
3482
3483 runScript({
3484 .code = R"NKSP_CODE(
3485 on init
3486 exit(9 <= 9.0)
3487 end on
3488 )NKSP_CODE",
3489 .expectBoolExitResult = true
3490 });
3491
3492 runScript({
3493 .code = R"NKSP_CODE(
3494 on init
3495 exit(9.0 <= 9)
3496 end on
3497 )NKSP_CODE",
3498 .expectBoolExitResult = true
3499 });
3500
3501 // std unit tests ...
3502
3503 runScript({
3504 .code = R"NKSP_CODE(
3505 on init
3506 exit(13ms <= 14ms)
3507 end on
3508 )NKSP_CODE",
3509 .expectBoolExitResult = true
3510 });
3511
3512 runScript({
3513 .code = R"NKSP_CODE(
3514 on init
3515 exit(14ms <= 13ms)
3516 end on
3517 )NKSP_CODE",
3518 .expectBoolExitResult = false
3519 });
3520
3521 runScript({
3522 .code = R"NKSP_CODE(
3523 on init
3524 exit(1s <= 990ms)
3525 end on
3526 )NKSP_CODE",
3527 .expectBoolExitResult = false
3528 });
3529
3530 runScript({
3531 .code = R"NKSP_CODE(
3532 on init
3533 exit(990ms <= 1s)
3534 end on
3535 )NKSP_CODE",
3536 .expectBoolExitResult = true
3537 });
3538
3539 runScript({
3540 .code = R"NKSP_CODE(
3541 on init
3542 exit(1000ms <= 1s)
3543 end on
3544 )NKSP_CODE",
3545 .expectBoolExitResult = true
3546 });
3547
3548 runScript({
3549 .code = R"NKSP_CODE(
3550 on init
3551 exit(1s <= 1000ms)
3552 end on
3553 )NKSP_CODE",
3554 .expectBoolExitResult = true
3555 });
3556
3557 runScript({
3558 .code = R"NKSP_CODE(
3559 on init
3560 exit(1s <= 1)
3561 end on
3562 )NKSP_CODE",
3563 .expectParseError = true // units on both sides must match
3564 });
3565
3566 runScript({
3567 .code = R"NKSP_CODE(
3568 on init
3569 exit(1 <= 1s)
3570 end on
3571 )NKSP_CODE",
3572 .expectParseError = true // units on both sides must match
3573 });
3574
3575 runScript({
3576 .code = R"NKSP_CODE(
3577 on init
3578 exit(1Hz <= 1B)
3579 end on
3580 )NKSP_CODE",
3581 .expectParseError = true // units on both sides must match
3582 });
3583
3584 runScript({
3585 .code = R"NKSP_CODE(
3586 on init
3587 exit(13.0ms <= 13.1ms)
3588 end on
3589 )NKSP_CODE",
3590 .expectBoolExitResult = true
3591 });
3592
3593 runScript({
3594 .code = R"NKSP_CODE(
3595 on init
3596 exit(13.1ms <= 13.0ms)
3597 end on
3598 )NKSP_CODE",
3599 .expectBoolExitResult = false
3600 });
3601
3602 runScript({
3603 .code = R"NKSP_CODE(
3604 on init
3605 exit(0.9s <= 600.0ms)
3606 end on
3607 )NKSP_CODE",
3608 .expectBoolExitResult = false
3609 });
3610
3611 runScript({
3612 .code = R"NKSP_CODE(
3613 on init
3614 exit(600.0ms <= 0.9s)
3615 end on
3616 )NKSP_CODE",
3617 .expectBoolExitResult = true
3618 });
3619
3620 runScript({
3621 .code = R"NKSP_CODE(
3622 on init
3623 exit(5.1kHz <= 5100.0Hz)
3624 end on
3625 )NKSP_CODE",
3626 .expectBoolExitResult = true
3627 });
3628
3629 runScript({
3630 .code = R"NKSP_CODE(
3631 on init
3632 exit(5100.0Hz <= 5.1kHz)
3633 end on
3634 )NKSP_CODE",
3635 .expectBoolExitResult = true
3636 });
3637
3638 runScript({
3639 .code = R"NKSP_CODE(
3640 on init
3641 exit(1.0Hz <= 1.1)
3642 end on
3643 )NKSP_CODE",
3644 .expectParseError = true // units on both sides must match
3645 });
3646
3647 runScript({
3648 .code = R"NKSP_CODE(
3649 on init
3650 exit(1.2 <= 1.34mdB)
3651 end on
3652 )NKSP_CODE",
3653 .expectParseError = true // units on both sides must match
3654 });
3655
3656 runScript({
3657 .code = R"NKSP_CODE(
3658 on init
3659 exit(9.23us <= 3.14kHz)
3660 end on
3661 )NKSP_CODE",
3662 .expectParseError = true // units on both sides must match
3663 });
3664
3665 // 'final' ('!') operator tests ...
3666 // (should always yield in false for relation operators)
3667
3668 runScript({
3669 .code = R"NKSP_CODE(
3670 on init
3671 exit(!-4 <= !3)
3672 end on
3673 )NKSP_CODE",
3674 .expectBoolExitResult = true,
3675 .expectExitResultFinal = false
3676 });
3677
3678 runScript({
3679 .code = R"NKSP_CODE(
3680 on init
3681 exit(-4 <= 3)
3682 end on
3683 )NKSP_CODE",
3684 .expectBoolExitResult = true,
3685 .expectExitResultFinal = false
3686 });
3687
3688 #if !SILENT_TEST
3689 std::cout << std::endl;
3690 #endif
3691 }
3692
3693 static void testGreaterOrEqualOperator() {
3694 #if !SILENT_TEST
3695 std::cout << "UNIT TEST: greater-or-equal (>=) operator\n";
3696 #endif
3697
3698 // integer tests ...
3699
3700 runScript({
3701 .code = R"NKSP_CODE(
3702 on init
3703 exit(3 >= 3)
3704 end on
3705 )NKSP_CODE",
3706 .expectBoolExitResult = true
3707 });
3708
3709 runScript({
3710 .code = R"NKSP_CODE(
3711 on init
3712 exit(4 >= 4)
3713 end on
3714 )NKSP_CODE",
3715 .expectBoolExitResult = true
3716 });
3717
3718 runScript({
3719 .code = R"NKSP_CODE(
3720 on init
3721 exit(-23 >= -23)
3722 end on
3723 )NKSP_CODE",
3724 .expectBoolExitResult = true
3725 });
3726
3727 runScript({
3728 .code = R"NKSP_CODE(
3729 on init
3730 exit(23 >= -23)
3731 end on
3732 )NKSP_CODE",
3733 .expectBoolExitResult = true
3734 });
3735
3736 runScript({
3737 .code = R"NKSP_CODE(
3738 on init
3739 exit(3 >= 4)
3740 end on
3741 )NKSP_CODE",
3742 .expectBoolExitResult = false
3743 });
3744
3745 runScript({
3746 .code = R"NKSP_CODE(
3747 on init
3748 exit(4 >= 3)
3749 end on
3750 )NKSP_CODE",
3751 .expectBoolExitResult = true
3752 });
3753
3754 runScript({
3755 .code = R"NKSP_CODE(
3756 on init
3757 exit(-4 >= 3)
3758 end on
3759 )NKSP_CODE",
3760 .expectBoolExitResult = false
3761 });
3762
3763 runScript({
3764 .code = R"NKSP_CODE(
3765 on init
3766 exit(3 >= -4)
3767 end on
3768 )NKSP_CODE",
3769 .expectBoolExitResult = true
3770 });
3771
3772 runScript({
3773 .code = R"NKSP_CODE(
3774 on init
3775 exit(123 >= -45)
3776 end on
3777 )NKSP_CODE",
3778 .expectBoolExitResult = true
3779 });
3780
3781 runScript({
3782 .code = R"NKSP_CODE(
3783 on init
3784 exit(-45 >= 123)
3785 end on
3786 )NKSP_CODE",
3787 .expectBoolExitResult = false
3788 });
3789
3790 // real number tests ...
3791
3792 runScript({
3793 .code = R"NKSP_CODE(
3794 on init
3795 exit(3.0 >= 3.0)
3796 end on
3797 )NKSP_CODE",
3798 .expectBoolExitResult = true
3799 });
3800
3801 runScript({
3802 .code = R"NKSP_CODE(
3803 on init
3804 exit(3.1 >= 3.1)
3805 end on
3806 )NKSP_CODE",
3807 .expectBoolExitResult = true
3808 });
3809
3810 runScript({
3811 .code = R"NKSP_CODE(
3812 on init
3813 exit(3.1 >= 3.0)
3814 end on
3815 )NKSP_CODE",
3816 .expectBoolExitResult = true
3817 });
3818
3819 runScript({
3820 .code = R"NKSP_CODE(
3821 on init
3822 exit(3.0 >= 3.1)
3823 end on
3824 )NKSP_CODE",
3825 .expectBoolExitResult = false
3826 });
3827
3828 runScript({
3829 .code = R"NKSP_CODE(
3830 on init
3831 exit(-23.33 >= -23.33)
3832 end on
3833 )NKSP_CODE",
3834 .expectBoolExitResult = true
3835 });
3836
3837 runScript({
3838 .code = R"NKSP_CODE(
3839 on init
3840 exit(23.0 >= -23.0)
3841 end on
3842 )NKSP_CODE",
3843 .expectBoolExitResult = true
3844 });
3845
3846 runScript({
3847 .code = R"NKSP_CODE(
3848 on init
3849 exit(3.0 >= 4.0)
3850 end on
3851 )NKSP_CODE",
3852 .expectBoolExitResult = false
3853 });
3854
3855 runScript({
3856 .code = R"NKSP_CODE(
3857 on init
3858 exit(4.0 >= 3.0)
3859 end on
3860 )NKSP_CODE",
3861 .expectBoolExitResult = true
3862 });
3863
3864 runScript({
3865 .code = R"NKSP_CODE(
3866 on init
3867 exit(-4.0 >= 3.0)
3868 end on
3869 )NKSP_CODE",
3870 .expectBoolExitResult = false
3871 });
3872
3873 runScript({
3874 .code = R"NKSP_CODE(
3875 on init
3876 exit(3.0 >= -4.0)
3877 end on
3878 )NKSP_CODE",
3879 .expectBoolExitResult = true
3880 });
3881
3882 runScript({
3883 .code = R"NKSP_CODE(
3884 on init
3885 exit(123.0 >= -45.0)
3886 end on
3887 )NKSP_CODE",
3888 .expectBoolExitResult = true
3889 });
3890
3891 runScript({
3892 .code = R"NKSP_CODE(
3893 on init
3894 exit(-45.0 >= 123.0)
3895 end on
3896 )NKSP_CODE",
3897 .expectBoolExitResult = false
3898 });
3899
3900 // mixed type tests ...
3901
3902 runScript({
3903 .code = R"NKSP_CODE(
3904 on init
3905 exit(9 >= 9.1)
3906 end on
3907 )NKSP_CODE",
3908 .expectBoolExitResult = false
3909 });
3910
3911 runScript({
3912 .code = R"NKSP_CODE(
3913 on init
3914 exit(9.1 >= 9)
3915 end on
3916 )NKSP_CODE",
3917 .expectBoolExitResult = true
3918 });
3919
3920 runScript({
3921 .code = R"NKSP_CODE(
3922 on init
3923 exit(9 >= 9.0)
3924 end on
3925 )NKSP_CODE",
3926 .expectBoolExitResult = true
3927 });
3928
3929 runScript({
3930 .code = R"NKSP_CODE(
3931 on init
3932 exit(9.0 >= 9)
3933 end on
3934 )NKSP_CODE",
3935 .expectBoolExitResult = true
3936 });
3937
3938 // std unit tests ...
3939
3940 runScript({
3941 .code = R"NKSP_CODE(
3942 on init
3943 exit(13ms >= 14ms)
3944 end on
3945 )NKSP_CODE",
3946 .expectBoolExitResult = false
3947 });
3948
3949 runScript({
3950 .code = R"NKSP_CODE(
3951 on init
3952 exit(14ms >= 13ms)
3953 end on
3954 )NKSP_CODE",
3955 .expectBoolExitResult = true
3956 });
3957
3958 runScript({
3959 .code = R"NKSP_CODE(
3960 on init
3961 exit(1s >= 990ms)
3962 end on
3963 )NKSP_CODE",
3964 .expectBoolExitResult = true
3965 });
3966
3967 runScript({
3968 .code = R"NKSP_CODE(
3969 on init
3970 exit(990ms >= 1s)
3971 end on
3972 )NKSP_CODE",
3973 .expectBoolExitResult = false
3974 });
3975
3976 runScript({
3977 .code = R"NKSP_CODE(
3978 on init
3979 exit(1000ms >= 1s)
3980 end on
3981 )NKSP_CODE",
3982 .expectBoolExitResult = true
3983 });
3984
3985 runScript({
3986 .code = R"NKSP_CODE(
3987 on init
3988 exit(1s >= 1000ms)
3989 end on
3990 )NKSP_CODE",
3991 .expectBoolExitResult = true
3992 });
3993
3994 runScript({
3995 .code = R"NKSP_CODE(
3996 on init
3997 exit(1s >= 1)
3998 end on
3999 )NKSP_CODE",
4000 .expectParseError = true // units on both sides must match
4001 });
4002
4003 runScript({
4004 .code = R"NKSP_CODE(
4005 on init
4006 exit(1 >= 1s)
4007 end on
4008 )NKSP_CODE",
4009 .expectParseError = true // units on both sides must match
4010 });
4011
4012 runScript({
4013 .code = R"NKSP_CODE(
4014 on init
4015 exit(1Hz >= 1B)
4016 end on
4017 )NKSP_CODE",
4018 .expectParseError = true // units on both sides must match
4019 });
4020
4021 runScript({
4022 .code = R"NKSP_CODE(
4023 on init
4024 exit(13.0ms >= 13.1ms)
4025 end on
4026 )NKSP_CODE",
4027 .expectBoolExitResult = false
4028 });
4029
4030 runScript({
4031 .code = R"NKSP_CODE(
4032 on init
4033 exit(13.1ms >= 13.0ms)
4034 end on
4035 )NKSP_CODE",
4036 .expectBoolExitResult = true
4037 });
4038
4039 runScript({
4040 .code = R"NKSP_CODE(
4041 on init
4042 exit(0.9s >= 600.0ms)
4043 end on
4044 )NKSP_CODE",
4045 .expectBoolExitResult = true
4046 });
4047
4048 runScript({
4049 .code = R"NKSP_CODE(
4050 on init
4051 exit(600.0ms >= 0.9s)
4052 end on
4053 )NKSP_CODE",
4054 .expectBoolExitResult = false
4055 });
4056
4057 runScript({
4058 .code = R"NKSP_CODE(
4059 on init
4060 exit(5.1kHz >= 5100.0Hz)
4061 end on
4062 )NKSP_CODE",
4063 .expectBoolExitResult = true
4064 });
4065
4066 runScript({
4067 .code = R"NKSP_CODE(
4068 on init
4069 exit(5100.0Hz >= 5.1kHz)
4070 end on
4071 )NKSP_CODE",
4072 .expectBoolExitResult = true
4073 });
4074
4075 runScript({
4076 .code = R"NKSP_CODE(
4077 on init
4078 exit(1.0Hz >= 1.1)
4079 end on
4080 )NKSP_CODE",
4081 .expectParseError = true // units on both sides must match
4082 });
4083
4084 runScript({
4085 .code = R"NKSP_CODE(
4086 on init
4087 exit(1.2 >= 1.34mdB)
4088 end on
4089 )NKSP_CODE",
4090 .expectParseError = true // units on both sides must match
4091 });
4092
4093 runScript({
4094 .code = R"NKSP_CODE(
4095 on init
4096 exit(9.23us >= 3.14kHz)
4097 end on
4098 )NKSP_CODE",
4099 .expectParseError = true // units on both sides must match
4100 });
4101
4102 // 'final' ('!') operator tests ...
4103 // (should always yield in false for relation operators)
4104
4105 runScript({
4106 .code = R"NKSP_CODE(
4107 on init
4108 exit(!-4 >= !3)
4109 end on
4110 )NKSP_CODE",
4111 .expectBoolExitResult = false,
4112 .expectExitResultFinal = false
4113 });
4114
4115 runScript({
4116 .code = R"NKSP_CODE(
4117 on init
4118 exit(-4 >= 3)
4119 end on
4120 )NKSP_CODE",
4121 .expectBoolExitResult = false,
4122 .expectExitResultFinal = false
4123 });
4124
4125 #if !SILENT_TEST
4126 std::cout << std::endl;
4127 #endif
4128 }
4129
4130 static void testEqualOperator() {
4131 #if !SILENT_TEST
4132 std::cout << "UNIT TEST: equal (=) operator\n";
4133 #endif
4134
4135 // integer tests ...
4136
4137 runScript({
4138 .code = R"NKSP_CODE(
4139 on init
4140 exit(3 = 3)
4141 end on
4142 )NKSP_CODE",
4143 .expectBoolExitResult = true
4144 });
4145
4146 runScript({
4147 .code = R"NKSP_CODE(
4148 on init
4149 exit(4 = 4)
4150 end on
4151 )NKSP_CODE",
4152 .expectBoolExitResult = true
4153 });
4154
4155 runScript({
4156 .code = R"NKSP_CODE(
4157 on init
4158 exit(3 = 4)
4159 end on
4160 )NKSP_CODE",
4161 .expectBoolExitResult = false
4162 });
4163
4164 runScript({
4165 .code = R"NKSP_CODE(
4166 on init
4167 exit(23 = -23)
4168 end on
4169 )NKSP_CODE",
4170 .expectBoolExitResult = false
4171 });
4172
4173 // real number tests ...
4174
4175 runScript({
4176 .code = R"NKSP_CODE(
4177 on init
4178 exit(3.0 = 3.0)
4179 end on
4180 )NKSP_CODE",
4181 .expectBoolExitResult = true
4182 });
4183
4184 runScript({
4185 .code = R"NKSP_CODE(
4186 on init
4187 exit(4.33 = 4.33)
4188 end on
4189 )NKSP_CODE",
4190 .expectBoolExitResult = true
4191 });
4192
4193 runScript({
4194 .code = R"NKSP_CODE(
4195 on init
4196 exit(4.31 = 4.35)
4197 end on
4198 )NKSP_CODE",
4199 .expectBoolExitResult = false
4200 });
4201
4202 runScript({
4203 .code = R"NKSP_CODE(
4204 on init
4205 exit(3.0 = 4.0)
4206 end on
4207 )NKSP_CODE",
4208 .expectBoolExitResult = false
4209 });
4210
4211 runScript({
4212 .code = R"NKSP_CODE(
4213 on init
4214 exit(23.0 = -23.0)
4215 end on
4216 )NKSP_CODE",
4217 .expectBoolExitResult = false
4218 });
4219
4220 // deal with inaccuracy of float point
4221 runScript({
4222 .code = R"NKSP_CODE(
4223 on init
4224 declare ~a := 0.165
4225 declare ~b := 0.185
4226 declare ~x := 0.1
4227 declare ~y := 0.25
4228 exit(~a + ~b = ~x + ~y) { both sides should actually be 0.35, they slightly deviate both though }
4229 end on
4230 )NKSP_CODE",
4231 .expectBoolExitResult = true // our implementation of real number equal comparison should take care about floating point tolerance
4232 });
4233
4234 // deal with inaccuracy of float point
4235 runScript({
4236 .code = R"NKSP_CODE(
4237 on init
4238 declare ~a := 0.166
4239 declare ~b := 0.185
4240 declare ~x := 0.1
4241 declare ~y := 0.25
4242 exit(~a + ~b = ~x + ~y) { left side approx. 0.351, right side approx. 0.35 }
4243 end on
4244 )NKSP_CODE",
4245 .expectBoolExitResult = false
4246 });
4247
4248 // mixed type tests ...
4249
4250 runScript({
4251 .code = R"NKSP_CODE(
4252 on init
4253 exit(23 = 23.0)
4254 end on
4255 )NKSP_CODE",
4256 .expectBoolExitResult = true
4257 });
4258
4259 runScript({
4260 .code = R"NKSP_CODE(
4261 on init
4262 exit(23.0 = 23)
4263 end on
4264 )NKSP_CODE",
4265 .expectBoolExitResult = true
4266 });
4267
4268 runScript({
4269 .code = R"NKSP_CODE(
4270 on init
4271 exit(23 = 23.1)
4272 end on
4273 )NKSP_CODE",
4274 .expectBoolExitResult = false
4275 });
4276
4277 runScript({
4278 .code = R"NKSP_CODE(
4279 on init
4280 exit(23.1 = 23)
4281 end on
4282 )NKSP_CODE",
4283 .expectBoolExitResult = false
4284 });
4285
4286 // std unit tests ...
4287
4288 runScript({
4289 .code = R"NKSP_CODE(
4290 on init
4291 exit(13ms = 14ms)
4292 end on
4293 )NKSP_CODE",
4294 .expectBoolExitResult = false
4295 });
4296
4297 runScript({
4298 .code = R"NKSP_CODE(
4299 on init
4300 exit(14ms = 13ms)
4301 end on
4302 )NKSP_CODE",
4303 .expectBoolExitResult = false
4304 });
4305
4306 runScript({
4307 .code = R"NKSP_CODE(
4308 on init
4309 exit(1s = 1ms)
4310 end on
4311 )NKSP_CODE",
4312 .expectBoolExitResult = false
4313 });
4314
4315 runScript({
4316 .code = R"NKSP_CODE(
4317 on init
4318 exit(1ms = 1s)
4319 end on
4320 )NKSP_CODE",
4321 .expectBoolExitResult = false
4322 });
4323
4324 runScript({
4325 .code = R"NKSP_CODE(
4326 on init
4327 exit(3.14kHz = 3140Hz)
4328 end on
4329 )NKSP_CODE",
4330 .expectBoolExitResult = true
4331 });
4332
4333 runScript({
4334 .code = R"NKSP_CODE(
4335