/[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 3747 - (show annotations) (download)
Sun Feb 16 11:31:46 2020 UTC (7 weeks, 2 days ago) by schoenebeck
File size: 226299 byte(s)
* NKSP: Fixed re-entrant issue with function calls which caused wrong
  result values if the same function was called multiple times in a term
  (specifically if metric prefixes were used).

* Tests: Added NKSP core language test cases to guard this fixed issue.

* Bumped version (2.1.1.svn50).

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 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 runScript({
2099 .code = R"NKSP_CODE(
2100 on init
2101 declare ~foo := 1.0 { neutral }
2102 declare $bar := 7000ms
2103 exit(~foo * real($bar))
2104 end on
2105 )NKSP_CODE",
2106 .expectRealExitResult = 7000.0,
2107 .expectExitResultUnitPrefix = { VM_MILLI },
2108 .expectExitResultUnit = VM_SECOND
2109 });
2110
2111 runScript({
2112 .code = R"NKSP_CODE(
2113 on init
2114 declare $foo := 1 { neutral }
2115 declare $bar := 7000ms
2116 exit(real($foo) * real($bar))
2117 end on
2118 )NKSP_CODE",
2119 .expectRealExitResult = 7000.0,
2120 .expectExitResultUnitPrefix = { VM_MILLI },
2121 .expectExitResultUnit = VM_SECOND
2122 });
2123
2124 // 'final' ('!') operator tests ...
2125
2126 runScript({
2127 .code = R"NKSP_CODE(
2128 on init
2129 exit(!10 * !8)
2130 end on
2131 )NKSP_CODE",
2132 .expectIntExitResult = 80,
2133 .expectExitResultFinal = true
2134 });
2135
2136 runScript({
2137 .code = R"NKSP_CODE(
2138 on init
2139 exit(10 * 8)
2140 end on
2141 )NKSP_CODE",
2142 .expectIntExitResult = 80,
2143 .expectExitResultFinal = false
2144 });
2145
2146 runScript({
2147 .code = R"NKSP_CODE(
2148 on init
2149 exit(!10 * 8)
2150 end on
2151 )NKSP_CODE",
2152 .expectIntExitResult = 80,
2153 .expectExitResultFinal = true,
2154 .expectParseWarning = true // since final only on one side, result will be final though
2155 });
2156
2157 runScript({
2158 .code = R"NKSP_CODE(
2159 on init
2160 exit(10 * !8)
2161 end on
2162 )NKSP_CODE",
2163 .expectIntExitResult = 80,
2164 .expectExitResultFinal = true,
2165 .expectParseWarning = true // since final only on one side, result will be final though
2166 });
2167
2168 runScript({
2169 .code = R"NKSP_CODE(
2170 on init
2171 exit(!10.1 * !8.0)
2172 end on
2173 )NKSP_CODE",
2174 .expectRealExitResult = 80.8,
2175 .expectExitResultFinal = true
2176 });
2177
2178 runScript({
2179 .code = R"NKSP_CODE(
2180 on init
2181 exit(10.1 * 8.0)
2182 end on
2183 )NKSP_CODE",
2184 .expectRealExitResult = 80.8,
2185 .expectExitResultFinal = false
2186 });
2187
2188 runScript({
2189 .code = R"NKSP_CODE(
2190 on init
2191 exit(!10.1 * 8.0)
2192 end on
2193 )NKSP_CODE",
2194 .expectRealExitResult = 80.8,
2195 .expectExitResultFinal = true,
2196 .expectParseWarning = true // since final only on one side, result will be final though
2197 });
2198
2199 runScript({
2200 .code = R"NKSP_CODE(
2201 on init
2202 exit(10.1 * !8.0)
2203 end on
2204 )NKSP_CODE",
2205 .expectRealExitResult = 80.8,
2206 .expectExitResultFinal = true,
2207 .expectParseWarning = true // since final only on one side, result will be final though
2208 });
2209
2210 #if !SILENT_TEST
2211 std::cout << std::endl;
2212 #endif
2213 }
2214
2215 static void testDivideOperator() {
2216 #if !SILENT_TEST
2217 std::cout << "UNIT TEST: divide (/) operator\n";
2218 #endif
2219
2220 // integer tests ...
2221
2222 runScript({
2223 .code = R"NKSP_CODE(
2224 on init
2225 exit(9 / 3)
2226 end on
2227 )NKSP_CODE",
2228 .expectIntExitResult = 3
2229 });
2230
2231 runScript({
2232 .code = R"NKSP_CODE(
2233 on init
2234 exit(-27 / 3)
2235 end on
2236 )NKSP_CODE",
2237 .expectIntExitResult = -9
2238 });
2239
2240 runScript({
2241 .code = R"NKSP_CODE(
2242 on init
2243 exit(35 / -5)
2244 end on
2245 )NKSP_CODE",
2246 .expectIntExitResult = -7
2247 });
2248
2249 runScript({
2250 .code = R"NKSP_CODE(
2251 on init
2252 exit(39 / -5)
2253 end on
2254 )NKSP_CODE",
2255 .expectIntExitResult = -7
2256 });
2257
2258 // real number tests ...
2259
2260 runScript({
2261 .code = R"NKSP_CODE(
2262 on init
2263 exit(9.0 / 10.0)
2264 end on
2265 )NKSP_CODE",
2266 .expectRealExitResult = 0.9
2267 });
2268
2269 runScript({
2270 .code = R"NKSP_CODE(
2271 on init
2272 exit(-9.0 / 10.0)
2273 end on
2274 )NKSP_CODE",
2275 .expectRealExitResult = -0.9
2276 });
2277
2278 runScript({
2279 .code = R"NKSP_CODE(
2280 on init
2281 exit(9.0 / -10.0)
2282 end on
2283 )NKSP_CODE",
2284 .expectRealExitResult = -0.9
2285 });
2286
2287 runScript({
2288 .code = R"NKSP_CODE(
2289 on init
2290 exit(-9.0 / -10.0)
2291 end on
2292 )NKSP_CODE",
2293 .expectRealExitResult = 0.9
2294 });
2295
2296 // mixed type tests ...
2297 // (mixed int / real forbidden ATM)
2298
2299 runScript({
2300 .code = R"NKSP_CODE(
2301 on init
2302 exit(9 / 10.0)
2303 end on
2304 )NKSP_CODE",
2305 .expectParseError = true // mixed int / real forbidden ATM
2306 });
2307
2308 runScript({
2309 .code = R"NKSP_CODE(
2310 on init
2311 exit(9.0 / 10)
2312 end on
2313 )NKSP_CODE",
2314 .expectParseError = true // mixed int / real forbidden ATM
2315 });
2316
2317 // std unit tests ...
2318
2319 runScript({
2320 .code = R"NKSP_CODE(
2321 on init
2322 exit(-27us / 3)
2323 end on
2324 )NKSP_CODE",
2325 .expectIntExitResult = -9,
2326 .expectExitResultUnitPrefix = { VM_MICRO },
2327 .expectExitResultUnit = VM_SECOND
2328 });
2329
2330 runScript({
2331 .code = R"NKSP_CODE(
2332 on init
2333 exit(-27mdB / 3mdB)
2334 end on
2335 )NKSP_CODE",
2336 .expectIntExitResult = -9,
2337 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
2338 .expectExitResultUnit = VM_NO_UNIT
2339 });
2340
2341 runScript({
2342 .code = R"NKSP_CODE(
2343 on init
2344 exit(-27s / 3m)
2345 end on
2346 )NKSP_CODE",
2347 .expectIntExitResult = -9,
2348 .expectExitResultUnitPrefix = { VM_KILO },
2349 .expectExitResultUnit = VM_SECOND
2350 });
2351
2352 runScript({
2353 .code = R"NKSP_CODE(
2354 on init
2355 exit(-27us / 3m)
2356 end on
2357 )NKSP_CODE",
2358 .expectIntExitResult = -9,
2359 .expectExitResultUnitPrefix = { VM_MILLI },
2360 .expectExitResultUnit = VM_SECOND
2361 });
2362
2363 runScript({
2364 .code = R"NKSP_CODE(
2365 on init
2366 exit(-27 / 3s)
2367 end on
2368 )NKSP_CODE",
2369 .expectParseError = true // illegal unit type arrangement for divisions
2370 });
2371
2372 runScript({
2373 .code = R"NKSP_CODE(
2374 on init
2375 exit(-27s / 3Hz)
2376 end on
2377 )NKSP_CODE",
2378 .expectParseError = true // unit types are not matching
2379 });
2380
2381 runScript({
2382 .code = R"NKSP_CODE(
2383 on init
2384 declare $foo := 1000000
2385 declare $bar := 7000ms
2386 exit(real($foo) / 1000000.0 * real($bar))
2387 end on
2388 )NKSP_CODE",
2389 .expectRealExitResult = 7000.0,
2390 .expectExitResultUnitPrefix = { VM_MILLI },
2391 .expectExitResultUnit = VM_SECOND
2392 });
2393
2394 // 'final' ('!') operator tests ...
2395
2396 runScript({
2397 .code = R"NKSP_CODE(
2398 on init
2399 exit(!-27 / !3)
2400 end on
2401 )NKSP_CODE",
2402 .expectIntExitResult = -9,
2403 .expectExitResultFinal = true
2404 });
2405
2406 runScript({
2407 .code = R"NKSP_CODE(
2408 on init
2409 exit(-27 / 3)
2410 end on
2411 )NKSP_CODE",
2412 .expectIntExitResult = -9,
2413 .expectExitResultFinal = false
2414 });
2415
2416 runScript({
2417 .code = R"NKSP_CODE(
2418 on init
2419 exit(!-27 / 3)
2420 end on
2421 )NKSP_CODE",
2422 .expectIntExitResult = -9,
2423 .expectExitResultFinal = true,
2424 .expectParseWarning = true // final only on one side, result will be final though
2425 });
2426
2427 runScript({
2428 .code = R"NKSP_CODE(
2429 on init
2430 exit(-27 / !3)
2431 end on
2432 )NKSP_CODE",
2433 .expectIntExitResult = -9,
2434 .expectExitResultFinal = true,
2435 .expectParseWarning = true // final only on one side, result will be final though
2436 });
2437
2438 #if !SILENT_TEST
2439 std::cout << std::endl;
2440 #endif
2441 }
2442
2443 static void testSmallerThanOperator() {
2444 #if !SILENT_TEST
2445 std::cout << "UNIT TEST: smaller than (<) operator\n";
2446 #endif
2447
2448 // integer tests ...
2449
2450 runScript({
2451 .code = R"NKSP_CODE(
2452 on init
2453 exit(3 < 4)
2454 end on
2455 )NKSP_CODE",
2456 .expectBoolExitResult = true
2457 });
2458
2459 runScript({
2460 .code = R"NKSP_CODE(
2461 on init
2462 exit(4 < 3)
2463 end on
2464 )NKSP_CODE",
2465 .expectBoolExitResult = false
2466 });
2467
2468 runScript({
2469 .code = R"NKSP_CODE(
2470 on init
2471 exit(-4 < 3)
2472 end on
2473 )NKSP_CODE",
2474 .expectBoolExitResult = true
2475 });
2476
2477 runScript({
2478 .code = R"NKSP_CODE(
2479 on init
2480 exit(3 < -4)
2481 end on
2482 )NKSP_CODE",
2483 .expectBoolExitResult = false
2484 });
2485
2486 runScript({
2487 .code = R"NKSP_CODE(
2488 on init
2489 exit(123 < -45)
2490 end on
2491 )NKSP_CODE",
2492 .expectBoolExitResult = false
2493 });
2494
2495 runScript({
2496 .code = R"NKSP_CODE(
2497 on init
2498 exit(-45 < 123)
2499 end on
2500 )NKSP_CODE",
2501 .expectBoolExitResult = true
2502 });
2503
2504 // real number tests ...
2505
2506 runScript({
2507 .code = R"NKSP_CODE(
2508 on init
2509 exit(3.0 < 4.0)
2510 end on
2511 )NKSP_CODE",
2512 .expectBoolExitResult = true
2513 });
2514
2515 runScript({
2516 .code = R"NKSP_CODE(
2517 on init
2518 exit(4.0 < 3.0)
2519 end on
2520 )NKSP_CODE",
2521 .expectBoolExitResult = false
2522 });
2523
2524 runScript({
2525 .code = R"NKSP_CODE(
2526 on init
2527 exit(1.2 < 1.23)
2528 end on
2529 )NKSP_CODE",
2530 .expectBoolExitResult = true
2531 });
2532
2533 runScript({
2534 .code = R"NKSP_CODE(
2535 on init
2536 exit(1.23 < 1.2)
2537 end on
2538 )NKSP_CODE",
2539 .expectBoolExitResult = false
2540 });
2541
2542 runScript({
2543 .code = R"NKSP_CODE(
2544 on init
2545 exit(-4.0 < 3.0)
2546 end on
2547 )NKSP_CODE",
2548 .expectBoolExitResult = true
2549 });
2550
2551 runScript({
2552 .code = R"NKSP_CODE(
2553 on init
2554 exit(3.0 < -4.0)
2555 end on
2556 )NKSP_CODE",
2557 .expectBoolExitResult = false
2558 });
2559
2560 runScript({
2561 .code = R"NKSP_CODE(
2562 on init
2563 exit(123.0 < -45.0)
2564 end on
2565 )NKSP_CODE",
2566 .expectBoolExitResult = false
2567 });
2568
2569 runScript({
2570 .code = R"NKSP_CODE(
2571 on init
2572 exit(-45.0 < 123.0)
2573 end on
2574 )NKSP_CODE",
2575 .expectBoolExitResult = true
2576 });
2577
2578 // mixed type tests ...
2579
2580 runScript({
2581 .code = R"NKSP_CODE(
2582 on init
2583 exit(9 < 9.1)
2584 end on
2585 )NKSP_CODE",
2586 .expectBoolExitResult = true
2587 });
2588
2589 runScript({
2590 .code = R"NKSP_CODE(
2591 on init
2592 exit(9.1 < 9)
2593 end on
2594 )NKSP_CODE",
2595 .expectBoolExitResult = false
2596 });
2597
2598 // std unit tests ...
2599
2600 runScript({
2601 .code = R"NKSP_CODE(
2602 on init
2603 exit(13ms < 14ms)
2604 end on
2605 )NKSP_CODE",
2606 .expectBoolExitResult = true
2607 });
2608
2609 runScript({
2610 .code = R"NKSP_CODE(
2611 on init
2612 exit(14ms < 13ms)
2613 end on
2614 )NKSP_CODE",
2615 .expectBoolExitResult = false
2616 });
2617
2618 runScript({
2619 .code = R"NKSP_CODE(
2620 on init
2621 exit(1s < 990ms)
2622 end on
2623 )NKSP_CODE",
2624 .expectBoolExitResult = false
2625 });
2626
2627 runScript({
2628 .code = R"NKSP_CODE(
2629 on init
2630 exit(990ms < 1s)
2631 end on
2632 )NKSP_CODE",
2633 .expectBoolExitResult = true
2634 });
2635
2636 runScript({
2637 .code = R"NKSP_CODE(
2638 on init
2639 exit(1000ms < 1s)
2640 end on
2641 )NKSP_CODE",
2642 .expectBoolExitResult = false
2643 });
2644
2645 runScript({
2646 .code = R"NKSP_CODE(
2647 on init
2648 exit(1s < 1000ms)
2649 end on
2650 )NKSP_CODE",
2651 .expectBoolExitResult = false
2652 });
2653
2654 runScript({
2655 .code = R"NKSP_CODE(
2656 on init
2657 exit(1s < 1)
2658 end on
2659 )NKSP_CODE",
2660 .expectParseError = true // units on both sides must match
2661 });
2662
2663 runScript({
2664 .code = R"NKSP_CODE(
2665 on init
2666 exit(1 < 1s)
2667 end on
2668 )NKSP_CODE",
2669 .expectParseError = true // units on both sides must match
2670 });
2671
2672 runScript({
2673 .code = R"NKSP_CODE(
2674 on init
2675 exit(1Hz < 1B)
2676 end on
2677 )NKSP_CODE",
2678 .expectParseError = true // units on both sides must match
2679 });
2680
2681 runScript({
2682 .code = R"NKSP_CODE(
2683 on init
2684 exit(13.0ms < 13.1ms)
2685 end on
2686 )NKSP_CODE",
2687 .expectBoolExitResult = true
2688 });
2689
2690 runScript({
2691 .code = R"NKSP_CODE(
2692 on init
2693 exit(13.1ms < 13.0ms)
2694 end on
2695 )NKSP_CODE",
2696 .expectBoolExitResult = false
2697 });
2698
2699 runScript({
2700 .code = R"NKSP_CODE(
2701 on init
2702 exit(0.9s < 600.0ms)
2703 end on
2704 )NKSP_CODE",
2705 .expectBoolExitResult = false
2706 });
2707
2708 runScript({
2709 .code = R"NKSP_CODE(
2710 on init
2711 exit(600.0ms < 0.9s)
2712 end on
2713 )NKSP_CODE",
2714 .expectBoolExitResult = true
2715 });
2716
2717 runScript({
2718 .code = R"NKSP_CODE(
2719 on init
2720 exit(5.1kHz < 5100.0Hz)
2721 end on
2722 )NKSP_CODE",
2723 .expectBoolExitResult = false
2724 });
2725
2726 runScript({
2727 .code = R"NKSP_CODE(
2728 on init
2729 exit(5100.0Hz < 5.1kHz)
2730 end on
2731 )NKSP_CODE",
2732 .expectBoolExitResult = false
2733 });
2734
2735 runScript({
2736 .code = R"NKSP_CODE(
2737 on init
2738 exit(1.0Hz < 1.1)
2739 end on
2740 )NKSP_CODE",
2741 .expectParseError = true // units on both sides must match
2742 });
2743
2744 runScript({
2745 .code = R"NKSP_CODE(
2746 on init
2747 exit(1.2 < 1.34mdB)
2748 end on
2749 )NKSP_CODE",
2750 .expectParseError = true // units on both sides must match
2751 });
2752
2753 runScript({
2754 .code = R"NKSP_CODE(
2755 on init
2756 exit(9.23us < 3.14kHz)
2757 end on
2758 )NKSP_CODE",
2759 .expectParseError = true // units on both sides must match
2760 });
2761
2762 // 'final' ('!') operator tests ...
2763 // (should always yield in false for relation operators)
2764
2765 runScript({
2766 .code = R"NKSP_CODE(
2767 on init
2768 exit(!-4 < !3)
2769 end on
2770 )NKSP_CODE",
2771 .expectBoolExitResult = true,
2772 .expectExitResultFinal = false
2773 });
2774
2775 runScript({
2776 .code = R"NKSP_CODE(
2777 on init
2778 exit(-4 < 3)
2779 end on
2780 )NKSP_CODE",
2781 .expectBoolExitResult = true,
2782 .expectExitResultFinal = false
2783 });
2784
2785 #if !SILENT_TEST
2786 std::cout << std::endl;
2787 #endif
2788 }
2789
2790 static void testGreaterThanOperator() {
2791 #if !SILENT_TEST
2792 std::cout << "UNIT TEST: greater than (>) operator\n";
2793 #endif
2794
2795 // integer tests ...
2796
2797 runScript({
2798 .code = R"NKSP_CODE(
2799 on init
2800 exit(3 > 4)
2801 end on
2802 )NKSP_CODE",
2803 .expectBoolExitResult = false
2804 });
2805
2806 runScript({
2807 .code = R"NKSP_CODE(
2808 on init
2809 exit(4 > 3)
2810 end on
2811 )NKSP_CODE",
2812 .expectBoolExitResult = true
2813 });
2814
2815 runScript({
2816 .code = R"NKSP_CODE(
2817 on init
2818 exit(-4 > 3)
2819 end on
2820 )NKSP_CODE",
2821 .expectBoolExitResult = false
2822 });
2823
2824 runScript({
2825 .code = R"NKSP_CODE(
2826 on init
2827 exit(3 > -4)
2828 end on
2829 )NKSP_CODE",
2830 .expectBoolExitResult = true
2831 });
2832
2833 runScript({
2834 .code = R"NKSP_CODE(
2835 on init
2836 exit(123 > -45)
2837 end on
2838 )NKSP_CODE",
2839 .expectBoolExitResult = true
2840 });
2841
2842 runScript({
2843 .code = R"NKSP_CODE(
2844 on init
2845 exit(-45 > 123)
2846 end on
2847 )NKSP_CODE",
2848 .expectBoolExitResult = false
2849 });
2850
2851 // real number tests ...
2852
2853 runScript({
2854 .code = R"NKSP_CODE(
2855 on init
2856 exit(3.0 > 4.0)
2857 end on
2858 )NKSP_CODE",
2859 .expectBoolExitResult = false
2860 });
2861
2862 runScript({
2863 .code = R"NKSP_CODE(
2864 on init
2865 exit(4.0 > 3.0)
2866 end on
2867 )NKSP_CODE",
2868 .expectBoolExitResult = true
2869 });
2870
2871 runScript({
2872 .code = R"NKSP_CODE(
2873 on init
2874 exit(1.2 > 1.23)
2875 end on
2876 )NKSP_CODE",
2877 .expectBoolExitResult = false
2878 });
2879
2880 runScript({
2881 .code = R"NKSP_CODE(
2882 on init
2883 exit(1.23 > 1.2)
2884 end on
2885 )NKSP_CODE",
2886 .expectBoolExitResult = true
2887 });
2888
2889 runScript({
2890 .code = R"NKSP_CODE(
2891 on init
2892 exit(-4.0 > 3.0)
2893 end on
2894 )NKSP_CODE",
2895 .expectBoolExitResult = false
2896 });
2897
2898 runScript({
2899 .code = R"NKSP_CODE(
2900 on init
2901 exit(3.0 > -4.0)
2902 end on
2903 )NKSP_CODE",
2904 .expectBoolExitResult = true
2905 });
2906
2907 runScript({
2908 .code = R"NKSP_CODE(
2909 on init
2910 exit(123.0 > -45.0)
2911 end on
2912 )NKSP_CODE",
2913 .expectBoolExitResult = true
2914 });
2915
2916 runScript({
2917 .code = R"NKSP_CODE(
2918 on init
2919 exit(-45.0 > 123.0)
2920 end on
2921 )NKSP_CODE",
2922 .expectBoolExitResult = false
2923 });
2924
2925 // mixed type tests ...
2926
2927 runScript({
2928 .code = R"NKSP_CODE(
2929 on init
2930 exit(9 > 9.1)
2931 end on
2932 )NKSP_CODE",
2933 .expectBoolExitResult = false
2934 });
2935
2936 runScript({
2937 .code = R"NKSP_CODE(
2938 on init
2939 exit(9.1 > 9)
2940 end on
2941 )NKSP_CODE",
2942 .expectBoolExitResult = true
2943 });
2944
2945 // std unit tests ...
2946
2947 runScript({
2948 .code = R"NKSP_CODE(
2949 on init
2950 exit(13ms > 14ms)
2951 end on
2952 )NKSP_CODE",
2953 .expectBoolExitResult = false
2954 });
2955
2956 runScript({
2957 .code = R"NKSP_CODE(
2958 on init
2959 exit(14ms > 13ms)
2960 end on
2961 )NKSP_CODE",
2962 .expectBoolExitResult = true
2963 });
2964
2965 runScript({
2966 .code = R"NKSP_CODE(
2967 on init
2968 exit(1s > 990ms)
2969 end on
2970 )NKSP_CODE",
2971 .expectBoolExitResult = true
2972 });
2973
2974 runScript({
2975 .code = R"NKSP_CODE(
2976 on init
2977 exit(990ms > 1s)
2978 end on
2979 )NKSP_CODE",
2980 .expectBoolExitResult = false
2981 });
2982
2983 runScript({
2984 .code = R"NKSP_CODE(
2985 on init
2986 exit(1000ms > 1s)
2987 end on
2988 )NKSP_CODE",
2989 .expectBoolExitResult = false
2990 });
2991
2992 runScript({
2993 .code = R"NKSP_CODE(
2994 on init
2995 exit(1s > 1000ms)
2996 end on
2997 )NKSP_CODE",
2998 .expectBoolExitResult = false
2999 });
3000
3001 runScript({
3002 .code = R"NKSP_CODE(
3003 on init
3004 exit(1s > 1)
3005 end on
3006 )NKSP_CODE",
3007 .expectParseError = true // units on both sides must match
3008 });
3009
3010 runScript({
3011 .code = R"NKSP_CODE(
3012 on init
3013 exit(1 > 1s)
3014 end on
3015 )NKSP_CODE",
3016 .expectParseError = true // units on both sides must match
3017 });
3018
3019 runScript({
3020 .code = R"NKSP_CODE(
3021 on init
3022 exit(1Hz > 1B)
3023 end on
3024 )NKSP_CODE",
3025 .expectParseError = true // units on both sides must match
3026 });
3027
3028 runScript({
3029 .code = R"NKSP_CODE(
3030 on init
3031 exit(13.0ms > 13.1ms)
3032 end on
3033 )NKSP_CODE",
3034 .expectBoolExitResult = false
3035 });
3036
3037 runScript({
3038 .code = R"NKSP_CODE(
3039 on init
3040 exit(13.1ms > 13.0ms)
3041 end on
3042 )NKSP_CODE",
3043 .expectBoolExitResult = true
3044 });
3045
3046 runScript({
3047 .code = R"NKSP_CODE(
3048 on init
3049 exit(0.9s > 600.0ms)
3050 end on
3051 )NKSP_CODE",
3052 .expectBoolExitResult = true
3053 });
3054
3055 runScript({
3056 .code = R"NKSP_CODE(
3057 on init
3058 exit(600.0ms > 0.9s)
3059 end on
3060 )NKSP_CODE",
3061 .expectBoolExitResult = false
3062 });
3063
3064 runScript({
3065 .code = R"NKSP_CODE(
3066 on init
3067 exit(5.1kHz > 5100.0Hz)
3068 end on
3069 )NKSP_CODE",
3070 .expectBoolExitResult = false
3071 });
3072
3073 runScript({
3074 .code = R"NKSP_CODE(
3075 on init
3076 exit(5100.0Hz > 5.1kHz)
3077 end on
3078 )NKSP_CODE",
3079 .expectBoolExitResult = false
3080 });
3081
3082 runScript({
3083 .code = R"NKSP_CODE(
3084 on init
3085 exit(1.0Hz > 1.1)
3086 end on
3087 )NKSP_CODE",
3088 .expectParseError = true // units on both sides must match
3089 });
3090
3091 runScript({
3092 .code = R"NKSP_CODE(
3093 on init
3094 exit(1.2 > 1.34mdB)
3095 end on
3096 )NKSP_CODE",
3097 .expectParseError = true // units on both sides must match
3098 });
3099
3100 runScript({
3101 .code = R"NKSP_CODE(
3102 on init
3103 exit(9.23us > 3.14kHz)
3104 end on
3105 )NKSP_CODE",
3106 .expectParseError = true // units on both sides must match
3107 });
3108
3109 // 'final' ('!') operator tests ...
3110 // (should always yield in false for relation operators)
3111
3112 runScript({
3113 .code = R"NKSP_CODE(
3114 on init
3115 exit(!-4 > !3)
3116 end on
3117 )NKSP_CODE",
3118 .expectBoolExitResult = false,
3119 .expectExitResultFinal = false
3120 });
3121
3122 runScript({
3123 .code = R"NKSP_CODE(
3124 on init
3125 exit(-4 > 3)
3126 end on
3127 )NKSP_CODE",
3128 .expectBoolExitResult = false,
3129 .expectExitResultFinal = false
3130 });
3131
3132 #if !SILENT_TEST
3133 std::cout << std::endl;
3134 #endif
3135 }
3136
3137 static void testSmallerOrEqualOperator() {
3138 #if !SILENT_TEST
3139 std::cout << "UNIT TEST: smaller-or-equal (<=) operator\n";
3140 #endif
3141
3142 // integer tests ...
3143
3144 runScript({
3145 .code = R"NKSP_CODE(
3146 on init
3147 exit(3 <= 3)
3148 end on
3149 )NKSP_CODE",
3150 .expectBoolExitResult = true
3151 });
3152
3153 runScript({
3154 .code = R"NKSP_CODE(
3155 on init
3156 exit(4 <= 4)
3157 end on
3158 )NKSP_CODE",
3159 .expectBoolExitResult = true
3160 });
3161
3162 runScript({
3163 .code = R"NKSP_CODE(
3164 on init
3165 exit(-23 <= -23)
3166 end on
3167 )NKSP_CODE",
3168 .expectBoolExitResult = true
3169 });
3170
3171 runScript({
3172 .code = R"NKSP_CODE(
3173 on init
3174 exit(23 <= -23)
3175 end on
3176 )NKSP_CODE",
3177 .expectBoolExitResult = false
3178 });
3179
3180 runScript({
3181 .code = R"NKSP_CODE(
3182 on init
3183 exit(3 <= 4)
3184 end on
3185 )NKSP_CODE",
3186 .expectBoolExitResult = true
3187 });
3188
3189 runScript({
3190 .code = R"NKSP_CODE(
3191 on init
3192 exit(4 <= 3)
3193 end on
3194 )NKSP_CODE",
3195 .expectBoolExitResult = false
3196 });
3197
3198 runScript({
3199 .code = R"NKSP_CODE(
3200 on init
3201 exit(-4 <= 3)
3202 end on
3203 )NKSP_CODE",
3204 .expectBoolExitResult = true
3205 });
3206
3207 runScript({
3208 .code = R"NKSP_CODE(
3209 on init
3210 exit(3 <= -4)
3211 end on
3212 )NKSP_CODE",
3213 .expectBoolExitResult = false
3214 });
3215
3216 runScript({
3217 .code = R"NKSP_CODE(
3218 on init
3219 exit(123 <= -45)
3220 end on
3221 )NKSP_CODE",
3222 .expectBoolExitResult = false
3223 });
3224
3225 runScript({
3226 .code = R"NKSP_CODE(
3227 on init
3228 exit(-45 <= 123)
3229 end on
3230 )NKSP_CODE",
3231 .expectBoolExitResult = true
3232 });
3233
3234 // real number tests ...
3235
3236 runScript({
3237 .code = R"NKSP_CODE(
3238 on init
3239 exit(3.0 <= 3.0)
3240 end on
3241 )NKSP_CODE",
3242 .expectBoolExitResult = true
3243 });
3244
3245 runScript({
3246 .code = R"NKSP_CODE(
3247 on init
3248 exit(4.33 <= 4.33)
3249 end on
3250 )NKSP_CODE",
3251 .expectBoolExitResult = true
3252 });
3253
3254 runScript({
3255 .code = R"NKSP_CODE(
3256 on init
3257 exit(-23.1 <= -23.1)
3258 end on
3259 )NKSP_CODE",
3260 .expectBoolExitResult = true
3261 });
3262
3263 runScript({
3264 .code = R"NKSP_CODE(
3265 on init
3266 exit(23.3 <= -23.3)
3267 end on
3268 )NKSP_CODE",
3269 .expectBoolExitResult = false
3270 });
3271
3272 runScript({
3273 .code = R"NKSP_CODE(
3274 on init
3275 exit(3.0 <= 4.0)
3276 end on
3277 )NKSP_CODE",
3278 .expectBoolExitResult = true
3279 });
3280
3281 runScript({
3282 .code = R"NKSP_CODE(
3283 on init
3284 exit(4.0 <= 3.0)
3285 end on
3286 )NKSP_CODE",
3287 .expectBoolExitResult = false
3288 });
3289
3290 runScript({
3291 .code = R"NKSP_CODE(
3292 on init
3293 exit(-4.0 <= 3.0)
3294 end on
3295 )NKSP_CODE",
3296 .expectBoolExitResult = true
3297 });
3298
3299 runScript({
3300 .code = R"NKSP_CODE(
3301 on init
3302 exit(3.0 <= -4.0)
3303 end on
3304 )NKSP_CODE",
3305 .expectBoolExitResult = false
3306 });
3307
3308 runScript({
3309 .code = R"NKSP_CODE(
3310 on init
3311 exit(123.0 <= -45.0)
3312 end on
3313 )NKSP_CODE",
3314 .expectBoolExitResult = false
3315 });
3316
3317 runScript({
3318 .code = R"NKSP_CODE(
3319 on init
3320 exit(-45.0 <= 123.0)
3321 end on
3322 )NKSP_CODE",
3323 .expectBoolExitResult = true
3324 });
3325
3326 // mixed type tests ...
3327
3328 runScript({
3329 .code = R"NKSP_CODE(
3330 on init
3331 exit(9 <= 9.1)
3332 end on
3333 )NKSP_CODE",
3334 .expectBoolExitResult = true
3335 });
3336
3337 runScript({
3338 .code = R"NKSP_CODE(
3339 on init
3340 exit(9.1 <= 9)
3341 end on
3342 )NKSP_CODE",
3343 .expectBoolExitResult = false
3344 });
3345
3346 runScript({
3347 .code = R"NKSP_CODE(
3348 on init
3349 exit(9 <= 9.0)
3350 end on
3351 )NKSP_CODE",
3352 .expectBoolExitResult = true
3353 });
3354
3355 runScript({
3356 .code = R"NKSP_CODE(
3357 on init
3358 exit(9.0 <= 9)
3359 end on
3360 )NKSP_CODE",
3361 .expectBoolExitResult = true
3362 });
3363
3364 // std unit tests ...
3365
3366 runScript({
3367 .code = R"NKSP_CODE(
3368 on init
3369 exit(13ms <= 14ms)
3370 end on
3371 )NKSP_CODE",
3372 .expectBoolExitResult = true
3373 });
3374
3375 runScript({
3376 .code = R"NKSP_CODE(
3377 on init
3378 exit(14ms <= 13ms)
3379 end on
3380 )NKSP_CODE",
3381 .expectBoolExitResult = false
3382 });
3383
3384 runScript({
3385 .code = R"NKSP_CODE(
3386 on init
3387 exit(1s <= 990ms)
3388 end on
3389 )NKSP_CODE",
3390 .expectBoolExitResult = false
3391 });
3392
3393 runScript({
3394 .code = R"NKSP_CODE(
3395 on init
3396 exit(990ms <= 1s)
3397 end on
3398 )NKSP_CODE",
3399 .expectBoolExitResult = true
3400 });
3401
3402 runScript({
3403 .code = R"NKSP_CODE(
3404 on init
3405 exit(1000ms <= 1s)
3406 end on
3407 )NKSP_CODE",
3408 .expectBoolExitResult = true
3409 });
3410
3411 runScript({
3412 .code = R"NKSP_CODE(
3413 on init
3414 exit(1s <= 1000ms)
3415 end on
3416 )NKSP_CODE",
3417 .expectBoolExitResult = true
3418 });
3419
3420 runScript({
3421 .code = R"NKSP_CODE(
3422 on init
3423 exit(1s <= 1)
3424 end on
3425 )NKSP_CODE",
3426 .expectParseError = true // units on both sides must match
3427 });
3428
3429 runScript({
3430 .code = R"NKSP_CODE(
3431 on init
3432 exit(1 <= 1s)
3433 end on
3434 )NKSP_CODE",
3435 .expectParseError = true // units on both sides must match
3436 });
3437
3438 runScript({
3439 .code = R"NKSP_CODE(
3440 on init
3441 exit(1Hz <= 1B)
3442 end on
3443 )NKSP_CODE",
3444 .expectParseError = true // units on both sides must match
3445 });
3446
3447 runScript({
3448 .code = R"NKSP_CODE(
3449 on init
3450 exit(13.0ms <= 13.1ms)
3451 end on
3452 )NKSP_CODE",
3453 .expectBoolExitResult = true
3454 });
3455
3456 runScript({
3457 .code = R"NKSP_CODE(
3458 on init
3459 exit(13.1ms <= 13.0ms)
3460 end on
3461 )NKSP_CODE",
3462 .expectBoolExitResult = false
3463 });
3464
3465 runScript({
3466 .code = R"NKSP_CODE(
3467 on init
3468 exit(0.9s <= 600.0ms)
3469 end on
3470 )NKSP_CODE",
3471 .expectBoolExitResult = false
3472 });
3473
3474 runScript({
3475 .code = R"NKSP_CODE(
3476 on init
3477 exit(600.0ms <= 0.9s)
3478 end on
3479 )NKSP_CODE",
3480 .expectBoolExitResult = true
3481 });
3482
3483 runScript({
3484 .code = R"NKSP_CODE(
3485 on init
3486 exit(5.1kHz <= 5100.0Hz)
3487 end on
3488 )NKSP_CODE",
3489 .expectBoolExitResult = true
3490 });
3491
3492 runScript({
3493 .code = R"NKSP_CODE(
3494 on init
3495 exit(5100.0Hz <= 5.1kHz)
3496 end on
3497 )NKSP_CODE",
3498 .expectBoolExitResult = true
3499 });
3500
3501 runScript({
3502 .code = R"NKSP_CODE(
3503 on init
3504 exit(1.0Hz <= 1.1)
3505 end on
3506 )NKSP_CODE",
3507 .expectParseError = true // units on both sides must match
3508 });
3509
3510 runScript({
3511 .code = R"NKSP_CODE(
3512 on init
3513 exit(1.2 <= 1.34mdB)
3514 end on
3515 )NKSP_CODE",
3516 .expectParseError = true // units on both sides must match
3517 });
3518
3519 runScript({
3520 .code = R"NKSP_CODE(
3521 on init
3522 exit(9.23us <= 3.14kHz)
3523 end on
3524 )NKSP_CODE",
3525 .expectParseError = true // units on both sides must match
3526 });
3527
3528 // 'final' ('!') operator tests ...
3529 // (should always yield in false for relation operators)
3530
3531 runScript({
3532 .code = R"NKSP_CODE(
3533 on init
3534 exit(!-4 <= !3)
3535 end on
3536 )NKSP_CODE",
3537 .expectBoolExitResult = true,
3538 .expectExitResultFinal = false
3539 });
3540
3541 runScript({
3542 .code = R"NKSP_CODE(
3543 on init
3544 exit(-4 <= 3)
3545 end on
3546 )NKSP_CODE",
3547 .expectBoolExitResult = true,
3548 .expectExitResultFinal = false
3549 });
3550
3551 #if !SILENT_TEST
3552 std::cout << std::endl;
3553 #endif
3554 }
3555
3556 static void testGreaterOrEqualOperator() {
3557 #if !SILENT_TEST
3558 std::cout << "UNIT TEST: greater-or-equal (>=) operator\n";
3559 #endif
3560
3561 // integer tests ...
3562
3563 runScript({
3564 .code = R"NKSP_CODE(
3565 on init
3566 exit(3 >= 3)
3567 end on
3568 )NKSP_CODE",
3569 .expectBoolExitResult = true
3570 });
3571
3572 runScript({
3573 .code = R"NKSP_CODE(
3574 on init
3575 exit(4 >= 4)
3576 end on
3577 )NKSP_CODE",
3578 .expectBoolExitResult = true
3579 });
3580
3581 runScript({
3582 .code = R"NKSP_CODE(
3583 on init
3584 exit(-23 >= -23)
3585 end on
3586 )NKSP_CODE",
3587 .expectBoolExitResult = true
3588 });
3589
3590 runScript({
3591 .code = R"NKSP_CODE(
3592 on init
3593 exit(23 >= -23)
3594 end on
3595 )NKSP_CODE",
3596 .expectBoolExitResult = true
3597 });
3598
3599 runScript({
3600 .code = R"NKSP_CODE(
3601 on init
3602 exit(3 >= 4)
3603 end on
3604 )NKSP_CODE",
3605 .expectBoolExitResult = false
3606 });
3607
3608 runScript({
3609 .code = R"NKSP_CODE(
3610 on init
3611 exit(4 >= 3)
3612 end on
3613 )NKSP_CODE",
3614 .expectBoolExitResult = true
3615 });
3616
3617 runScript({
3618 .code = R"NKSP_CODE(
3619 on init
3620 exit(-4 >= 3)
3621 end on
3622 )NKSP_CODE",
3623 .expectBoolExitResult = false
3624 });
3625
3626 runScript({
3627 .code = R"NKSP_CODE(
3628 on init
3629 exit(3 >= -4)
3630 end on
3631 )NKSP_CODE",
3632 .expectBoolExitResult = true
3633 });
3634
3635 runScript({
3636 .code = R"NKSP_CODE(
3637 on init
3638 exit(123 >= -45)
3639 end on
3640 )NKSP_CODE",
3641 .expectBoolExitResult = true
3642 });
3643
3644 runScript({
3645 .code = R"NKSP_CODE(
3646 on init
3647 exit(-45 >= 123)
3648 end on
3649 )NKSP_CODE",
3650 .expectBoolExitResult = false
3651 });
3652
3653 // real number tests ...
3654
3655 runScript({
3656 .code = R"NKSP_CODE(
3657 on init
3658 exit(3.0 >= 3.0)
3659 end on
3660 )NKSP_CODE",
3661 .expectBoolExitResult = true
3662 });
3663
3664 runScript({
3665 .code = R"NKSP_CODE(
3666 on init
3667 exit(3.1 >= 3.1)
3668 end on
3669 )NKSP_CODE",
3670 .expectBoolExitResult = true
3671 });
3672
3673 runScript({
3674 .code = R"NKSP_CODE(
3675 on init
3676 exit(3.1 >= 3.0)
3677 end on
3678 )NKSP_CODE",
3679 .expectBoolExitResult = true
3680 });
3681
3682 runScript({
3683 .code = R"NKSP_CODE(
3684 on init
3685 exit(3.0 >= 3.1)
3686 end on
3687 )NKSP_CODE",
3688 .expectBoolExitResult = false
3689 });
3690
3691 runScript({
3692 .code = R"NKSP_CODE(
3693 on init
3694 exit(-23.33 >= -23.33)
3695 end on
3696 )NKSP_CODE",
3697 .expectBoolExitResult = true
3698 });
3699
3700 runScript({
3701 .code = R"NKSP_CODE(
3702 on init
3703 exit(23.0 >= -23.0)
3704 end on
3705 )NKSP_CODE",
3706 .expectBoolExitResult = true
3707 });
3708
3709 runScript({
3710 .code = R"NKSP_CODE(
3711 on init
3712 exit(3.0 >= 4.0)
3713 end on
3714 )NKSP_CODE",
3715 .expectBoolExitResult = false
3716 });
3717
3718 runScript({
3719 .code = R"NKSP_CODE(
3720 on init
3721 exit(4.0 >= 3.0)
3722 end on
3723 )NKSP_CODE",
3724 .expectBoolExitResult = true
3725 });
3726
3727 runScript({
3728 .code = R"NKSP_CODE(
3729 on init
3730 exit(-4.0 >= 3.0)
3731 end on
3732 )NKSP_CODE",
3733 .expectBoolExitResult = false
3734 });
3735
3736 runScript({
3737 .code = R"NKSP_CODE(
3738 on init
3739 exit(3.0 >= -4.0)
3740 end on
3741 )NKSP_CODE",
3742 .expectBoolExitResult = true
3743 });
3744
3745 runScript({
3746 .code = R"NKSP_CODE(
3747 on init
3748 exit(123.0 >= -45.0)
3749 end on
3750 )NKSP_CODE",
3751 .expectBoolExitResult = true
3752 });
3753
3754 runScript({
3755 .code = R"NKSP_CODE(
3756 on init
3757 exit(-45.0 >= 123.0)
3758 end on
3759 )NKSP_CODE",
3760 .expectBoolExitResult = false
3761 });
3762
3763 // mixed type tests ...
3764
3765 runScript({
3766 .code = R"NKSP_CODE(
3767 on init
3768 exit(9 >= 9.1)
3769 end on
3770 )NKSP_CODE",
3771 .expectBoolExitResult = false
3772 });
3773
3774 runScript({
3775 .code = R"NKSP_CODE(
3776 on init
3777 exit(9.1 >= 9)
3778 end on
3779 )NKSP_CODE",
3780 .expectBoolExitResult = true
3781 });
3782
3783 runScript({
3784 .code = R"NKSP_CODE(
3785 on init
3786 exit(9 >= 9.0)
3787 end on
3788 )NKSP_CODE",
3789 .expectBoolExitResult = true
3790 });
3791
3792 runScript({
3793 .code = R"NKSP_CODE(
3794 on init
3795 exit(9.0 >= 9)
3796 end on
3797 )NKSP_CODE",
3798 .expectBoolExitResult = true
3799 });
3800
3801 // std unit tests ...
3802
3803 runScript({
3804 .code = R"NKSP_CODE(
3805 on init
3806 exit(13ms >= 14ms)
3807 end on
3808 )NKSP_CODE",
3809 .expectBoolExitResult = false
3810 });
3811
3812 runScript({
3813 .code = R"NKSP_CODE(
3814 on init
3815 exit(14ms >= 13ms)
3816 end on
3817 )NKSP_CODE",
3818 .expectBoolExitResult = true
3819 });
3820
3821 runScript({
3822 .code = R"NKSP_CODE(
3823 on init
3824 exit(1s >= 990ms)
3825 end on
3826 )NKSP_CODE",
3827 .expectBoolExitResult = true
3828 });
3829
3830 runScript({
3831 .code = R"NKSP_CODE(
3832 on init
3833 exit(990ms >= 1s)
3834 end on
3835 )NKSP_CODE",
3836 .expectBoolExitResult = false
3837 });
3838
3839 runScript({
3840 .code = R"NKSP_CODE(
3841 on init
3842 exit(1000ms >= 1s)
3843 end on
3844 )NKSP_CODE",
3845 .expectBoolExitResult = true
3846 });
3847
3848 runScript({
3849 .code = R"NKSP_CODE(
3850 on init
3851 exit(1s >= 1000ms)
3852 end on
3853 )NKSP_CODE",
3854 .expectBoolExitResult = true
3855 });
3856
3857 runScript({
3858 .code = R"NKSP_CODE(
3859 on init
3860 exit(1s >= 1)
3861 end on
3862 )NKSP_CODE",
3863 .expectParseError = true // units on both sides must match
3864 });
3865
3866 runScript({
3867 .code = R"NKSP_CODE(
3868 on init
3869 exit(1 >= 1s)
3870 end on
3871 )NKSP_CODE",
3872 .expectParseError = true // units on both sides must match
3873 });
3874
3875 runScript({
3876 .code = R"NKSP_CODE(
3877 on init
3878 exit(1Hz >= 1B)
3879 end on
3880 )NKSP_CODE",
3881 .expectParseError = true // units on both sides must match
3882 });
3883
3884 runScript({
3885 .code = R"NKSP_CODE(
3886 on init
3887 exit(13.0ms >= 13.1ms)
3888 end on
3889 )NKSP_CODE",
3890 .expectBoolExitResult = false
3891 });
3892
3893 runScript({
3894 .code = R"NKSP_CODE(
3895 on init
3896 exit(13.1ms >= 13.0ms)
3897 end on
3898 )NKSP_CODE",
3899 .expectBoolExitResult = true
3900 });
3901
3902 runScript({
3903 .code = R"NKSP_CODE(
3904 on init
3905 exit(0.9s >= 600.0ms)
3906 end on
3907 )NKSP_CODE",
3908 .expectBoolExitResult = true
3909 });
3910
3911 runScript({
3912 .code = R"NKSP_CODE(
3913 on init
3914 exit(600.0ms >= 0.9s)
3915 end on
3916 )NKSP_CODE",
3917 .expectBoolExitResult = false
3918 });
3919
3920 runScript({
3921 .code = R"NKSP_CODE(
3922 on init
3923 exit(5.1kHz >= 5100.0Hz)
3924 end on
3925 )NKSP_CODE",
3926 .expectBoolExitResult = true
3927 });
3928
3929 runScript({
3930 .code = R"NKSP_CODE(
3931 on init
3932 exit(5100.0Hz >= 5.1kHz)
3933 end on
3934 )NKSP_CODE",
3935 .expectBoolExitResult = true
3936 });
3937
3938 runScript({
3939 .code = R"NKSP_CODE(
3940 on init
3941 exit(1.0Hz >= 1.1)
3942 end on
3943 )NKSP_CODE",
3944 .expectParseError = true // units on both sides must match
3945 });
3946
3947 runScript({
3948 .code = R"NKSP_CODE(
3949 on init
3950 exit(1.2 >= 1.34mdB)
3951 end on
3952 )NKSP_CODE",
3953 .expectParseError = true // units on both sides must match
3954 });
3955
3956 runScript({
3957 .code = R"NKSP_CODE(
3958 on init
3959 exit(9.23us >= 3.14kHz)
3960 end on
3961 )NKSP_CODE",
3962 .expectParseError = true // units on both sides must match
3963 });
3964
3965 // 'final' ('!') operator tests ...
3966 // (should always yield in false for relation operators)
3967
3968 runScript({
3969 .code = R"NKSP_CODE(
3970 on init
3971 exit(!-4 >= !3)
3972 end on
3973 )NKSP_CODE",
3974 .expectBoolExitResult = false,
3975 .expectExitResultFinal = false
3976 });
3977
3978 runScript({
3979 .code = R"NKSP_CODE(
3980 on init
3981 exit(-4 >= 3)
3982 end on
3983 )NKSP_CODE",
3984 .expectBoolExitResult = false,
3985 .expectExitResultFinal = false
3986 });
3987
3988 #if !SILENT_TEST
3989 std::cout << std::endl;
3990 #endif
3991 }
3992
3993 static void testEqualOperator() {
3994 #if !SILENT_TEST
3995 std::cout << "UNIT TEST: equal (=) operator\n";
3996 #endif
3997
3998 // integer tests ...
3999
4000 runScript({
4001 .code = R"NKSP_CODE(
4002 on init
4003 exit(3 = 3)
4004 end on
4005 )NKSP_CODE",
4006 .expectBoolExitResult = true
4007 });
4008
4009 runScript({
4010 .code = R"NKSP_CODE(
4011 on init
4012 exit(4 = 4)
4013 end on
4014 )NKSP_CODE",
4015 .expectBoolExitResult = true
4016 });
4017
4018 runScript({
4019 .code = R"NKSP_CODE(
4020 on init
4021 exit(3 = 4)
4022 end on
4023 )NKSP_CODE",
4024 .expectBoolExitResult = false
4025 });
4026
4027 runScript({
4028 .code = R"NKSP_CODE(
4029 on init
4030 exit(23 = -23)
4031 end on
4032 )NKSP_CODE",
4033 .expectBoolExitResult = false
4034 });
4035
4036 // real number tests ...
4037
4038 runScript({
4039 .code = R"NKSP_CODE(
4040 on init
4041 exit(3.0 = 3.0)
4042 end on
4043 )NKSP_CODE",
4044 .expectBoolExitResult = true
4045 });
4046
4047 runScript({
4048 .code = R"NKSP_CODE(
4049 on init
4050 exit(4.33 = 4.33)
4051 end on
4052 )NKSP_CODE",
4053 .expectBoolExitResult = true
4054 });
4055
4056 runScript({
4057 .code = R"NKSP_CODE(
4058 on init
4059 exit(4.31 = 4.35)
4060 end on
4061 )NKSP_CODE",
4062 .expectBoolExitResult = false
4063 });
4064
4065 runScript({
4066 .code = R"NKSP_CODE(
4067 on init
4068 exit(3.0 = 4.0)
4069 end on
4070 )NKSP_CODE",
4071 .expectBoolExitResult = false
4072 });
4073
4074 runScript({
4075 .code = R"NKSP_CODE(
4076 on init
4077 exit(23.0 = -23.0)
4078 end on
4079 )NKSP_CODE",
4080 .expectBoolExitResult = false
4081 });
4082
4083 // deal with inaccuracy of float point
4084 runScript({
4085 .code = R"NKSP_CODE(
4086 on init
4087 declare ~a := 0.165
4088 declare ~b := 0.185
4089 declare ~x := 0.1
4090 declare ~y := 0.25
4091 exit(~a + ~b = ~x + ~y) { both sides should actually be 0.35, they slightly deviate both though }
4092 end on
4093 )NKSP_CODE",
4094 .expectBoolExitResult = true // our implementation of real number equal comparison should take care about floating point tolerance
4095 });
4096
4097 // deal with inaccuracy of float point
4098 runScript({
4099 .code = R"NKSP_CODE(
4100 on init
4101 declare ~a := 0.166
4102 declare ~b := 0.185
4103 declare ~x := 0.1
4104 declare ~y := 0.25
4105 exit(~a + ~b = ~x + ~y) { left side approx. 0.351, right side approx. 0.35 }
4106 end on
4107 )NKSP_CODE",
4108 .expectBoolExitResult = false
4109 });
4110
4111 // mixed type tests ...
4112
4113 runScript({
4114 .code = R"NKSP_CODE(
4115 on init
4116 exit(23 = 23.0)
4117 end on
4118 )NKSP_CODE",
4119 .expectBoolExitResult = true
4120 });
4121
4122 runScript({
4123 .code = R"NKSP_CODE(
4124 on init
4125 exit(23.0 = 23)
4126 end on
4127 )NKSP_CODE",
4128 .expectBoolExitResult = true
4129 });
4130
4131 runScript({
4132 .code = R"NKSP_CODE(
4133 on init
4134 exit(23 = 23.1)
4135 end on
4136 )NKSP_CODE",
4137 .expectBoolExitResult = false
4138 });
4139
4140 runScript({
4141 .code = R"NKSP_CODE(
4142 on init
4143 exit(23.1 = 23)
4144 end on
4145 )NKSP_CODE",
4146 .expectBoolExitResult = false
4147 });
4148
4149 // std unit tests ...
4150
4151 runScript({
4152 .code = R"NKSP_CODE(
4153 on init
4154 exit(13ms = 14ms)
4155 end on
4156 )NKSP_CODE",
4157 .expectBoolExitResult = false
4158 });
4159
4160 runScript({
4161 .code = R"NKSP_CODE(
4162 on init
4163 exit(14ms = 13ms)
4164 end on
4165 )NKSP_CODE",
4166 .expectBoolExitResult = false
4167 });
4168
4169 runScript({
4170 .code = R"NKSP_CODE(
4171 on init
4172 exit(1s = 1ms)
4173 end on
4174 )NKSP_CODE",
4175 .expectBoolExitResult = false
4176 });
4177
4178 runScript({
4179 .code = R"NKSP_CODE(
4180 on init
4181 exit(1ms = 1s)
4182 end on
4183 )NKSP_CODE",
4184 .expectBoolExitResult = false
4185 });
4186
4187 runScript({
4188 .code = R"NKSP_CODE(
4189 on init
4190 exit(3.14kHz = 3140Hz)
4191 end on
4192 )NKSP_CODE",
4193 .expectBoolExitResult = true
4194 });
4195
4196 runScript({
4197 .code = R"NKSP_CODE(
4198 on init
4199 exit(3140Hz = 3.14kHz)
4200 end on
4201 )NKSP_CODE",
4202 .expectBoolExitResult = true
4203 });
4204
4205 runScript({
4206 .code = R"NKSP_CODE(
4207 on init
4208 exit(1s = 1)
4209 end on
4210 )NKSP_CODE",
4211 .expectParseError = true // units on both sides must match
4212 });
4213
4214 runScript({
4215 .code = R"NKSP_CODE(
4216 on init
4217 exit(1 = 1s)
4218 end on
4219 )NKSP_CODE",
4220 .expectParseError = true // units on both sides must match
4221 });
4222
4223 runScript({
4224 .code = R"NKSP_CODE(
4225 on init
4226 exit(1Hz = 1B)
4227 end on
4228 )NKSP_CODE",
4229 .expectParseError = true // units on both sides must match
4230 });
4231
4232 // 'final' ('!') operator tests ...
4233 // (should always yield in false for relation operators)
4234
4235 runScript({
4236 .code = R"NKSP_CODE(
4237 on init
4238 exit(!-4 = !3)
4239 end on
4240 )NKSP_CODE",
4241 .expectBoolExitResult = false,
4242 .expectExitResultFinal = false
4243 });
4244
4245 runScript({
4246 .code = R"NKSP_CODE(
4247 on init
4248 exit(-4 = 3)
4249 end on
4250 )NKSP_CODE",
4251 .expectBoolExitResult = false,
4252 .expectExitResultFinal = false
4253 });
4254
4255 #if !SILENT_TEST
4256 std::cout << std::endl;
4257 #endif
4258 }
4259
4260 static void testUnequalOperator() {
4261 #if !SILENT_TEST
4262 std::cout << "UNIT TEST: unequal (#) operator\n";
4263 #endif
4264
4265 // integer tests ...
4266
4267 runScript({
4268 .code = R"NKSP_CODE(
4269 on init
4270 exit(3 # 3)
4271 end on
4272 )NKSP_CODE",
4273 .expectBoolExitResult = false
4274 });
4275
4276 runScript({
4277 .code = R"NKSP_CODE(
4278 on init
4279 exit(4 # 4)
4280 end on
4281 )NKSP_CODE",
4282 .expectBoolExitResult = false
4283 });
4284
4285 runScript({
4286 .code = R"NKSP_CODE(
4287 on init
4288 exit(3 # 4)
4289 end on
4290 )NKSP_CODE",
4291 .expectBoolExitResult = true
4292 });
4293
4294 runScript({
4295 .code = R"NKSP_CODE(
4296 on init
4297 exit(23 # -23)
4298 end on
4299 )NKSP_CODE",
4300 .expectBoolExitResult = true
4301 });
4302
4303 // real number tests ...
4304
4305 runScript({
4306 .code = R"NKSP_CODE(
4307 on init
4308 exit(3.0 # 3.0)
4309 end on
4310 )NKSP_CODE",
4311 .expectBoolExitResult = false
4312 });
4313
4314 runScript({
4315 .code = R"NKSP_CODE(
4316 on init
4317 exit(3.14 # 3.14)
4318 end on
4319 )NKSP_CODE",
4320 .expectBoolExitResult = false
4321 });
4322
4323 runScript({
4324 .code = R"NKSP_CODE(
4325 on init
4326 exit(3.19 # 3.12)
4327 end on
4328 )NKSP_CODE",
4329 .expectBoolExitResult = true
4330 });
4331
4332 runScript({
4333 .code = R"NKSP_CODE(
4334