/[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 3792 - (show annotations) (download)
Mon Jun 15 15:26:10 2020 UTC (3 years, 10 months ago) by schoenebeck
File size: 227601 byte(s)
* NKSP language: emit warning if an array variable was declared with bigger
  array size than amount of initial values been assigned, and initialize the
  missing array elements with zero in this case.

* Bumped version (2.1.1.svn60).

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 on init
4335 exit(23.0 # -23.0)
4336 end on
4337 )NKSP_CODE",
4338 .expectBoolExitResult = true
4339 });
4340
4341 // deal with inaccuracy of float point
4342 runScript({
4343 .code = R"NKSP_CODE(
4344 on init
4345 declare ~a := 0.165
4346 declare ~b := 0.185
4347 declare ~x := 0.1
4348 declare ~y := 0.25
4349 exit(~a + ~b # ~x + ~y) { both sides should actually be 0.35, they slightly deviate both though }
4350 end on
4351 )NKSP_CODE",
4352 .expectBoolExitResult = false // our implementation of real number unequal comparison should take care about floating point tolerance
4353 });
4354
4355 // deal with inaccuracy of float point
4356 runScript({
4357 .code = R"NKSP_CODE(
4358 on init
4359 declare ~a := 0.166
4360 declare ~b := 0.185
4361 declare ~x := 0.1
4362 declare ~y := 0.25
4363 exit(~a + ~b # ~x + ~y) { left side approx. 0.351, right side approx. 0.35 }
4364 end on
4365 )NKSP_CODE",
4366 .expectBoolExitResult = true
4367 });
4368
4369 // mixed type tests ...
4370
4371 runScript({
4372 .code = R"NKSP_CODE(
4373 on init
4374 exit(3 # 3.0)
4375 end on
4376 )NKSP_CODE",
4377 .expectBoolExitResult = false
4378 });
4379
4380 runScript({
4381 .code = R"NKSP_CODE(
4382 on init
4383 exit(3.0 # 3)
4384 end on
4385 )NKSP_CODE",
4386 .expectBoolExitResult = false
4387 });
4388
4389 runScript({
4390 .code = R"NKSP_CODE(
4391 on init
4392 exit(3.1 # 3)
4393 end on
4394 )NKSP_CODE",
4395 .expectBoolExitResult = true
4396 });
4397
4398 runScript({
4399 .code = R"NKSP_CODE(
4400 on init
4401 exit(3 # 3.1)
4402 end on
4403 )NKSP_CODE",
4404 .expectBoolExitResult = true
4405 });
4406
4407 // std unit tests ...
4408
4409 runScript({
4410 .code = R"NKSP_CODE(
4411 on init
4412 exit(13ms # 14ms)
4413 end on
4414 )NKSP_CODE",
4415 .expectBoolExitResult = true
4416 });
4417
4418 runScript({
4419 .code = R"NKSP_CODE(
4420 on init
4421 exit(14ms # 13ms)
4422 end on
4423 )NKSP_CODE",
4424 .expectBoolExitResult = true
4425 });
4426
4427 runScript({
4428 .code = R"NKSP_CODE(
4429 on init
4430 exit(1s # 1ms)
4431 end on
4432 )NKSP_CODE",
4433 .expectBoolExitResult = true
4434 });
4435
4436 runScript({
4437 .code = R"NKSP_CODE(
4438 on init
4439 exit(1ms # 1s)
4440 end on
4441 )NKSP_CODE",
4442 .expectBoolExitResult = true
4443 });
4444
4445 runScript({
4446 .code = R"NKSP_CODE(
4447 on init
4448 exit(3.14kHz # 3140Hz)
4449 end on
4450 )NKSP_CODE",
4451 .expectBoolExitResult = false
4452 });
4453
4454 runScript({
4455 .code = R"NKSP_CODE(
4456 on init
4457 exit(3140Hz # 3.14kHz)
4458 end on
4459 )NKSP_CODE",
4460 .expectBoolExitResult = false
4461 });
4462
4463 runScript({
4464 .code = R"NKSP_CODE(
4465 on init
4466 exit(1s # 1)
4467 end on
4468 )NKSP_CODE",
4469 .expectParseError = true // units on both sides must match
4470 });
4471
4472 runScript({
4473 .code = R"NKSP_CODE(
4474 on init
4475 exit(1 # 1s)
4476 end on
4477 )NKSP_CODE",
4478 .expectParseError = true // units on both sides must match
4479 });
4480
4481 runScript({
4482 .code = R"NKSP_CODE(
4483 on init
4484 exit(1Hz # 1B)
4485 end on
4486 )NKSP_CODE",
4487 .expectParseError = true // units on both sides must match
4488 });
4489
4490 // 'final' ('!') operator tests ...
4491 // (should always yield in false for relation operators)
4492
4493 runScript({
4494 .code = R"NKSP_CODE(
4495 on init
4496 exit(!-4 # !3)
4497 end on
4498 )NKSP_CODE",
4499 .expectBoolExitResult = true,
4500 .expectExitResultFinal = false
4501 });
4502
4503 runScript({
4504 .code = R"NKSP_CODE(
4505 on init
4506 exit(-4 # 3)
4507 end on
4508 )NKSP_CODE",
4509 .expectBoolExitResult = true,
4510 .expectExitResultFinal = false
4511 });
4512
4513 #if !SILENT_TEST
4514 std::cout << std::endl;
4515 #endif
4516 }
4517
4518 static void testLogicalAndOperator() {
4519 #if !SILENT_TEST
4520 std::cout << "UNIT TEST: logical and (and) operator\n";
4521 #endif
4522
4523 // integer tests ...
4524
4525 runScript({
4526 .code = R"NKSP_CODE(
4527 on init
4528 exit(1 and 1)
4529 end on
4530 )NKSP_CODE",
4531 .expectBoolExitResult = true
4532 });
4533
4534 runScript({
4535 .code = R"NKSP_CODE(
4536 on init
4537 exit(1 and 2)
4538 end on
4539 )NKSP_CODE",
4540 .expectBoolExitResult = true
4541 });
4542
4543 runScript({
4544 .code = R"NKSP_CODE(
4545 on init
4546 exit(1 and 3)
4547 end on
4548 )NKSP_CODE",
4549 .expectBoolExitResult = true
4550 });
4551
4552 runScript({
4553 .code = R"NKSP_CODE(
4554 on init
4555 exit(1 and 0)
4556 end on
4557 )NKSP_CODE",
4558 .expectBoolExitResult = false
4559 });
4560
4561 runScript({
4562 .code = R"NKSP_CODE(
4563 on init
4564 exit(0 and 1)
4565 end on
4566 )NKSP_CODE",
4567 .expectBoolExitResult = false
4568 });
4569
4570 runScript({
4571 .code = R"NKSP_CODE(
4572 on init
4573 exit(0 and 0)
4574 end on
4575 )NKSP_CODE",
4576 .expectBoolExitResult = false
4577 });
4578
4579 // real number tests ...
4580 // (not allowed for this operator)
4581
4582 runScript({
4583 .code = R"NKSP_CODE(
4584 on init
4585 exit(1.0 and 1.0)
4586 end on
4587 )NKSP_CODE",
4588 .expectParseError = true // real numbers not allowed for this operator
4589 });
4590
4591 // mixed type tests ...
4592 // (not allowed for this operator)
4593
4594 runScript({
4595 .code = R"NKSP_CODE(
4596 on init
4597 exit(1.0 and 1)
4598 end on
4599 )NKSP_CODE",
4600 .expectParseError = true // real numbers not allowed for this operator
4601 });
4602
4603 runScript({
4604 .code = R"NKSP_CODE(
4605 on init
4606 exit(1 and 1.0)
4607 end on
4608 )NKSP_CODE",
4609 .expectParseError = true // real numbers not allowed for this operator
4610 });
4611
4612 // std unit tests ...
4613 // (not allowed for this operator)
4614
4615 runScript({
4616 .code = R"NKSP_CODE(
4617 on init
4618 exit(1s and 0)
4619 end on
4620 )NKSP_CODE",
4621 .expectParseError = true // std units not allowed for this operator
4622 });
4623
4624 runScript({
4625 .code = R"NKSP_CODE(
4626 on init
4627 exit(0 and 1s)
4628 end on
4629 )NKSP_CODE",
4630 .expectParseError = true // std units not allowed for this operator
4631 });
4632
4633 // 'final' ('!') operator tests ...
4634
4635 runScript({
4636 .code = R"NKSP_CODE(
4637 on init
4638 exit(!0 and !0)
4639 end on
4640 )NKSP_CODE",
4641 .expectExitResultFinal = true
4642 });
4643
4644 runScript({
4645 .code = R"NKSP_CODE(
4646 on init
4647 exit(0 and 0)
4648 end on
4649 )NKSP_CODE",
4650 .expectExitResultFinal = false
4651 });
4652
4653 #if !SILENT_TEST
4654 std::cout << std::endl;
4655 #endif
4656 }
4657
4658 static void testLogicalOrOperator() {
4659 #if !SILENT_TEST
4660 std::cout << "UNIT TEST: logical or (or) operator\n";
4661 #endif
4662
4663 // integer tests ...
4664
4665 runScript({
4666 .code = R"NKSP_CODE(
4667 on init
4668 exit(1 or 1)
4669 end on
4670 )NKSP_CODE",
4671 .expectBoolExitResult = true
4672 });
4673
4674 runScript({
4675 .code = R"NKSP_CODE(
4676 on init
4677 exit(1 or 2)
4678 end on
4679 )NKSP_CODE",
4680 .expectBoolExitResult = true
4681 });
4682
4683 runScript({
4684 .code = R"NKSP_CODE(
4685 on init
4686 exit(1 or 3)
4687 end on
4688 )NKSP_CODE",
4689 .expectBoolExitResult = true
4690 });
4691
4692 runScript({
4693 .code = R"NKSP_CODE(
4694 on init
4695 exit(1 or 0)
4696 end on
4697 )NKSP_CODE",
4698 .expectBoolExitResult = true
4699 });
4700
4701 runScript({
4702 .code = R"NKSP_CODE(
4703 on init
4704 exit(0 or 1)
4705 end on
4706 )NKSP_CODE",
4707 .expectBoolExitResult = true
4708 });
4709
4710 runScript({
4711 .code = R"NKSP_CODE(
4712 on init
4713 exit(0 or 0)
4714 end on
4715 )NKSP_CODE",
4716 .expectBoolExitResult = false
4717 });
4718
4719 // real number tests ...
4720 // (not allowed for this operator)
4721
4722 runScript({
4723 .code = R"NKSP_CODE(
4724 on init
4725 exit(1.0 or 1.0)
4726 end on
4727 )NKSP_CODE",
4728 .expectParseError = true // real numbers not allowed for this operator
4729 });
4730
4731 // mixed type tests ...
4732 // (not allowed for this operator)
4733
4734 runScript({
4735 .code = R"NKSP_CODE(
4736 on init
4737 exit(1.0 or 1)
4738 end on
4739 )NKSP_CODE",
4740 .expectParseError = true // real numbers not allowed for this operator
4741 });
4742
4743 runScript({
4744 .code = R"NKSP_CODE(
4745 on init
4746 exit(1 or 1.0)
4747 end on
4748 )NKSP_CODE",
4749 .expectParseError = true // real numbers not allowed for this operator
4750 });
4751
4752 // std unit tests ...
4753 // (not allowed for this operator)
4754
4755 runScript({
4756 .code = R"NKSP_CODE(
4757 on init
4758 exit(1s or 0)
4759 end on
4760 )NKSP_CODE",
4761 .expectParseError = true // std units not allowed for this operator
4762 });
4763
4764 runScript({
4765 .code = R"NKSP_CODE(
4766 on init
4767 exit(0 or 1s)
4768 end on
4769 )NKSP_CODE",
4770 .expectParseError = true // std units not allowed for this operator
4771 });
4772
4773 // 'final' ('!') operator tests ...
4774
4775 runScript({
4776 .code = R"NKSP_CODE(
4777 on init
4778 exit(!0 or !0)
4779 end on
4780 )NKSP_CODE",
4781 .expectExitResultFinal = true
4782 });
4783
4784 runScript({
4785 .code = R"NKSP_CODE(
4786 on init
4787 exit(0 or 0)
4788 end on
4789 )NKSP_CODE",
4790 .expectExitResultFinal = false
4791 });
4792
4793 #if !SILENT_TEST
4794 std::cout << std::endl;
4795 #endif
4796 }
4797
4798 static void testLogicalNotOperator() {
4799 #if !SILENT_TEST
4800 std::cout << "UNIT TEST: logical not (not) operator\n";
4801 #endif
4802
4803 // integer tests ...
4804
4805 runScript({
4806 .code = R"NKSP_CODE(
4807 on init
4808 exit(not 1)
4809 end on
4810 )NKSP_CODE",
4811 .expectBoolExitResult = false
4812 });
4813
4814 runScript({
4815 .code = R"NKSP_CODE(
4816 on init
4817 exit(not 2)
4818 end on
4819 )NKSP_CODE",
4820 .expectBoolExitResult = false
4821 });
4822
4823 runScript({
4824 .code = R"NKSP_CODE(
4825 on init
4826 exit(not 0)
4827 end on
4828 )NKSP_CODE",
4829 .expectBoolExitResult = true
4830 });
4831
4832 // real number tests ...
4833 // (not allowed for this operator)
4834
4835 runScript({
4836 .code = R"NKSP_CODE(
4837 on init
4838 exit(not 1.0)
4839 end on
4840 )NKSP_CODE",
4841 .expectParseError = true // real numbers not allowed for this operator
4842 });
4843
4844 // std unit tests ...
4845 // (not allowed for this operator)
4846
4847 runScript({
4848 .code = R"NKSP_CODE(
4849 on init
4850 exit(not 1s)
4851 end on
4852 )NKSP_CODE",
4853 .expectParseError = true // std units not allowed for this operator
4854 });
4855
4856 // 'final' ('!') operator tests ...
4857
4858 runScript({
4859 .code = R"NKSP_CODE(
4860 on init
4861 exit(not !1)
4862 end on
4863 )NKSP_CODE",
4864 .expectExitResultFinal = true
4865 });
4866
4867 runScript({
4868 .code = R"NKSP_CODE(
4869 on init
4870 exit(not 1)
4871 end on
4872 )NKSP_CODE",
4873 .expectExitResultFinal = false
4874 });
4875
4876 #if !SILENT_TEST
4877 std::cout << std::endl;
4878 #endif
4879 }
4880
4881 static void testBitwiseAndOperator() {
4882 #if !SILENT_TEST
4883 std::cout << "UNIT TEST: bitwise and (.and.) operator\n";
4884 #endif
4885
4886 // integer tests ...
4887
4888 runScript({
4889 .code = R"NKSP_CODE(
4890 on init
4891 exit(1 .and. 1)
4892 end on
4893 )NKSP_CODE",
4894 .expectIntExitResult = 1
4895 });
4896
4897 runScript({
4898 .code = R"NKSP_CODE(
4899 on init
4900 exit(43 .and. 142)
4901 end on
4902 )NKSP_CODE",
4903 .expectIntExitResult = 10
4904 });
4905
4906 // real number tests ...
4907 // (not allowed for this operator)
4908
4909 runScript({
4910 .code = R"NKSP_CODE(
4911 on init
4912 exit(1.0 .and. 1.0)
4913 end on
4914 )NKSP_CODE",
4915 .expectParseError = true // real numbers not allowed for this operator
4916 });
4917
4918 // mixed type tests ...
4919 // (not allowed for this operator)
4920
4921 runScript({
4922 .code = R"NKSP_CODE(
4923 on init
4924 exit(1.0 .and. 1)
4925 end on
4926 )NKSP_CODE",
4927 .expectParseError = true // real numbers not allowed for this operator
4928 });
4929
4930 runScript({
4931 .code = R"NKSP_CODE(
4932 on init
4933 exit(1 .and. 1.0)
4934 end on
4935 )NKSP_CODE",
4936 .expectParseError = true // real numbers not allowed for this operator
4937 });
4938
4939 // std unit tests ...
4940 // (not allowed for this operator)
4941
4942 runScript({
4943 .code = R"NKSP_CODE(
4944 on init
4945 exit(1s .and. 1)
4946 end on
4947 )NKSP_CODE",
4948 .expectParseError = true // std units not allowed for this operator
4949 });
4950
4951 runScript({
4952 .code = R"NKSP_CODE(
4953 on init
4954 exit(1 .and. 1s)
4955 end on
4956 )NKSP_CODE",
4957 .expectParseError = true // std units not allowed for this operator
4958 });
4959
4960 // 'final' ('!') operator tests ...
4961
4962 runScript({
4963 .code = R"NKSP_CODE(
4964 on init
4965 exit(!43 .and. !142)
4966 end on
4967 )NKSP_CODE",
4968 .expectIntExitResult = 10,
4969 .expectExitResultFinal = true
4970 });
4971
4972 runScript({
4973 .code = R"NKSP_CODE(
4974 on init
4975 exit(43 .and. 142)
4976 end on
4977 )NKSP_CODE",
4978 .expectIntExitResult = 10,
4979 .expectExitResultFinal = false
4980 });
4981
4982 #if !SILENT_TEST
4983 std::cout << std::endl;
4984 #endif
4985 }
4986
4987 static void testBitwiseOrOperator() {
4988 #if !SILENT_TEST
4989 std::cout << "UNIT TEST: bitwise or (.or.) operator\n";
4990 #endif
4991
4992 // integer tests ...
4993
4994 runScript({
4995 .code = R"NKSP_CODE(
4996 on init
4997 exit(1 .or. 1)
4998 end on
4999 )NKSP_CODE",
5000 .expectIntExitResult = 1
5001 });
5002
5003 runScript({
5004 .code = R"NKSP_CODE(
5005 on init
5006 exit(0 .or. 0)
5007 end on
5008 )NKSP_CODE",
5009 .expectIntExitResult = 0
5010 });
5011
5012 runScript({
5013 .code = R"NKSP_CODE(
5014 on init
5015 exit(43 .or. 142)
5016 end on
5017 )NKSP_CODE",
5018 .expectIntExitResult = 175
5019 });
5020
5021 // real number tests ...
5022 // (not allowed for this operator)
5023
5024 runScript({
5025 .code = R"NKSP_CODE(
5026 on init
5027 exit(1.0 .or. 1.0)
5028 end on
5029 )NKSP_CODE",
5030 .expectParseError = true // real numbers not allowed for this operator
5031 });
5032
5033 // mixed type tests ...
5034 // (not allowed for this operator)
5035
5036 runScript({
5037 .code = R"NKSP_CODE(
5038 on init
5039 exit(1.0 .or. 1)
5040 end on
5041 )NKSP_CODE",
5042 .expectParseError = true // real numbers not allowed for this operator
5043 });
5044
5045 runScript({
5046 .code = R"NKSP_CODE(
5047 on init
5048 exit(1 .or. 1.0)
5049 end on
5050 )NKSP_CODE",
5051 .expectParseError = true // real numbers not allowed for this operator
5052 });
5053
5054 // std unit tests ...
5055 // (not allowed for this operator)
5056
5057 runScript({
5058 .code = R"NKSP_CODE(
5059 on init
5060 exit(1s .or. 1)
5061 end on
5062 )NKSP_CODE",
5063 .expectParseError = true // std units not allowed for this operator
5064 });
5065
5066 runScript({
5067 .code = R"NKSP_CODE(
5068 on init
5069 exit(1 .or. 1s)
5070 end on
5071 )NKSP_CODE",
5072 .expectParseError = true // std units not allowed for this operator
5073 });
5074
5075 // 'final' ('!') operator tests ...
5076
5077 runScript({
5078 .code = R"NKSP_CODE(
5079 on init
5080 exit(!43 .or. !142)
5081 end on
5082 )NKSP_CODE",
5083 .expectIntExitResult = 175,
5084 .expectExitResultFinal = true
5085 });
5086
5087 runScript({
5088 .code = R"NKSP_CODE(
5089 on init
5090 exit(43 .or. 142)
5091 end on
5092 )NKSP_CODE",
5093 .expectIntExitResult = 175,
5094 .expectExitResultFinal = false
5095 });
5096
5097 #if !SILENT_TEST
5098 std::cout << std::endl;
5099 #endif
5100 }
5101
5102 static void testBitwiseNotOperator() {
5103 #if !SILENT_TEST
5104 std::cout << "UNIT TEST: bitwise not (.not.) operator\n";
5105 #endif
5106
5107 // integer tests ...
5108
5109 runScript({
5110 .code = R"NKSP_CODE(
5111 on init
5112 exit(.not. -1)
5113 end on
5114 )NKSP_CODE",
5115 .expectIntExitResult = 0
5116 });
5117
5118 runScript({
5119 .code = R"NKSP_CODE(
5120 on init
5121 exit(.not. 0)
5122 end on
5123 )NKSP_CODE",
5124 .expectIntExitResult = -1
5125 });
5126
5127 runScript({
5128 .code = R"NKSP_CODE(
5129 on init
5130 exit(.not. 3)
5131 end on
5132 )NKSP_CODE",
5133 .expectIntExitResult = ssize_t(size_t(-1) << 2)
5134 });
5135
5136 // real number tests ...
5137 // (not allowed for this operator)
5138
5139 runScript({
5140 .code = R"NKSP_CODE(
5141 on init
5142 exit(.not. 1.0)
5143 end on
5144 )NKSP_CODE",
5145 .expectParseError = true // real numbers not allowed for this operator
5146 });
5147
5148 runScript({
5149 .code = R"NKSP_CODE(
5150 on init
5151 exit(.not. -1.0)
5152 end on
5153 )NKSP_CODE",
5154 .expectParseError = true // real numbers not allowed for this operator
5155 });
5156
5157 // std unit tests ...
5158 // (not allowed for this operator)
5159
5160 runScript({
5161 .code = R"NKSP_CODE(
5162 on init
5163 exit(.not. 1s)
5164 end on
5165 )NKSP_CODE",
5166 .expectParseError = true // std units not allowed for this operator
5167 });
5168
5169 // 'final' ('!') operator tests ...
5170
5171 runScript({
5172 .code = R"NKSP_CODE(
5173 on init
5174 exit(.not. !0)
5175 end on
5176 )NKSP_CODE",
5177 .expectIntExitResult = -1,
5178 .expectExitResultFinal = true
5179 });
5180
5181 runScript({
5182 .code = R"NKSP_CODE(
5183 on init
5184 exit(.not. 0)
5185 end on
5186 )NKSP_CODE",
5187 .expectIntExitResult = -1,
5188 .expectExitResultFinal = false
5189 });
5190
5191 #if !SILENT_TEST
5192 std::cout << std::endl;
5193 #endif
5194 }
5195
5196 static void testPrecedenceOfOperators() {
5197 #if !SILENT_TEST
5198 std::cout << "UNIT TEST: precedence of operators\n";
5199 #endif
5200
5201 // integer tests ...
5202
5203 runScript({
5204 .code = R"NKSP_CODE(
5205 on init
5206 exit(3 + 4 * 2)
5207 end on
5208 )NKSP_CODE",
5209 .expectIntExitResult = 11
5210 });
5211
5212 runScript({
5213 .code = R"NKSP_CODE(
5214 on init
5215 exit(4 * 2 + 3)
5216 end on
5217 )NKSP_CODE",
5218 .expectIntExitResult = 11
5219 });
5220
5221 runScript({
5222 .code = R"NKSP_CODE(
5223 on init
5224 exit((3 + 4) * 2)
5225 end on
5226 )NKSP_CODE",
5227 .expectIntExitResult = 14
5228 });
5229
5230 runScript({
5231 .code = R"NKSP_CODE(
5232 on init
5233 exit(4 * (2 + 3))
5234 end on
5235 )NKSP_CODE",
5236 .expectIntExitResult = 20
5237 });
5238
5239 // real number tests ...
5240
5241 runScript({
5242 .code = R"NKSP_CODE(
5243 on init
5244 exit(3.2 + 4.0 * 2.0)
5245 end on
5246 )NKSP_CODE",
5247 .expectRealExitResult = 11.2
5248 });
5249
5250 runScript({
5251 .code = R"NKSP_CODE(
5252 on init
5253 exit(4.0 * 2.0 + 3.2)
5254 end on
5255 )NKSP_CODE",
5256 .expectRealExitResult = 11.2
5257 });
5258
5259 runScript({
5260 .code = R"NKSP_CODE(
5261 on init
5262 exit((3.2 + 4.0) * 2.0)
5263 end on
5264 )NKSP_CODE",
5265 .expectRealExitResult = 14.4
5266 });
5267
5268 runScript({
5269 .code = R"NKSP_CODE(
5270 on init
5271 exit(4.0 * (2.0 + 3.2))
5272 end on
5273 )NKSP_CODE",
5274 .expectRealExitResult = 20.8
5275 });
5276
5277 // std unit tests ...
5278
5279 runScript({
5280 .code = R"NKSP_CODE(
5281 on init
5282 exit(4 * (2us + 3us) + 7ms)
5283 end on
5284 )NKSP_CODE",
5285 .expectIntExitResult = 7020,
5286 .expectExitResultUnitPrefix = { VM_MICRO },
5287 .expectExitResultUnit = VM_SECOND
5288 });
5289
5290 runScript({
5291 .code = R"NKSP_CODE(
5292 on init
5293 declare $a := 4
5294 declare $c := 3us
5295 exit($a * (2us + $c) + 7ms)
5296 end on
5297 )NKSP_CODE",
5298 .expectIntExitResult = 7020,
5299 .expectExitResultUnitPrefix = { VM_MICRO },
5300 .expectExitResultUnit = VM_SECOND
5301 });
5302
5303 runScript({
5304 .code = R"NKSP_CODE(
5305 on init
5306 declare $a := 4
5307 declare $b := 2us
5308 declare $c := 3us
5309 exit($a * ($b + $c) + 7ms)
5310 end on
5311 )NKSP_CODE",
5312 .expectIntExitResult = 7020,
5313 .expectExitResultUnitPrefix = { VM_MICRO },
5314 .expectExitResultUnit = VM_SECOND
5315 });
5316
5317 runScript({
5318 .code = R"NKSP_CODE(
5319 on init
5320 declare $a := 4
5321 declare $b := 2us
5322 declare $c := 3us
5323 declare $d := 7ms
5324 exit($a * ($b + $c) + 7ms)
5325 end on
5326 )NKSP_CODE",
5327 .expectIntExitResult = 7020,
5328 .expectExitResultUnitPrefix = { VM_MICRO },
5329 .expectExitResultUnit = VM_SECOND
5330 });
5331
5332 runScript({
5333 .code = R"NKSP_CODE(
5334 on init
5335 declare $c := 3us
5336 declare $a := 4
5337 declare $d := 7ms
5338 declare $b := 2us
5339 exit($a * ($b + $c) + 7ms)
5340 end on
5341 )NKSP_CODE",
5342 .expectIntExitResult = 7020,
5343 .expectExitResultUnitPrefix = { VM_MICRO },
5344 .expectExitResultUnit = VM_SECOND
5345 });
5346
5347 runScript({
5348 .code = R"NKSP_CODE(
5349 on init
5350 exit(4.0 * (2.0mdB + 3.2mdB) / 2.0)
5351 end on
5352 )NKSP_CODE",
5353 .expectRealExitResult = 10.4,
5354 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5355 .expectExitResultUnit = VM_BEL
5356 });
5357
5358 runScript({
5359 .code = R"NKSP_CODE(
5360 on init
5361 declare ~a := 2.0mdB
5362 declare ~b := 3.2mdB
5363 exit(4.0 * (~a + ~b) / 2.0)
5364 end on
5365 )NKSP_CODE",
5366 .expectRealExitResult = 10.4,
5367 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5368 .expectExitResultUnit = VM_BEL
5369 });
5370
5371 runScript({
5372 .code = R"NKSP_CODE(
5373 on init
5374 declare ~b := 3.2mdB
5375 declare ~a := 2.0mdB
5376 exit(4.0 * (~a + ~b) / 2.0)
5377 end on
5378 )NKSP_CODE",
5379 .expectRealExitResult = 10.4,
5380 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5381 .expectExitResultUnit = VM_BEL
5382 });
5383
5384 runScript({
5385 .code = R"NKSP_CODE(
5386 on init
5387 declare ~a := 4.0
5388 declare ~b := 2.0mdB
5389 declare ~c := 3.2mdB
5390 declare ~d := 2.0
5391 exit((~a * (~b + ~c) / ~d) + 1.1mdB)
5392 end on
5393 )NKSP_CODE",
5394 .expectRealExitResult = 11.5,
5395 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5396 .expectExitResultUnit = VM_BEL
5397 });
5398
5399 runScript({
5400 .code = R"NKSP_CODE(
5401 on init
5402 declare ~c := 3.2mdB
5403 declare ~a := 4.0
5404 declare ~d := 2.0
5405 declare ~b := 2.0mdB
5406 exit(~a * (~b + ~c) / ~d + 1.1mdB)
5407 end on
5408 )NKSP_CODE",
5409 .expectRealExitResult = 11.5,
5410 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5411 .expectExitResultUnit = VM_BEL
5412 });
5413
5414 // 'final' ('!') operator tests ...
5415
5416 runScript({
5417 .code = R"NKSP_CODE(
5418 on init
5419 declare $a := 4
5420 declare $b := !2us
5421 declare $c := 3us
5422 declare $d := 7ms
5423 exit($a * ($b + $c) + 7ms)
5424 end on
5425 )NKSP_CODE",
5426 .expectIntExitResult = 7020,
5427 .expectExitResultUnitPrefix = { VM_MICRO },
5428 .expectExitResultUnit = VM_SECOND,
5429 .expectExitResultFinal = true,
5430 .expectParseWarning = true // only one operand is defined as 'final', result will be final though
5431 });
5432
5433 runScript({
5434 .code = R"NKSP_CODE(
5435 on init
5436 declare $a := 4
5437 declare $b := 2us
5438 declare $c := !3us
5439 declare $d := 7ms
5440 exit($a * ($b + $c) + 7ms)
5441 end on
5442 )NKSP_CODE",
5443 .expectIntExitResult = 7020,
5444 .expectExitResultUnitPrefix = { VM_MICRO },
5445 .expectExitResultUnit = VM_SECOND,
5446 .expectExitResultFinal = true,
5447 .expectParseWarning = true // only one operand is defined as 'final', result will be final though
5448 });
5449
5450 #if !SILENT_TEST
5451 std::cout << std::endl;
5452 #endif
5453 }
5454
5455 static void testIntVarDeclaration() {
5456 #if !SILENT_TEST
5457 std::cout << "UNIT TEST: int var declaration\n";
5458 #endif
5459
5460 runScript({
5461 .code = R"NKSP_CODE(
5462 on init
5463 declare $a
5464 exit($a)
5465 end on
5466 )NKSP_CODE",
5467 .expectIntExitResult = 0
5468 });
5469
5470 runScript({
5471 .code = R"NKSP_CODE(
5472 on init
5473 declare $a := 24
5474 exit($a)
5475 end on
5476 )NKSP_CODE",
5477 .expectIntExitResult = 24
5478 });
5479
5480 runScript({
5481 .code = R"NKSP_CODE(
5482 on init
5483 declare $a := 24
5484 $a := 8
5485 exit($a)
5486 end on
5487 )NKSP_CODE",
5488 .expectIntExitResult = 8
5489 });
5490
5491 runScript({
5492 .code = R"NKSP_CODE(
5493 on init
5494 declare $a
5495 declare $a
5496 end on
5497 )NKSP_CODE",
5498 .expectParseError = true // variable re-declaration
5499 });
5500
5501 runScript({
5502 .code = R"NKSP_CODE(
5503 on init
5504 declare const $a
5505 end on
5506 )NKSP_CODE",
5507 .expectParseError = true // const variable declaration without assignment
5508 });
5509
5510 runScript({
5511 .code = R"NKSP_CODE(
5512 on init
5513 declare const $a := 24
5514 exit($a)
5515 end on
5516 )NKSP_CODE",
5517 .expectIntExitResult = 24
5518 });
5519
5520 runScript({
5521 .code = R"NKSP_CODE(
5522 on init
5523 declare const $a := 24
5524 $a := 8
5525 end on
5526 )NKSP_CODE",
5527 .expectParseError = true // attempt to modify const variable
5528 });
5529
5530 runScript({
5531 .code = R"NKSP_CODE(
5532 on init
5533 declare const $a := 24
5534 declare const $b := $a
5535 exit($b)
5536 end on
5537 )NKSP_CODE",
5538 .expectIntExitResult = 24
5539 });
5540
5541 runScript({
5542 .code = R"NKSP_CODE(
5543 on init
5544 declare $a := 24
5545 declare const $b := $a
5546 end on
5547 )NKSP_CODE",
5548 .expectParseError = true // const variable defined with non-const assignment
5549 });
5550
5551 runScript({
5552 .code = R"NKSP_CODE(
5553 on init
5554 declare polyphonic $a
5555 exit($a)
5556 end on
5557 )NKSP_CODE",
5558 .expectIntExitResult = 0
5559 });
5560
5561 runScript({
5562 .code = R"NKSP_CODE(
5563 on init
5564 declare const polyphonic $a
5565 end on
5566 )NKSP_CODE",
5567 .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
5568 });
5569
5570 runScript({
5571 .code = R"NKSP_CODE(
5572 on init
5573 declare polyphonic const $a
5574 end on
5575 )NKSP_CODE",
5576 .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
5577 });
5578
5579 runScript({
5580 .code = R"NKSP_CODE(
5581 on init
5582 declare const polyphonic $a := 3
5583 end on
5584 )NKSP_CODE",
5585 .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
5586 });
5587
5588 runScript({
5589 .code = R"NKSP_CODE(
5590 on init
5591 declare polyphonic const $a := 3
5592 end on
5593 )NKSP_CODE",
5594 .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
5595 });
5596
5597 runScript({
5598 .code = R"NKSP_CODE(
5599 on init
5600 declare ~a := 24
5601 exit(~a)
5602 end on
5603 )NKSP_CODE",
5604 .expectParseWarning = true, // real type declaration vs. int value assignment
5605 .expectIntExitResult = 24
5606 });
5607
5608 runScript({
5609 .code = R"NKSP_CODE(
5610 on init
5611 declare %a := 24
5612 exit(%a)
5613 end on
5614 )NKSP_CODE",
5615 .expectParseWarning = true, // int array type declaration vs. int scalar value assignment
5616 .expectIntExitResult = 24
5617 });
5618
5619 runScript({
5620 .code = R"NKSP_CODE(
5621 on init
5622 declare const %a := 24
5623 exit(%a)
5624 end on
5625 )NKSP_CODE",
5626 .expectParseWarning = true, // int array type declaration vs. int scalar value assignment
5627 .expectIntExitResult = 24
5628 });
5629
5630 runScript({
5631 .code = R"NKSP_CODE(
5632 on init
5633 declare ?a := 24
5634 exit(?a)
5635 end on
5636 )NKSP_CODE",
5637 .expectParseWarning = true, // real array type declaration vs. int scalar value assignment
5638 .expectIntExitResult = 24
5639 });
5640
5641 runScript({
5642 .code = R"NKSP_CODE(
5643 on init
5644 declare const ?a := 24
5645 exit(?a)
5646 end on
5647 )NKSP_CODE",
5648 .expectParseWarning = true, // real array type declaration vs. int scalar value assignment
5649 .expectIntExitResult = 24
5650 });
5651
5652 runScript({
5653 .code = R"NKSP_CODE(
5654 on init
5655 declare @a := 24
5656 exit(@a)
5657 end on
5658 )NKSP_CODE",
5659 .expectParseWarning = true, // string type declaration vs. int scalar value assignment
5660 .expectIntExitResult = 24
5661 });
5662
5663 runScript({
5664 .code = R"NKSP_CODE(
5665 on init
5666 declare const @a := 24
5667 exit(@a)
5668 end on
5669 )NKSP_CODE",
5670 .expectParseWarning = true, // string type declaration vs. int scalar value assignment
5671 .expectIntExitResult = 24
5672 });
5673
5674 runScript({
5675 .code = R"NKSP_CODE(
5676 on init
5677 declare $a := ( 0, 1, 2 )
5678 end on
5679 )NKSP_CODE",
5680 .expectParseError = true // int scalar type declaration vs. int array value assignment
5681 });
5682
5683 runScript({
5684 .code = R"NKSP_CODE(
5685 on init
5686 declare const $a := ( 0, 1, 2 )
5687 end on
5688 )NKSP_CODE",
5689 .expectParseError = true // int scalar type declaration vs. int array value assignment
5690 });
5691
5692 runScript({
5693 .code = R"NKSP_CODE(
5694 on init
5695 declare a
5696 end on
5697 )NKSP_CODE",
5698 .expectParseError = true // missing type prefix character in variable name
5699 });
5700
5701 runScript({
5702 .code = R"NKSP_CODE(
5703 on init
5704 declare a := 24
5705 end on
5706 )NKSP_CODE",
5707 .expectParseError = true // missing type prefix character in variable name
5708 });
5709
5710 runScript({
5711 .code = R"NKSP_CODE(
5712 on init
5713 declare const a := 24
5714 end on
5715 )NKSP_CODE",
5716 .expectParseError = true // missing type prefix character in variable name
5717 });
5718
5719 runScript({
5720 .code = R"NKSP_CODE(
5721 on init
5722 declare polyphonic a
5723 end on
5724 )NKSP_CODE",
5725 .expectParseError = true // missing type prefix character in variable name
5726 });
5727
5728 runScript({
5729 .code = R"NKSP_CODE(
5730 on init
5731 declare $a := max(8,24)
5732 exit($a)
5733 end on
5734 )NKSP_CODE",
5735 .expectIntExitResult = 24
5736 });
5737
5738 runScript({
5739 .code = R"NKSP_CODE(
5740 on init
5741 declare $a := abort($NI_CALLBACK_ID)
5742 end on
5743 )NKSP_CODE",
5744 .expectParseError = true // assigned expression does not result in a value
5745 });
5746
5747 runScript({
5748 .code = R"NKSP_CODE(
5749 on init
5750 declare const $a := abort($NI_CALLBACK_ID)
5751 end on
5752 )NKSP_CODE",
5753 .expectParseError = true // assigned expression does not result in a value
5754 });
5755
5756 #if !SILENT_TEST
5757 std::cout << std::endl;
5758 #endif
5759 }
5760
5761 static void testIntArrayVarDeclaration() {
5762 #if !SILENT_TEST
5763 std::cout << "UNIT TEST: int array var declaration\n";
5764 #endif
5765
5766 runScript({
5767 .code = R"NKSP_CODE(
5768 on init
5769 declare %a[3]
5770 exit( %a[0] + %a[1] + %a[2] )
5771 end on
5772 )NKSP_CODE",
5773 .expectIntExitResult = 0
5774 });
5775
5776 runScript({
5777 .code = R"NKSP_CODE(
5778 on init
5779 declare %a[0]
5780 end on
5781 )NKSP_CODE",
5782 .expectParseWarning = true // unusable array size
5783 });
5784
5785 runScript({
5786 .code = R"NKSP_CODE(
5787 on init
5788 declare %a[-1]
5789 end on
5790 )NKSP_CODE",
5791 .expectParseError = true // illegal array size
5792 });
5793
5794 runScript({
5795 .code = R"NKSP_CODE(
5796 on init
5797 declare %a[3] := ( 1, 2, 3 )
5798 exit( %a[0] + %a[1] + %a[2] )
5799 end on
5800 )NKSP_CODE",
5801 .expectIntExitResult = (1 + 2 + 3)
5802 });
5803
5804 runScript({
5805 .code = R"NKSP_CODE(
5806 on init
5807 declare %a[4] := ( 1, 2, 3 )
5808 exit( %a[0] + %a[1] + %a[2] + %a[3] )
5809 end on
5810 )NKSP_CODE",
5811 .expectParseWarning = true, // less values assigned than array size declared
5812 .expectIntExitResult = (1 + 2 + 3 + 0)
5813 });
5814
5815 runScript({
5816 .code = R"NKSP_CODE(
5817 on init
5818 declare %a[] := ( 1, 2, 3 )
5819 exit( %a[0] + %a[1] + %a[2] )
5820 end on
5821 )NKSP_CODE",
5822 .expectIntExitResult = (1 + 2 + 3)
5823 });
5824
5825 runScript({
5826 .code = R"NKSP_CODE(
5827 on init
5828 declare %a[]
5829 end on
5830 )NKSP_CODE",
5831 .expectParseWarning = true // unusable array size (zero)
5832 });
5833
5834 runScript({
5835 .code = R"NKSP_CODE(
5836 on init
5837 declare const $sz := 3
5838 declare %a[$sz] := ( 1, 2, 3 )
5839 exit( %a[0] + %a[1] + %a[2] )
5840 end on
5841 )NKSP_CODE",
5842 .expectIntExitResult = (1 + 2 + 3)
5843 });
5844
5845 runScript({
5846 .code = R"NKSP_CODE(
5847 on init
5848 declare const $sz := 3
5849 declare const %a[$sz] := ( 1, 2, 3 )
5850 exit( %a[0] + %a[1] + %a[2] )
5851 end on
5852 )NKSP_CODE",
5853 .expectIntExitResult = (1 + 2 + 3)
5854 });
5855
5856 runScript({
5857 .code = R"NKSP_CODE(
5858 on init
5859 declare $sz := 3
5860 declare %a[$sz] := ( 1, 2, 3 )
5861 end on
5862 )NKSP_CODE",
5863 .expectParseError = true // array size must be constant expression
5864 });
5865
5866 runScript({
5867 .code = R"NKSP_CODE(
5868 on init
5869 declare $sz := 3
5870 declare const %a[$sz] := ( 1, 2, 3 )
5871 end on
5872 )NKSP_CODE",
5873 .expectParseError = true // array size must be constant expression
5874 });
5875
5876 runScript({
5877 .code = R"NKSP_CODE(
5878 on init
5879 declare const ~sz := 3.0
5880 declare const %a[~sz] := ( 1, 2, 3 )
5881 end on
5882 )NKSP_CODE",
5883 .expectParseError = true // array size must be integer type
5884 });
5885
5886 runScript({
5887 .code = R"NKSP_CODE(
5888 on init
5889 declare %a[3s] := ( 1, 2, 3 )
5890 end on
5891 )NKSP_CODE",
5892 .expectParseError = true // units not allowed for array size
5893 });
5894
5895 runScript({
5896 .code = R"NKSP_CODE(
5897 on init
5898 declare %a[3m] := ( 1, 2, 3 )
5899 end on
5900 )NKSP_CODE",
5901 .expectParseError = true // units not allowed for array size
5902 });
5903
5904 runScript({
5905 .code = R"NKSP_CODE(
5906 on init
5907 declare const %a[!3] := ( 1, 2, 3 )
5908 exit( %a[0] + %a[1] + %a[2] )
5909 end on
5910 )NKSP_CODE",
5911 .expectIntExitResult = (1 + 2 + 3),
5912 .expectParseWarning = true // 'final' operator is meaningless for array size
5913 });
5914
5915 runScript({
5916 .code = R"NKSP_CODE(
5917 on init
5918 declare %a[3] := ( 1, 2, 3 )
5919 %a[0] := 4
5920 %a[1] := 5
5921 %a[2] := 6
5922 exit( %a[0] + %a[1] + %a[2] )
5923 end on
5924 )NKSP_CODE",
5925 .expectIntExitResult = (4 + 5 + 6)
5926 });
5927
5928 runScript({
5929 .code = R"NKSP_CODE(
5930 on init
5931 declare %a[3]
5932 declare %a[3]
5933 end on
5934 )NKSP_CODE",
5935 .expectParseError = true // variable re-declaration
5936 });
5937
5938 runScript({
5939 .code = R"NKSP_CODE(
5940 on init
5941 declare const %a[3]
5942 end on
5943 )NKSP_CODE",
5944 .expectParseError = true // const variable declaration without assignment
5945 });
5946
5947 runScript({
5948 .code = R"NKSP_CODE(
5949 on init
5950 declare const %a[3] := ( 1, 2, 3 )
5951 exit( %a[0] + %a[1] + %a[2] )
5952 end on
5953 )NKSP_CODE",
5954 .expectIntExitResult = (1 + 2 + 3)
5955 });
5956
5957 runScript({
5958 .code = R"NKSP_CODE(
5959 on init
5960 declare const %a[3] := ( 1, 2, 3, 4 )
5961 end on
5962 )NKSP_CODE",
5963 .expectParseError = true // incompatible array sizes
5964 });
5965
5966 runScript({
5967 .code = R"NKSP_CODE(
5968 on init
5969 declare const %a[3] := ( 1, 2, 3 )
5970 %a[0] := 8
5971 end on
5972 )NKSP_CODE",
5973 .expectParseError = true // attempt to modify const variable
5974 });
5975
5976 runScript({
5977 .code = R"NKSP_CODE(
5978 on init
5979 declare const %a[3] := ( 1, 2, 3 )
5980 declare const %b[3] := ( %a[0], %a[1], %a[2] )
5981 exit( %b[0] + %b[1] + %b[2] )
5982 end on
5983 )NKSP_CODE",
5984 .expectIntExitResult = (1 + 2 + 3)
5985 });
5986
5987 runScript({
5988 .code = R"NKSP_CODE(
5989 on init
5990 declare %a[3] := ( 1, 2, 3 )
5991 declare const %b[3] := ( %a[0], %a[1], %a[2] )
5992 end on
5993 )NKSP_CODE",
5994 .expectParseError = true // const array defined with non-const assignment
5995 });
5996
5997 runScript({
5998 .code = R"NKSP_CODE(
5999 on init
6000 declare polyphonic %a[3]
6001 end on
6002 )NKSP_CODE",
6003 .expectParseError = true // polyphonic not allowed for array types
6004 });
6005
6006 runScript({
6007 .code = R"NKSP_CODE(
6008 on init
6009 declare polyphonic %a[3] := ( 1, 2, 3 )
6010 end on
6011 )NKSP_CODE",
6012 .expectParseError = true // polyphonic not allowed for array types
6013 });
6014
6015 runScript({
6016 .code = R"NKSP_CODE(
6017 on init
6018 declare const polyphonic %a[3]
6019 end on
6020 )NKSP_CODE",
6021 .expectParseError = true // polyphonic not allowed for array types
6022 });
6023
6024 runScript({
6025 .code = R"NKSP_CODE(
6026 on init
6027 declare const polyphonic %a[3] := ( 1, 2, 3 )
6028 end on
6029 )NKSP_CODE",
6030 .expectParseError = true // polyphonic not allowed for array types
6031 });
6032
6033 runScript({
6034 .code = R"NKSP_CODE(
6035 on init
6036 declare polyphonic const %a[3]
6037 end on
6038 )NKSP_CODE",
6039 .expectParseError = true // polyphonic not allowed for array types
6040 });
6041
6042 runScript({
6043 .code = R"NKSP_CODE(
6044 on init
6045 declare polyphonic const %a[3] := ( 1, 2, 3 )
6046 end on
6047 )NKSP_CODE",
6048 .expectParseError = true // polyphonic not allowed for array types
6049 });
6050
6051 runScript({
6052 .code = R"NKSP_CODE(
6053 on init
6054 declare %a[3] := ( 1, max(8,24), 3 )
6055 exit( %a[0] + %a[1] + %a[2] )
6056 end on
6057 )NKSP_CODE",
6058 .expectIntExitResult = ( 1 + 24 + 3 )
6059 });
6060
6061 runScript({
6062 .code = R"NKSP_CODE(
6063 on init
6064 declare %a[3] := ( 1, abort($NI_CALLBACK_ID), 3 )
6065 end on
6066 )NKSP_CODE",
6067 .expectParseError = true // assigned expression does not result in a value
6068 });
6069
6070 runScript({
6071 .code = R"NKSP_CODE(
6072 on init
6073 declare const %a[3] := ( 1, abort($NI_CALLBACK_ID), 3 )
6074 end on
6075 )NKSP_CODE",
6076 .expectParseError = true // assigned expression does not result in a value
6077 });
6078
6079 runScript({
6080 .code = R"NKSP_CODE(
6081 on init
6082 declare %a[3] := ( 1.0, 2.0, 3.0 )
6083 end on
6084 )NKSP_CODE",
6085 .expectParseError = true // int array declaration vs. real array assignment
6086 });
6087
6088 runScript({
6089 .code = R"NKSP_CODE(
6090 on init
6091 declare %a[3] := ( 1, 2, 3.0 )
6092 end on
6093 )NKSP_CODE",
6094 .expectParseError = true // 3rd element not an integer
6095 });
6096
6097 runScript({
6098 .code = R"NKSP_CODE(
6099 on init
6100 declare %a[3] := ( "x", "y", "z" )
6101 end on
6102 )NKSP_CODE",
6103 .expectParseError = true // int array declaration vs. string array assignment
6104 });
6105
6106 runScript({
6107 .code = R"NKSP_CODE(
6108 on init
6109 declare a[3] := ( 1, 2, 3 )
6110 end on
6111 )NKSP_CODE",
6112 .expectParseError = true // missing type prefix character in variable name
6113 });
6114
6115 runScript({
6116 .code = R"NKSP_CODE(
6117 on init
6118 declare a[3]
6119 end on
6120 )NKSP_CODE",
6121 .expectParseError = true // missing type prefix character in variable name
6122 });
6123
6124 runScript({
6125 .code = R"NKSP_CODE(
6126 on init
6127 declare const %a[3] := ( 1, 2s, 3 )
6128 end on
6129 )NKSP_CODE",
6130 .expectParseError = true // unit types not allowed for arrays
6131 });
6132
6133 runScript({
6134 .code = R"NKSP_CODE(
6135 on init
6136 declare const %a[3] := ( 1, !2, 3 )
6137 end on
6138 )NKSP_CODE",
6139 .expectParseError = true // 'final' not allowed for arrays
6140 });
6141
6142 #if !SILENT_TEST
6143 std::cout << std::endl;
6144 #endif
6145 }
6146
6147 static void testRealVarDeclaration() {
6148 #if !SILENT_TEST
6149 std::cout << "UNIT TEST: real var declaration\n";
6150 #endif
6151
6152 runScript({
6153 .code = R"NKSP_CODE(
6154 on init
6155 declare ~a
6156 exit(~a)
6157 end on
6158 )NKSP_CODE",
6159 .expectRealExitResult = 0.0
6160 });
6161
6162 runScript({
6163 .code = R"NKSP_CODE(
6164 on init
6165 declare ~a := 24.8
6166 exit(~a)
6167 end on
6168 )NKSP_CODE",
6169 .expectRealExitResult = 24.8
6170 });
6171
6172 runScript({
6173 .code = R"NKSP_CODE(
6174 on init
6175 declare ~a := 8.24
6176 ~a := 24.8
6177 exit(~a)
6178 end on
6179 )NKSP_CODE",
6180 .expectRealExitResult = 24.8
6181 });
6182
6183 runScript({
6184 .code = R"NKSP_CODE(
6185 on init
6186 declare ~a
6187 declare ~a
6188 end on
6189 )NKSP_CODE",
6190 .expectParseError = true // variable re-declaration
6191 });
6192
6193 runScript({
6194 .code = R"NKSP_CODE(
6195 on init
6196 declare const ~a
6197 end on
6198 )NKSP_CODE",
6199 .expectParseError = true // const variable declaration without assignment
6200 });
6201
6202 runScript({
6203 .code = R"NKSP_CODE(
6204 on init
6205 declare const ~a := 8.24
6206 exit(~a)
6207 end on
6208 )NKSP_CODE",
6209 .expectRealExitResult = 8.24
6210 });
6211
6212 runScript({
6213 .code = R"NKSP_CODE(
6214 on init
6215 declare const ~a := 28.0
6216 ~a := 8.0
6217 end on
6218 )NKSP_CODE",
6219 .expectParseError = true // attempt to modify const variable
6220 });
6221
6222 runScript({
6223 .code = R"NKSP_CODE(
6224 on init
6225 declare const ~a := 24.8
6226 declare const ~b := ~a
6227 exit(~b)
6228 end on
6229 )NKSP_CODE",
6230 .expectRealExitResult = 24.8
6231 });
6232
6233 runScript({
6234 .code = R"NKSP_CODE(
6235 on init
6236 declare ~a := 24.0
6237 declare const ~b := ~a
6238 end on
6239 )NKSP_CODE",
6240 .expectParseError = true // const variable defined with non-const assignment
6241 });
6242
6243 runScript({
6244 .code = R"NKSP_CODE(
6245 on init
6246 declare polyphonic ~a
6247 exit(~a)
6248 end on
6249 )NKSP_CODE",
6250 .expectRealExitResult = 0.0
6251 });
6252
6253 runScript({
6254 .code = R"NKSP_CODE(
6255 on init
6256 declare const polyphonic ~a
6257 end on
6258 )NKSP_CODE",
6259 .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
6260 });
6261
6262 runScript({
6263 .code = R"NKSP_CODE(
6264 on init
6265 declare polyphonic const ~a
6266 end on
6267 )NKSP_CODE",
6268 .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
6269 });
6270
6271 runScript({
6272 .code = R"NKSP_CODE(
6273 on init
6274 declare const polyphonic ~a := 3.0
6275 end on
6276 )NKSP_CODE",
6277 .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
6278 });
6279
6280 runScript({
6281 .code = R"NKSP_CODE(
6282 on init
6283 declare polyphonic const ~a := 3.0
6284 end on
6285 )NKSP_CODE",
6286 .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
6287 });
6288
6289 runScript({
6290 .code = R"NKSP_CODE(
6291 on init
6292 declare $a := 24.8
6293 exit($a)
6294 end on
6295 )NKSP_CODE",
6296 .expectParseWarning = true, // int type declaration vs. real value assignment
6297 .expectRealExitResult = 24.8
6298 });
6299
6300 runScript({
6301 .code = R"NKSP_CODE(
6302 on init
6303 declare %a := 24.8
6304 exit(%a)
6305 end on
6306 )NKSP_CODE",
6307 .expectParseWarning = true, // int array type declaration vs. real scalar value assignment
6308 .expectRealExitResult = 24.8
6309 });
6310
6311 runScript({
6312 .code = R"NKSP_CODE(
6313 on init
6314 declare const %a := 24.8
6315 exit(%a)
6316 end on
6317 )NKSP_CODE",
6318 .expectParseWarning = true, // int array type declaration vs. real scalar value assignment
6319 .expectRealExitResult = 24.8
6320 });
6321
6322 runScript({
6323 .code = R"NKSP_CODE(
6324 on init
6325 declare ?a := 24.8
6326 exit(?a)
6327 end on
6328 )NKSP_CODE",
6329 .expectParseWarning = true, // real array type declaration vs. real scalar value assignment
6330 .expectRealExitResult = 24.8
6331 });
6332
6333 runScript({
6334 .code = R"NKSP_CODE(
6335 on init
6336 declare const ?a := 24.8
6337 exit(?a)
6338 end on
6339 )NKSP_CODE",
6340 .expectParseWarning = true, // real array type declaration vs. real scalar value assignment
6341 .expectRealExitResult = 24.8
6342 });
6343
6344 runScript({
6345 .code = R"NKSP_CODE(
6346 on init
6347 declare @a := 24.8
6348 exit(@a)
6349 end on
6350 )NKSP_CODE",
6351 .expectParseWarning = true, // string type declaration vs. real scalar value assignment
6352 .expectRealExitResult = 24.8
6353 });
6354
6355 runScript({
6356 .code = R"NKSP_CODE(
6357 on init
6358 declare const @a := 24.8
6359 exit(@a)
6360 end on
6361 )NKSP_CODE",
6362 .expectParseWarning = true, // string type declaration vs. real scalar value assignment
6363 .expectRealExitResult = 24.8
6364 });
6365
6366 runScript({
6367 .code = R"NKSP_CODE(
6368 on init
6369 declare ~a := ( 0, 1, 2 )
6370 end on
6371 )NKSP_CODE",
6372 .expectParseError = true // real scalar type declaration vs. int array value assignment
6373 });
6374
6375 runScript({
6376 .code = R"NKSP_CODE(
6377 on init
6378 declare const ~a := ( 0, 1, 2 )
6379 end on
6380 )NKSP_CODE",
6381 .expectParseError = true // real scalar type declaration vs. int array value assignment
6382 });
6383
6384 runScript({
6385 .code = R"NKSP_CODE(
6386 on init
6387 declare a := 24.8
6388 end on
6389 )NKSP_CODE",
6390 .expectParseError = true // missing type prefix character in variable name
6391 });
6392
6393 runScript({
6394 .code = R"NKSP_CODE(
6395 on init
6396 declare const a := 24.8
6397 end on
6398 )NKSP_CODE",
6399 .expectParseError = true // missing type prefix character in variable name
6400 });
6401
6402 runScript({
6403 .code = R"NKSP_CODE(
6404 on init
6405 declare ~a := max(8.1,24.2)
6406 exit(~a)
6407 end on
6408 )NKSP_CODE",
6409 .expectRealExitResult = 24.2
6410 });
6411
6412 runScript({
6413 .code = R"NKSP_CODE(
6414 on init
6415 declare ~a := abort($NI_CALLBACK_ID)
6416 end on
6417 )NKSP_CODE",
6418 .expectParseError = true // assigned expression does not result in a value
6419 });
6420
6421 runScript({
6422 .code = R"NKSP_CODE(
6423 on init
6424 declare const ~a := abort($NI_CALLBACK_ID)
6425 end on
6426 )NKSP_CODE",
6427 .expectParseError = true // assigned expression does not result in a value
6428 });
6429
6430 #if !SILENT_TEST
6431 std::cout << std::endl;
6432 #endif
6433 }
6434
6435 static void testRealArrayVarDeclaration() {
6436 #if !SILENT_TEST
6437 std::cout << "UNIT TEST: real array var declaration\n";
6438 #endif
6439
6440 runScript({
6441 .code = R"NKSP_CODE(
6442 on init
6443 declare ?a[3]
6444 exit( ?a[0] + ?a[1] + ?a[2] )
6445 end on
6446 )NKSP_CODE",
6447 .expectRealExitResult = 0.0
6448 });
6449
6450 runScript({
6451 .code = R"NKSP_CODE(
6452 on init
6453 declare ?a[0]
6454 end on
6455 )NKSP_CODE",
6456 .expectParseWarning = true // unusable array size
6457 });
6458
6459 runScript({
6460 .code = R"NKSP_CODE(
6461 on init
6462 declare ?a[-1]
6463 end on
6464 )NKSP_CODE",
6465 .expectParseError = true // illegal array size
6466 });
6467
6468 runScript({
6469 .code = R"NKSP_CODE(
6470 on init
6471 declare ?a[3] := ( 1.1, 2.2, 3.3 )
6472 exit( ?a[0] + ?a[1] + ?a[2] )
6473 end on
6474 )NKSP_CODE",
6475 .expectRealExitResult = (1.1 + 2.2 + 3.3)
6476 });
6477
6478 runScript({
6479 .code = R"NKSP_CODE(
6480 on init
6481 declare ?a[4] := ( 1.1, 2.2, 3.3 )
6482 exit( ?a[0] + ?a[1] + ?a[2] + ?a[3] )
6483 end on
6484 )NKSP_CODE",
6485 .expectParseWarning = true, // less values assigned than array size declared
6486 .expectRealExitResult = (1.1 + 2.2 + 3.3 + 0.0)
6487 });
6488
6489 runScript({
6490 .code = R"NKSP_CODE(
6491 on init
6492 declare ?a[] := ( 1.1, 2.2, 3.3 )
6493 exit( ?a[0] + ?a[1] + ?a[2] )
6494 end on
6495 )NKSP_CODE",
6496 .expectRealExitResult = (1.1 + 2.2 + 3.3)
6497 });
6498
6499 runScript({
6500 .code = R"NKSP_CODE(
6501 on init
6502 declare ?a[]
6503 end on
6504 )NKSP_CODE",
6505 .expectParseWarning = true // unusable array size (zero)
6506 });
6507
6508 runScript({
6509 .code = R"NKSP_CODE(
6510 on init
6511 declare const $sz := 3
6512 declare ?a[$sz] := ( 1.1, 2.2, 3.3 )
6513 exit( ?a[0] + ?a[1] + ?a[2] )
6514 end on
6515 )NKSP_CODE",
6516 .expectRealExitResult = (1.1 + 2.2 + 3.3)
6517 });
6518
6519 runScript({
6520 .code = R"NKSP_CODE(
6521 on init
6522 declare const $sz := 3
6523 declare const ?a[$sz] := ( 1.1, 2.2, 3.3 )
6524 exit( ?a[0] + ?a[1] + ?a[2] )
6525 end on
6526 )NKSP_CODE",
6527 .expectRealExitResult = (1.1 + 2.2 + 3.3)
6528 });
6529
6530 runScript({
6531 .code = R"NKSP_CODE(
6532 on init
6533 declare $sz := 3
6534 declare ?a[$sz] := ( 1.1, 2.2, 3.3 )
6535 end on
6536 )NKSP_CODE",
6537 .expectParseError = true // array size must be constant expression
6538 });
6539
6540 runScript({
6541 .code = R"NKSP_CODE(
6542 on init
6543 declare $sz := 3
6544 declare const ?a[$sz] := ( 1.1, 2.2, 3.3 )
6545 end on
6546 )NKSP_CODE",
6547 .expectParseError = true // array size must be constant expression
6548 });
6549
6550 runScript({
6551 .code = R"NKSP_CODE(
6552 on init
6553 declare const ~sz := 3.0
6554 declare const ?a[~sz] := ( 1.1, 2.2, 3.3 )
6555 end on
6556 )NKSP_CODE",
6557 .expectParseError = true // array size must be integer type
6558 });
6559
6560 runScript({
6561 .code = R"NKSP_CODE(
6562 on init
6563 declare ?a[3s] := ( 1.1, 2.2, 3.3 )
6564 end on
6565 )NKSP_CODE",
6566 .expectParseError = true // units not allowed for array size
6567 });
6568
6569 runScript({
6570 .code = R"NKSP_CODE(
6571 on init
6572 declare ?a[3m] := ( 1.1, 2.2, 3.3 )
6573 end on
6574 )NKSP_CODE",
6575 .expectParseError = true // units not allowed for array size
6576 });
6577
6578 runScript({
6579 .code = R"NKSP_CODE(
6580 on init
6581 declare const ?a[!3] := ( 1.1, 2.2, 3.3 )
6582 exit( ?a[0] + ?a[1] + ?a[2] )
6583 end on
6584 )NKSP_CODE",
6585 .expectRealExitResult = (1.1 + 2.2 + 3.3),
6586 .expectParseWarning = true // 'final' operator is meaningless for array size
6587 });
6588
6589 runScript({
6590 .code = R"NKSP_CODE(
6591 on init
6592 declare ?a[3] := ( 1.0, 2.0, 3.0 )
6593 ?a[0] := 4.5
6594 ?a[1] := 5.5
6595 ?a[2] := 6.5
6596 exit( ?a[0] + ?a[1] + ?a[2] )
6597 end on
6598 )NKSP_CODE",
6599 .expectRealExitResult = (4.5 + 5.5 + 6.5)
6600 });
6601
6602 runScript({
6603 .code = R"NKSP_CODE(
6604 on init
6605 declare ?a[3]
6606 declare ?a[3]
6607 end on
6608 )NKSP_CODE",
6609 .expectParseError = true // variable re-declaration
6610 });
6611
6612 runScript({
6613 .code = R"NKSP_CODE(
6614 on init
6615 declare const ?a[3]
6616 end on
6617 )NKSP_CODE",
6618 .expectParseError = true // const variable declaration without assignment
6619 });
6620
6621 runScript({
6622 .code = R"NKSP_CODE(
6623 on init
6624 declare const ?a[3] := ( 1.1, 2.2, 3.3 )
6625 exit( ?a[0] + ?a[1] + ?a[2] )
6626 end on
6627 )NKSP_CODE",
6628 .expectRealExitResult = (1.1 + 2.2 + 3.3)
6629 });
6630
6631 runScript({
6632 .code = R"NKSP_CODE(
6633 on init
6634 declare const ?a[3] := ( 1.1, 2.2, 3.3, 4.4 )
6635 end on
6636 )NKSP_CODE",
6637 .expectParseError = true // incompatible array sizes
6638 });
6639
6640 runScript({
6641 .code = R"NKSP_CODE(
6642 on init
6643 declare const ?a[3] := ( 1.0, 2.0, 3.0 )
6644 ?a[0] := 8.0
6645 end on
6646 )NKSP_CODE",
6647 .expectParseError = true // attempt to modify const variable
6648 });
6649
6650 runScript({
6651 .code = R"NKSP_CODE(
6652 on init
6653 declare const ?a[3] := ( 1.1, 2.2, 3.3 )
6654 declare const ?b[3] := ( ?a[0], ?a[1], ?a[2] )
6655 exit( ?b[0] + ?b[1] + ?b[2] )
6656 end on
6657 )NKSP_CODE",
6658 .expectRealExitResult = (1.1 + 2.2 + 3.3)
6659 });
6660
6661 runScript({
6662 .code = R"NKSP_CODE(
6663 on init
6664 declare ?a[3] := ( 1.1, 2.2, 3.3 )
6665 declare const ?b[3] := ( ?a[0], ?a[1], ?a[2] )
6666 end on
6667 )NKSP_CODE",
6668 .expectParseError = true // const array defined with non-const assignment
6669 });
6670
6671 runScript({
6672 .code = R"NKSP_CODE(
6673 on init
6674 declare polyphonic ?a[3]
6675 end on
6676 )NKSP_CODE",
6677 .expectParseError = true // polyphonic not allowed for array types
6678 });
6679
6680 runScript({
6681 .code = R"NKSP_CODE(
6682 on init
6683 declare polyphonic ?a[3] := ( 1.0, 2.0, 3.0 )
6684 end on
6685 )NKSP_CODE",
6686 .expectParseError = true // polyphonic not allowed for array types
6687 });
6688
6689 runScript({
6690 .code = R"NKSP_CODE(
6691 on init
6692 declare const polyphonic ?a[3]
6693 end on
6694 )NKSP_CODE",
6695 .expectParseError = true // polyphonic not allowed for array types
6696 });
6697
6698 runScript({
6699 .code = R"NKSP_CODE(
6700 on init
6701 declare const polyphonic ?a[3] := ( 1.0, 2.0, 3.0 )
6702 end on
6703 )NKSP_CODE",
6704 .expectParseError = true // polyphonic not allowed for array types
6705 });
6706
6707 runScript({
6708 .code = R"NKSP_CODE(
6709 on init
6710 declare polyphonic const ?a[3]
6711 end on
6712 )NKSP_CODE",
6713 .expectParseError = true // polyphonic not allowed for array types
6714 });
6715
6716 runScript({
6717 .code = R"NKSP_CODE(
6718 on init
6719 declare polyphonic const ?a[3] := ( 1.0, 2.0, 3.0 )
6720 end on
6721 )NKSP_CODE",
6722 .expectParseError = true // polyphonic not allowed for array types
6723 });
6724
6725 runScript({
6726 .code = R"NKSP_CODE(
6727 on init
6728 declare ?a[3] := ( 1.0, max(8.3,24.6), 3.0 )
6729 exit( ?a[0] + ?a[1] + ?a[2] )
6730 end on
6731 )NKSP_CODE",
6732 .expectRealExitResult = ( 1.0 + 24.6 + 3.0 )
6733 });
6734
6735 runScript({
6736 .code = R"NKSP_CODE(
6737 on init
6738 declare ?a[3] := ( 1.0, abort($NI_CALLBACK_ID), 3.0 )
6739 end on
6740 )NKSP_CODE",
6741 .expectParseError = true // assigned expression does not result in a value
6742 });
6743
6744 runScript({
6745 .code = R"NKSP_CODE(
6746 on init
6747 declare const ?a[3] := ( 1.0, abort($NI_CALLBACK_ID), 3.0 )
6748 end on
6749 )NKSP_CODE",
6750 .expectParseError = true // assigned expression does not result in a value
6751 });
6752
6753 runScript({
6754 .code = R"NKSP_CODE(
6755 on init
6756 declare ?a[3] := ( 1, 2, 3 )
6757 end on
6758 )NKSP_CODE",
6759 .expectParseError = true // real array declaration vs. int array assignment
6760 });
6761
6762 runScript({
6763 .code = R"NKSP_CODE(
6764 on init
6765 declare ?a[3] := ( 1.0, 2.0, 3 )
6766 end on
6767 )NKSP_CODE",
6768 .expectParseError = true // 3rd element not a real value
6769 });
6770
6771 runScript({
6772 .code = R"NKSP_CODE(
6773 on init
6774 declare ?a[3] := ( "x", "y", "z" )
6775 end on
6776 )NKSP_CODE",
6777 .expectParseError = true // real array declaration vs. string array assignment
6778 });
6779
6780 runScript({
6781 .code = R"NKSP_CODE(
6782 on init
6783 declare a[3] := ( 1.0, 2.0, 3.0 )
6784 end on
6785 )NKSP_CODE",
6786 .expectParseError = true // missing type prefix character in variable name
6787 });
6788
6789 runScript({
6790 .code = R"NKSP_CODE(
6791 on init
6792 declare const ?a[3] := ( 1.0, 2.0s, 3.0 )
6793 end on
6794 )NKSP_CODE",
6795 .expectParseError = true // unit types not allowed for arrays
6796 });
6797
6798 runScript({
6799 .code = R"NKSP_CODE(
6800 on init
6801 declare const ?a[3] := ( 1.0, !2.0, 3.0 )
6802 end on
6803 )NKSP_CODE",
6804 .expectParseError = true // 'final' not allowed for arrays
6805 });
6806
6807 #if !SILENT_TEST
6808 std::cout << std::endl;
6809 #endif
6810 }
6811
6812 static void testStringVarDeclaration() {
6813 #if !SILENT_TEST
6814 std::cout << "UNIT TEST: string var declaration\n";
6815 #endif
6816
6817 runScript({
6818 .code = R"NKSP_CODE(
6819 on init
6820 declare @a
6821 exit(@a)
6822 end on
6823 )NKSP_CODE",
6824 .expectStringExitResult = ""
6825 });
6826
6827 runScript({
6828 .code = R"NKSP_CODE(
6829 on init
6830 declare @a := "foo"
6831 exit(@a)
6832 end on
6833 )NKSP_CODE",
6834 .expectStringExitResult = "foo"
6835 });
6836
6837 runScript({
6838 .code = R"NKSP_CODE(
6839 on init
6840 declare @a := "foo"
6841 @a := "bar"
6842 exit(@a)
6843 end on
6844 )NKSP_CODE",
6845 .expectStringExitResult = "bar"
6846 });
6847
6848 runScript({
6849 .code = R"NKSP_CODE(
6850 on init
6851 declare @a
6852 declare @a
6853 end on
6854 )NKSP_CODE",
6855 .expectParseError = true // variable re-declaration
6856 });
6857
6858 runScript({
6859 .code = R"NKSP_CODE(
6860 on init
6861 declare const @a
6862 end on
6863 )NKSP_CODE",
6864 .expectParseError = true // const variable declaration without assignment
6865 });
6866
6867 runScript({
6868 .code = R"NKSP_CODE(
6869 on init
6870 declare const @a := "foo"
6871 exit(@a)
6872 end on
6873 )NKSP_CODE",
6874 .expectStringExitResult = "foo"
6875 });
6876
6877 runScript({
6878 .code = R"NKSP_CODE(
6879 on init
6880 declare const @a := "foo"
6881 @a := "bar"
6882 end on
6883 )NKSP_CODE",
6884 .expectParseError = true // attempt to modify const variable
6885 });
6886
6887 runScript({
6888 .code = R"NKSP_CODE(
6889 on init
6890 declare const @a := "foo"
6891 declare const @b := @a
6892 exit(@b)
6893 end on
6894 )NKSP_CODE",
6895 .expectStringExitResult = "foo"
6896 });
6897
6898 runScript({
6899 .code = R"NKSP_CODE(
6900 on init
6901 declare @a := "foo"
6902 declare const @b := @a
6903 end on
6904 )NKSP_CODE",
6905 .expectParseError = true // const variable defined with non-const assignment
6906 });
6907
6908 runScript({
6909 .code = R"NKSP_CODE(
6910 on init
6911 declare polyphonic @a
6912 end on
6913 )NKSP_CODE",
6914 .expectParseError = true // 'polyphonic' not allowed for string type
6915 });
6916
6917 runScript({
6918 .code = R"NKSP_CODE(
6919 on init
6920 declare const polyphonic @a
6921 end on
6922 )NKSP_CODE",
6923 .expectParseError = true // 'polyphonic' not allowed for string type
6924 });
6925
6926 runScript({
6927 .code = R"NKSP_CODE(
6928 on init
6929 declare polyphonic const @a
6930 end on
6931 )NKSP_CODE",
6932 .expectParseError = true // 'polyphonic' not allowed for string type
6933 });
6934
6935 runScript({
6936 .code = R"NKSP_CODE(
6937 on init
6938 declare polyphonic @a = "foo"
6939 end on
6940 )NKSP_CODE",
6941 .expectParseError = true // 'polyphonic' not allowed for string type
6942 });
6943
6944 runScript({
6945 .code = R"NKSP_CODE(
6946 on init
6947 declare polyphonic const @a = "foo"
6948 end on
6949 )NKSP_CODE",
6950 .expectParseError = true // 'polyphonic' not allowed for string type
6951 });
6952
6953 runScript({
6954 .code = R"NKSP_CODE(
6955 on init
6956 declare const polyphonic @a = "foo"
6957 end on
6958 )NKSP_CODE",
6959 .expectParseError = true // 'polyphonic' not allowed for string type
6960 });
6961
6962 runScript({
6963 .code = R"NKSP_CODE(
6964 on init
6965 declare $a := "foo"
6966 exit($a)
6967 end on
6968 )NKSP_CODE",
6969 .expectParseWarning = true, // int type declaration vs. string assignment
6970 .expectStringExitResult = "foo"
6971 });
6972
6973 runScript({
6974 .code = R"NKSP_CODE(
6975 on init
6976 declare ~a := "foo"
6977 exit(~a)
6978 end on
6979 )NKSP_CODE",
6980 .expectParseWarning = true, // real type declaration vs. string assignment
6981 .expectStringExitResult = "foo"
6982 });
6983
6984 runScript({
6985 .code = R"NKSP_CODE(
6986 on init
6987 declare %a := "foo"
6988 exit(%a)
6989 end on
6990 )NKSP_CODE",
6991 .expectParseWarning = true, // int array type declaration vs. string assignment
6992 .expectStringExitResult = "foo"
6993 });
6994
6995 runScript({
6996 .code = R"NKSP_CODE(
6997 on init
6998 declare const $a := "foo"
6999 exit($a)
7000 end on
7001 )NKSP_CODE",
7002 .expectParseWarning = true, // int type declaration vs. string assignment
7003 .expectStringExitResult = "foo"
7004 });
7005
7006 runScript({
7007 .code = R"NKSP_CODE(
7008 on init
7009 declare const ~a := "foo"
7010 exit(~a)
7011 end on
7012 )NKSP_CODE",
7013 .expectParseWarning = true, // real type declaration vs. string assignment
7014 .expectStringExitResult = "foo"
7015 });
7016
7017 runScript({
7018 .code = R"NKSP_CODE(
7019 on init
7020 declare const %a := "foo"
7021 exit(%a)
7022 end on
7023 )NKSP_CODE",
7024 .expectParseWarning = true, // int array type declaration vs. string assignment
7025 .expectStringExitResult = "foo"
7026 });
7027
7028 runScript({
7029 .code = R"NKSP_CODE(
7030 on init
7031 declare a := "foo"
7032 end on
7033 )NKSP_CODE",
7034 .expectParseError = true // missing type prefix character in variable name
7035 });
7036
7037 runScript({
7038 .code = R"NKSP_CODE(
7039 on init
7040 declare const a := "foo"
7041 end on
7042 )NKSP_CODE",
7043 .expectParseError = true // missing type prefix character in variable name
7044 });
7045
7046 runScript({
7047 .code = R"NKSP_CODE(
7048 on init
7049 declare @a := abort($NI_CALLBACK_ID)
7050 end on
7051 )NKSP_CODE",
7052 .expectParseError = true // assigned expression does not result in a value
7053 });
7054
7055 runScript({
7056 .code = R"NKSP_CODE(
7057 on init
7058 declare const @a := abort($NI_CALLBACK_ID)
7059 end on
7060 )NKSP_CODE",
7061 .expectParseError = true // assigned expression does not result in a value
7062 });
7063
7064 #if !SILENT_TEST
7065 std::cout << std::endl;
7066 #endif
7067 }
7068
7069 static void testBuiltInMinFunction() {
7070 #if !SILENT_TEST
7071 std::cout << "UNIT TEST: built-in min() function\n";
7072 #endif
7073
7074 runScript({
7075 .code = R"NKSP_CODE(
7076 on init
7077 declare $foo := min
7078 end on
7079 )NKSP_CODE",
7080 .expectParseError = true // because min() function requires 2 arguments
7081 });
7082
7083 runScript({
7084 .code = R"NKSP_CODE(
7085 on init
7086 declare $foo := min()
7087 end on
7088 )NKSP_CODE",
7089 .expectParseError = true // because min() function requires 2 arguments
7090 });
7091
7092 runScript({
7093 .code = R"NKSP_CODE(
7094 on init
7095 declare $foo := min(1)
7096 end on
7097 )NKSP_CODE",
7098 .expectParseError = true // because min() function requires 2 arguments
7099 });
7100
7101 // integer tests ...
7102
7103 runScript({
7104 .code = R"NKSP_CODE(
7105 on init
7106 declare $foo := min(1,2)
7107 exit($foo)
7108 end on
7109 )NKSP_CODE",
7110 .expectIntExitResult = 1
7111 });
7112
7113 runScript({
7114 .code = R"NKSP_CODE(
7115 on init
7116 declare $foo := min(-30,4)
7117 exit($foo)
7118 end on
7119 )NKSP_CODE",
7120 .expectIntExitResult = -30
7121 });
7122
7123 // real number tests ...
7124
7125 runScript({
7126 .code = R"NKSP_CODE(
7127 on init
7128 declare ~foo := min(1.0, 2.0)
7129 exit(~foo)
7130 end on
7131 )NKSP_CODE",
7132 .expectRealExitResult = 1.0
7133 });
7134
7135 runScript({
7136 .code = R"NKSP_CODE(
7137 on init
7138 declare ~foo := min(-30.0, 4.0)
7139 exit(~foo)
7140 end on
7141 )NKSP_CODE",
7142 .expectRealExitResult = -30.0
7143 });
7144
7145 runScript({
7146 .code = R"NKSP_CODE(
7147 on init
7148 declare ~foo := min(1.1, 1.13)
7149 exit(~foo)
7150 end on
7151 )NKSP_CODE",
7152 .expectRealExitResult = 1.1
7153 });
7154
7155 runScript({
7156 .code = R"NKSP_CODE(
7157 on init
7158 declare ~foo := min(1.13, 1.1)
7159 exit(~foo)
7160 end on
7161 )NKSP_CODE",
7162 .expectRealExitResult = 1.1
7163 });
7164
7165 // mixed type tests ...
7166
7167 runScript({
7168 .code = R"NKSP_CODE(
7169 on init
7170 declare ~foo := min(1, 1.16)
7171 exit(~foo)
7172 end on
7173 )NKSP_CODE",
7174 .expectRealExitResult = 1.0,
7175 .expectParseWarning = true // min() warns if data types of arguments not matching
7176 });
7177
7178 runScript({
7179 .code = R"NKSP_CODE(
7180 on init
7181 declare ~foo := min(-3.92, 9)
7182 exit(~foo)
7183 end on
7184 )NKSP_CODE",
7185 .expectRealExitResult = -3.92,
7186 .expectParseWarning = true // min() warns if data types of arguments not matching
7187 });
7188
7189 // std unit tests ...
7190
7191 runScript({
7192 .code = R"NKSP_CODE(
7193 on init
7194 declare $foo := min(30ms,4s)
7195 exit($foo)
7196 end on
7197 )NKSP_CODE",
7198 .expectIntExitResult = 30,
7199 .expectExitResultUnitPrefix = { VM_MILLI },
7200 .expectExitResultUnit = VM_SECOND,
7201 });
7202
7203 runScript({
7204 .code = R"NKSP_CODE(
7205 on init
7206 declare $foo := min(4s,30ms)
7207 exit($foo)
7208 end on
7209 )NKSP_CODE",
7210 .expectIntExitResult = 30,
7211 .expectExitResultUnitPrefix = { VM_MILLI },
7212 .expectExitResultUnit = VM_SECOND,
7213 });
7214
7215 runScript({
7216 .code = R"NKSP_CODE(
7217 on init
7218 declare $foo := min(-30mdB,-4dB)
7219 exit($foo)
7220 end on
7221 )NKSP_CODE",
7222 .expectIntExitResult = -4,
7223 .expectExitResultUnitPrefix = { VM_DECI },
7224 .expectExitResultUnit = VM_BEL,
7225 });
7226
7227 runScript({
7228 .code = R"NKSP_CODE(
7229 on init
7230 declare $foo := min(-4dB,-30mdB)
7231 exit($foo)
7232 end on
7233 )NKSP_CODE",
7234 .expectIntExitResult = -4,
7235 .expectExitResultUnitPrefix = { VM_DECI },
7236 .expectExitResultUnit = VM_BEL,
7237 });
7238
7239 runScript({
7240 .code = R"NKSP_CODE(
7241 on init
7242 declare $foo := min(-4s,-30Hz)
7243 exit($foo)
7244 end on
7245 )NKSP_CODE",
7246 .expectParseError = true // min() requires arguments to have same unit type
7247 });
7248
7249 runScript({
7250 .code = R"NKSP_CODE(
7251 on init
7252 declare $foo := min(-4s,-30)
7253 exit($foo)
7254 end on
7255 )NKSP_CODE",
7256 .expectParseError = true // min() requires arguments to have same unit type
7257 });
7258
7259 runScript({
7260 .code = R"NKSP_CODE(
7261 on init
7262 declare $foo := min(-4,-30s)
7263 exit($foo)
7264 end on
7265 )NKSP_CODE",
7266 .expectParseError = true // min() requires arguments to have same unit type
7267 });
7268
7269 runScript({
7270 .code = R"NKSP_CODE(
7271 on init
7272 declare ~foo := min(0.9s,1.0s)
7273 exit(~foo)
7274 end on
7275 )NKSP_CODE",
7276 .expectRealExitResult = 0.9,
7277 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
7278 .expectExitResultUnit = VM_SECOND,
7279 });
7280
7281 // 'final' ('!') operator tests ...
7282
7283 runScript({
7284 .code = R"NKSP_CODE(
7285 on init
7286 declare $foo := min(!30,!4)
7287 exit($foo)
7288 end on
7289 )NKSP_CODE",
7290 .expectIntExitResult = 4,
7291 .expectExitResultFinal = true
7292 });
7293
7294 runScript({
7295 .code = R"NKSP_CODE(
7296 on init
7297 declare $foo := min(30,4)
7298 exit($foo)
7299 end on
7300 )NKSP_CODE",
7301 .expectIntExitResult = 4,
7302 .expectExitResultFinal = false
7303 });
7304
7305 runScript({
7306 .code = R"NKSP_CODE(
7307 on init
7308 declare $foo := min(30,!4)
7309 exit($foo)
7310 end on
7311 )NKSP_CODE",
7312 .expectIntExitResult = 4,
7313 .expectExitResultFinal = true,
7314 .expectParseWarning = true // min() warns if only one argument is 'final'
7315 });
7316
7317 runScript({
7318 .code = R"NKSP_CODE(
7319 on init
7320 declare $foo := min(!30,4)
7321 exit($foo)
7322 end on
7323 )NKSP_CODE",
7324 .expectIntExitResult = 4,
7325 .expectExitResultFinal = true,
7326 .expectParseWarning = true // min() warns if only one argument is 'final'
7327 });
7328
7329 runScript({
7330 .code = R"NKSP_CODE(
7331 on init
7332 declare ~foo := min(!12.1,!12.2)
7333 exit(~foo)
7334 end on
7335 )NKSP_CODE",
7336 .expectRealExitResult = 12.1,
7337 .expectExitResultFinal = true
7338 });
7339
7340 runScript({
7341 .code = R"NKSP_CODE(
7342 on init
7343 declare ~foo := min(12.1,12.2)
7344 exit(~foo)
7345 end on
7346 )NKSP_CODE",
7347 .expectRealExitResult = 12.1,
7348 .expectExitResultFinal = false
7349 });
7350
7351 runScript({
7352 .code = R"NKSP_CODE(
7353 on init
7354 declare ~foo := min(!12.1,12.2)
7355 exit(~foo)
7356 end on
7357 )NKSP_CODE",
7358 .expectRealExitResult = 12.1,
7359 .expectExitResultFinal = true,
7360 .expectParseWarning = true // min() warns if only one argument is 'final'
7361 });
7362
7363 runScript({
7364 .code = R"NKSP_CODE(
7365 on init
7366 declare ~foo := min(12.1,!12.2)
7367 exit(~foo)
7368 end on
7369 )NKSP_CODE",
7370 .expectRealExitResult = 12.1,
7371 .expectExitResultFinal = true,
7372 .expectParseWarning = true // min() warns if only one argument is 'final'
7373 });
7374
7375 #if !SILENT_TEST
7376 std::cout << std::endl;
7377 #endif
7378 }
7379
7380 static void testBuiltInMaxFunction() {
7381 #if !SILENT_TEST
7382 std::cout << "UNIT TEST: built-in max() function\n";
7383 #endif
7384
7385 // integer tests ...
7386
7387 runScript({
7388 .code = R"NKSP_CODE(
7389 on init
7390 declare $foo := max
7391 end on
7392 )NKSP_CODE",
7393 .expectParseError = true // because max() function requires 2 arguments
7394 });
7395
7396 runScript({
7397 .code = R"NKSP_CODE(
7398 on init
7399 declare $foo := max()
7400 end on
7401 )NKSP_CODE",
7402 .expectParseError = true // because max() function requires 2 arguments
7403 });
7404
7405 runScript({
7406 .code = R"NKSP_CODE(
7407 on init
7408 declare $foo := max(1)
7409 end on
7410 )NKSP_CODE",
7411 .expectParseError = true // because max() function requires 2 arguments
7412 });
7413
7414 runScript({
7415 .code = R"NKSP_CODE(
7416 on init
7417 declare $foo := max(1,2)
7418 exit($foo)
7419 end on
7420 )NKSP_CODE",
7421 .expectIntExitResult = 2
7422 });
7423
7424 runScript({
7425 .code = R"NKSP_CODE(
7426 on init
7427 declare $foo := max(-30,4)
7428 exit($foo)
7429 end on
7430 )NKSP_CODE",
7431 .expectIntExitResult = 4
7432 });
7433
7434 // real number tests ...
7435
7436 runScript({
7437 .code = R"NKSP_CODE(
7438 on init
7439 declare ~foo := max(1.0, 2.0)
7440 exit(~foo)
7441 end on
7442 )NKSP_CODE",
7443 .expectRealExitResult = 2.0
7444 });
7445
7446 runScript({
7447 .code = R"NKSP_CODE(
7448 on init
7449 declare ~foo := max(-30.0, 4.0)
7450 exit(~foo)
7451 end on
7452 )NKSP_CODE",
7453 .expectRealExitResult = 4.0
7454 });
7455
7456 runScript({
7457 .code = R"NKSP_CODE(
7458 on init
7459 declare ~foo := max(1.1, 1.13)
7460 exit(~foo)
7461 end on
7462 )NKSP_CODE",
7463 .expectRealExitResult = 1.13
7464 });
7465
7466 runScript({
7467 .code = R"NKSP_CODE(
7468 on init
7469 declare ~foo := max(1.13, 1.1)
7470 exit(~foo)
7471 end on
7472 )NKSP_CODE",
7473 .expectRealExitResult = 1.13
7474 });
7475
7476 // mixed type tests ...
7477
7478 runScript({
7479 .code = R"NKSP_CODE(
7480 on init
7481 declare ~foo := max(1, 1.16)
7482 exit(~foo)
7483 end on
7484 )NKSP_CODE",
7485 .expectRealExitResult = 1.16,
7486 .expectParseWarning = true // max() warns if data types of arguments not matching
7487 });
7488
7489 runScript({
7490 .code = R"NKSP_CODE(
7491 on init
7492 declare ~foo := max(-3.92, 9)
7493 exit(~foo)
7494 end on
7495 )NKSP_CODE",
7496 .expectRealExitResult = 9.0,
7497 .expectParseWarning = true // max() warns if data types of arguments not matching
7498 });
7499
7500 // std unit tests ...
7501
7502 runScript({
7503 .code = R"NKSP_CODE(
7504 on init
7505 declare $foo := max(30ms,4s)
7506 exit($foo)
7507 end on
7508 )NKSP_CODE",
7509 .expectIntExitResult = 4,
7510 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
7511 .expectExitResultUnit = VM_SECOND,
7512 });
7513
7514 runScript({
7515 .code = R"NKSP_CODE(
7516 on init
7517 declare $foo := max(4s,30ms)
7518 exit($foo)
7519 end on
7520 )NKSP_CODE",
7521 .expectIntExitResult = 4,
7522 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
7523 .expectExitResultUnit = VM_SECOND,
7524 });
7525
7526 runScript({
7527 .code = R"NKSP_CODE(
7528 on init
7529 declare $foo := max(-30mdB,-4dB)
7530 exit($foo)
7531 end on
7532 )NKSP_CODE",
7533 .expectIntExitResult = -30,
7534 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7535 .expectExitResultUnit = VM_BEL,
7536 });
7537
7538 runScript({
7539 .code = R"NKSP_CODE(
7540 on init
7541 declare $foo := max(-4dB,-30mdB)
7542 exit($foo)
7543 end on
7544 )NKSP_CODE",
7545 .expectIntExitResult = -30,
7546 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7547 .expectExitResultUnit = VM_BEL,
7548 });
7549
7550 runScript({
7551 .code = R"NKSP_CODE(
7552 on init
7553 declare $foo := max(-4s,-30Hz)
7554 exit($foo)
7555 end on
7556 )NKSP_CODE",
7557 .expectParseError = true // max() requires arguments to have same unit type
7558 });
7559
7560 runScript({
7561 .code = R"NKSP_CODE(
7562 on init
7563 declare $foo := max(-4s,-30)
7564 exit($foo)
7565 end on
7566 )NKSP_CODE",
7567 .expectParseError = true // max() requires arguments to have same unit type
7568 });
7569
7570 runScript({
7571 .code = R"NKSP_CODE(
7572 on init
7573 declare $foo := max(-4,-30s)
7574 exit($foo)
7575 end on
7576 )NKSP_CODE",
7577 .expectParseError = true // max() requires arguments to have same unit type
7578 });
7579
7580 runScript({
7581 .code = R"NKSP_CODE(
7582 on init
7583 declare ~foo := max(0.9s,1.0s)
7584 exit(~foo)
7585 end on
7586 )NKSP_CODE",
7587 .expectRealExitResult = 1.0,
7588 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
7589 .expectExitResultUnit = VM_SECOND,
7590 });
7591
7592 // 'final' ('!') operator tests ...
7593
7594 runScript({
7595 .code = R"NKSP_CODE(
7596 on init
7597 declare $foo := max(!30,!4)
7598 exit($foo)
7599 end on
7600 )NKSP_CODE",
7601 .expectIntExitResult = 30,
7602 .expectExitResultFinal = true
7603 });
7604
7605 runScript({
7606 .code = R"NKSP_CODE(
7607 on init
7608 declare $foo := max(30,4)
7609 exit($foo)
7610 end on
7611 )NKSP_CODE",
7612 .expectIntExitResult = 30,
7613 .expectExitResultFinal = false
7614 });
7615
7616 runScript({
7617 .code = R"NKSP_CODE(
7618 on init
7619 declare $foo := max(30,!4)
7620 exit($foo)
7621 end on
7622 )NKSP_CODE",
7623 .expectIntExitResult = 30,
7624 .expectExitResultFinal = true,
7625 .expectParseWarning = true // max() warns if only one argument is 'final'
7626 });
7627
7628 runScript({
7629 .code = R"NKSP_CODE(
7630 on init
7631 declare $foo := max(!30,4)
7632 exit($foo)
7633 end on
7634 )NKSP_CODE",
7635 .expectIntExitResult = 30,
7636 .expectExitResultFinal = true,
7637 .expectParseWarning = true // max() warns if only one argument is 'final'
7638 });
7639
7640 runScript({
7641 .code = R"NKSP_CODE(
7642 on init
7643 declare ~foo := max(!12.1,!12.2)
7644 exit(~foo)
7645 end on
7646 )NKSP_CODE",
7647 .expectRealExitResult = 12.2,
7648 .expectExitResultFinal = true
7649 });
7650
7651 runScript({
7652 .code = R"NKSP_CODE(
7653 on init
7654 declare ~foo := max(12.1,12.2)
7655 exit(~foo)
7656 end on
7657 )NKSP_CODE",
7658 .expectRealExitResult = 12.2,
7659 .expectExitResultFinal = false
7660 });
7661
7662 runScript({
7663 .code = R"NKSP_CODE(
7664 on init
7665 declare ~foo := max(!12.1,12.2)
7666 exit(~foo)
7667 end on
7668 )NKSP_CODE",
7669 .expectRealExitResult = 12.2,
7670 .expectExitResultFinal = true,
7671 .expectParseWarning = true // max() warns if only one argument is 'final'
7672 });
7673
7674 runScript({
7675 .code = R"NKSP_CODE(
7676 on init
7677 declare ~foo := max(12.1,!12.2)
7678 exit(~foo)
7679 end on
7680 )NKSP_CODE",
7681 .expectRealExitResult = 12.2,
7682 .expectExitResultFinal = true,
7683 .expectParseWarning = true // max() warns if only one argument is 'final'
7684 });
7685
7686 #if !SILENT_TEST
7687 std::cout << std::endl;
7688 #endif
7689 }
7690
7691 static void testBuiltInAbsFunction() {
7692 #if !SILENT_TEST
7693 std::cout << "UNIT TEST: built-in abs() function\n";
7694 #endif
7695
7696 runScript({
7697 .code = R"NKSP_CODE(
7698 on init
7699 declare $foo := abs
7700 end on
7701 )NKSP_CODE",
7702 .expectParseError = true // because abs() function requires 1 argument
7703 });
7704
7705 runScript({
7706 .code = R"NKSP_CODE(
7707 on init
7708 declare $foo := abs()
7709 end on
7710 )NKSP_CODE",
7711 .expectParseError = true // because abs() function requires 1 argument
7712 });
7713
7714 // integer tests ...
7715
7716 runScript({
7717 .code = R"NKSP_CODE(
7718 on init
7719 declare $foo := abs(23)
7720 exit($foo)
7721 end on
7722 )NKSP_CODE",
7723 .expectIntExitResult = 23
7724 });
7725
7726 runScript({
7727 .code = R"NKSP_CODE(
7728 on init
7729 declare $foo := abs(-23)
7730 exit($foo)
7731 end on
7732 )NKSP_CODE",
7733 .expectIntExitResult = 23
7734 });
7735
7736 // real number tests ...
7737
7738 runScript({
7739 .code = R"NKSP_CODE(
7740 on init
7741 declare ~foo := abs(23.0)
7742 exit(~foo)
7743 end on
7744 )NKSP_CODE",
7745 .expectRealExitResult = 23.0
7746 });
7747
7748 runScript({
7749 .code = R"NKSP_CODE(
7750 on init
7751 declare ~foo := abs(23.11)
7752 exit(~foo)
7753 end on
7754 )NKSP_CODE",
7755 .expectRealExitResult = 23.11
7756 });
7757
7758 runScript({
7759 .code = R"NKSP_CODE(
7760 on init
7761 declare ~foo := abs(-23.11)
7762 exit(~foo)
7763 end on
7764 )NKSP_CODE",
7765 .expectRealExitResult = 23.11
7766 });
7767
7768 runScript({
7769 .code = R"NKSP_CODE(
7770 on init
7771 declare ~bar := -23.11
7772 declare ~foo := abs(~bar)
7773 exit(~foo)
7774 end on
7775 )NKSP_CODE",
7776 .expectRealExitResult = 23.11
7777 });
7778
7779 // std unit tests ...
7780
7781 runScript({
7782 .code = R"NKSP_CODE(
7783 on init
7784 declare $foo := abs(-23kHz)
7785 exit($foo)
7786 end on
7787 )NKSP_CODE",
7788 .expectIntExitResult = 23,
7789 .expectExitResultUnitPrefix = { VM_KILO },
7790 .expectExitResultUnit = VM_HERTZ
7791 });
7792
7793 runScript({
7794 .code = R"NKSP_CODE(
7795 on init
7796 declare ~foo := abs(-23.4kHz)
7797 exit(~foo)
7798 end on
7799 )NKSP_CODE",
7800 .expectRealExitResult = 23.4,
7801 .expectExitResultUnitPrefix = { VM_KILO },
7802 .expectExitResultUnit = VM_HERTZ
7803 });
7804
7805 // 'final' ('!') operator tests ...
7806
7807 runScript({
7808 .code = R"NKSP_CODE(
7809 on init
7810 declare $foo := abs(!-23)
7811 exit($foo)
7812 end on
7813 )NKSP_CODE",
7814 .expectIntExitResult = 23,
7815 .expectExitResultFinal = true
7816 });
7817
7818 runScript({
7819 .code = R"NKSP_CODE(
7820 on init
7821 declare $foo := abs(-23)
7822 exit($foo)
7823 end on
7824 )NKSP_CODE",
7825 .expectIntExitResult = 23,
7826 .expectExitResultFinal = false
7827 });
7828
7829 runScript({
7830 .code = R"NKSP_CODE(
7831 on init
7832 declare ~foo := abs(!-23.2)
7833 exit(~foo)
7834 end on
7835 )NKSP_CODE",
7836 .expectRealExitResult = 23.2,
7837 .expectExitResultFinal = true
7838 });
7839
7840 runScript({
7841 .code = R"NKSP_CODE(
7842 on init
7843 declare ~foo := abs(-23.9)
7844 exit(~foo)
7845 end on
7846 )NKSP_CODE",
7847 .expectRealExitResult = 23.9,
7848 .expectExitResultFinal = false
7849 });
7850
7851 #if !SILENT_TEST
7852 std::cout << std::endl;
7853 #endif
7854 }
7855
7856 static void testBuiltInIncFunction() {
7857 #if !SILENT_TEST
7858 std::cout << "UNIT TEST: built-in inc() function\n";
7859 #endif
7860
7861 // integer tests ...
7862
7863 runScript({
7864 .code = R"NKSP_CODE(
7865 on init
7866 declare $foo := 5
7867 inc($foo)
7868 exit($foo)
7869 end on
7870 )NKSP_CODE",
7871 .expectIntExitResult = 6
7872 });
7873
7874 runScript({
7875 .code = R"NKSP_CODE(
7876 on init
7877 declare $foo := 5
7878 inc($foo)
7879 inc($foo)
7880 inc($foo)
7881 exit($foo)
7882 end on
7883 )NKSP_CODE",
7884 .expectIntExitResult = 8
7885 });
7886
7887 runScript({
7888 .code = R"NKSP_CODE(
7889 on init
7890 declare $foo := 5
7891 inc($foo)
7892 exit( inc($foo) )
7893 end on
7894 )NKSP_CODE",
7895 .expectIntExitResult = 7
7896 });
7897
7898 // std unit tests ...
7899
7900 runScript({
7901 .code = R"NKSP_CODE(
7902 on init
7903 declare $foo := 53mdB
7904 inc($foo)
7905 exit( inc($foo) )
7906 end on
7907 )NKSP_CODE",
7908 .expectIntExitResult = 55,
7909 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7910 .expectExitResultUnit = VM_BEL,
7911 .expectParseWarning = true // inc() warns if argument has a unit
7912 });
7913
7914 // 'final' ('!') operator tests ...
7915
7916 runScript({
7917 .code = R"NKSP_CODE(
7918 on init
7919 declare $foo := !53
7920 inc($foo)
7921 exit( inc($foo) )
7922 end on
7923 )NKSP_CODE",
7924 .expectIntExitResult = 55,
7925 .expectExitResultFinal = true
7926 });
7927
7928 runScript({
7929 .code = R"NKSP_CODE(
7930 on init
7931 declare $foo := 53
7932 inc($foo)
7933 exit( inc($foo) )
7934 end on
7935 )NKSP_CODE",
7936 .expectIntExitResult = 55,
7937 .expectExitResultFinal = false
7938 });
7939
7940 runScript({
7941 .code = R"NKSP_CODE(
7942 on init
7943 declare $foo := 53
7944 inc($foo)
7945 exit( !inc($foo) )
7946 end on
7947 )NKSP_CODE",
7948 .expectIntExitResult = 55,
7949 .expectExitResultFinal = true
7950 });
7951
7952 #if !SILENT_TEST
7953 std::cout << std::endl;
7954 #endif
7955 }
7956
7957 static void testBuiltInDecFunction() {
7958 #if !SILENT_TEST
7959 std::cout << "UNIT TEST: built-in dec() function\n";
7960 #endif
7961
7962 // integer tests ...
7963
7964 runScript({
7965 .code = R"NKSP_CODE(
7966 on init
7967 declare $foo := 5
7968 dec($foo)
7969 exit($foo)
7970 end on
7971 )NKSP_CODE",
7972 .expectIntExitResult = 4
7973 });
7974
7975 runScript({
7976 .code = R"NKSP_CODE(
7977 on init
7978 declare $foo := 5
7979 dec($foo)
7980 dec($foo)
7981 dec($foo)
7982 exit($foo)
7983 end on
7984 )NKSP_CODE",
7985 .expectIntExitResult = 2
7986 });
7987
7988 runScript({
7989 .code = R"NKSP_CODE(
7990 on init
7991 declare $foo := 5
7992 dec($foo)
7993 exit( dec($foo) )
7994 end on
7995 )NKSP_CODE",
7996 .expectIntExitResult = 3
7997 });
7998
7999 // std unit tests ...
8000
8001 runScript({
8002 .code = R"NKSP_CODE(
8003 on init
8004 declare $foo := 53mdB
8005 dec($foo)
8006 exit( dec($foo) )
8007 end on
8008 )NKSP_CODE",
8009 .expectIntExitResult = 51,
8010 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
8011 .expectExitResultUnit = VM_BEL,
8012 .expectParseWarning = true // dec() warns if argument has a unit
8013 });
8014
8015 // 'final' ('!') operator tests ...
8016
8017 runScript({
8018 .code = R"NKSP_CODE(
8019 on init
8020 declare $foo := !53
8021 dec($foo)
8022 exit( dec($foo) )
8023 end on
8024 )NKSP_CODE",
8025 .expectIntExitResult = 51,
8026 .expectExitResultFinal = true
8027 });
8028
8029 runScript({
8030 .code = R"NKSP_CODE(
8031 on init
8032 declare $foo := 53
8033 dec($foo)
8034 exit( dec($foo) )
8035 end on
8036 )NKSP_CODE",
8037 .expectIntExitResult = 51,
8038 .expectExitResultFinal = false
8039 });
8040
8041 runScript({
8042 .code = R"NKSP_CODE(
8043 on init
8044 declare $foo := 53
8045 dec($foo)
8046 exit( !dec($foo) )
8047 end on
8048 )NKSP_CODE",
8049 .expectIntExitResult = 51,
8050 .expectExitResultFinal = true
8051 });
8052
8053 #if !SILENT_TEST
8054 std::cout << std::endl;
8055 #endif
8056 }
8057
8058 static void testBuiltInInRangeFunction() {
8059 #if !SILENT_TEST
8060 std::cout << "UNIT TEST: built-in in_range() function\n";
8061 #endif
8062
8063 // integer tests ...
8064
8065 runScript({
8066 .code = R"NKSP_CODE(
8067 on init
8068 exit( in_range(1,4,9) )
8069 end on
8070 )NKSP_CODE",
8071 .expectBoolExitResult = false
8072 });
8073
8074 runScript({
8075 .code = R"NKSP_CODE(
8076 on init
8077 exit( in_range(5,4,9) )
8078 end on
8079 )NKSP_CODE",
8080 .expectBoolExitResult = true
8081 });
8082
8083 runScript({
8084 .code = R"NKSP_CODE(
8085 on init
8086 exit( in_range(9,4,9) )
8087 end on
8088 )NKSP_CODE",
8089 .expectBoolExitResult = true
8090 });
8091
8092 runScript({
8093 .code = R"NKSP_CODE(
8094 on init
8095 exit( in_range(10,4,9) )
8096 end on
8097 )NKSP_CODE",
8098 .expectBoolExitResult = false
8099 });
8100
8101 runScript({
8102 .code = R"NKSP_CODE(
8103 on init
8104 exit( in_range(-6,-5,5) )
8105 end on
8106 )NKSP_CODE",
8107 .expectBoolExitResult = false
8108 });
8109
8110 runScript({
8111 .code = R"NKSP_CODE(
8112 on init
8113 exit( in_range(-5,-5,5) )
8114 end on
8115 )NKSP_CODE",
8116 .expectBoolExitResult = true
8117 });
8118
8119 runScript({
8120 .code = R"NKSP_CODE(
8121 on init
8122 exit( in_range(0,-5,5) )
8123 end on
8124 )NKSP_CODE",
8125 .expectBoolExitResult = true
8126 });
8127
8128 runScript({
8129 .code = R"NKSP_CODE(
8130 on init
8131 exit( in_range(5,-5,5) )
8132 end on
8133 )NKSP_CODE",
8134 .expectBoolExitResult = true
8135 });
8136
8137 runScript({
8138 .code = R"NKSP_CODE(
8139 on init
8140 exit( in_range(6,-5,5) )
8141 end on
8142 )NKSP_CODE",
8143 .expectBoolExitResult = false
8144 });
8145
8146 // real number tests ...
8147
8148 runScript({
8149 .code = R"NKSP_CODE(
8150 on init
8151 exit( in_range(12.2,12.1,12.9) )
8152 end on
8153 )NKSP_CODE",
8154 .expectBoolExitResult = true
8155 });
8156
8157 runScript({
8158 .code = R"NKSP_CODE(
8159 on init
8160 exit( in_range(12.2,12.9,12.1) )
8161 end on
8162 )NKSP_CODE",
8163 .expectBoolExitResult = true
8164 });
8165
8166 runScript({
8167 .code = R"NKSP_CODE(
8168 on init
8169 exit( in_range(12.0,12.1,12.9) )
8170 end on
8171 )NKSP_CODE",
8172 .expectBoolExitResult = false
8173 });
8174
8175 runScript({
8176 .code = R"NKSP_CODE(
8177 on init
8178 exit( in_range(12.0,12.9,12.1) )
8179 end on
8180 )NKSP_CODE",
8181 .expectBoolExitResult = false
8182 });
8183
8184 runScript({
8185 .code = R"NKSP_CODE(
8186 on init
8187 exit( in_range(0.0,-0.3,0.3) )
8188 end on
8189 )NKSP_CODE",
8190 .expectBoolExitResult = true
8191 });
8192
8193 runScript({
8194 .code = R"NKSP_CODE(
8195 on init
8196 exit( in_range(-0.34,-0.3,0.3) )
8197 end on
8198 )NKSP_CODE",
8199 .expectBoolExitResult = false
8200 });
8201
8202 runScript({
8203 .code = R"NKSP_CODE(
8204 on init
8205 exit( in_range(0.34,-0.3,0.3) )
8206 end on
8207 )NKSP_CODE",
8208 .expectBoolExitResult = false
8209 });
8210
8211 runScript({
8212 .code = R"NKSP_CODE(
8213 on init
8214 exit( in_range(-0.3,-0.3,0.3) )
8215 end on
8216 )NKSP_CODE",
8217 .expectBoolExitResult = true
8218 });
8219
8220 runScript({
8221 .code = R"NKSP_CODE(
8222 on init
8223 exit( in_range(0.3,-0.3,0.3) )
8224 end on
8225 )NKSP_CODE",
8226 .expectBoolExitResult = true
8227 });
8228
8229 // mixed type tests ...
8230
8231 runScript({
8232 .code = R"NKSP_CODE(
8233 on init
8234 exit( in_range(4.0,-5,5) )
8235 end on
8236 )NKSP_CODE",
8237 .expectBoolExitResult = true,
8238 .expectParseWarning = true // in_range() warns if not all arguments are of same type
8239 });
8240
8241 runScript({
8242 .code = R"NKSP_CODE(
8243 on init
8244 exit( in_range(5,-5,5.0) )
8245 end on
8246 )NKSP_CODE",
8247 .expectBoolExitResult = true,
8248 .expectParseWarning = true // in_range() warns if not all arguments are of same type
8249 });
8250
8251 runScript({
8252 .code = R"NKSP_CODE(
8253 on init
8254 exit( in_range(-5,-5.0,5) )
8255 end on
8256 )NKSP_CODE",
8257 .expectBoolExitResult = true,
8258 .expectParseWarning = true // in_range() warns if not all arguments are of same type
8259 });
8260
8261 // std unit tests ...
8262
8263 runScript({
8264 .code = R"NKSP_CODE(
8265 on init
8266 exit( in_range(4000Hz,3kHz,5kHz) )
8267 end on
8268 )NKSP_CODE",
8269 .expectBoolExitResult = true,
8270 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8271 .expectExitResultUnit = VM_NO_UNIT
8272 });
8273
8274 runScript({
8275 .code = R"NKSP_CODE(
8276 on init
8277 exit( in_range(5000Hz,3kHz,5kHz) )
8278 end on
8279 )NKSP_CODE",
8280 .expectBoolExitResult = true,
8281 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8282 .expectExitResultUnit = VM_NO_UNIT
8283 });
8284
8285 runScript({
8286 .code = R"NKSP_CODE(
8287 on init
8288 exit( in_range(5001Hz,3kHz,5kHz) )
8289 end on
8290 )NKSP_CODE",
8291 .expectBoolExitResult = false,
8292 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8293 .expectExitResultUnit = VM_NO_UNIT
8294 });
8295
8296 runScript({
8297 .code = R"NKSP_CODE(
8298 on init
8299 exit( in_range(3000Hz,3kHz,5kHz) )
8300 end on
8301 )NKSP_CODE",
8302 .expectBoolExitResult = true,
8303 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8304 .expectExitResultUnit = VM_NO_UNIT
8305 });
8306
8307 runScript({
8308 .code = R"NKSP_CODE(
8309 on init
8310 exit( in_range(2999Hz,3kHz,5kHz) )
8311 end on
8312 )NKSP_CODE",
8313 .expectBoolExitResult = false,
8314 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8315 .expectExitResultUnit = VM_NO_UNIT
8316 });
8317
8318 runScript({
8319 .code = R"NKSP_CODE(
8320 on init
8321 exit( in_range(0.003s,3000.0us,5ms) )
8322 end on
8323 )NKSP_CODE",
8324 .expectBoolExitResult = true,
8325 .expectParseWarning = true, // in_range() warns if not all arguments are of same type
8326 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8327 .expectExitResultUnit = VM_NO_UNIT
8328 });
8329
8330 runScript({
8331 .code = R"NKSP_CODE(
8332 on init
8333 exit( in_range(0.005s,3000.0us,5ms) )
8334 end on
8335 )NKSP_CODE",
8336 .expectBoolExitResult = true,
8337 .expectParseWarning = true, // in_range() warns if not all arguments are of same type,
8338 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8339 .expectExitResultUnit = VM_NO_UNIT
8340 });
8341
8342 runScript({
8343 .code = R"NKSP_CODE(
8344 on init
8345 exit( in_range(0.0051s,3000.0us,5ms) )
8346 end on
8347 )NKSP_CODE",
8348 .expectBoolExitResult = false,
8349 .expectParseWarning = true, // in_range() warns if not all arguments are of same type
8350 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8351 .expectExitResultUnit = VM_NO_UNIT
8352 });
8353
8354 runScript({
8355 .code = R"NKSP_CODE(
8356 on init
8357 exit( in_range(3s,2Hz,5Hz) )
8358 end on
8359 )NKSP_CODE",
8360 .expectParseError = true // in_range() throws error if not all arguments' unit types equal,
8361 });
8362
8363 runScript({
8364 .code = R"NKSP_CODE(
8365 on init
8366 exit( in_range(3Hz,2s,5Hz) )
8367 end on
8368 )NKSP_CODE",
8369 .expectParseError = true // in_range() throws error if not all arguments' unit types equal
8370 });
8371
8372 runScript({
8373 .code = R"NKSP_CODE(
8374 on init
8375 exit( in_range(3Hz,2Hz,5s) )
8376 end on
8377 )NKSP_CODE",
8378 .expectParseError = true // in_range() throws error if not all arguments' unit types equal
8379 });
8380
8381 // 'final' ('!') operator tests ...
8382 // (result should always be NOT final)
8383
8384 runScript({
8385 .code = R"NKSP_CODE(
8386 on init
8387 exit( in_range(!9,!4,!9) )
8388 end on
8389 )NKSP_CODE",
8390 .expectBoolExitResult = true,
8391 .expectExitResultFinal = false
8392 });
8393
8394 #if !SILENT_TEST
8395 std::cout << std::endl;
8396 #endif
8397 }
8398
8399 static void testBuiltInRandomFunction() {
8400 #if !SILENT_TEST
8401 std::cout << "UNIT TEST: built-in random() function\n";
8402 #endif
8403
8404 // integer tests ...
8405
8406 runScript({
8407 .code = R"NKSP_CODE(
8408 on init
8409 exit( random(-5,5) )
8410 end on
8411 )NKSP_CODE",
8412 .expectExitResultIsInt = true // only check type, exact value is irrelevant here
8413 });
8414
8415 for (int run = 0; run < 20; ++run) {
8416 runScript({
8417 .code = R"NKSP_CODE(
8418 on init
8419 declare $foo := random(-5,5)
8420 exit( in_range($foo,-5,5) )
8421 end on
8422 )NKSP_CODE",
8423 .expectBoolExitResult = true
8424 });
8425 }
8426
8427 // real number tests ...
8428
8429 runScript({
8430 .code = R"NKSP_CODE(
8431 on init
8432 exit( random(-0.5,0.5) )
8433 end on
8434 )NKSP_CODE",
8435 .expectExitResultIsReal = true // only check type, exact value is irrelevant here
8436 });
8437
8438 runScript({
8439 .code = R"NKSP_CODE(
8440 on init
8441 declare ~foo := random(-5.0,5.0)
8442 exit(~foo)
8443 end on
8444 )NKSP_CODE",
8445 .expectExitResultIsReal = true // only check type, exact value is irrelevant here
8446 });
8447
8448 for (int run = 0; run < 20; ++run) {
8449 runScript({
8450 .code = R"NKSP_CODE(
8451 on init
8452 declare ~foo := random(-0.5,0.5)
8453 exit( in_range(~foo,-0.5,0.5) )
8454 end on
8455 )NKSP_CODE",
8456 .expectBoolExitResult = true
8457 });
8458 }
8459
8460 for (int run = 0; run < 20; ++run) {
8461 runScript({
8462 .code = R"NKSP_CODE(
8463 on init
8464 declare ~foo := random(-5.0,12.0)
8465 exit( in_range(~foo,-5.0,12.0) )
8466 end on
8467 )NKSP_CODE",
8468 .expectBoolExitResult = true
8469 });
8470 }
8471
8472 for (int run = 0; run < 20; ++run) {
8473 runScript({
8474 .code = R"NKSP_CODE(
8475 on init
8476 declare ~foo := random(23.3,98.4)
8477 exit( in_range(~foo,23.3,98.4) )
8478 end on
8479 )NKSP_CODE",
8480 .expectBoolExitResult = true
8481 });
8482 }
8483
8484 // std unit tests ...
8485
8486 runScript({
8487 .code = R"NKSP_CODE(
8488 on init
8489 exit( random(-5Hz,5Hz) )
8490 end on
8491 )NKSP_CODE",
8492 .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
8493 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8494 .expectExitResultUnit = VM_HERTZ
8495 });
8496
8497 for (int run = 0; run < 20; ++run) {
8498 runScript({
8499 .code = R"NKSP_CODE(
8500 on init
8501 declare $foo := random(-5Hz,5Hz)
8502 exit( in_range($foo,-5Hz,5Hz) )
8503 end on
8504 )NKSP_CODE",
8505 .expectBoolExitResult = true
8506 });
8507 }
8508
8509 runScript({
8510 .code = R"NKSP_CODE(
8511 on init
8512 exit( random(5us,1ms) )
8513 end on
8514 )NKSP_CODE",
8515 .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
8516 .expectExitResultUnitPrefix = { VM_MICRO },
8517 .expectExitResultUnit = VM_SECOND
8518 });
8519
8520 for (int run = 0; run < 20; ++run) {
8521 runScript({
8522 .code = R"NKSP_CODE(
8523 on init
8524 declare $foo := random(5us,1ms)
8525 exit( in_range($foo,5us,1ms) )
8526 end on
8527 )NKSP_CODE",
8528 .expectBoolExitResult = true
8529 });
8530 }
8531
8532 runScript({
8533 .code = R"NKSP_CODE(
8534 on init
8535 exit( random(1ms,5000us) )
8536 end on
8537 )NKSP_CODE",
8538 .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
8539 .expectExitResultUnitPrefix = { VM_MICRO },
8540 .expectExitResultUnit = VM_SECOND
8541 });
8542
8543 for (int run = 0; run < 20; ++run) {
8544 runScript({
8545 .code = R"NKSP_CODE(
8546 on init
8547 declare $foo := random(1ms,5000us)
8548 exit( in_range($foo,1ms,5000us) )
8549 end on
8550 )NKSP_CODE",
8551 .expectBoolExitResult = true
8552 });
8553 }
8554
8555 runScript({
8556 .code = R"NKSP_CODE(
8557 on init
8558 exit( random(1kHz,20kHz) )
8559 end on
8560 )NKSP_CODE",
8561 .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
8562 .expectExitResultUnitPrefix = { VM_KILO },
8563 .expectExitResultUnit = VM_HERTZ
8564 });
8565
8566 for (int run = 0; run < 20; ++run) {
8567 runScript({
8568 .code = R"NKSP_CODE(
8569 on init
8570 declare $foo := random(1kHz,20kHz)
8571 exit( in_range($foo,1kHz,20kHz) )
8572 end on
8573 )NKSP_CODE",
8574 .expectBoolExitResult = true
8575 });
8576 }
8577
8578 runScript({
8579 .code = R"NKSP_CODE(
8580 on init
8581 exit( random(1.2us,3.5us) )
8582 end on
8583 )NKSP_CODE",
8584 .expectExitResultIsReal = true, // only check type, exact value is irrelevant here
8585 .expectExitResultUnitPrefix = { VM_MICRO },
8586 .expectExitResultUnit = VM_SECOND
8587 });
8588
8589 for (int run = 0; run < 20; ++run) {
8590 runScript({
8591 .code = R"NKSP_CODE(
8592 on init
8593 declare ~foo := random(1.2us,3.5us)
8594 exit( in_range(~foo,1.2us,3.5us) )
8595 end on
8596 )NKSP_CODE",
8597 .expectBoolExitResult = true
8598 });
8599 }
8600
8601 runScript({
8602 .code = R"NKSP_CODE(
8603 on init
8604 exit( random(5.2us,1.1ms) )
8605 end on
8606 )NKSP_CODE",
8607 .expectExitResultIsReal = true, // only check type, exact value is irrelevant here
8608 .expectExitResultUnitPrefix = { VM_MICRO },
8609 .expectExitResultUnit = VM_SECOND
8610 });
8611
8612 for (int run = 0; run < 20; ++run) {
8613 runScript({
8614 .code = R"NKSP_CODE(
8615 on init
8616 declare ~foo := random(5.2us,1.1ms)
8617 exit( in_range(~foo,5.2us,1.1ms) )
8618 end on
8619 )NKSP_CODE",
8620 .expectBoolExitResult = true
8621 });
8622 }
8623
8624 runScript({
8625 .code = R"NKSP_CODE(
8626 on init
8627 exit( random(1Hz,12s) )
8628 end on
8629 )NKSP_CODE",
8630 .expectParseError = true // random() throws error if arguments' unit types don't match
8631 });
8632
8633 runScript({
8634 .code = R"NKSP_CODE(
8635 on init
8636 exit( random(1,12s) )
8637 end on
8638 )NKSP_CODE",
8639 .expectParseError = true // random() throws error if arguments' unit types don't match
8640 });
8641
8642 runScript({
8643 .code = R"NKSP_CODE(
8644 on init
8645 exit( random(1s,12) )
8646 end on
8647 )NKSP_CODE",
8648 .expectParseError = true // random() throws error if arguments' unit types don't match
8649 });
8650
8651 // 'final' ('!') operator tests ...
8652
8653 runScript({
8654 .code = R"NKSP_CODE(
8655 on init
8656 exit( random(!1,!12) )
8657 end on
8658 )NKSP_CODE",
8659 .expectExitResultFinal = true
8660 });
8661
8662 runScript({
8663 .code = R"NKSP_CODE(
8664 on init
8665 exit( random(1,12) )
8666 end on
8667 )NKSP_CODE",
8668 .expectExitResultFinal = false
8669 });
8670
8671 runScript({
8672 .code = R"NKSP_CODE(
8673 on init
8674 exit( random(!1,12) )
8675 end on
8676 )NKSP_CODE",
8677 .expectExitResultFinal = true,
8678 .expectParseWarning = true // random() warns if only one argument is 'final'
8679 });
8680
8681 runScript({
8682 .code = R"NKSP_CODE(
8683 on init
8684 exit( random(1,!12) )
8685 end on
8686 )NKSP_CODE",
8687 .expectExitResultFinal = true,
8688 .expectParseWarning = true // random() warns if only one argument is 'final'
8689 });
8690
8691 #if !SILENT_TEST
8692 std::cout << std::endl;
8693 #endif
8694 }
8695
8696 static void testBuiltInShiftLeftFunction() {
8697 #if !SILENT_TEST
8698 std::cout << "UNIT TEST: built-in sh_left() function\n";
8699 #endif
8700
8701 runScript({
8702 .code = R"NKSP_CODE(
8703 on init
8704 exit( sh_left(1,0) )
8705 end on
8706 )NKSP_CODE",
8707 .expectIntExitResult = 1
8708 });
8709
8710 runScript({
8711 .code = R"NKSP_CODE(
8712 on init
8713 exit( sh_left(1,1) )
8714 end on
8715 )NKSP_CODE",
8716 .expectIntExitResult = 2
8717 });
8718
8719 runScript({
8720 .code = R"NKSP_CODE(
8721 on init
8722 exit( sh_left(1,2) )
8723 end on
8724 )NKSP_CODE",
8725 .expectIntExitResult = 4
8726 });
8727
8728 runScript({
8729 .code = R"NKSP_CODE(
8730 on init
8731 exit( sh_left(1,3) )
8732 end on
8733 )NKSP_CODE",
8734 .expectIntExitResult = 8
8735 });
8736
8737 #if !SILENT_TEST
8738 std::cout << std::endl;
8739 #endif
8740 }
8741
8742 static void testBuiltInShiftRightFunction() {
8743 #if !SILENT_TEST
8744 std::cout << "UNIT TEST: built-in sh_right() function\n";
8745 #endif
8746
8747 runScript({
8748 .code = R"NKSP_CODE(
8749 on init
8750 exit( sh_right(8,0) )
8751 end on
8752 )NKSP_CODE",
8753 .expectIntExitResult = 8
8754 });
8755
8756 runScript({
8757 .code = R"NKSP_CODE(
8758 on init
8759 exit( sh_right(8,1) )
8760 end on
8761 )NKSP_CODE",
8762 .expectIntExitResult = 4
8763 });
8764
8765 runScript({
8766 .code = R"NKSP_CODE(
8767 on init
8768 exit( sh_right(8,2) )
8769 end on
8770 )NKSP_CODE",
8771 .expectIntExitResult = 2
8772 });
8773
8774 runScript({
8775 .code = R"NKSP_CODE(
8776 on init
8777 exit( sh_right(8,3) )
8778 end on
8779 )NKSP_CODE",
8780 .expectIntExitResult = 1
8781 });
8782
8783 runScript({
8784 .code = R"NKSP_CODE(
8785 on init
8786 exit( sh_right(8,4) )
8787 end on
8788 )NKSP_CODE",
8789 .expectIntExitResult = 0
8790 });
8791
8792 #if !SILENT_TEST
8793 std::cout << std::endl;
8794 #endif
8795 }
8796
8797 static void testBuiltInMsbFunction() {
8798 #if !SILENT_TEST
8799 std::cout << "UNIT TEST: built-in msb() function\n";
8800 #endif
8801
8802 runScript({
8803 .code = R"NKSP_CODE(
8804 on init
8805 exit( msb(0) )
8806 end on
8807 )NKSP_CODE",
8808 .expectIntExitResult = 0
8809 });
8810
8811 runScript({
8812 .code = R"NKSP_CODE(
8813 on init
8814 exit( msb(127) )
8815 end on
8816 )NKSP_CODE",
8817 .expectIntExitResult = 0
8818 });
8819
8820 runScript({
8821 .code = R"NKSP_CODE(
8822 on init
8823 exit( msb(128) )
8824 end on
8825 )NKSP_CODE",
8826 .expectIntExitResult = 1
8827 });
8828
8829 runScript({
8830 .code = R"NKSP_CODE(
8831 on init
8832 exit( msb(16255) )
8833 end on
8834 )NKSP_CODE",
8835 .expectIntExitResult = 126
8836 });
8837
8838 runScript({
8839 .code = R"NKSP_CODE(
8840 on init
8841 exit( msb(16256) )
8842 end on
8843 )NKSP_CODE",
8844 .expectIntExitResult = 127
8845 });
8846
8847 runScript({
8848 .code = R"NKSP_CODE(
8849 on init
8850 exit( msb(16383) )
8851 end on
8852 )NKSP_CODE",
8853 .expectIntExitResult = 127
8854 });
8855
8856 #if !SILENT_TEST
8857 std::cout << std::endl;
8858 #endif
8859 }
8860
8861 static void testBuiltInLsbFunction() {
8862 #if !SILENT_TEST
8863 std::cout << "UNIT TEST: built-in lsb() function\n";
8864 #endif
8865
8866 runScript({
8867 .code = R"NKSP_CODE(
8868 on init
8869 exit( lsb(0) )
8870 end on
8871 )NKSP_CODE",
8872 .expectIntExitResult = 0
8873 });
8874
8875 runScript({
8876 .code = R"NKSP_CODE(
8877 on init
8878 exit( lsb(1) )
8879 end on
8880 )NKSP_CODE",
8881 .expectIntExitResult = 1
8882 });
8883
8884 runScript({
8885 .code = R"NKSP_CODE(
8886 on init
8887 exit( lsb(126) )
8888 end on
8889 )NKSP_CODE",
8890 .expectIntExitResult = 126
8891 });
8892
8893 runScript({
8894 .code = R"NKSP_CODE(
8895 on init
8896 exit( lsb(127) )
8897 end on
8898 )NKSP_CODE",
8899 .expectIntExitResult = 127
8900 });
8901
8902 runScript({
8903 .code = R"NKSP_CODE(
8904 on init
8905 exit( lsb(128) )
8906 end on
8907 )NKSP_CODE",
8908 .expectIntExitResult = 0
8909 });
8910
8911 runScript({
8912 .code = R"NKSP_CODE(
8913 on init
8914 exit( lsb(16255) )
8915 end on
8916 )NKSP_CODE",
8917 .expectIntExitResult = 127
8918 });
8919
8920 runScript({
8921 .code = R"NKSP_CODE(
8922 on init
8923 exit( lsb(16256) )
8924 end on
8925 )NKSP_CODE",
8926 .expectIntExitResult = 0
8927 });
8928
8929 #if !SILENT_TEST
8930 std::cout << std::endl;
8931 #endif
8932 }
8933
8934 static void testBuiltInIntToRealFunction() {
8935 #if !SILENT_TEST
8936 std::cout << "UNIT TEST: built-in int_to_real() function\n";
8937 #endif
8938
8939 runScript({
8940 .code = R"NKSP_CODE(
8941 on init
8942 exit( int_to_real(8) )
8943 end on
8944 )NKSP_CODE",
8945 .expectRealExitResult = 8.0
8946 });
8947
8948 runScript({
8949 .code = R"NKSP_CODE(
8950 on init
8951 declare $foo := 23
8952 exit( int_to_real($foo) )
8953 end on
8954 )NKSP_CODE",
8955 .expectRealExitResult = 23.0
8956 });
8957
8958 // std unit tests ...
8959
8960 runScript({
8961 .code = R"NKSP_CODE(
8962 on init
8963 exit( int_to_real(-58mdB) )
8964 end on
8965 )NKSP_CODE",
8966 .expectRealExitResult = -58.0,
8967 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
8968 .expectExitResultUnit = VM_BEL
8969 });
8970
8971 runScript({
8972 .code = R"NKSP_CODE(
8973 on init
8974 declare $foo := -58mdB
8975 exit( int_to_real($foo) )
8976 end on
8977 )NKSP_CODE",
8978 .expectRealExitResult = -58.0,
8979 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
8980 .expectExitResultUnit = VM_BEL
8981 });
8982
8983 runScript({
8984 .code = R"NKSP_CODE(
8985 on init
8986 declare $foo := 7000ms
8987 exit( int_to_real($foo) )
8988 end on
8989 )NKSP_CODE",
8990 .expectRealExitResult = 7000.0,
8991 .expectExitResultUnitPrefix = { VM_MILLI },
8992 .expectExitResultUnit = VM_SECOND
8993 });
8994
8995 runScript({
8996 .code = R"NKSP_CODE(
8997 on init
8998 declare $foo := 7000ms
8999 declare @s := "" & int_to_real($foo)
9000 exit( @s )
9001 end on
9002 )NKSP_CODE",
9003 .expectStringExitResult = "7000ms",
9004 });
9005
9006 runScript({
9007 .code = R"NKSP_CODE(
9008 on init
9009 declare $foo := 700ms
9010 exit( int_to_real($foo) / 7.0 )
9011 end on
9012 )NKSP_CODE",
9013 .expectRealExitResult = 100.0,
9014 .expectExitResultUnitPrefix = { VM_MILLI },
9015 .expectExitResultUnit = VM_SECOND
9016 });
9017
9018 runScript({
9019 .code = R"NKSP_CODE(
9020 on init
9021 declare $foo := 700ms
9022 exit( int_to_real($foo) / 7.0 & "" )
9023 end on
9024 )NKSP_CODE",
9025 .expectStringExitResult = "100ms"
9026 });
9027
9028 // 'final' ('!') operator tests ...
9029
9030 runScript({
9031 .code = R"NKSP_CODE(
9032 on init
9033 declare $foo := !-58
9034 exit( int_to_real($foo) )
9035 end on
9036 )NKSP_CODE",
9037 .expectRealExitResult = -58.0,
9038 .expectExitResultFinal = true
9039 });
9040
9041 runScript({
9042 .code = R"NKSP_CODE(
9043 on init
9044 declare $foo := -58
9045 exit( int_to_real($foo) )
9046 end on
9047 )NKSP_CODE",
9048 .expectRealExitResult = -58.0,
9049 .expectExitResultFinal = false
9050 });
9051
9052 #if !SILENT_TEST
9053 std::cout << std::endl;
9054 #endif
9055 }
9056
9057 static void testBuiltInRealFunction() {
9058 #if !SILENT_TEST
9059 std::cout << "UNIT TEST: built-in real() function\n";
9060 #endif
9061
9062 runScript({
9063 .code = R"NKSP_CODE(
9064 on init
9065 exit( real(8) )
9066 end on
9067 )NKSP_CODE",
9068 .expectRealExitResult = 8.0
9069 });
9070
9071 runScript({
9072 .code = R"NKSP_CODE(
9073 on init
9074 declare $foo := 23
9075 exit( real($foo) )
9076 end on
9077 )NKSP_CODE",
9078 .expectRealExitResult = 23.0
9079 });
9080
9081 // std unit tests ...
9082
9083 runScript({
9084 .code = R"NKSP_CODE(
9085 on init
9086 exit( real(-58mdB) )
9087 end on
9088 )NKSP_CODE",
9089 .expectRealExitResult = -58.0,
9090 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
9091 .expectExitResultUnit = VM_BEL
9092 });
9093
9094 runScript({
9095 .code = R"NKSP_CODE(
9096 on init
9097 declare $foo := -58mdB
9098 exit( real($foo) )
9099 end on
9100 )NKSP_CODE",
9101 .expectRealExitResult = -58.0,
9102 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
9103 .expectExitResultUnit = VM_BEL
9104 });
9105
9106 runScript({
9107 .code = R"NKSP_CODE(
9108 on init
9109 declare $foo := 7000ms
9110 exit( real($foo) )
9111 end on
9112 )NKSP_CODE",
9113 .expectRealExitResult = 7000.0,
9114 .expectExitResultUnitPrefix = { VM_MILLI },
9115 .expectExitResultUnit = VM_SECOND
9116 });
9117
9118 runScript({
9119 .code = R"NKSP_CODE(
9120 on init
9121 declare $foo := 7000ms
9122 declare @s := "" & real($foo)
9123 exit( @s )
9124 end on
9125 )NKSP_CODE",
9126 .expectStringExitResult = "7000ms",
9127 });
9128
9129 runScript({
9130 .code = R"NKSP_CODE(
9131 on init
9132 declare $foo := 700ms
9133 exit( real($foo) / 7.0 )
9134 end on
9135 )NKSP_CODE",
9136 .expectRealExitResult = 100.0,
9137 .expectExitResultUnitPrefix = { VM_MILLI },
9138 .expectExitResultUnit = VM_SECOND
9139 });
9140
9141 runScript({
9142 .code = R"NKSP_CODE(
9143 on init
9144 declare $foo := 700ms
9145 exit( real($foo) / 7.0 & "" )
9146 end on
9147 )NKSP_CODE",
9148 .expectStringExitResult = "100ms"
9149 });
9150
9151 // 'final' ('!') operator tests ...
9152
9153 runScript({
9154 .code = R"NKSP_CODE(
9155 on init
9156 declare $foo := !-58
9157 exit( real($foo) )
9158 end on
9159 )NKSP_CODE",
9160 .expectRealExitResult = -58.0,
9161 .expectExitResultFinal = true
9162 });
9163
9164 runScript({
9165 .code = R"NKSP_CODE(
9166 on init
9167 declare $foo := -58
9168 exit( real($foo) )
9169 end on
9170 )NKSP_CODE",
9171 .expectRealExitResult = -58.0,
9172 .expectExitResultFinal = false
9173 });
9174
9175 #if !SILENT_TEST
9176 std::cout << std::endl;
9177 #endif
9178 }
9179
9180 static void testBuiltInRealToIntFunction() {
9181 #if !SILENT_TEST
9182 std::cout << "UNIT TEST: built-in real_to_int() function\n";
9183 #endif
9184
9185 runScript({
9186 .code = R"NKSP_CODE(
9187 on init
9188 exit( real_to_int(8.9) )
9189 end on
9190 )NKSP_CODE",
9191 .expectIntExitResult = 8
9192 });
9193
9194 runScript({
9195 .code = R"NKSP_CODE(
9196 on init
9197 declare ~foo := 8.9
9198 exit( real_to_int(~foo) )
9199 end on
9200 )NKSP_CODE",
9201 .expectIntExitResult = 8
9202 });
9203
9204 // std unit tests ...
9205
9206 runScript({
9207 .code = R"NKSP_CODE(
9208 on init
9209 declare ~foo := 8.9mdB
9210 exit( real_to_int(~foo) )
9211 end on
9212 )NKSP_CODE",
9213 .expectIntExitResult = 8,
9214 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
9215 .expectExitResultUnit = VM_BEL
9216 });
9217
9218 runScript({
9219 .code = R"NKSP_CODE(
9220 on init
9221 declare ~foo := 9000.0us
9222 exit( real_to_int(~foo) )
9223 end on
9224 )NKSP_CODE",
9225 .expectIntExitResult = 9000.0,
9226 .expectExitResultUnitPrefix = { VM_MICRO },
9227 .expectExitResultUnit = VM_SECOND
9228 });
9229
9230 runScript({
9231 .code = R"NKSP_CODE(
9232 on init
9233 declare ~foo := 9000.0us
9234 declare @s := "" & real_to_int(~foo)
9235 exit( @s )
9236 end on
9237 )NKSP_CODE",
9238 .expectStringExitResult = "9000us",
9239 });
9240
9241 runScript({
9242 .code = R"NKSP_CODE(
9243 on init
9244 declare ~foo := 700.0ms
9245 exit( real_to_int(~foo) / 7 )
9246 end on
9247 )NKSP_CODE",
9248 .expectIntExitResult = 100,
9249 .expectExitResultUnitPrefix = { VM_MILLI },
9250 .expectExitResultUnit = VM_SECOND
9251 });
9252
9253 runScript({
9254 .code = R"NKSP_CODE(
9255 on init
9256 declare ~foo := 700.0ms
9257 exit( real_to_int(~foo) / 7 & "" )
9258 end on
9259 )NKSP_CODE",
9260 .expectStringExitResult = "100ms"
9261 });
9262
9263 // 'final' ('!') operator tests ...
9264
9265 runScript({
9266 .code = R"NKSP_CODE(
9267 on init
9268 declare ~foo := !8.9
9269 exit( real_to_int(~foo) )
9270 end on
9271 )NKSP_CODE",
9272 .expectIntExitResult = 8,
9273 .expectExitResultFinal = true
9274 });
9275
9276 runScript({
9277 .code = R"NKSP_CODE(
9278 on init
9279 declare ~foo := 8.9
9280 exit( real_to_int(~foo) )
9281 end on
9282 )NKSP_CODE",
9283 .expectIntExitResult = 8,
9284 .expectExitResultFinal = false
9285 });
9286
9287 #if !SILENT_TEST
9288 std::cout << std::endl;
9289 #endif
9290 }
9291
9292 static void testBuiltInIntFunction() {
9293 #if !SILENT_TEST
9294 std::cout << "UNIT TEST: built-in int() function\n";
9295 #endif
9296
9297 runScript({
9298 .code = R"NKSP_CODE(
9299 on init
9300 exit( int(8.9) )
9301 end on
9302 )NKSP_CODE",
9303 .expectIntExitResult = 8
9304 });
9305
9306 runScript({
9307 .code = R"NKSP_CODE(
9308 on init
9309 declare ~foo := 8.9
9310 exit( int(~foo) )
9311 end on
9312 )NKSP_CODE",
9313 .expectIntExitResult = 8
9314 });
9315
9316 // std unit tests ...
9317
9318 runScript({
9319 .code = R"NKSP_CODE(
9320 on init
9321 declare ~foo := 8.9mdB
9322 exit( int(~foo) )
9323 end on
9324 )NKSP_CODE",
9325 .expectIntExitResult = 8,
9326 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
9327 .expectExitResultUnit = VM_BEL
9328 });
9329
9330 runScript({
9331 .code = R"NKSP_CODE(
9332 on init
9333 declare ~foo := 9000.0us
9334 exit( int(~foo) )
9335 end on
9336 )NKSP_CODE",
9337 .expectIntExitResult = 9000.0,
9338 .expectExitResultUnitPrefix = { VM_MICRO },
9339 .expectExitResultUnit = VM_SECOND
9340 });
9341
9342 runScript({
9343 .code = R"NKSP_CODE(
9344 on init
9345 declare ~foo := 9000.0us
9346 declare @s := "" & int(~foo)
9347 exit( @s )
9348 end on
9349 )NKSP_CODE",
9350 .expectStringExitResult = "9000us",
9351 });
9352
9353 runScript({
9354 .code = R"NKSP_CODE(
9355 on init
9356 declare ~foo := 700.0ms
9357 exit( int(~foo) / 7 )
9358 end on
9359 )NKSP_CODE",
9360 .expectIntExitResult = 100,
9361 .expectExitResultUnitPrefix = { VM_MILLI },
9362 .expectExitResultUnit = VM_SECOND
9363 });
9364
9365 runScript({
9366 .code = R"NKSP_CODE(
9367 on init
9368 declare ~foo := 700.0ms
9369 exit( int(~foo) / 7 & "" )
9370 end on
9371 )NKSP_CODE",
9372 .expectStringExitResult = "100ms"
9373 });
9374
9375 // 'final' ('!') operator tests ...
9376
9377 runScript({
9378 .code = R"NKSP_CODE(
9379 on init
9380 declare ~foo := !8.9
9381 exit( int(~foo) )
9382 end on
9383 )NKSP_CODE",
9384 .expectIntExitResult = 8,
9385 .expectExitResultFinal = true
9386 });
9387
9388 runScript({
9389 .code = R"NKSP_CODE(
9390 on init
9391 declare ~foo := 8.9
9392 exit( int(~foo) )
9393 end on
9394 )NKSP_CODE",
9395 .expectIntExitResult = 8,
9396 .expectExitResultFinal = false
9397 });
9398
9399 #if !SILENT_TEST
9400 std::cout << std::endl;
9401 #endif
9402 }
9403
9404 static void testBuiltInArrayEqualFunction() {
9405 #if !SILENT_TEST
9406 std::cout << "UNIT TEST: built-in array_equal() function\n";
9407 #endif
9408
9409 // integer array tests ...
9410
9411 runScript({
9412 .code = R"NKSP_CODE(
9413 on init
9414 declare %foo[3] := ( 1, 2, 3 )
9415 declare %bar[3] := ( 1, 2, 3 )
9416 exit( array_equal(%foo, %bar) )
9417 end on
9418 )NKSP_CODE",
9419 .expectBoolExitResult = true
9420 });
9421
9422 runScript({
9423 .code = R"NKSP_CODE(
9424 on init
9425 declare %foo[1] := ( 1 )
9426 declare %bar[1] := ( 1 )
9427 exit( array_equal(%foo, %bar) )
9428 end on
9429 )NKSP_CODE",
9430 .expectBoolExitResult = true
9431 });
9432
9433 runScript({
9434 .code = R"NKSP_CODE(
9435 on init
9436 declare %foo[3] := ( 1, 2, 3 )
9437 declare %bar[3] := ( 0, 2, 3 )
9438 exit( array_equal(%foo, %bar) )
9439 end on
9440 )NKSP_CODE",
9441 .expectBoolExitResult = false
9442 });
9443
9444 runScript({
9445 .code = R"NKSP_CODE(
9446 on init
9447 declare %foo[3] := ( 1, 2, 3 )
9448 declare %bar[3] := ( 3, 2, 1 )
9449 exit( array_equal(%foo, %bar) )
9450 end on
9451 )NKSP_CODE",
9452 .expectBoolExitResult = false
9453 });
9454
9455 runScript({
9456 .code = R"NKSP_CODE(
9457 on init
9458 declare %foo[3] := ( 1, 2, 3 )
9459 declare %bar[2] := ( 1, 2 )
9460 exit( array_equal(%foo, %bar) )
9461 end on
9462 )NKSP_CODE",
9463 .expectBoolExitResult = false,
9464 .expectParseWarning = true // array_equal() warns if array sizes do not match
9465 });
9466
9467 // real number array tests ...
9468
9469 runScript({
9470 .code = R"NKSP_CODE(
9471 on init
9472 declare ?foo[3] := ( 1.0, 2.0, 3.0 )
9473 declare ?bar[3] := ( 1.0, 2.0, 3.0 )
9474 exit( array_equal(?foo, ?bar) )
9475 end on
9476 )NKSP_CODE",
9477 .expectBoolExitResult = true
9478 });
9479
9480 runScript({
9481 .code = R"NKSP_CODE(
9482 on init
9483 declare ?foo[3] := ( 1.0, 1.1, 3.4 )
9484 declare ?bar[3] := ( 1.0, 1.1, 3.4 )
9485 exit( array_equal(?foo, ?bar) )
9486 end on
9487 )NKSP_CODE",
9488 .expectBoolExitResult = true
9489 });
9490
9491 runScript({
9492 .code = R"NKSP_CODE(
9493 on init
9494 declare ?foo[3] := ( 1.0, 1.1, 3.4 )
9495 declare ?bar[3] := ( 1.0, 1.2, 3.4 )
9496 exit( array_equal(?foo, ?bar) )
9497 end on
9498 )NKSP_CODE",
9499 .expectBoolExitResult = false
9500 });
9501
9502 runScript({
9503 .code = R"NKSP_CODE(
9504 on init
9505 declare ?foo[3] := ( 1.0, 1.1, 3.4 )
9506 declare ?bar[2] := ( 1.0, 1.1 )
9507 exit( array_equal(?foo, ?bar) )
9508 end on
9509 )NKSP_CODE",
9510 .expectBoolExitResult = false,
9511 .expectParseWarning = true // array_equal() warns if array sizes do not match
9512 });
9513
9514 // std unit tests ...
9515 // (only metric prefixes allowed, unit types are prohibited for arrays ATM)
9516
9517 runScript({
9518 .code = R"NKSP_CODE(
9519 on init
9520 declare %foo[3] := ( 1, 1s, 1 )
9521 declare %bar[3] := ( 1, 1, 1 )
9522 exit( array_equal(%foo, %bar) )
9523 end on
9524 )NKSP_CODE",
9525 .expectParseError = true // see comment above
9526 });
9527
9528 runScript({
9529 .code = R"NKSP_CODE(
9530 on init
9531 declare %foo[3] := ( 1k, 1, 1m )
9532 declare %bar[3] := ( 1k, 1, 1m )
9533 exit( array_equal(%foo, %bar) )
9534 end on
9535 )NKSP_CODE",
9536 .expectBoolExitResult = true
9537 });
9538
9539 runScript({
9540 .code = R"NKSP_CODE(
9541 on init
9542 declare %foo[3] := ( 1m, 1, 1k )
9543 declare %bar[3] := ( 1k, 1, 1m )
9544 exit( array_equal(%foo, %bar) )
9545 end on
9546 )NKSP_CODE",
9547 .expectBoolExitResult = false
9548 });
9549
9550 runScript({
9551 .code = R"NKSP_CODE(
9552 on init
9553 declare %foo[3] := ( 1, 1k, 1 )
9554 declare %bar[3] := ( 1, 1, 1 )
9555 exit( array_equal(%foo, %bar) )
9556 end on
9557 )NKSP_CODE",
9558 .expectBoolExitResult = false
9559 });
9560
9561 runScript({
9562 .code = R"NKSP_CODE(
9563 on init
9564 declare %foo[3] := ( 1, 1k, 1 )
9565 declare %bar[3] := ( 1, 1000, 1 )
9566 exit( array_equal(%foo, %bar) )
9567 end on
9568 )NKSP_CODE",
9569 .expectBoolExitResult = true
9570 });
9571
9572 runScript({
9573 .code = R"NKSP_CODE(
9574 on init
9575 declare %foo[3] := ( 1, 2, 3000 )
9576 declare %bar[3] := ( 1, 2, 3k )
9577 exit( array_equal(%foo, %bar) )
9578 end on
9579 )NKSP_CODE",
9580 .expectBoolExitResult = true
9581 });
9582
9583 runScript({
9584 .code = R"NKSP_CODE(
9585 on init
9586 declare %foo[3] := ( 1, 2, 3m )
9587 declare %bar[3] := ( 1, 2, 3k )
9588 exit( array_equal(%foo, %bar) )
9589 end on
9590 )NKSP_CODE",
9591 .expectBoolExitResult = false
9592 });
9593
9594 runScript({
9595 .code = R"NKSP_CODE(
9596 on init
9597 declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
9598 declare ?bar[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
9599 exit( array_equal(?foo, ?bar) )
9600 end on
9601 )NKSP_CODE",
9602 .expectBoolExitResult = true
9603 });
9604
9605 runScript({
9606 .code = R"NKSP_CODE(
9607 on init
9608 declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
9609 declare ?bar[4] := ( 1.0, 1.0 , 1.1m, 3.4k )
9610 exit( array_equal(?foo, ?bar) )
9611 end on
9612 )NKSP_CODE",
9613 .expectBoolExitResult = false
9614 });
9615
9616 runScript({
9617 .code = R"NKSP_CODE(
9618 on init
9619 declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
9620 declare ?bar[4] := ( 1.0, 1.0m, 1.1k, 3.4k )
9621 exit( array_equal(?foo, ?bar) )
9622 end on
9623 )NKSP_CODE",
9624 .expectBoolExitResult = false
9625 });
9626
9627 runScript({
9628 .code = R"NKSP_CODE(
9629 on init
9630 declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
9631 declare ?bar[4] := ( 1.0, 1.0m, 1.1m, 3.4u )
9632 exit( array_equal(?foo, ?bar) )
9633 end on
9634 )NKSP_CODE",
9635 .expectBoolExitResult = false
9636 });
9637
9638 runScript({
9639 .code = R"NKSP_CODE(
9640 on init
9641 declare ?foo[3] := ( 1.0, 1.0k, 1.1m )
9642 declare ?bar[3] := ( 1.0, 1000.0, 1.1m )
9643 exit( array_equal(?foo, ?bar) )
9644 end on
9645 )NKSP_CODE",
9646 .expectBoolExitResult = true
9647 });
9648
9649 runScript({
9650 .code = R"NKSP_CODE(
9651 on init
9652 declare ?foo[3] := ( 1.0, 1.0k, 1.1u )
9653 declare ?bar[3] := ( 1.0, 1000.0, 0.0011m )
9654 exit( array_equal(?foo, ?bar) )
9655 end on
9656 )NKSP_CODE",
9657 .expectBoolExitResult = true
9658 });
9659
9660 runScript({
9661 .code = R"NKSP_CODE(
9662 on init
9663 declare ?foo[3] := ( 1.0, 1.0k, 1.1u )
9664 declare ?bar[3] := ( 1.0, 1000.0, 0.0016m )
9665 exit( array_equal(?foo, ?bar) )
9666 end on
9667 )NKSP_CODE",
9668 .expectBoolExitResult = false
9669 });
9670
9671 // 'final' ('!') operator tests ...
9672 // (currently prohibited for arrays)
9673
9674 runScript({
9675 .code = R"NKSP_CODE(
9676 on init
9677 declare %foo[3] := ( !1, !1, !1 )
9678 declare %bar[3] := ( !1, !1, !1 )
9679 exit( array_equal(%foo, %bar) )
9680 end on
9681 )NKSP_CODE",
9682 .expectParseError = true // see comment above
9683 });
9684
9685 runScript({
9686 .code = R"NKSP_CODE(
9687 on init
9688 declare ?foo[3] := ( !1.0, !1.0, !1.0 )
9689 declare ?bar[3] := ( !1.0, !1.0, !1.0 )
9690 exit( array_equal(?foo, ?bar) )
9691 end on
9692 )NKSP_CODE",
9693 .expectParseError = true // see comment above
9694 });
9695
9696 #if !SILENT_TEST
9697 std::cout << std::endl;
9698 #endif
9699 }
9700
9701 static void testBuiltInSortFunction() {
9702 #if !SILENT_TEST
9703 std::cout << "UNIT TEST: built-in sort() function\n";
9704 #endif
9705
9706 // integer array tests ...
9707
9708 runScript({
9709 .code = R"NKSP_CODE(
9710 on init
9711 declare %input[3] := ( 19, 3, 6 )
9712 declare %expected[3] := ( 3, 6, 19 )
9713 sort(%input, 0)
9714 exit( array_equal(%input, %expected) )
9715 end on
9716 )NKSP_CODE",
9717 .expectBoolExitResult = true
9718 });
9719
9720 runScript({
9721 .code = R"NKSP_CODE(
9722 on init
9723 declare %input[3] := ( 19, 3, 6 )
9724 declare %expected[3] := ( 19, 6, 3 )
9725 sort(%input, 1)
9726 exit( array_equal(%input, %expected) )
9727 end on
9728 )NKSP_CODE",
9729 .expectBoolExitResult = true
9730 });
9731
9732 runScript({
9733 .code = R"NKSP_CODE(
9734 on init
9735 declare %input[6] := ( 1, 80, 120, 40, 3000, 20 )
9736 declare %expected[6] := ( 1, 20, 40, 80, 120, 3000 )
9737 sort(%input, 0)
9738 exit( array_equal(%input, %expected) )
9739 end on
9740 )NKSP_CODE",
9741 .expectBoolExitResult = true
9742 });
9743
9744 // real number array tests ...
9745
9746 runScript({
9747 .code = R"NKSP_CODE(
9748 on init
9749 declare ?input[4] := ( 1.4, 1.0, 13.4, 2.7 )
9750 declare ?expected[4] := ( 1.0, 1.4, 2.7, 13.4 )
9751 sort(?input, 0)
9752 exit( array_equal(?input, ?expected) )
9753 end on
9754 )NKSP_CODE",
9755 .expectBoolExitResult = true
9756 });
9757
9758 runScript({
9759 .code = R"NKSP_CODE(
9760 on init
9761 declare ?input[4] := ( 1.4, 1.0, 13.4, 2.7 )
9762 declare ?expected[4] := ( 13.4, 2.7, 1.4, 1.0 )
9763 sort(?input, 1)
9764 exit( array_equal(?input, ?expected) )
9765 end on
9766 )NKSP_CODE",
9767 .expectBoolExitResult = true
9768 });
9769
9770 // std unit tests ...
9771 // (only metric prefixes are allowed for arrays ATM)
9772
9773 runScript({
9774 .code = R"NKSP_CODE(
9775 on init
9776 declare %input[3] := ( 1k, 6, 900 )
9777 declare %expected[3] := ( 6, 900, 1k )
9778 sort(%input, 0)
9779 exit( array_equal(%input, %expected) )
9780 end on
9781 )NKSP_CODE",
9782 .expectBoolExitResult = true
9783 });
9784
9785 runScript({
9786 .code = R"NKSP_CODE(
9787 on init
9788 declare %input[3] := ( 900, 1k, 6 )
9789 declare %expected[3] := ( 1k, 900, 6 )
9790 sort(%input, 1)
9791 exit( array_equal(%input, %expected) )
9792 end on
9793 )NKSP_CODE",
9794 .expectBoolExitResult = true
9795 });
9796
9797 runScript({
9798 .code = R"NKSP_CODE(
9799 on init
9800 declare %input[6] := ( 1k, 8m, 4k, 12000u, 3000u, 1000u )
9801 declare %expected[6] := ( 1000u, 3000u, 8m, 12000u, 1k, 4k )
9802 sort(%input, 0)
9803 exit( array_equal(%input, %expected) )
9804 end on
9805 )NKSP_CODE",
9806 .expectBoolExitResult = true
9807 });
9808
9809 runScript({
9810 .code = R"NKSP_CODE(
9811 on init
9812 declare ?input[3] := ( 1.0k, 6.0, 900.0 )
9813 declare ?expected[3] := ( 6.0, 900.0, 1.0k )
9814 sort(?input, 0)
9815 exit( array_equal(?input, ?expected) )
9816 end on
9817 )NKSP_CODE",
9818 .expectBoolExitResult = true
9819 });
9820
9821 runScript({
9822 .code = R"NKSP_CODE(
9823 on init
9824 declare ?input[3] := ( 900.0, 1.0k, 6.0 )
9825 declare ?expected[3] := ( 1.0k, 900.0, 6.0 )
9826 sort(?input, 1)
9827 exit( array_equal(?input, ?expected) )
9828 end on
9829 )NKSP_CODE",
9830 .expectBoolExitResult = true
9831 });
9832
9833 runScript({
9834 .code = R"NKSP_CODE(
9835 on init
9836 declare ?input[3] := ( 1.0k, 0.9k, 1.1k )
9837 declare ?expected[3] := ( 0.9k, 1.0k, 1.1k )
9838 sort(?input, 0)
9839 exit( array_equal(?input, ?expected) )
9840 end on
9841 )NKSP_CODE",
9842 .expectBoolExitResult = true
9843 });
9844
9845 runScript({
9846 .code = R"NKSP_CODE(
9847 on init
9848 declare ?input[3] := ( 2.0m, 1000.1u, 1.0 )
9849 declare ?expected[3] := ( 1000.1u, 2.0m, 1.0 )
9850 sort(?input, 0)
9851 exit( array_equal(?input, ?expected) )
9852 end on
9853 )NKSP_CODE",
9854 .expectBoolExitResult = true
9855 });
9856
9857 runScript({
9858 .code = R"NKSP_CODE(
9859 on init
9860 declare ?input[4] := ( 2.0m, 1000.1u, 1.0, 1400.0u )
9861 declare ?expected[4] := ( 1000.1u, 1400.0u, 2.0m, 1.0 )
9862 sort(?input, 0)
9863 exit( array_equal(?input, ?expected) )
9864 end on
9865 )NKSP_CODE",
9866 .expectBoolExitResult = true
9867 });
9868
9869 runScript({
9870 .code = R"NKSP_CODE(
9871 on init
9872 declare ?input[4] := ( 2.0m, 1000.1u, 1.0, 1400.0u )
9873 declare ?expected[4] := ( 1.0, 2.0m, 1400.0u, 1000.1u )
9874 sort(?input, 1)
9875 exit( array_equal(?input, ?expected) )
9876 end on
9877 )NKSP_CODE",
9878 .expectBoolExitResult = true
9879 });
9880
9881 runScript({
9882 .code = R"NKSP_CODE(
9883 on init
9884 declare ?input[6] := ( 0.9k, 8.0m, 1.1k, 12000.0u, 3000.0u, 1000.0u )
9885 declare ?expected[6] := ( 1000.0u, 3000.0u, 8.0m, 12000.0u, 0.9k, 1.1k )
9886 sort(?input, 0)
9887 exit( array_equal(?input, ?expected) )
9888 end on
9889 )NKSP_CODE",
9890 .expectBoolExitResult = true
9891 });
9892
9893 runScript({
9894 .code = R"NKSP_CODE(
9895 on init
9896 declare ?input[6] := ( 0.9k, 8.0m, 1.1k, 12000.0u, 3000.0u, 1000.0u )
9897 declare ?expected[6] := ( 1.1k, 0.9k, 12000.0u, 8.0m, 3000.0u, 1000.0u )
9898 sort(?input, 1)
9899 exit( array_equal(?input, ?expected) )
9900 end on
9901 )NKSP_CODE",
9902 .expectBoolExitResult = true
9903 });
9904
9905 #if !SILENT_TEST
9906 std::cout << std::endl;
9907 #endif
9908 }
9909
9910 static void testBuiltInRoundFunction() {
9911 #if !SILENT_TEST
9912 std::cout << "UNIT TEST: built-in round() function\n";
9913 #endif
9914
9915 // integer tests ...
9916 // (ATM not allowed for this function)
9917
9918 runScript({
9919 .code = R"NKSP_CODE(
9920 on init
9921 declare $foo := 1
9922 exit( round($foo) )
9923 end on
9924 )NKSP_CODE",
9925 .expectParseError = true // integer not allowed for this function ATM
9926 });
9927
9928 // real number tests ...
9929
9930 runScript({
9931 .code = R"NKSP_CODE(
9932 on init
9933 exit( round(99.4) )
9934 end on
9935 )NKSP_CODE",
9936 .expectRealExitResult = 99.0
9937 });
9938
9939 runScript({
9940 .code = R"NKSP_CODE(
9941 on init
9942 exit( round(99.5) )
9943 end on
9944 )NKSP_CODE",
9945 .expectRealExitResult = 100.0
9946 });
9947
9948 // std unit tests ...
9949
9950 runScript({
9951 .code = R"NKSP_CODE(
9952 on init
9953 exit( round(2.4ms) )
9954 end on
9955 )NKSP_CODE",
9956 .expectRealExitResult = 2.0,
9957 .expectExitResultUnitPrefix = { VM_MILLI },
9958 .expectExitResultUnit = VM_SECOND
9959 });
9960
9961 runScript({
9962 .code = R"NKSP_CODE(
9963 on init
9964 exit( round(2.6kHz) )
9965 end on
9966 )NKSP_CODE",
9967 .expectRealExitResult = 3.0,
9968 .expectExitResultUnitPrefix = { VM_KILO },
9969 .expectExitResultUnit = VM_HERTZ
9970 });
9971
9972 // 'final' ('!') operator tests ...
9973
9974 runScript({
9975 .code = R"NKSP_CODE(
9976 on init
9977 exit( round(123.8) )
9978 end on
9979 )NKSP_CODE",
9980 .expectRealExitResult = 124.0,
9981 .expectExitResultFinal = false
9982 });
9983
9984 runScript({
9985 .code = R"NKSP_CODE(
9986 on init
9987 exit( round(!123.8) )
9988 end on
9989 )NKSP_CODE",
9990 .expectRealExitResult = 124.0,
9991 .expectExitResultFinal = true
9992 });
9993
9994 #if !SILENT_TEST
9995 std::cout << std::endl;
9996 #endif
9997 }
9998
9999 static void testBuiltInCeilFunction() {
10000 #if !SILENT_TEST
10001 std::cout << "UNIT TEST: built-in ceil() function\n";
10002 #endif
10003
10004 // integer tests ...
10005 // (ATM not allowed for this function)
10006
10007 runScript({
10008 .code = R"NKSP_CODE(
10009 on init
10010 declare $foo := 1
10011 exit( ceil($foo) )
10012 end on
10013 )NKSP_CODE",
10014 .expectParseError = true // integer not allowed for this function ATM
10015 });
10016
10017 // real number tests ...
10018
10019 runScript({
10020 .code = R"NKSP_CODE(
10021 on init
10022 exit( ceil(99.0) )
10023 end on
10024 )NKSP_CODE",
10025 .expectRealExitResult = 99.0
10026 });
10027
10028 runScript({
10029 .code = R"NKSP_CODE(
10030 on init
10031 exit( ceil(99.1) )
10032 end on
10033 )NKSP_CODE",
10034 .expectRealExitResult = 100.0
10035 });
10036
10037 runScript({
10038 .code = R"NKSP_CODE(
10039 on init
10040 exit( ceil(99.9) )
10041 end on
10042 )NKSP_CODE",
10043 .expectRealExitResult = 100.0
10044 });
10045
10046 // std unit tests ...
10047
10048 runScript({
10049 .code = R"NKSP_CODE(
10050 on init
10051 exit( ceil(2.4ms) )
10052 end on
10053 )NKSP_CODE",
10054 .expectRealExitResult = 3.0,
10055 .expectExitResultUnitPrefix = { VM_MILLI },
10056 .expectExitResultUnit = VM_SECOND
10057 });
10058
10059 runScript({
10060 .code = R"NKSP_CODE(
10061 on init
10062 exit( ceil(2.6kHz) )
10063 end on
10064 )NKSP_CODE",
10065 .expectRealExitResult = 3.0,
10066 .expectExitResultUnitPrefix = { VM_KILO },
10067 .expectExitResultUnit = VM_HERTZ
10068 });
10069
10070 runScript({
10071 .code = R"NKSP_CODE(
10072 on init
10073 exit( ceil(9.4ms / 2.0) )
10074 end on
10075 )NKSP_CODE",
10076 .expectRealExitResult = 5.0,
10077 .expectExitResultUnitPrefix = { VM_MILLI },
10078 .expectExitResultUnit = VM_SECOND
10079 });
10080
10081 runScript({
10082 .code = R"NKSP_CODE(
10083 on init
10084 exit( ceil( ceil(8.4us) / 2.0) )
10085 end on
10086 )NKSP_CODE",
10087 .expectRealExitResult = 5.0,
10088 .expectExitResultUnitPrefix = { VM_MICRO },
10089 .expectExitResultUnit = VM_SECOND
10090 });
10091
10092 // 'final' ('!') operator tests ...
10093
10094 runScript({
10095 .code = R"NKSP_CODE(
10096 on init
10097 exit( ceil(123.1) )
10098 end on
10099 )NKSP_CODE",
10100 .expectRealExitResult = 124.0,
10101 .expectExitResultFinal = false
10102 });
10103
10104 runScript({
10105 .code = R"NKSP_CODE(
10106 on init
10107 exit( ceil(!123.8) )
10108 end on
10109 )NKSP_CODE",
10110 .expectRealExitResult = 124.0,
10111 .expectExitResultFinal = true
10112 });
10113
10114 #if !SILENT_TEST
10115 std::cout << std::endl;
10116 #endif
10117 }
10118
10119 static void testBuiltInFloorFunction() {
10120 #if !SILENT_TEST
10121 std::cout << "UNIT TEST: built-in floor() function\n";
10122 #endif
10123
10124 // integer tests ...
10125 // (ATM not allowed for this function)
10126
10127 runScript({
10128 .code = R"NKSP_CODE(
10129 on init
10130 declare $foo := 1
10131 exit( floor($foo) )
10132 end on
10133 )NKSP_CODE",
10134 .expectParseError = true // integer not allowed for this function ATM
10135 });
10136
10137 // real number tests ...
10138
10139 runScript({
10140 .code = R"NKSP_CODE(
10141 on init
10142 exit( floor(99.0) )
10143 end on
10144 )NKSP_CODE",
10145 .expectRealExitResult = 99.0
10146 });
10147
10148 runScript({
10149 .code = R"NKSP_CODE(
10150 on init
10151 exit( floor(99.1) )
10152 end on
10153 )NKSP_CODE",
10154 .expectRealExitResult = 99.0
10155 });
10156
10157 runScript({
10158 .code = R"NKSP_CODE(
10159 on init
10160 exit( floor(99.9) )
10161 end on
10162 )NKSP_CODE",
10163 .expectRealExitResult = 99.0
10164 });
10165
10166 // std unit tests ...
10167
10168 runScript({
10169 .code = R"NKSP_CODE(
10170 on init
10171 exit( floor(2.4ms) )
10172 end on
10173 )NKSP_CODE",
10174 .expectRealExitResult = 2.0,
10175 .expectExitResultUnitPrefix = { VM_MILLI },
10176 .expectExitResultUnit = VM_SECOND
10177 });
10178
10179 runScript({
10180 .code = R"NKSP_CODE(
10181 on init
10182 exit( floor(2.6kHz) )
10183 end on
10184 )NKSP_CODE",
10185 .expectRealExitResult = 2.0,
10186 .expectExitResultUnitPrefix = { VM_KILO },
10187 .expectExitResultUnit = VM_HERTZ
10188 });
10189
10190 runScript({
10191 .code = R"NKSP_CODE(
10192 on init
10193 exit( floor(4.4ms / 2.0) )
10194 end on
10195 )NKSP_CODE",
10196 .expectRealExitResult = 2.0,
10197 .expectExitResultUnitPrefix = { VM_MILLI },
10198 .expectExitResultUnit = VM_SECOND
10199 });
10200
10201 runScript({
10202 .code = R"NKSP_CODE(
10203 on init
10204 exit( floor( floor(8.4us) / 4.0) )
10205 end on
10206 )NKSP_CODE",
10207 .expectRealExitResult = 2.0,
10208 .expectExitResultUnitPrefix = { VM_MICRO },
10209 .expectExitResultUnit = VM_SECOND
10210 });
10211
10212 // 'final' ('!') operator tests ...
10213
10214 runScript({
10215 .code = R"NKSP_CODE(
10216 on init
10217 exit( floor(123.1) )
10218 end on
10219 )NKSP_CODE",
10220 .expectRealExitResult = 123.0,
10221 .expectExitResultFinal = false
10222 });
10223
10224 runScript({
10225 .code = R"NKSP_CODE(
10226 on init
10227 exit( floor(!123.8) )
10228 end on
10229 )NKSP_CODE",
10230 .expectRealExitResult = 123.0,
10231 .expectExitResultFinal = true
10232 });
10233
10234 #if !SILENT_TEST
10235 std::cout << std::endl;
10236 #endif
10237 }
10238
10239 static void testBuiltInSqrtFunction() {
10240 #if !SILENT_TEST
10241 std::cout << "UNIT TEST: built-in sqrt() function\n";
10242 #endif
10243
10244 // integer tests ...
10245 // (ATM not allowed for this function)
10246
10247 runScript({
10248 .code = R"NKSP_CODE(
10249 on init
10250 declare $foo := 1
10251 exit( sqrt($foo) )
10252 end on
10253 )NKSP_CODE",
10254 .expectParseError = true // integer not allowed for this function ATM
10255 });
10256
10257 // real number tests ...
10258
10259 runScript({
10260 .code = R"NKSP_CODE(
10261 on init
10262 exit( sqrt(36.0) )
10263 end on
10264 )NKSP_CODE",
10265 .expectRealExitResult = 6.0
10266 });
10267
10268 // std unit tests ...
10269
10270 runScript({
10271 .code = R"NKSP_CODE(
10272 on init
10273 exit( sqrt(100.0ms) )
10274 end on
10275 )NKSP_CODE",
10276 .expectRealExitResult = 10.0,
10277 .expectExitResultUnitPrefix = { VM_MILLI },
10278 .expectExitResultUnit = VM_SECOND
10279 });
10280
10281 runScript({
10282 .code = R"NKSP_CODE(
10283 on init
10284 exit( sqrt(5.76kHz) )
10285 end on
10286 )NKSP_CODE",
10287 .expectRealExitResult = 2.4,
10288 .expectExitResultUnitPrefix = { VM_KILO },
10289 .expectExitResultUnit = VM_HERTZ
10290 });
10291
10292 // 'final' ('!') operator tests ...
10293
10294 runScript({
10295 .code = R"NKSP_CODE(
10296 on init
10297 exit( sqrt(25.0) )
10298 end on
10299 )NKSP_CODE",
10300 .expectRealExitResult = 5.0,
10301 .expectExitResultFinal = false
10302 });
10303
10304 runScript({
10305 .code = R"NKSP_CODE(
10306 on init
10307 exit( sqrt(!25.0) )
10308 end on
10309 )NKSP_CODE",
10310 .expectRealExitResult = 5.0,
10311 .expectExitResultFinal = true
10312 });
10313
10314 #if !SILENT_TEST
10315 std::cout << std::endl;
10316 #endif
10317 }
10318
10319 static void testBuiltInLogFunction() {
10320 #if !SILENT_TEST
10321 std::cout << "UNIT TEST: built-in log() function\n";
10322 #endif
10323
10324 // integer tests ...
10325 // (ATM not allowed for this function)
10326
10327 runScript({
10328 .code = R"NKSP_CODE(
10329 on init
10330 declare $foo := 1
10331 exit( log($foo) )
10332 end on
10333 )NKSP_CODE",
10334 .expectParseError = true // integer not allowed for this function ATM
10335 });
10336
10337 // real number tests ...
10338
10339 runScript({
10340 .code = R"NKSP_CODE(
10341 on init
10342 exit( log(1.0) )
10343 end on
10344 )NKSP_CODE",
10345 .expectRealExitResult = 0.0
10346 });
10347
10348 runScript({
10349 .code = R"NKSP_CODE(
10350 on init
10351 exit( log(~NI_MATH_E) )
10352 end on
10353 )NKSP_CODE",
10354 .expectRealExitResult = 1.0
10355 });
10356
10357 // std unit tests ...
10358
10359 runScript({
10360 .code = R"NKSP_CODE(
10361 on init
10362 exit( log(~NI_MATH_E * 1.0ms) )
10363 end on
10364 )NKSP_CODE",
10365 .expectRealExitResult = 1.0,
10366 .expectExitResultUnitPrefix = { VM_MILLI },
10367 .expectExitResultUnit = VM_SECOND
10368 });
10369
10370 runScript({
10371 .code = R"NKSP_CODE(
10372 on init
10373 exit( log(~NI_MATH_E * 1.0kHz) )
10374 end on
10375 )NKSP_CODE",
10376 .expectRealExitResult = 1.0,
10377 .expectExitResultUnitPrefix = { VM_KILO },
10378 .expectExitResultUnit = VM_HERTZ
10379 });
10380
10381 // 'final' ('!') operator tests ...
10382
10383 runScript({
10384 .code = R"NKSP_CODE(
10385 on init
10386 exit( log(~NI_MATH_E * 1.0) )
10387 end on
10388 )NKSP_CODE",
10389 .expectRealExitResult = 1.0,
10390 .expectExitResultFinal = false
10391 });
10392
10393 runScript({
10394 .code = R"NKSP_CODE(
10395 on init
10396 exit( log(!(~NI_MATH_E * 1.0)) )
10397 end on
10398 )NKSP_CODE",
10399 .expectRealExitResult = 1.0,
10400 .expectExitResultFinal = true
10401 });
10402
10403 #if !SILENT_TEST
10404 std::cout << std::endl;
10405 #endif
10406 }
10407
10408 static void testBuiltInLog2Function() {
10409 #if !SILENT_TEST
10410 std::cout << "UNIT TEST: built-in log2() function\n";
10411 #endif
10412
10413 // integer tests ...
10414 // (ATM not allowed for this function)
10415
10416 runScript({
10417 .code = R"NKSP_CODE(
10418 on init
10419 declare $foo := 1
10420 exit( log2($foo) )
10421 end on
10422 )NKSP_CODE",
10423 .expectParseError = true // integer not allowed for this function ATM
10424 });
10425
10426 // real number tests ...
10427
10428 runScript({
10429 .code = R"NKSP_CODE(
10430 on init
10431 exit( log2(1.0) )
10432 end on
10433 )NKSP_CODE",
10434 .expectRealExitResult = 0.0
10435 });
10436
10437 runScript({
10438 .code = R"NKSP_CODE(
10439 on init
10440 exit( log2(32.0) )
10441 end on
10442 )NKSP_CODE",
10443 .expectRealExitResult = 5.0
10444 });
10445
10446 // std unit tests ...
10447
10448 runScript({
10449 .code = R"NKSP_CODE(
10450 on init
10451 exit( log2(32.0ms) )
10452 end on
10453 )NKSP_CODE",
10454 .expectRealExitResult = 5.0,
10455 .expectExitResultUnitPrefix = { VM_MILLI },
10456 .expectExitResultUnit = VM_SECOND
10457 });
10458
10459 runScript({
10460 .code = R"NKSP_CODE(
10461 on init
10462 exit( log2(32.0kHz) )
10463 end on
10464 )NKSP_CODE",
10465 .expectRealExitResult = 5.0,
10466 .expectExitResultUnitPrefix = { VM_KILO },
10467 .expectExitResultUnit = VM_HERTZ
10468 });
10469
10470 // 'final' ('!') operator tests ...
10471
10472 runScript({
10473 .code = R"NKSP_CODE(
10474 on init
10475 exit( log2(32.0) )
10476 end on
10477 )NKSP_CODE",
10478 .expectRealExitResult = 5.0,
10479 .expectExitResultFinal = false
10480 });
10481
10482 runScript({
10483 .code = R"NKSP_CODE(
10484 on init
10485 exit( log2(!32.0) )
10486 end on
10487 )NKSP_CODE",
10488 .expectRealExitResult = 5.0,
10489 .expectExitResultFinal = true
10490 });
10491
10492 #if !SILENT_TEST
10493 std::cout << std::endl;
10494 #endif
10495 }
10496
10497 static void testBuiltInLog10Function() {
10498 #if !SILENT_TEST
10499 std::cout << "UNIT TEST: built-in log10() function\n";
10500 #endif
10501
10502 // integer tests ...
10503 // (ATM not allowed for this function)
10504
10505 runScript({
10506 .code = R"NKSP_CODE(
10507 on init
10508 declare $foo := 1
10509 exit( log10($foo) )
10510 end on
10511 )NKSP_CODE",
10512 .expectParseError = true // integer not allowed for this function ATM
10513 });
10514
10515 // real number tests ...
10516
10517 runScript({
10518 .code = R"NKSP_CODE(
10519 on init
10520 exit( log10(1000.0) )
10521 end on
10522 )NKSP_CODE",
10523 .expectRealExitResult = 3.0
10524 });
10525
10526 runScript({
10527 .code = R"NKSP_CODE(
10528 on init
10529 exit( log10(1000.0) )
10530 end on
10531 )NKSP_CODE",
10532 .expectRealExitResult = 3.0
10533 });
10534
10535 // std unit tests ...
10536
10537 runScript({
10538 .code = R"NKSP_CODE(
10539 on init
10540 exit( log10(1000.0ms) )
10541 end on
10542 )NKSP_CODE",
10543 .expectRealExitResult = 3.0,
10544 .expectExitResultUnitPrefix = { VM_MILLI },
10545 .expectExitResultUnit = VM_SECOND
10546 });
10547
10548 runScript({
10549 .code = R"NKSP_CODE(
10550 on init
10551 exit( log10(1000.0kHz) )
10552 end on
10553 )NKSP_CODE",
10554 .expectRealExitResult = 3.0,
10555 .expectExitResultUnitPrefix = { VM_KILO },
10556 .expectExitResultUnit = VM_HERTZ
10557 });
10558
10559 // 'final' ('!') operator tests ...
10560
10561 runScript({
10562 .code = R"NKSP_CODE(
10563 on init
10564 exit( log10(1000.0) )
10565 end on
10566 )NKSP_CODE",
10567 .expectRealExitResult = 3.0,
10568 .expectExitResultFinal = false
10569 });
10570
10571 runScript({
10572 .code = R"NKSP_CODE(
10573 on init
10574 exit( log10(!1000.0) )
10575 end on
10576 )NKSP_CODE",
10577 .expectRealExitResult = 3.0,
10578 .expectExitResultFinal = true
10579 });
10580
10581 #if !SILENT_TEST
10582 std::cout << std::endl;
10583 #endif
10584 }
10585
10586 static void testBuiltInExpFunction() {
10587 #if !SILENT_TEST
10588 std::cout << "UNIT TEST: built-in exp() function\n";
10589 #endif
10590
10591 // integer tests ...
10592 // (ATM not allowed for this function)
10593
10594 runScript({
10595 .code = R"NKSP_CODE(
10596 on init
10597 declare $foo := 1
10598 exit( exp($foo) )
10599 end on
10600 )NKSP_CODE",
10601 .expectParseError = true // integer not allowed for this function ATM
10602 });
10603
10604 // real number tests ...
10605
10606 runScript({
10607 .code = R"NKSP_CODE(
10608 on init
10609 exit( exp(0.0) )
10610 end on
10611 )NKSP_CODE",
10612 .expectRealExitResult = 1.0
10613 });
10614
10615 runScript({
10616 .code = R"NKSP_CODE(
10617 on init
10618 exit( exp(1.0) )
10619 end on
10620 )NKSP_CODE",
10621 .expectRealExitResult = M_E
10622 });
10623
10624 // std unit tests ...
10625
10626 runScript({
10627 .code = R"NKSP_CODE(
10628 on init
10629 exit( exp(0.0ms) )
10630 end on
10631 )NKSP_CODE",
10632 .expectRealExitResult = 1.0,
10633 .expectExitResultUnitPrefix = { VM_MILLI },
10634 .expectExitResultUnit = VM_SECOND
10635 });
10636
10637 runScript({
10638 .code = R"NKSP_CODE(
10639 on init
10640 exit( exp(0.0kHz) )
10641 end on
10642 )NKSP_CODE",
10643 .expectRealExitResult = 1.0,
10644 .expectExitResultUnitPrefix = { VM_KILO },
10645 .expectExitResultUnit = VM_HERTZ
10646 });
10647
10648 // 'final' ('!') operator tests ...
10649
10650 runScript({
10651 .code = R"NKSP_CODE(
10652 on init
10653 exit( exp(0.0) )
10654 end on
10655 )NKSP_CODE",
10656 .expectRealExitResult = 1.0,
10657 .expectExitResultFinal = false
10658 });
10659
10660 runScript({
10661 .code = R"NKSP_CODE(
10662 on init
10663 exit( exp(!0.0) )
10664 end on
10665 )NKSP_CODE",
10666 .expectRealExitResult = 1.0,
10667 .expectExitResultFinal = true
10668 });
10669
10670 #if !SILENT_TEST
10671 std::cout << std::endl;
10672 #endif
10673 }
10674
10675 static void testBuiltInPowFunction() {
10676 #if !SILENT_TEST
10677 std::cout << "UNIT TEST: built-in pow() function\n";
10678 #endif
10679
10680 // integer tests ...
10681 // (ATM not allowed for this function)
10682
10683 runScript({
10684 .code = R"NKSP_CODE(
10685 on init
10686 declare $foo := 1
10687 exit( pow($foo,$foo) )
10688 end on
10689 )NKSP_CODE",
10690 .expectParseError = true // integer not allowed for this function ATM
10691 });
10692
10693 // real number tests ...
10694
10695 runScript({
10696 .code = R"NKSP_CODE(
10697 on init
10698 exit( pow(1.0) )
10699 end on
10700 )NKSP_CODE",
10701 .expectParseError = true // because pow() requires exactly 2 arguments
10702 });
10703
10704 runScript({
10705 .code = R"NKSP_CODE(
10706 on init
10707 exit( pow(3.0,4.0) )
10708 end on
10709 )NKSP_CODE",
10710 .expectRealExitResult = 81.0
10711 });
10712
10713 // std unit tests ...
10714
10715 runScript({
10716 .code = R"NKSP_CODE(
10717 on init
10718 exit( pow(3.0ms,4.0ms) )
10719 end on
10720 )NKSP_CODE",
10721 .expectParseError = true // because units are prohibited for 2nd argument
10722 });
10723
10724 runScript({
10725 .code = R"NKSP_CODE(
10726 on init
10727 exit( pow(3.0,4.0ms) )
10728 end on
10729 )NKSP_CODE",
10730 .expectParseError = true // because units are prohibited for 2nd argument
10731 });
10732
10733 runScript({
10734 .code = R"NKSP_CODE(
10735 on init
10736 exit( pow(3.0ms,4.0) )
10737 end on
10738 )NKSP_CODE",
10739 .expectRealExitResult = 81.0,
10740 .expectExitResultUnitPrefix = { VM_MILLI },
10741 .expectExitResultUnit = VM_SECOND
10742 });
10743
10744 runScript({
10745 .code = R"NKSP_CODE(
10746 on init
10747 exit( pow(3.0kHz,4.0) )
10748 end on
10749 )NKSP_CODE",
10750 .expectRealExitResult = 81.0,
10751 .expectExitResultUnitPrefix = { VM_KILO },
10752 .expectExitResultUnit = VM_HERTZ
10753 });
10754
10755 // 'final' ('!') operator tests ...
10756
10757 runScript({
10758 .code = R"NKSP_CODE(
10759 on init
10760 exit( pow(3.0,4.0) )
10761 end on
10762 )NKSP_CODE",
10763 .expectRealExitResult = 81.0,
10764 .expectExitResultFinal = false
10765 });
10766
10767 runScript({
10768 .code = R"NKSP_CODE(
10769 on init
10770 exit( pow(!3.0,4.0) )
10771 end on
10772 )NKSP_CODE",
10773 .expectRealExitResult = 81.0,
10774 .expectExitResultFinal = true
10775 });
10776
10777 runScript({
10778 .code = R"NKSP_CODE(
10779 on init
10780 exit( pow(3.0,!4.0) )
10781 end on
10782 )NKSP_CODE",
10783 .expectParseError = true // because 'final' is meaningless for 2nd argument
10784 });
10785
10786 #if !SILENT_TEST
10787 std::cout << std::endl;
10788 #endif
10789 }
10790
10791 static void testBuiltInSinFunction() {
10792 #if !SILENT_TEST
10793 std::cout << "UNIT TEST: built-in sin() function\n";
10794 #endif
10795
10796 // integer tests ...
10797 // (ATM not allowed for this function)
10798
10799 runScript({
10800 .code = R"NKSP_CODE(
10801 on init
10802 declare $foo := 1
10803 exit( sin($foo) )
10804 end on
10805 )NKSP_CODE",
10806 .expectParseError = true // integer not allowed for this function ATM
10807 });
10808
10809 // real number tests ...
10810
10811 runScript({
10812 .code = R"NKSP_CODE(
10813 on init
10814 exit( sin(0.0) )
10815 end on
10816 )NKSP_CODE",
10817 .expectRealExitResult = 0.0
10818 });
10819
10820 runScript({
10821 .code = R"NKSP_CODE(
10822 on init
10823 exit( sin(0.5 * ~NI_MATH_PI) )
10824 end on
10825 )NKSP_CODE",
10826 .expectRealExitResult = 1.0
10827 });
10828
10829 runScript({
10830 .code = R"NKSP_CODE(
10831 on init
10832 exit( sin(~NI_MATH_PI) )
10833 end on
10834 )NKSP_CODE",
10835 .expectRealExitResult = 0.0
10836 });
10837
10838 runScript({
10839 .code = R"NKSP_CODE(
10840 on init
10841 exit( sin(1.5 * ~NI_MATH_PI) )
10842 end on
10843 )NKSP_CODE",
10844 .expectRealExitResult = -1.0
10845 });
10846
10847 // std unit tests ...
10848
10849 runScript({
10850 .code = R"NKSP_CODE(
10851 on init
10852 exit( sin(0.0ms) )
10853 end on
10854 )NKSP_CODE",
10855 .expectRealExitResult = 0.0,
10856 .expectExitResultUnitPrefix = { VM_MILLI },
10857 .expectExitResultUnit = VM_SECOND
10858 });
10859
10860 runScript({
10861 .code = R"NKSP_CODE(
10862 on init
10863 exit( sin(0.0kHz) )
10864 end on
10865 )NKSP_CODE",
10866 .expectRealExitResult = 0.0,
10867 .expectExitResultUnitPrefix = { VM_KILO },
10868 .expectExitResultUnit = VM_HERTZ
10869 });
10870
10871 // 'final' ('!') operator tests ...
10872
10873 runScript({
10874 .code = R"NKSP_CODE(
10875 on init
10876 exit( sin(0.0) )
10877 end on
10878 )NKSP_CODE",
10879 .expectRealExitResult = 0.0,
10880 .expectExitResultFinal = false
10881 });
10882
10883 runScript({
10884 .code = R"NKSP_CODE(
10885 on init
10886 exit( sin(!0.0) )
10887 end on
10888 )NKSP_CODE",
10889 .expectRealExitResult = 0.0,
10890 .expectExitResultFinal = true
10891 });
10892
10893 #if !SILENT_TEST
10894 std::cout << std::endl;
10895 #endif
10896 }
10897
10898 static void testBuiltInCosFunction() {
10899 #if !SILENT_TEST
10900 std::cout << "UNIT TEST: built-in cos() function\n";
10901 #endif
10902
10903 // integer tests ...
10904 // (ATM not allowed for this function)
10905
10906 runScript({
10907 .code = R"NKSP_CODE(
10908 on init
10909 declare $foo := 1
10910 exit( cos($foo) )
10911 end on
10912 )NKSP_CODE",
10913 .expectParseError = true // integer not allowed for this function ATM
10914 });
10915
10916 // real number tests ...
10917
10918 runScript({
10919 .code = R"NKSP_CODE(
10920 on init
10921 exit( cos(0.0) )
10922 end on
10923 )NKSP_CODE",
10924 .expectRealExitResult = 1.0
10925 });
10926
10927 runScript({
10928 .code = R"NKSP_CODE(
10929 on init
10930 exit( cos(0.5 * ~NI_MATH_PI) )
10931 end on
10932 )NKSP_CODE",
10933 .expectRealExitResult = 0.0
10934 });
10935
10936 runScript({
10937 .code = R"NKSP_CODE(
10938 on init
10939 exit( cos(~NI_MATH_PI) )
10940 end on
10941 )NKSP_CODE",
10942 .expectRealExitResult = -1.0
10943 });
10944
10945 runScript({
10946 .code = R"NKSP_CODE(
10947 on init
10948 exit( cos(1.5 * ~NI_MATH_PI) )
10949 end on
10950 )NKSP_CODE",
10951 .expectRealExitResult = 0.0
10952 });
10953
10954 // std unit tests ...
10955
10956 runScript({
10957 .code = R"NKSP_CODE(
10958 on init
10959 exit( cos(0.0ms) )
10960 end on
10961 )NKSP_CODE",
10962 .expectRealExitResult = 1.0,
10963 .expectExitResultUnitPrefix = { VM_MILLI },
10964 .expectExitResultUnit = VM_SECOND
10965 });
10966
10967 runScript({
10968 .code = R"NKSP_CODE(
10969 on init
10970 exit( cos(0.0kHz) )
10971 end on
10972 )NKSP_CODE",
10973 .expectRealExitResult = 1.0,
10974 .expectExitResultUnitPrefix = { VM_KILO },
10975 .expectExitResultUnit = VM_HERTZ
10976 });
10977
10978 // 'final' ('!') operator tests ...
10979
10980 runScript({
10981 .code = R"NKSP_CODE(
10982 on init
10983 exit( cos(0.0) )
10984 end on
10985 )NKSP_CODE",
10986 .expectRealExitResult = 1.0,
10987 .expectExitResultFinal = false
10988 });
10989
10990 runScript({
10991 .code = R"NKSP_CODE(
10992 on init
10993 exit( cos(!0.0) )
10994 end on
10995 )NKSP_CODE",
10996 .expectRealExitResult = 1.0,
10997 .expectExitResultFinal = true
10998 });
10999
11000 #if !SILENT_TEST
11001 std::cout << std::endl;
11002 #endif
11003 }
11004
11005 static void testBuiltInTanFunction() {
11006 #if !SILENT_TEST
11007 std::cout << "UNIT TEST: built-in tan() function\n";
11008 #endif
11009
11010 // integer tests ...
11011 // (ATM not allowed for this function)
11012
11013 runScript({
11014 .code = R"NKSP_CODE(
11015 on init
11016 declare $foo := 1
11017 exit( tan($foo) )
11018 end on
11019 )NKSP_CODE",
11020 .expectParseError = true // integer not allowed for this function ATM
11021 });
11022
11023 // real number tests ...
11024
11025 runScript({
11026 .code = R"NKSP_CODE(
11027 on init
11028 exit( tan(0.0) )
11029 end on
11030 )NKSP_CODE",
11031 .expectRealExitResult = 0.0
11032 });
11033
11034 runScript({
11035 .code = R"NKSP_CODE(
11036 on init
11037 exit( tan(0.25 * ~NI_MATH_PI) )
11038 end on
11039 )NKSP_CODE",
11040 .expectRealExitResult = 1.0
11041 });
11042
11043 // std unit tests ...
11044
11045 runScript({
11046 .code = R"NKSP_CODE(
11047 on init
11048 exit( tan(0.0ms) )
11049 end on
11050 )NKSP_CODE",
11051 .expectRealExitResult = 0.0,
11052 .expectExitResultUnitPrefix = { VM_MILLI },
11053 .expectExitResultUnit = VM_SECOND
11054 });
11055
11056 runScript({
11057 .code = R"NKSP_CODE(
11058 on init
11059 exit( tan(0.0kHz) )
11060 end on
11061 )NKSP_CODE",
11062 .expectRealExitResult = 0.0,
11063 .expectExitResultUnitPrefix = { VM_KILO },
11064 .expectExitResultUnit = VM_HERTZ
11065 });
11066
11067 // 'final' ('!') operator tests ...
11068
11069 runScript({
11070 .code = R"NKSP_CODE(
11071 on init
11072 exit( tan(0.0) )
11073 end on
11074 )NKSP_CODE",
11075 .expectRealExitResult = 0.0,
11076 .expectExitResultFinal = false
11077 });
11078
11079 runScript({
11080 .code = R"NKSP_CODE(
11081 on init
11082 exit( tan(!0.0) )
11083 end on
11084 )NKSP_CODE",
11085 .expectRealExitResult = 0.0,
11086 .expectExitResultFinal = true
11087 });
11088
11089 #if !SILENT_TEST
11090 std::cout << std::endl;
11091 #endif
11092 }
11093
11094 static void testBuiltInAsinFunction() {
11095 #if !SILENT_TEST
11096 std::cout << "UNIT TEST: built-in asin() function\n";
11097 #endif
11098
11099 // integer tests ...
11100 // (ATM not allowed for this function)
11101
11102 runScript({
11103 .code = R"NKSP_CODE(
11104 on init
11105 declare $foo := 1
11106 exit( asin($foo) )
11107 end on
11108 )NKSP_CODE",
11109 .expectParseError = true // integer not allowed for this function ATM
11110 });
11111
11112 // real number tests ...
11113
11114 runScript({
11115 .code = R"NKSP_CODE(
11116 on init
11117 exit( asin(0.0) )
11118 end on
11119 )NKSP_CODE",
11120 .expectRealExitResult = 0.0
11121 });
11122
11123 runScript({
11124 .code = R"NKSP_CODE(
11125 on init
11126 exit( asin(1.0) )
11127 end on
11128 )NKSP_CODE",
11129 .expectRealExitResult = 0.5 * M_PI
11130 });
11131
11132 runScript({
11133 .code = R"NKSP_CODE(
11134 on init
11135 exit( asin(-1.0) )
11136 end on
11137 )NKSP_CODE",
11138 .expectRealExitResult = -0.5 * M_PI
11139 });
11140
11141 // std unit tests ...
11142
11143 runScript({
11144 .code = R"NKSP_CODE(
11145 on init
11146 exit( asin(0.0ms) )
11147 end on
11148 )NKSP_CODE",
11149 .expectRealExitResult = 0.0,
11150 .expectExitResultUnitPrefix = { VM_MILLI },
11151 .expectExitResultUnit = VM_SECOND
11152 });
11153
11154 runScript({
11155 .code = R"NKSP_CODE(
11156 on init
11157 exit( asin(0.0kHz) )
11158 end on
11159 )NKSP_CODE",
11160 .expectRealExitResult = 0.0,
11161 .expectExitResultUnitPrefix = { VM_KILO },
11162 .expectExitResultUnit = VM_HERTZ
11163 });
11164
11165 // 'final' ('!') operator tests ...
11166
11167 runScript({
11168 .code = R"NKSP_CODE(
11169 on init
11170 exit( asin(0.0) )
11171 end on
11172 )NKSP_CODE",
11173 .expectRealExitResult = 0.0,
11174 .expectExitResultFinal = false
11175 });
11176
11177 runScript({
11178 .code = R"NKSP_CODE(
11179 on init
11180 exit( asin(!0.0) )
11181 end on
11182 )NKSP_CODE",
11183 .expectRealExitResult = 0.0,
11184 .expectExitResultFinal = true
11185 });
11186
11187 #if !SILENT_TEST
11188 std::cout << std::endl;
11189 #endif
11190 }
11191
11192 static void testBuiltInAcosFunction() {
11193 #if !SILENT_TEST
11194 std::cout << "UNIT TEST: built-in acos() function\n";
11195 #endif
11196
11197 // integer tests ...
11198 // (ATM not allowed for this function)
11199
11200 runScript({
11201 .code = R"NKSP_CODE(
11202 on init
11203 declare $foo := 1
11204 exit( acos($foo) )
11205 end on
11206 )NKSP_CODE",
11207 .expectParseError = true // integer not allowed for this function ATM
11208 });
11209
11210 // real number tests ...
11211
11212 runScript({
11213 .code = R"NKSP_CODE(
11214 on init
11215 exit( acos(1.0) )
11216 end on
11217 )NKSP_CODE",
11218 .expectRealExitResult = 0.0
11219 });
11220
11221 runScript({
11222 .code = R"NKSP_CODE(
11223 on init
11224 exit( acos(0.0) )
11225 end on
11226 )NKSP_CODE",
11227 .expectRealExitResult = 0.5 * M_PI
11228 });
11229
11230 runScript({
11231 .code = R"NKSP_CODE(
11232 on init
11233 exit( acos(-1.0) )
11234 end on
11235 )NKSP_CODE",
11236 .expectRealExitResult = M_PI
11237 });
11238
11239 // std unit tests ...
11240
11241 runScript({
11242 .code = R"NKSP_CODE(
11243 on init
11244 exit( acos(1.0ms) )
11245 end on
11246 )NKSP_CODE",
11247 .expectRealExitResult = 0.0,
11248 .expectExitResultUnitPrefix = { VM_MILLI },
11249 .expectExitResultUnit = VM_SECOND
11250 });
11251
11252 runScript({
11253 .code = R"NKSP_CODE(
11254 on init
11255 exit( acos(1.0kHz) )
11256 end on
11257 )NKSP_CODE",
11258 .expectRealExitResult = 0.0,
11259 .expectExitResultUnitPrefix = { VM_KILO },
11260 .expectExitResultUnit = VM_HERTZ
11261 });
11262
11263 // 'final' ('!') operator tests ...
11264
11265 runScript({
11266 .code = R"NKSP_CODE(
11267 on init
11268 exit( acos(1.0) )
11269 end on
11270 )NKSP_CODE",
11271 .expectRealExitResult = 0.0,
11272 .expectExitResultFinal = false
11273 });
11274
11275 runScript({
11276 .code = R"NKSP_CODE(
11277 on init
11278 exit( acos(!1.0) )
11279 end on
11280 )NKSP_CODE",
11281 .expectRealExitResult = 0.0,
11282 .expectExitResultFinal = true
11283 });
11284
11285 #if !SILENT_TEST
11286 std::cout << std::endl;
11287 #endif
11288 }
11289
11290 static void testBuiltInAtanFunction() {
11291 #if !SILENT_TEST
11292 std::cout << "UNIT TEST: built-in atan() function\n";
11293 #endif
11294
11295 // integer tests ...
11296 // (ATM not allowed for this function)
11297
11298 runScript({
11299 .code = R"NKSP_CODE(
11300 on init
11301 declare $foo := 1
11302 exit( atan($foo) )
11303 end on
11304 )NKSP_CODE",
11305 .expectParseError = true // integer not allowed for this function ATM
11306 });
11307
11308 // real number tests ...
11309
11310 runScript({
11311 .code = R"NKSP_CODE(
11312 on init
11313 exit( atan(0.0) )
11314 end on
11315 )NKSP_CODE",
11316 .expectRealExitResult = 0.0
11317 });
11318
11319 runScript({
11320 .code = R"NKSP_CODE(
11321 on init
11322 exit( atan(1.0) )
11323 end on
11324 )NKSP_CODE",
11325 .expectRealExitResult = 0.25 * M_PI
11326 });
11327
11328 // std unit tests ...
11329
11330 runScript({
11331 .code = R"NKSP_CODE(
11332 on init
11333 exit( atan(0.0ms) )
11334 end on
11335 )NKSP_CODE",
11336 .expectRealExitResult = 0.0,
11337 .expectExitResultUnitPrefix = { VM_MILLI },
11338 .expectExitResultUnit = VM_SECOND
11339 });
11340
11341 runScript({
11342 .code = R"NKSP_CODE(
11343 on init
11344 exit( atan(0.0kHz) )
11345 end on
11346 )NKSP_CODE",
11347 .expectRealExitResult = 0.0,
11348 .expectExitResultUnitPrefix = { VM_KILO },
11349 .expectExitResultUnit = VM_HERTZ
11350 });
11351
11352 // 'final' ('!') operator tests ...
11353
11354 runScript({
11355 .code = R"NKSP_CODE(
11356 on init
11357 exit( atan(0.0) )
11358 end on
11359 )NKSP_CODE",
11360 .expectRealExitResult = 0.0,
11361 .expectExitResultFinal = false
11362 });
11363
11364 runScript({
11365 .code = R"NKSP_CODE(
11366 on init
11367 exit( atan(!0.0) )
11368 end on
11369 )NKSP_CODE",
11370 .expectRealExitResult = 0.0,
11371 .expectExitResultFinal = true
11372 });
11373
11374 #if !SILENT_TEST
11375 std::cout << std::endl;
11376 #endif
11377 }
11378
11379 static void testBuiltInNumElementsFunction() {
11380 #if !SILENT_TEST
11381 std::cout << "UNIT TEST: built-in num_elements() function\n";
11382 #endif
11383
11384 // integer array tests ...
11385
11386 runScript({
11387 .code = R"NKSP_CODE(
11388 on init
11389 declare %foo[3] := ( 19, 3, 6 )
11390 exit( num_elements(%foo) )
11391 end on
11392 )NKSP_CODE",
11393 .expectIntExitResult = 3
11394 });
11395
11396 runScript({
11397 .code = R"NKSP_CODE(
11398 on init
11399 declare %foo[1] := ( 19 )
11400 exit( num_elements(%foo) )
11401 end on
11402 )NKSP_CODE",
11403 .expectIntExitResult = 1
11404 });
11405
11406 runScript({
11407 .code = R"NKSP_CODE(
11408 on init
11409 declare %foo[5] := ( 1, 2, 3, 4, 5 )
11410 exit( num_elements(%foo) )
11411 end on
11412 )NKSP_CODE",
11413 .expectIntExitResult = 5
11414 });
11415
11416 // real array tests ...
11417
11418 runScript({
11419 .code = R"NKSP_CODE(
11420 on init
11421 declare ?foo[3] := ( 19.0, 3.2, 6.5 )
11422 exit( num_elements(?foo) )
11423 end on
11424 )NKSP_CODE",
11425 .expectIntExitResult = 3
11426 });
11427
11428 runScript({
11429 .code = R"NKSP_CODE(
11430 on init
11431 declare ?foo[1] := ( 19.0 )
11432 exit( num_elements(?foo) )
11433 end on
11434 )NKSP_CODE",
11435 .expectIntExitResult = 1
11436 });
11437
11438 runScript({
11439 .code = R"NKSP_CODE(
11440 on init
11441 declare ?foo[5] := ( 1.1, 2.2, 3.3, 4.4, 5.5 )
11442 exit( num_elements(?foo) )
11443 end on
11444 )NKSP_CODE",
11445 .expectIntExitResult = 5
11446 });
11447
11448 #if !SILENT_TEST
11449 std::cout << std::endl;
11450 #endif
11451 }
11452
11453 static void testBuiltInSearchFunction() {
11454 #if !SILENT_TEST
11455 std::cout << "UNIT TEST: built-in search() function\n";
11456 #endif
11457
11458 // integer array tests ...
11459
11460 runScript({
11461 .code = R"NKSP_CODE(
11462 on init
11463 declare %foo[3] := ( 19, 3, 6 )
11464 exit( search(%foo, 19) )
11465 end on
11466 )NKSP_CODE",
11467 .expectIntExitResult = 0
11468 });
11469
11470 runScript({
11471 .code = R"NKSP_CODE(
11472 on init
11473 declare %foo[3] := ( 19, 3, 6 )
11474 exit( search(%foo, 3) )
11475 end on
11476 )NKSP_CODE",
11477 .expectIntExitResult = 1
11478 });
11479
11480 runScript({
11481 .code = R"NKSP_CODE(
11482 on init
11483 declare %foo[3] := ( 19, 3, 6 )
11484 exit( search(%foo, 6) )
11485 end on
11486 )NKSP_CODE",
11487 .expectIntExitResult = 2
11488 });
11489
11490 runScript({
11491 .code = R"NKSP_CODE(
11492 on init
11493 declare %foo[3] := ( 19, 3, 6 )
11494 exit( search(%foo, 2) )
11495 end on
11496 )NKSP_CODE",
11497 .expectIntExitResult = -1
11498 });
11499
11500 // real array tests ...
11501
11502 runScript({
11503 .code = R"NKSP_CODE(
11504 on init
11505 declare ?foo[3] := ( 19.12, 3.45, 6.89 )
11506 exit( search(?foo, 19.12) )
11507 end on
11508 )NKSP_CODE",
11509 .expectIntExitResult = 0
11510 });
11511
11512 runScript({
11513 .code = R"NKSP_CODE(
11514 on init
11515 declare ?foo[3] := ( 19.12, 3.45, 6.89 )
11516 exit( search(?foo, 3.45) )
11517 end on
11518 )NKSP_CODE",
11519 .expectIntExitResult = 1
11520 });
11521
11522 runScript({
11523 .code = R"NKSP_CODE(
11524 on init
11525 declare ?foo[3] := ( 19.12, 3.45, 6.89 )
11526 exit( search(?foo, 6.89) )
11527 end on
11528 )NKSP_CODE",
11529 .expectIntExitResult = 2
11530 });
11531
11532 runScript({
11533 .code = R"NKSP_CODE(
11534 on init
11535 declare ?foo[3] := ( 19.12, 3.45, 6.89 )
11536 exit( search(?foo, 6.99) )
11537 end on
11538 )NKSP_CODE",
11539 .expectIntExitResult = -1
11540 });
11541
11542 #if !SILENT_TEST
11543 std::cout << std::endl;
11544 #endif
11545 }
11546
11547 static void testIfStatement() {
11548 #if !SILENT_TEST
11549 std::cout << "UNIT TEST: if statement\n";
11550 #endif
11551
11552 runScript({
11553 .code = R"NKSP_CODE(
11554 on init
11555 declare $foo := 1
11556 if ($foo)
11557 exit(42)
11558 end if
11559 end on
11560 )NKSP_CODE",
11561 .expectIntExitResult = 42
11562 });
11563
11564 runScript({
11565 .code = R"NKSP_CODE(
11566 on init
11567 declare $foo := 0
11568 if ($foo)
11569 exit(42)
11570 end if
11571 exit(3)
11572 end on
11573 )NKSP_CODE",
11574 .expectIntExitResult = 3
11575 });
11576
11577 runScript({
11578 .code = R"NKSP_CODE(
11579 on init
11580 declare $foo := 1
11581 if ($foo)
11582 exit(42)
11583 else
11584 exit(3)
11585 end if
11586 end on
11587 )NKSP_CODE",
11588 .expectIntExitResult = 42
11589 });
11590
11591 runScript({
11592 .code = R"NKSP_CODE(
11593 on init
11594 declare $foo := 0
11595 if ($foo)
11596 exit(42)
11597 else
11598 exit(3)
11599 end if
11600 end on
11601 )NKSP_CODE",
11602 .expectIntExitResult = 3
11603 });
11604
11605 #if !SILENT_TEST
11606 std::cout << std::endl;
11607 #endif
11608 }
11609
11610 static void testWhileStatement() {
11611 #if !SILENT_TEST
11612 std::cout << "UNIT TEST: while statement\n";
11613 #endif
11614
11615 runScript({
11616 .code = R"NKSP_CODE(
11617 on init
11618 declare $foo := 100
11619 declare $i := 50
11620 while ($i)
11621 $foo := $foo + 1
11622 $i := $i - 1
11623 end while
11624 exit($foo)
11625 end on
11626 )NKSP_CODE",
11627 .expectIntExitResult = 150
11628 });
11629
11630 #if !SILENT_TEST
11631 std::cout << std::endl;
11632 #endif
11633 }
11634
11635 static void testBuiltInVars() {
11636 #if !SILENT_TEST
11637 std::cout << "UNIT TEST: built-in variables\n";
11638 #endif
11639
11640 runScript({
11641 .code = R"NKSP_CODE(
11642 on init
11643 exit($NKSP_PERF_TIMER)
11644 end on
11645 )NKSP_CODE",
11646 .expectExitResultIsInt = true,
11647 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11648 .expectExitResultUnit = VM_NO_UNIT
11649 });
11650
11651 runScript({
11652 .code = R"NKSP_CODE(
11653 on init
11654 exit($NKSP_REAL_TIMER)
11655 end on
11656 )NKSP_CODE",
11657 .expectExitResultIsInt = true,
11658 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11659 .expectExitResultUnit = VM_NO_UNIT
11660 });
11661
11662 runScript({
11663 .code = R"NKSP_CODE(
11664 on init
11665 exit($KSP_TIMER)
11666 end on
11667 )NKSP_CODE",
11668 .expectExitResultIsInt = true,
11669 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11670 .expectExitResultUnit = VM_NO_UNIT
11671 });
11672
11673 runScript({
11674 .code = R"NKSP_CODE(
11675 on init
11676 exit(~NI_MATH_PI)
11677 end on
11678 )NKSP_CODE",
11679 .expectExitResultIsReal = true,
11680 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11681 .expectExitResultUnit = VM_NO_UNIT
11682 });
11683
11684 runScript({
11685 .code = R"NKSP_CODE(
11686 on init
11687 exit(~NI_MATH_E)
11688 end on
11689 )NKSP_CODE",
11690 .expectExitResultIsReal = true,
11691 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11692 .expectExitResultUnit = VM_NO_UNIT
11693 });
11694
11695 runScript({
11696 .code = R"NKSP_CODE(
11697 on init
11698 exit($NI_CB_TYPE_INIT)
11699 end on
11700 )NKSP_CODE",
11701 .expectIntExitResult = VM_EVENT_HANDLER_INIT,
11702 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11703 .expectExitResultUnit = VM_NO_UNIT
11704 });
11705
11706 runScript({
11707 .code = R"NKSP_CODE(
11708 on init
11709 exit($NI_CB_TYPE_NOTE)
11710 end on
11711 )NKSP_CODE",
11712 .expectIntExitResult = VM_EVENT_HANDLER_NOTE,
11713 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11714 .expectExitResultUnit = VM_NO_UNIT
11715 });
11716
11717 runScript({
11718 .code = R"NKSP_CODE(
11719 on init
11720 exit($NI_CB_TYPE_RELEASE)
11721 end on
11722 )NKSP_CODE",
11723 .expectIntExitResult = VM_EVENT_HANDLER_RELEASE,
11724 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11725 .expectExitResultUnit = VM_NO_UNIT
11726 });
11727
11728 runScript({
11729 .code = R"NKSP_CODE(
11730 on init
11731 exit($NI_CB_TYPE_CONTROLLER)
11732 end on
11733 )NKSP_CODE",
11734 .expectIntExitResult = VM_EVENT_HANDLER_CONTROLLER,
11735 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11736 .expectExitResultUnit = VM_NO_UNIT
11737 });
11738
11739 runScript({
11740 .code = R"NKSP_CODE(
11741 on init
11742 exit($NI_CB_TYPE_RPN)
11743 end on
11744 )NKSP_CODE",
11745 .expectIntExitResult = VM_EVENT_HANDLER_RPN,
11746 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11747 .expectExitResultUnit = VM_NO_UNIT
11748 });
11749
11750 runScript({
11751 .code = R"NKSP_CODE(
11752 on init
11753 exit($NI_CB_TYPE_NRPN)
11754 end on
11755 )NKSP_CODE",
11756 .expectIntExitResult = VM_EVENT_HANDLER_NRPN,
11757 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11758 .expectExitResultUnit = VM_NO_UNIT
11759 });
11760
11761 #if !SILENT_TEST
11762 std::cout << std::endl;
11763 #endif
11764 }
11765
11766 #if !NO_MAIN
11767
11768 int main() {
11769 testBuiltInExitFunction();
11770 testStringConcatOperator();
11771 testNegOperator();
11772 testPlusOperator();
11773 testMinusOperator();
11774 testModuloOperator();
11775 testMultiplyOperator();
11776 testDivideOperator();
11777 testSmallerThanOperator();
11778 testGreaterThanOperator();
11779 testSmallerOrEqualOperator();
11780 testGreaterOrEqualOperator();
11781 testEqualOperator();
11782 testUnequalOperator();
11783 testLogicalAndOperator();
11784 testLogicalOrOperator();
11785 testLogicalNotOperator();
11786 testBitwiseAndOperator();
11787 testBitwiseOrOperator();
11788 testBitwiseNotOperator();
11789 testPrecedenceOfOperators();
11790 testIntVarDeclaration();
11791 testIntArrayVarDeclaration();
11792 testRealVarDeclaration();
11793 testRealArrayVarDeclaration();
11794 testStringVarDeclaration();
11795 testBuiltInMinFunction();
11796 testBuiltInMaxFunction();
11797 testBuiltInAbsFunction();
11798 testBuiltInIncFunction();
11799 testBuiltInDecFunction();
11800 testBuiltInInRangeFunction();
11801 testBuiltInRandomFunction();
11802 testBuiltInShiftLeftFunction();
11803 testBuiltInShiftRightFunction();
11804 testBuiltInMsbFunction();
11805 testBuiltInLsbFunction();
11806 testBuiltInIntToRealFunction();
11807 testBuiltInRealFunction();
11808 testBuiltInRealToIntFunction();
11809 testBuiltInIntFunction();
11810 testBuiltInRoundFunction();
11811 testBuiltInCeilFunction();
11812 testBuiltInFloorFunction();
11813 testBuiltInSqrtFunction();
11814 testBuiltInLogFunction();
11815 testBuiltInLog2Function();
11816 testBuiltInLog10Function();
11817 testBuiltInExpFunction();
11818 testBuiltInPowFunction();
11819 testBuiltInSinFunction();
11820 testBuiltInCosFunction();
11821 testBuiltInTanFunction();
11822 testBuiltInAsinFunction();
11823 testBuiltInAcosFunction();
11824 testBuiltInAtanFunction();
11825 testBuiltInArrayEqualFunction();
11826 testBuiltInSortFunction();
11827 testBuiltInNumElementsFunction();
11828 testBuiltInSearchFunction();
11829 testIfStatement();
11830 testWhileStatement();
11831 testBuiltInVars();
11832 std::cout << "\nAll tests passed successfully. :-)\n";
11833 return 0;
11834 }
11835
11836 #endif // !NO_MAIN

  ViewVC Help
Powered by ViewVC