/[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 3600 - (show annotations) (download)
Sun Sep 15 22:25:17 2019 UTC (2 months, 4 weeks ago) by schoenebeck
File size: 183414 byte(s)
Just renamed NKSPTest.cpp -> NKSPCoreLangTest.cpp.

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