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

Diff of /linuxsampler/trunk/src/scriptvm/tests/NKSPTest.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3577 by schoenebeck, Wed Aug 28 15:23:23 2019 UTC revision 3586 by schoenebeck, Fri Aug 30 18:59:21 2019 UTC
# Line 31  using namespace std; Line 31  using namespace std;
31  struct RunScriptOpt {  struct RunScriptOpt {
32      String code;      String code;
33      bool expectParseError;      bool expectParseError;
34        bool expectParseWarning;
35      bool expectRuntimeError;      bool expectRuntimeError;
36      bool expectNoExitResult;      bool expectNoExitResult;
37        bool expectExitResultIsInt;
38        bool expectExitResultIsReal;
39      bool prohibitExitFunctionArguments;      bool prohibitExitFunctionArguments;
40      optional<vmint> expectIntExitResult;      optional<vmint> expectIntExitResult;
41      optional<bool> expectBoolExitResult;      optional<bool> expectBoolExitResult;
42      optional<vmfloat> expectRealExitResult;      optional<vmfloat> expectRealExitResult;
43      optional<String> expectStringExitResult;      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) {  static void runScript(const RunScriptOpt& opt) {
# Line 49  static void runScript(const RunScriptOpt Line 55  static void runScript(const RunScriptOpt
55          vm.loadScript(opt.code)          vm.loadScript(opt.code)
56      );      );
57      vector<ParserIssue> errors = parserCtx->errors();      vector<ParserIssue> errors = parserCtx->errors();
58        vector<ParserIssue> warnings = parserCtx->warnings();
59      if (opt.expectParseError) {      if (opt.expectParseError) {
60          TEST_ASSERT(!errors.empty());          TEST_ASSERT(!errors.empty());
61          return;          return;
# Line 58  static void runScript(const RunScriptOpt Line 65  static void runScript(const RunScriptOpt
65          }          }
66          TEST_ASSERT(errors.empty());          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));      TEST_ASSERT(parserCtx->eventHandler(0));
76      unique_ptr<VMExecContext> execCtx(      unique_ptr<VMExecContext> execCtx(
77          vm.createExecContext(&*parserCtx)          vm.createExecContext(&*parserCtx)
# Line 74  static void runScript(const RunScriptOpt Line 88  static void runScript(const RunScriptOpt
88              VMExpr* resExpr = execCtx->exitResult();              VMExpr* resExpr = execCtx->exitResult();
89              TEST_ASSERT(!resExpr);              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) {          if (opt.expectIntExitResult) {
102              VMExpr* resExpr = execCtx->exitResult();              VMExpr* resExpr = execCtx->exitResult();
103              TEST_ASSERT(resExpr);              TEST_ASSERT(resExpr);
# Line 102  static void runScript(const RunScriptOpt Line 126  static void runScript(const RunScriptOpt
126              TEST_ASSERT(resExpr->exprType() == STRING_EXPR);              TEST_ASSERT(resExpr->exprType() == STRING_EXPR);
127              TEST_ASSERT(resExpr->asString()->evalStr() == *opt.expectStringExitResult);              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    
# Line 231  end on Line 285  end on
285          .expectRealExitResult = 6.9          .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      #if !SILENT_TEST
1010      std::cout << std::endl;      std::cout << std::endl;
1011      #endif      #endif
# Line 241  static void testStringConcatOperator() { Line 1016  static void testStringConcatOperator() {
1016      std::cout << "UNIT TEST: string concatenation (&) operator\n";      std::cout << "UNIT TEST: string concatenation (&) operator\n";
1017      #endif      #endif
1018    
1019        // strings only tests ...
1020    
1021      runScript({      runScript({
1022          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
1023  on init  on init
# Line 251  end on Line 1028  end on
1028          .expectStringExitResult = "foo bar"          .expectStringExitResult = "foo bar"
1029      });      });
1030    
1031        // integer tests ...
1032    
1033      runScript({      runScript({
1034          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
1035  on init  on init
# Line 272  end on Line 1051  end on
1051          .expectStringExitResult = "foo bar 123"          .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      #if !SILENT_TEST
1168      std::cout << std::endl;      std::cout << std::endl;
1169      #endif      #endif
# Line 324  end on Line 1216  end on
1216          .expectRealExitResult = 99.3          .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      #if !SILENT_TEST      #if !SILENT_TEST
1258      std::cout << std::endl;      std::cout << std::endl;
1259      #endif      #endif
# Line 392  end on Line 1322  end on
1322          .expectRealExitResult = -1.8          .expectRealExitResult = -1.8
1323      });      });
1324    
1325        // std unit tests ...
1326    
1327        runScript({
1328            .code = R"NKSP_CODE(
1329    on init
1330      exit(42ms + 145ms)
1331    end on
1332    )NKSP_CODE",
1333            .expectIntExitResult = 187,
1334            .expectExitResultUnitPrefix = { VM_MILLI },
1335            .expectExitResultUnit = VM_SECOND
1336        });
1337    
1338        runScript({
1339            .code = R"NKSP_CODE(
1340    on init
1341      exit(1s + 145ms)
1342    end on
1343    )NKSP_CODE",
1344            .expectIntExitResult = 1145,
1345            .expectExitResultUnitPrefix = { VM_MILLI },
1346            .expectExitResultUnit = VM_SECOND
1347        });
1348    
1349        runScript({
1350            .code = R"NKSP_CODE(
1351    on init
1352      exit(42ms + 145)
1353    end on
1354    )NKSP_CODE",
1355            .expectParseError = true // units must match for + operator
1356        });
1357    
1358        runScript({
1359            .code = R"NKSP_CODE(
1360    on init
1361      exit(42 + 145ms)
1362    end on
1363    )NKSP_CODE",
1364            .expectParseError = true // units must match for + operator
1365        });
1366    
1367        runScript({
1368            .code = R"NKSP_CODE(
1369    on init
1370      exit(42Hz + 145s)
1371    end on
1372    )NKSP_CODE",
1373            .expectParseError = true // units must match for + operator
1374        });
1375    
1376        runScript({
1377            .code = R"NKSP_CODE(
1378    on init
1379      exit(42.1ms + 145.3ms)
1380    end on
1381    )NKSP_CODE",
1382            .expectRealExitResult = 187.4,
1383            .expectExitResultUnitPrefix = { VM_MILLI },
1384            .expectExitResultUnit = VM_SECOND
1385        });
1386    
1387        runScript({
1388            .code = R"NKSP_CODE(
1389    on init
1390      exit(1.1s + 145.0ms)
1391    end on
1392    )NKSP_CODE",
1393            .expectRealExitResult = 1245.0,
1394            .expectExitResultUnitPrefix = { VM_MILLI },
1395            .expectExitResultUnit = VM_SECOND
1396        });
1397    
1398        runScript({
1399            .code = R"NKSP_CODE(
1400    on init
1401      exit(42.1ms + 145.3)
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(42.0 + 145.0ms)
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.0Hz + 145.0s)
1420    end on
1421    )NKSP_CODE",
1422            .expectParseError = true // units must match for + operator
1423        });
1424    
1425        // 'final' ('!') operator tests ...
1426    
1427        runScript({
1428            .code = R"NKSP_CODE(
1429    on init
1430      exit(!4 + !3)
1431    end on
1432    )NKSP_CODE",
1433            .expectIntExitResult = 7,
1434            .expectExitResultFinal = true
1435        });
1436    
1437        runScript({
1438            .code = R"NKSP_CODE(
1439    on init
1440      exit(4 + 3)
1441    end on
1442    )NKSP_CODE",
1443            .expectIntExitResult = 7,
1444            .expectExitResultFinal = false
1445        });
1446    
1447        runScript({
1448            .code = R"NKSP_CODE(
1449    on init
1450      exit(!4.1 + !3.3)
1451    end on
1452    )NKSP_CODE",
1453            .expectRealExitResult = 7.4,
1454            .expectExitResultFinal = true
1455        });
1456    
1457        runScript({
1458            .code = R"NKSP_CODE(
1459    on init
1460      exit(4.1 + 3.3)
1461    end on
1462    )NKSP_CODE",
1463            .expectRealExitResult = 7.4,
1464            .expectExitResultFinal = false
1465        });
1466    
1467      #if !SILENT_TEST      #if !SILENT_TEST
1468      std::cout << std::endl;      std::cout << std::endl;
1469      #endif      #endif
# Line 469  end on Line 1541  end on
1541          .expectRealExitResult = -21.1          .expectRealExitResult = -21.1
1542      });      });
1543    
1544        // std unit tests ...
1545    
1546        runScript({
1547            .code = R"NKSP_CODE(
1548    on init
1549      exit(1000ms - 145ms)
1550    end on
1551    )NKSP_CODE",
1552            .expectIntExitResult = 855,
1553            .expectExitResultUnitPrefix = { VM_MILLI },
1554            .expectExitResultUnit = VM_SECOND
1555        });
1556    
1557        runScript({
1558            .code = R"NKSP_CODE(
1559    on init
1560      exit(1s - 145ms)
1561    end on
1562    )NKSP_CODE",
1563            .expectIntExitResult = 855,
1564            .expectExitResultUnitPrefix = { VM_MILLI },
1565            .expectExitResultUnit = VM_SECOND
1566        });
1567    
1568        runScript({
1569            .code = R"NKSP_CODE(
1570    on init
1571      exit(1s - 145)
1572    end on
1573    )NKSP_CODE",
1574            .expectParseError = true // units must match for - operator
1575        });
1576    
1577        runScript({
1578            .code = R"NKSP_CODE(
1579    on init
1580      exit(1 - 145s)
1581    end on
1582    )NKSP_CODE",
1583            .expectParseError = true // units must match for - operator
1584        });
1585    
1586        runScript({
1587            .code = R"NKSP_CODE(
1588    on init
1589      exit(1ms - 145mB)
1590    end on
1591    )NKSP_CODE",
1592            .expectParseError = true // units must match for - operator
1593        });
1594    
1595        runScript({
1596            .code = R"NKSP_CODE(
1597    on init
1598      exit(1.0ms - 0.1ms)
1599    end on
1600    )NKSP_CODE",
1601            .expectRealExitResult = 0.9,
1602            .expectExitResultUnitPrefix = { VM_MILLI },
1603            .expectExitResultUnit = VM_SECOND
1604        });
1605    
1606        runScript({
1607            .code = R"NKSP_CODE(
1608    on init
1609      exit(1.1s - 106.0ms)
1610    end on
1611    )NKSP_CODE",
1612            .expectRealExitResult = 994.0,
1613            .expectExitResultUnitPrefix = { VM_MILLI },
1614            .expectExitResultUnit = VM_SECOND
1615        });
1616    
1617        runScript({
1618            .code = R"NKSP_CODE(
1619    on init
1620      exit(1100.0ms - 0.106s)
1621    end on
1622    )NKSP_CODE",
1623            .expectRealExitResult = 994.0,
1624            .expectExitResultUnitPrefix = { VM_MILLI },
1625            .expectExitResultUnit = VM_SECOND
1626        });
1627    
1628        runScript({
1629            .code = R"NKSP_CODE(
1630    on init
1631      exit(1.0s - 145.0)
1632    end on
1633    )NKSP_CODE",
1634            .expectParseError = true // units must match for - operator
1635        });
1636    
1637        runScript({
1638            .code = R"NKSP_CODE(
1639    on init
1640      exit(1.0 - 145.0s)
1641    end on
1642    )NKSP_CODE",
1643            .expectParseError = true // units must match for - operator
1644        });
1645    
1646        runScript({
1647            .code = R"NKSP_CODE(
1648    on init
1649      exit(1.0ms - 145.0mB)
1650    end on
1651    )NKSP_CODE",
1652            .expectParseError = true // units must match for - operator
1653        });
1654    
1655        // 'final' ('!') operator tests ...
1656    
1657        runScript({
1658            .code = R"NKSP_CODE(
1659    on init
1660      exit(!5 - !3)
1661    end on
1662    )NKSP_CODE",
1663            .expectIntExitResult = 2,
1664            .expectExitResultFinal = true
1665        });
1666    
1667        runScript({
1668            .code = R"NKSP_CODE(
1669    on init
1670      exit(5 - 3)
1671    end on
1672    )NKSP_CODE",
1673            .expectIntExitResult = 2,
1674            .expectExitResultFinal = false
1675        });
1676    
1677        runScript({
1678            .code = R"NKSP_CODE(
1679    on init
1680      exit(!5.9 - !3.3)
1681    end on
1682    )NKSP_CODE",
1683            .expectRealExitResult = 2.6,
1684            .expectExitResultFinal = true
1685        });
1686    
1687        runScript({
1688            .code = R"NKSP_CODE(
1689    on init
1690      exit(5.9 - 3.3)
1691    end on
1692    )NKSP_CODE",
1693            .expectRealExitResult = 2.6,
1694            .expectExitResultFinal = false
1695        });
1696    
1697      #if !SILENT_TEST      #if !SILENT_TEST
1698      std::cout << std::endl;      std::cout << std::endl;
1699      #endif      #endif
# Line 542  end on Line 1767  end on
1767          .expectParseError = true // mod operator prohibits real numbers ATM          .expectParseError = true // mod operator prohibits real numbers ATM
1768      });      });
1769    
1770        // std unit tests ...
1771    
1772        runScript({
1773            .code = R"NKSP_CODE(
1774    on init
1775      exit(10s mod 8)
1776    end on
1777    )NKSP_CODE",
1778            .expectParseError = true // mod operator prohibits std units ATM
1779        });
1780    
1781        runScript({
1782            .code = R"NKSP_CODE(
1783    on init
1784      exit(10 mod 8s)
1785    end on
1786    )NKSP_CODE",
1787            .expectParseError = true // mod operator prohibits std units ATM
1788        });
1789    
1790        runScript({
1791            .code = R"NKSP_CODE(
1792    on init
1793      exit(10s mod 8s)
1794    end on
1795    )NKSP_CODE",
1796            .expectParseError = true // mod operator prohibits std units ATM
1797        });
1798    
1799        // 'final' ('!') operator tests ...
1800    
1801        runScript({
1802            .code = R"NKSP_CODE(
1803    on init
1804      exit(!10 mod !8)
1805    end on
1806    )NKSP_CODE",
1807            .expectIntExitResult = 2,
1808            .expectExitResultFinal = true
1809        });
1810    
1811        runScript({
1812            .code = R"NKSP_CODE(
1813    on init
1814      exit(10 mod 8)
1815    end on
1816    )NKSP_CODE",
1817            .expectIntExitResult = 2,
1818            .expectExitResultFinal = false
1819        });
1820    
1821      #if !SILENT_TEST      #if !SILENT_TEST
1822      std::cout << std::endl;      std::cout << std::endl;
1823      #endif      #endif
# Line 649  end on Line 1925  end on
1925          .expectParseError = true // mixed int * real forbidden ATM          .expectParseError = true // mixed int * real forbidden ATM
1926      });      });
1927    
1928        // std unit tests ...
1929    
1930        runScript({
1931            .code = R"NKSP_CODE(
1932    on init
1933      exit(10ms * 8)
1934    end on
1935    )NKSP_CODE",
1936            .expectIntExitResult = 80,
1937            .expectExitResultUnitPrefix = { VM_MILLI },
1938            .expectExitResultUnit = VM_SECOND
1939        });
1940    
1941        runScript({
1942            .code = R"NKSP_CODE(
1943    on init
1944      exit(10 * 8ms)
1945    end on
1946    )NKSP_CODE",
1947            .expectIntExitResult = 80,
1948            .expectExitResultUnitPrefix = { VM_MILLI },
1949            .expectExitResultUnit = VM_SECOND
1950        });
1951    
1952        runScript({
1953            .code = R"NKSP_CODE(
1954    on init
1955      exit(10s * 8s)
1956    end on
1957    )NKSP_CODE",
1958            .expectParseError = true // units on both sides not allowed for * ATM
1959        });
1960    
1961        runScript({
1962            .code = R"NKSP_CODE(
1963    on init
1964      exit(10cs * 8d)
1965    end on
1966    )NKSP_CODE",
1967            .expectIntExitResult = 80,
1968            .expectExitResultUnitPrefix = { VM_MILLI },
1969            .expectExitResultUnit = VM_SECOND
1970        });
1971    
1972        runScript({
1973            .code = R"NKSP_CODE(
1974    on init
1975      exit(10m * 8ms)
1976    end on
1977    )NKSP_CODE",
1978            .expectIntExitResult = 80,
1979            .expectExitResultUnitPrefix = { VM_MICRO },
1980            .expectExitResultUnit = VM_SECOND
1981        });
1982    
1983        runScript({
1984            .code = R"NKSP_CODE(
1985    on init
1986      exit(10ms * 8k)
1987    end on
1988    )NKSP_CODE",
1989            .expectIntExitResult = 80,
1990            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
1991            .expectExitResultUnit = VM_SECOND
1992        });
1993    
1994        runScript({
1995            .code = R"NKSP_CODE(
1996    on init
1997      exit(10.1ms * 8.0)
1998    end on
1999    )NKSP_CODE",
2000            .expectRealExitResult = 80.8,
2001            .expectExitResultUnitPrefix = { VM_MILLI },
2002            .expectExitResultUnit = VM_SECOND
2003        });
2004    
2005        runScript({
2006            .code = R"NKSP_CODE(
2007    on init
2008      exit(10.1 * 8.0ms)
2009    end on
2010    )NKSP_CODE",
2011            .expectRealExitResult = 80.8,
2012            .expectExitResultUnitPrefix = { VM_MILLI },
2013            .expectExitResultUnit = VM_SECOND
2014        });
2015    
2016        runScript({
2017            .code = R"NKSP_CODE(
2018    on init
2019      exit(10.0s * 8.0s)
2020    end on
2021    )NKSP_CODE",
2022            .expectParseError = true // units on both sides not allowed for * ATM
2023        });
2024    
2025        runScript({
2026            .code = R"NKSP_CODE(
2027    on init
2028      exit(10.1ds * 8.0c)
2029    end on
2030    )NKSP_CODE",
2031            .expectRealExitResult = 80.8,
2032            .expectExitResultUnitPrefix = { VM_MILLI },
2033            .expectExitResultUnit = VM_SECOND
2034        });
2035    
2036        runScript({
2037            .code = R"NKSP_CODE(
2038    on init
2039      exit(10.1m * 8.0ms)
2040    end on
2041    )NKSP_CODE",
2042            .expectRealExitResult = 80.8,
2043            .expectExitResultUnitPrefix = { VM_MICRO },
2044            .expectExitResultUnit = VM_SECOND
2045        });
2046    
2047        runScript({
2048            .code = R"NKSP_CODE(
2049    on init
2050      exit(10.1m * 8.0ks)
2051    end on
2052    )NKSP_CODE",
2053            .expectRealExitResult = 80.8,
2054            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
2055            .expectExitResultUnit = VM_SECOND
2056        });
2057    
2058        // 'final' ('!') operator tests ...
2059    
2060        runScript({
2061            .code = R"NKSP_CODE(
2062    on init
2063      exit(!10 * !8)
2064    end on
2065    )NKSP_CODE",
2066            .expectIntExitResult = 80,
2067            .expectExitResultFinal = true
2068        });
2069    
2070        runScript({
2071            .code = R"NKSP_CODE(
2072    on init
2073      exit(10 * 8)
2074    end on
2075    )NKSP_CODE",
2076            .expectIntExitResult = 80,
2077            .expectExitResultFinal = false
2078        });
2079    
2080        runScript({
2081            .code = R"NKSP_CODE(
2082    on init
2083      exit(!10 * 8)
2084    end on
2085    )NKSP_CODE",
2086            .expectIntExitResult = 80,
2087            .expectExitResultFinal = true,
2088            .expectParseWarning = true // since final only on one side, result will be final though
2089        });
2090    
2091        runScript({
2092            .code = R"NKSP_CODE(
2093    on init
2094      exit(10 * !8)
2095    end on
2096    )NKSP_CODE",
2097            .expectIntExitResult = 80,
2098            .expectExitResultFinal = true,
2099            .expectParseWarning = true // since final only on one side, result will be final though
2100        });
2101    
2102        runScript({
2103            .code = R"NKSP_CODE(
2104    on init
2105      exit(!10.1 * !8.0)
2106    end on
2107    )NKSP_CODE",
2108            .expectRealExitResult = 80.8,
2109            .expectExitResultFinal = true
2110        });
2111    
2112        runScript({
2113            .code = R"NKSP_CODE(
2114    on init
2115      exit(10.1 * 8.0)
2116    end on
2117    )NKSP_CODE",
2118            .expectRealExitResult = 80.8,
2119            .expectExitResultFinal = false
2120        });
2121    
2122        runScript({
2123            .code = R"NKSP_CODE(
2124    on init
2125      exit(!10.1 * 8.0)
2126    end on
2127    )NKSP_CODE",
2128            .expectRealExitResult = 80.8,
2129            .expectExitResultFinal = true,
2130            .expectParseWarning = true // since final only on one side, result will be final though
2131        });
2132    
2133        runScript({
2134            .code = R"NKSP_CODE(
2135    on init
2136      exit(10.1 * !8.0)
2137    end on
2138    )NKSP_CODE",
2139            .expectRealExitResult = 80.8,
2140            .expectExitResultFinal = true,
2141            .expectParseWarning = true // since final only on one side, result will be final though
2142        });
2143    
2144      #if !SILENT_TEST      #if !SILENT_TEST
2145      std::cout << std::endl;      std::cout << std::endl;
2146      #endif      #endif
# Line 756  end on Line 2248  end on
2248          .expectParseError = true // mixed int / real forbidden ATM          .expectParseError = true // mixed int / real forbidden ATM
2249      });      });
2250    
2251        // std unit tests ...
2252    
2253        runScript({
2254            .code = R"NKSP_CODE(
2255    on init
2256      exit(-27us / 3)
2257    end on
2258    )NKSP_CODE",
2259            .expectIntExitResult = -9,
2260            .expectExitResultUnitPrefix = { VM_MICRO },
2261            .expectExitResultUnit = VM_SECOND
2262        });
2263    
2264        runScript({
2265            .code = R"NKSP_CODE(
2266    on init
2267      exit(-27mdB / 3mdB)
2268    end on
2269    )NKSP_CODE",
2270            .expectIntExitResult = -9,
2271            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
2272            .expectExitResultUnit = VM_NO_UNIT
2273        });
2274    
2275        runScript({
2276            .code = R"NKSP_CODE(
2277    on init
2278      exit(-27s / 3m)
2279    end on
2280    )NKSP_CODE",
2281            .expectIntExitResult = -9,
2282            .expectExitResultUnitPrefix = { VM_KILO },
2283            .expectExitResultUnit = VM_SECOND
2284        });
2285    
2286        runScript({
2287            .code = R"NKSP_CODE(
2288    on init
2289      exit(-27us / 3m)
2290    end on
2291    )NKSP_CODE",
2292            .expectIntExitResult = -9,
2293            .expectExitResultUnitPrefix = { VM_MILLI },
2294            .expectExitResultUnit = VM_SECOND
2295        });
2296    
2297        runScript({
2298            .code = R"NKSP_CODE(
2299    on init
2300      exit(-27 / 3s)
2301    end on
2302    )NKSP_CODE",
2303            .expectParseError = true // illegal unit type arrangement for divisions
2304        });
2305    
2306        runScript({
2307            .code = R"NKSP_CODE(
2308    on init
2309      exit(-27s / 3Hz)
2310    end on
2311    )NKSP_CODE",
2312            .expectParseError = true // unit types are not matching
2313        });
2314    
2315        // 'final' ('!') operator tests ...
2316    
2317        runScript({
2318            .code = R"NKSP_CODE(
2319    on init
2320      exit(!-27 / !3)
2321    end on
2322    )NKSP_CODE",
2323            .expectIntExitResult = -9,
2324            .expectExitResultFinal = true
2325        });
2326    
2327        runScript({
2328            .code = R"NKSP_CODE(
2329    on init
2330      exit(-27 / 3)
2331    end on
2332    )NKSP_CODE",
2333            .expectIntExitResult = -9,
2334            .expectExitResultFinal = false
2335        });
2336    
2337        runScript({
2338            .code = R"NKSP_CODE(
2339    on init
2340      exit(!-27 / 3)
2341    end on
2342    )NKSP_CODE",
2343            .expectIntExitResult = -9,
2344            .expectExitResultFinal = true,
2345            .expectParseWarning = true // final only on one side, result will be final though
2346        });
2347    
2348        runScript({
2349            .code = R"NKSP_CODE(
2350    on init
2351      exit(-27 / !3)
2352    end on
2353    )NKSP_CODE",
2354            .expectIntExitResult = -9,
2355            .expectExitResultFinal = true,
2356            .expectParseWarning = true // final only on one side, result will be final though
2357        });
2358    
2359      #if !SILENT_TEST      #if !SILENT_TEST
2360      std::cout << std::endl;      std::cout << std::endl;
2361      #endif      #endif
# Line 916  end on Line 2516  end on
2516          .expectBoolExitResult = false          .expectBoolExitResult = false
2517      });      });
2518    
2519        // std unit tests ...
2520    
2521        runScript({
2522            .code = R"NKSP_CODE(
2523    on init
2524      exit(13ms < 14ms)
2525    end on
2526    )NKSP_CODE",
2527            .expectBoolExitResult = true
2528        });
2529    
2530        runScript({
2531            .code = R"NKSP_CODE(
2532    on init
2533      exit(14ms < 13ms)
2534    end on
2535    )NKSP_CODE",
2536            .expectBoolExitResult = false
2537        });
2538    
2539        runScript({
2540            .code = R"NKSP_CODE(
2541    on init
2542      exit(1s < 990ms)
2543    end on
2544    )NKSP_CODE",
2545            .expectBoolExitResult = false
2546        });
2547    
2548        runScript({
2549            .code = R"NKSP_CODE(
2550    on init
2551      exit(990ms < 1s)
2552    end on
2553    )NKSP_CODE",
2554            .expectBoolExitResult = true
2555        });
2556    
2557        runScript({
2558            .code = R"NKSP_CODE(
2559    on init
2560      exit(1000ms < 1s)
2561    end on
2562    )NKSP_CODE",
2563            .expectBoolExitResult = false
2564        });
2565    
2566        runScript({
2567            .code = R"NKSP_CODE(
2568    on init
2569      exit(1s < 1000ms)
2570    end on
2571    )NKSP_CODE",
2572            .expectBoolExitResult = false
2573        });
2574    
2575        runScript({
2576            .code = R"NKSP_CODE(
2577    on init
2578      exit(1s < 1)
2579    end on
2580    )NKSP_CODE",
2581            .expectParseError = true // units on both sides must match
2582        });
2583    
2584        runScript({
2585            .code = R"NKSP_CODE(
2586    on init
2587      exit(1 < 1s)
2588    end on
2589    )NKSP_CODE",
2590            .expectParseError = true // units on both sides must match
2591        });
2592    
2593        runScript({
2594            .code = R"NKSP_CODE(
2595    on init
2596      exit(1Hz < 1B)
2597    end on
2598    )NKSP_CODE",
2599            .expectParseError = true // units on both sides must match
2600        });
2601    
2602        runScript({
2603            .code = R"NKSP_CODE(
2604    on init
2605      exit(13.0ms < 13.1ms)
2606    end on
2607    )NKSP_CODE",
2608            .expectBoolExitResult = true
2609        });
2610    
2611        runScript({
2612            .code = R"NKSP_CODE(
2613    on init
2614      exit(13.1ms < 13.0ms)
2615    end on
2616    )NKSP_CODE",
2617            .expectBoolExitResult = false
2618        });
2619    
2620        runScript({
2621            .code = R"NKSP_CODE(
2622    on init
2623      exit(0.9s < 600.0ms)
2624    end on
2625    )NKSP_CODE",
2626            .expectBoolExitResult = false
2627        });
2628    
2629        runScript({
2630            .code = R"NKSP_CODE(
2631    on init
2632      exit(600.0ms < 0.9s)
2633    end on
2634    )NKSP_CODE",
2635            .expectBoolExitResult = true
2636        });
2637    
2638        runScript({
2639            .code = R"NKSP_CODE(
2640    on init
2641      exit(5.1kHz < 5100.0Hz)
2642    end on
2643    )NKSP_CODE",
2644            .expectBoolExitResult = false
2645        });
2646    
2647        runScript({
2648            .code = R"NKSP_CODE(
2649    on init
2650      exit(5100.0Hz < 5.1kHz)
2651    end on
2652    )NKSP_CODE",
2653            .expectBoolExitResult = false
2654        });
2655    
2656        runScript({
2657            .code = R"NKSP_CODE(
2658    on init
2659      exit(1.0Hz < 1.1)
2660    end on
2661    )NKSP_CODE",
2662            .expectParseError = true // units on both sides must match
2663        });
2664    
2665        runScript({
2666            .code = R"NKSP_CODE(
2667    on init
2668      exit(1.2 < 1.34mdB)
2669    end on
2670    )NKSP_CODE",
2671            .expectParseError = true // units on both sides must match
2672        });
2673    
2674        runScript({
2675            .code = R"NKSP_CODE(
2676    on init
2677      exit(9.23us < 3.14kHz)
2678    end on
2679    )NKSP_CODE",
2680            .expectParseError = true // units on both sides must match
2681        });
2682    
2683        // 'final' ('!') operator tests ...
2684        // (should always yield in false for relation operators)
2685    
2686        runScript({
2687            .code = R"NKSP_CODE(
2688    on init
2689      exit(!-4 < !3)
2690    end on
2691    )NKSP_CODE",
2692            .expectBoolExitResult = true,
2693            .expectExitResultFinal = false
2694        });
2695    
2696        runScript({
2697            .code = R"NKSP_CODE(
2698    on init
2699      exit(-4 < 3)
2700    end on
2701    )NKSP_CODE",
2702            .expectBoolExitResult = true,
2703            .expectExitResultFinal = false
2704        });
2705    
2706      #if !SILENT_TEST      #if !SILENT_TEST
2707      std::cout << std::endl;      std::cout << std::endl;
2708      #endif      #endif
# Line 1076  end on Line 2863  end on
2863          .expectBoolExitResult = true          .expectBoolExitResult = true
2864      });      });
2865    
2866        // std unit tests ...
2867    
2868        runScript({
2869            .code = R"NKSP_CODE(
2870    on init
2871      exit(13ms > 14ms)
2872    end on
2873    )NKSP_CODE",
2874            .expectBoolExitResult = false
2875        });
2876    
2877        runScript({
2878            .code = R"NKSP_CODE(
2879    on init
2880      exit(14ms > 13ms)
2881    end on
2882    )NKSP_CODE",
2883            .expectBoolExitResult = true
2884        });
2885    
2886        runScript({
2887            .code = R"NKSP_CODE(
2888    on init
2889      exit(1s > 990ms)
2890    end on
2891    )NKSP_CODE",
2892            .expectBoolExitResult = true
2893        });
2894    
2895        runScript({
2896            .code = R"NKSP_CODE(
2897    on init
2898      exit(990ms > 1s)
2899    end on
2900    )NKSP_CODE",
2901            .expectBoolExitResult = false
2902        });
2903    
2904        runScript({
2905            .code = R"NKSP_CODE(
2906    on init
2907      exit(1000ms > 1s)
2908    end on
2909    )NKSP_CODE",
2910            .expectBoolExitResult = false
2911        });
2912    
2913        runScript({
2914            .code = R"NKSP_CODE(
2915    on init
2916      exit(1s > 1000ms)
2917    end on
2918    )NKSP_CODE",
2919            .expectBoolExitResult = false
2920        });
2921    
2922        runScript({
2923            .code = R"NKSP_CODE(
2924    on init
2925      exit(1s > 1)
2926    end on
2927    )NKSP_CODE",
2928            .expectParseError = true // units on both sides must match
2929        });
2930    
2931        runScript({
2932            .code = R"NKSP_CODE(
2933    on init
2934      exit(1 > 1s)
2935    end on
2936    )NKSP_CODE",
2937            .expectParseError = true // units on both sides must match
2938        });
2939    
2940        runScript({
2941            .code = R"NKSP_CODE(
2942    on init
2943      exit(1Hz > 1B)
2944    end on
2945    )NKSP_CODE",
2946            .expectParseError = true // units on both sides must match
2947        });
2948    
2949        runScript({
2950            .code = R"NKSP_CODE(
2951    on init
2952      exit(13.0ms > 13.1ms)
2953    end on
2954    )NKSP_CODE",
2955            .expectBoolExitResult = false
2956        });
2957    
2958        runScript({
2959            .code = R"NKSP_CODE(
2960    on init
2961      exit(13.1ms > 13.0ms)
2962    end on
2963    )NKSP_CODE",
2964            .expectBoolExitResult = true
2965        });
2966    
2967        runScript({
2968            .code = R"NKSP_CODE(
2969    on init
2970      exit(0.9s > 600.0ms)
2971    end on
2972    )NKSP_CODE",
2973            .expectBoolExitResult = true
2974        });
2975    
2976        runScript({
2977            .code = R"NKSP_CODE(
2978    on init
2979      exit(600.0ms > 0.9s)
2980    end on
2981    )NKSP_CODE",
2982            .expectBoolExitResult = false
2983        });
2984    
2985        runScript({
2986            .code = R"NKSP_CODE(
2987    on init
2988      exit(5.1kHz > 5100.0Hz)
2989    end on
2990    )NKSP_CODE",
2991            .expectBoolExitResult = false
2992        });
2993    
2994        runScript({
2995            .code = R"NKSP_CODE(
2996    on init
2997      exit(5100.0Hz > 5.1kHz)
2998    end on
2999    )NKSP_CODE",
3000            .expectBoolExitResult = false
3001        });
3002    
3003        runScript({
3004            .code = R"NKSP_CODE(
3005    on init
3006      exit(1.0Hz > 1.1)
3007    end on
3008    )NKSP_CODE",
3009            .expectParseError = true // units on both sides must match
3010        });
3011    
3012        runScript({
3013            .code = R"NKSP_CODE(
3014    on init
3015      exit(1.2 > 1.34mdB)
3016    end on
3017    )NKSP_CODE",
3018            .expectParseError = true // units on both sides must match
3019        });
3020    
3021        runScript({
3022            .code = R"NKSP_CODE(
3023    on init
3024      exit(9.23us > 3.14kHz)
3025    end on
3026    )NKSP_CODE",
3027            .expectParseError = true // units on both sides must match
3028        });
3029    
3030        // 'final' ('!') operator tests ...
3031        // (should always yield in false for relation operators)
3032    
3033        runScript({
3034            .code = R"NKSP_CODE(
3035    on init
3036      exit(!-4 > !3)
3037    end on
3038    )NKSP_CODE",
3039            .expectBoolExitResult = false,
3040            .expectExitResultFinal = false
3041        });
3042    
3043        runScript({
3044            .code = R"NKSP_CODE(
3045    on init
3046      exit(-4 > 3)
3047    end on
3048    )NKSP_CODE",
3049            .expectBoolExitResult = false,
3050            .expectExitResultFinal = false
3051        });
3052    
3053      #if !SILENT_TEST      #if !SILENT_TEST
3054      std::cout << std::endl;      std::cout << std::endl;
3055      #endif      #endif
# Line 1308  end on Line 3282  end on
3282          .expectBoolExitResult = true          .expectBoolExitResult = true
3283      });      });
3284    
3285        // std unit tests ...
3286    
3287        runScript({
3288            .code = R"NKSP_CODE(
3289    on init
3290      exit(13ms <= 14ms)
3291    end on
3292    )NKSP_CODE",
3293            .expectBoolExitResult = true
3294        });
3295    
3296        runScript({
3297            .code = R"NKSP_CODE(
3298    on init
3299      exit(14ms <= 13ms)
3300    end on
3301    )NKSP_CODE",
3302            .expectBoolExitResult = false
3303        });
3304    
3305        runScript({
3306            .code = R"NKSP_CODE(
3307    on init
3308      exit(1s <= 990ms)
3309    end on
3310    )NKSP_CODE",
3311            .expectBoolExitResult = false
3312        });
3313    
3314        runScript({
3315            .code = R"NKSP_CODE(
3316    on init
3317      exit(990ms <= 1s)
3318    end on
3319    )NKSP_CODE",
3320            .expectBoolExitResult = true
3321        });
3322    
3323        runScript({
3324            .code = R"NKSP_CODE(
3325    on init
3326      exit(1000ms <= 1s)
3327    end on
3328    )NKSP_CODE",
3329            .expectBoolExitResult = true
3330        });
3331    
3332        runScript({
3333            .code = R"NKSP_CODE(
3334    on init
3335      exit(1s <= 1000ms)
3336    end on
3337    )NKSP_CODE",
3338            .expectBoolExitResult = true
3339        });
3340    
3341        runScript({
3342            .code = R"NKSP_CODE(
3343    on init
3344      exit(1s <= 1)
3345    end on
3346    )NKSP_CODE",
3347            .expectParseError = true // units on both sides must match
3348        });
3349    
3350        runScript({
3351            .code = R"NKSP_CODE(
3352    on init
3353      exit(1 <= 1s)
3354    end on
3355    )NKSP_CODE",
3356            .expectParseError = true // units on both sides must match
3357        });
3358    
3359        runScript({
3360            .code = R"NKSP_CODE(
3361    on init
3362      exit(1Hz <= 1B)
3363    end on
3364    )NKSP_CODE",
3365            .expectParseError = true // units on both sides must match
3366        });
3367    
3368        runScript({
3369            .code = R"NKSP_CODE(
3370    on init
3371      exit(13.0ms <= 13.1ms)
3372    end on
3373    )NKSP_CODE",
3374            .expectBoolExitResult = true
3375        });
3376    
3377        runScript({
3378            .code = R"NKSP_CODE(
3379    on init
3380      exit(13.1ms <= 13.0ms)
3381    end on
3382    )NKSP_CODE",
3383            .expectBoolExitResult = false
3384        });
3385    
3386        runScript({
3387            .code = R"NKSP_CODE(
3388    on init
3389      exit(0.9s <= 600.0ms)
3390    end on
3391    )NKSP_CODE",
3392            .expectBoolExitResult = false
3393        });
3394    
3395        runScript({
3396            .code = R"NKSP_CODE(
3397    on init
3398      exit(600.0ms <= 0.9s)
3399    end on
3400    )NKSP_CODE",
3401            .expectBoolExitResult = true
3402        });
3403    
3404        runScript({
3405            .code = R"NKSP_CODE(
3406    on init
3407      exit(5.1kHz <= 5100.0Hz)
3408    end on
3409    )NKSP_CODE",
3410            .expectBoolExitResult = true
3411        });
3412    
3413        runScript({
3414            .code = R"NKSP_CODE(
3415    on init
3416      exit(5100.0Hz <= 5.1kHz)
3417    end on
3418    )NKSP_CODE",
3419            .expectBoolExitResult = true
3420        });
3421    
3422        runScript({
3423            .code = R"NKSP_CODE(
3424    on init
3425      exit(1.0Hz <= 1.1)
3426    end on
3427    )NKSP_CODE",
3428            .expectParseError = true // units on both sides must match
3429        });
3430    
3431        runScript({
3432            .code = R"NKSP_CODE(
3433    on init
3434      exit(1.2 <= 1.34mdB)
3435    end on
3436    )NKSP_CODE",
3437            .expectParseError = true // units on both sides must match
3438        });
3439    
3440        runScript({
3441            .code = R"NKSP_CODE(
3442    on init
3443      exit(9.23us <= 3.14kHz)
3444    end on
3445    )NKSP_CODE",
3446            .expectParseError = true // units on both sides must match
3447        });
3448    
3449        // 'final' ('!') operator tests ...
3450        // (should always yield in false for relation operators)
3451    
3452        runScript({
3453            .code = R"NKSP_CODE(
3454    on init
3455      exit(!-4 <= !3)
3456    end on
3457    )NKSP_CODE",
3458            .expectBoolExitResult = true,
3459            .expectExitResultFinal = false
3460        });
3461    
3462        runScript({
3463            .code = R"NKSP_CODE(
3464    on init
3465      exit(-4 <= 3)
3466    end on
3467    )NKSP_CODE",
3468            .expectBoolExitResult = true,
3469            .expectExitResultFinal = false
3470        });
3471    
3472      #if !SILENT_TEST      #if !SILENT_TEST
3473      std::cout << std::endl;      std::cout << std::endl;
3474      #endif      #endif
# Line 1558  end on Line 3719  end on
3719          .expectBoolExitResult = true          .expectBoolExitResult = true
3720      });      });
3721    
3722        // std unit tests ...
3723    
3724        runScript({
3725            .code = R"NKSP_CODE(
3726    on init
3727      exit(13ms >= 14ms)
3728    end on
3729    )NKSP_CODE",
3730            .expectBoolExitResult = false
3731        });
3732    
3733        runScript({
3734            .code = R"NKSP_CODE(
3735    on init
3736      exit(14ms >= 13ms)
3737    end on
3738    )NKSP_CODE",
3739            .expectBoolExitResult = true
3740        });
3741    
3742        runScript({
3743            .code = R"NKSP_CODE(
3744    on init
3745      exit(1s >= 990ms)
3746    end on
3747    )NKSP_CODE",
3748            .expectBoolExitResult = true
3749        });
3750    
3751        runScript({
3752            .code = R"NKSP_CODE(
3753    on init
3754      exit(990ms >= 1s)
3755    end on
3756    )NKSP_CODE",
3757            .expectBoolExitResult = false
3758        });
3759    
3760        runScript({
3761            .code = R"NKSP_CODE(
3762    on init
3763      exit(1000ms >= 1s)
3764    end on
3765    )NKSP_CODE",
3766            .expectBoolExitResult = true
3767        });
3768    
3769        runScript({
3770            .code = R"NKSP_CODE(
3771    on init
3772      exit(1s >= 1000ms)
3773    end on
3774    )NKSP_CODE",
3775            .expectBoolExitResult = true
3776        });
3777    
3778        runScript({
3779            .code = R"NKSP_CODE(
3780    on init
3781      exit(1s >= 1)
3782    end on
3783    )NKSP_CODE",
3784            .expectParseError = true // units on both sides must match
3785        });
3786    
3787        runScript({
3788            .code = R"NKSP_CODE(
3789    on init
3790      exit(1 >= 1s)
3791    end on
3792    )NKSP_CODE",
3793            .expectParseError = true // units on both sides must match
3794        });
3795    
3796        runScript({
3797            .code = R"NKSP_CODE(
3798    on init
3799      exit(1Hz >= 1B)
3800    end on
3801    )NKSP_CODE",
3802            .expectParseError = true // units on both sides must match
3803        });
3804    
3805        runScript({
3806            .code = R"NKSP_CODE(
3807    on init
3808      exit(13.0ms >= 13.1ms)
3809    end on
3810    )NKSP_CODE",
3811            .expectBoolExitResult = false
3812        });
3813    
3814        runScript({
3815            .code = R"NKSP_CODE(
3816    on init
3817      exit(13.1ms >= 13.0ms)
3818    end on
3819    )NKSP_CODE",
3820            .expectBoolExitResult = true
3821        });
3822    
3823        runScript({
3824            .code = R"NKSP_CODE(
3825    on init
3826      exit(0.9s >= 600.0ms)
3827    end on
3828    )NKSP_CODE",
3829            .expectBoolExitResult = true
3830        });
3831    
3832        runScript({
3833            .code = R"NKSP_CODE(
3834    on init
3835      exit(600.0ms >= 0.9s)
3836    end on
3837    )NKSP_CODE",
3838            .expectBoolExitResult = false
3839        });
3840    
3841        runScript({
3842            .code = R"NKSP_CODE(
3843    on init
3844      exit(5.1kHz >= 5100.0Hz)
3845    end on
3846    )NKSP_CODE",
3847            .expectBoolExitResult = true
3848        });
3849    
3850        runScript({
3851            .code = R"NKSP_CODE(
3852    on init
3853      exit(5100.0Hz >= 5.1kHz)
3854    end on
3855    )NKSP_CODE",
3856            .expectBoolExitResult = true
3857        });
3858    
3859        runScript({
3860            .code = R"NKSP_CODE(
3861    on init
3862      exit(1.0Hz >= 1.1)
3863    end on
3864    )NKSP_CODE",
3865            .expectParseError = true // units on both sides must match
3866        });
3867    
3868        runScript({
3869            .code = R"NKSP_CODE(
3870    on init
3871      exit(1.2 >= 1.34mdB)
3872    end on
3873    )NKSP_CODE",
3874            .expectParseError = true // units on both sides must match
3875        });
3876    
3877        runScript({
3878            .code = R"NKSP_CODE(
3879    on init
3880      exit(9.23us >= 3.14kHz)
3881    end on
3882    )NKSP_CODE",
3883            .expectParseError = true // units on both sides must match
3884        });
3885    
3886        // 'final' ('!') operator tests ...
3887        // (should always yield in false for relation operators)
3888    
3889        runScript({
3890            .code = R"NKSP_CODE(
3891    on init
3892      exit(!-4 >= !3)
3893    end on
3894    )NKSP_CODE",
3895            .expectBoolExitResult = false,
3896            .expectExitResultFinal = false
3897        });
3898    
3899        runScript({
3900            .code = R"NKSP_CODE(
3901    on init
3902      exit(-4 >= 3)
3903    end on
3904    )NKSP_CODE",
3905            .expectBoolExitResult = false,
3906            .expectExitResultFinal = false
3907        });
3908    
3909      #if !SILENT_TEST      #if !SILENT_TEST
3910      std::cout << std::endl;      std::cout << std::endl;
3911      #endif      #endif
# Line 1653  end on Line 4001  end on
4001          .expectBoolExitResult = false          .expectBoolExitResult = false
4002      });      });
4003    
4004        // deal with inaccuracy of float point
4005        runScript({
4006            .code = R"NKSP_CODE(
4007    on init
4008      declare ~a := 0.165
4009      declare ~b := 0.185
4010      declare ~x := 0.1
4011      declare ~y := 0.25
4012      exit(~a + ~b = ~x + ~y) { both sides should actually be 0.35, they slightly deviate both though }
4013    end on
4014    )NKSP_CODE",
4015            .expectBoolExitResult = true // our implementation of real number equal comparison should take care about floating point tolerance
4016        });
4017    
4018        // deal with inaccuracy of float point
4019        runScript({
4020            .code = R"NKSP_CODE(
4021    on init
4022      declare ~a := 0.166
4023      declare ~b := 0.185
4024      declare ~x := 0.1
4025      declare ~y := 0.25
4026      exit(~a + ~b = ~x + ~y) { left side approx. 0.351, right side approx. 0.35 }
4027    end on
4028    )NKSP_CODE",
4029            .expectBoolExitResult = false
4030        });
4031    
4032      // mixed type tests ...      // mixed type tests ...
4033    
4034      runScript({      runScript({
# Line 1691  end on Line 4067  end on
4067          .expectBoolExitResult = false          .expectBoolExitResult = false
4068      });      });
4069    
4070        // std unit tests ...
4071    
4072        runScript({
4073            .code = R"NKSP_CODE(
4074    on init
4075      exit(13ms = 14ms)
4076    end on
4077    )NKSP_CODE",
4078            .expectBoolExitResult = false
4079        });
4080    
4081        runScript({
4082            .code = R"NKSP_CODE(
4083    on init
4084      exit(14ms = 13ms)
4085    end on
4086    )NKSP_CODE",
4087            .expectBoolExitResult = false
4088        });
4089    
4090        runScript({
4091            .code = R"NKSP_CODE(
4092    on init
4093      exit(1s = 1ms)
4094    end on
4095    )NKSP_CODE",
4096            .expectBoolExitResult = false
4097        });
4098    
4099        runScript({
4100            .code = R"NKSP_CODE(
4101    on init
4102      exit(1ms = 1s)
4103    end on
4104    )NKSP_CODE",
4105            .expectBoolExitResult = false
4106        });
4107    
4108        runScript({
4109            .code = R"NKSP_CODE(
4110    on init
4111      exit(3.14kHz = 3140Hz)
4112    end on
4113    )NKSP_CODE",
4114            .expectBoolExitResult = true
4115        });
4116    
4117        runScript({
4118            .code = R"NKSP_CODE(
4119    on init
4120      exit(3140Hz = 3.14kHz)
4121    end on
4122    )NKSP_CODE",
4123            .expectBoolExitResult = true
4124        });
4125    
4126        runScript({
4127            .code = R"NKSP_CODE(
4128    on init
4129      exit(1s = 1)
4130    end on
4131    )NKSP_CODE",
4132            .expectParseError = true // units on both sides must match
4133        });
4134    
4135        runScript({
4136            .code = R"NKSP_CODE(
4137    on init
4138      exit(1 = 1s)
4139    end on
4140    )NKSP_CODE",
4141            .expectParseError = true // units on both sides must match
4142        });
4143    
4144        runScript({
4145            .code = R"NKSP_CODE(
4146    on init
4147      exit(1Hz = 1B)
4148    end on
4149    )NKSP_CODE",
4150            .expectParseError = true // units on both sides must match
4151        });
4152    
4153        // 'final' ('!') operator tests ...
4154        // (should always yield in false for relation operators)
4155    
4156        runScript({
4157            .code = R"NKSP_CODE(
4158    on init
4159      exit(!-4 = !3)
4160    end on
4161    )NKSP_CODE",
4162            .expectBoolExitResult = false,
4163            .expectExitResultFinal = false
4164        });
4165    
4166        runScript({
4167            .code = R"NKSP_CODE(
4168    on init
4169      exit(-4 = 3)
4170    end on
4171    )NKSP_CODE",
4172            .expectBoolExitResult = false,
4173            .expectExitResultFinal = false
4174        });
4175    
4176      #if !SILENT_TEST      #if !SILENT_TEST
4177      std::cout << std::endl;      std::cout << std::endl;
4178      #endif      #endif
# Line 1777  end on Line 4259  end on
4259          .expectBoolExitResult = true          .expectBoolExitResult = true
4260      });      });
4261    
4262        // deal with inaccuracy of float point
4263        runScript({
4264            .code = R"NKSP_CODE(
4265    on init
4266      declare ~a := 0.165
4267      declare ~b := 0.185
4268      declare ~x := 0.1
4269      declare ~y := 0.25
4270            exit(~a + ~b # ~x + ~y) { both sides should actually be 0.35, they slightly deviate both though }
4271    end on
4272    )NKSP_CODE",
4273            .expectBoolExitResult = false // our implementation of real number unequal comparison should take care about floating point tolerance
4274        });
4275    
4276        // deal with inaccuracy of float point
4277        runScript({
4278            .code = R"NKSP_CODE(
4279    on init
4280      declare ~a := 0.166
4281      declare ~b := 0.185
4282      declare ~x := 0.1
4283      declare ~y := 0.25
4284            exit(~a + ~b # ~x + ~y) { left side approx. 0.351, right side approx. 0.35 }
4285    end on
4286    )NKSP_CODE",
4287            .expectBoolExitResult = true
4288        });
4289    
4290      // mixed type tests ...      // mixed type tests ...
4291    
4292      runScript({      runScript({
# Line 1815  end on Line 4325  end on
4325          .expectBoolExitResult = true          .expectBoolExitResult = true
4326      });      });
4327    
4328        // std unit tests ...
4329    
4330        runScript({
4331            .code = R"NKSP_CODE(
4332    on init
4333      exit(13ms # 14ms)
4334    end on
4335    )NKSP_CODE",
4336            .expectBoolExitResult = true
4337        });
4338    
4339        runScript({
4340            .code = R"NKSP_CODE(
4341    on init
4342      exit(14ms # 13ms)
4343    end on
4344    )NKSP_CODE",
4345            .expectBoolExitResult = true
4346        });
4347    
4348        runScript({
4349            .code = R"NKSP_CODE(
4350    on init
4351      exit(1s # 1ms)
4352    end on
4353    )NKSP_CODE",
4354            .expectBoolExitResult = true
4355        });
4356    
4357        runScript({
4358            .code = R"NKSP_CODE(
4359    on init
4360      exit(1ms # 1s)
4361    end on
4362    )NKSP_CODE",
4363            .expectBoolExitResult = true
4364        });
4365    
4366        runScript({
4367            .code = R"NKSP_CODE(
4368    on init
4369      exit(3.14kHz # 3140Hz)
4370    end on
4371    )NKSP_CODE",
4372            .expectBoolExitResult = false
4373        });
4374    
4375        runScript({
4376            .code = R"NKSP_CODE(
4377    on init
4378      exit(3140Hz # 3.14kHz)
4379    end on
4380    )NKSP_CODE",
4381            .expectBoolExitResult = false
4382        });
4383    
4384        runScript({
4385            .code = R"NKSP_CODE(
4386    on init
4387      exit(1s # 1)
4388    end on
4389    )NKSP_CODE",
4390            .expectParseError = true // units on both sides must match
4391        });
4392    
4393        runScript({
4394            .code = R"NKSP_CODE(
4395    on init
4396      exit(1 # 1s)
4397    end on
4398    )NKSP_CODE",
4399            .expectParseError = true // units on both sides must match
4400        });
4401    
4402        runScript({
4403            .code = R"NKSP_CODE(
4404    on init
4405      exit(1Hz # 1B)
4406    end on
4407    )NKSP_CODE",
4408            .expectParseError = true // units on both sides must match
4409        });
4410    
4411        // 'final' ('!') operator tests ...
4412        // (should always yield in false for relation operators)
4413    
4414        runScript({
4415            .code = R"NKSP_CODE(
4416    on init
4417      exit(!-4 # !3)
4418    end on
4419    )NKSP_CODE",
4420            .expectBoolExitResult = true,
4421            .expectExitResultFinal = false
4422        });
4423    
4424        runScript({
4425            .code = R"NKSP_CODE(
4426    on init
4427      exit(-4 # 3)
4428    end on
4429    )NKSP_CODE",
4430            .expectBoolExitResult = true,
4431            .expectExitResultFinal = false
4432        });
4433    
4434      #if !SILENT_TEST      #if !SILENT_TEST
4435      std::cout << std::endl;      std::cout << std::endl;
4436      #endif      #endif
# Line 1914  end on Line 4530  end on
4530          .expectParseError = true // real numbers not allowed for this operator          .expectParseError = true // real numbers not allowed for this operator
4531      });      });
4532    
4533        // std unit tests ...
4534        // (not allowed for this operator)
4535    
4536        runScript({
4537            .code = R"NKSP_CODE(
4538    on init
4539      exit(1s and 0)
4540    end on
4541    )NKSP_CODE",
4542            .expectParseError = true // std units not allowed for this operator
4543        });
4544    
4545        runScript({
4546            .code = R"NKSP_CODE(
4547    on init
4548      exit(0 and 1s)
4549    end on
4550    )NKSP_CODE",
4551            .expectParseError = true // std units not allowed for this operator
4552        });
4553    
4554        // 'final' ('!') operator tests ...
4555    
4556        runScript({
4557            .code = R"NKSP_CODE(
4558    on init
4559      exit(!0 and !0)
4560    end on
4561    )NKSP_CODE",
4562            .expectExitResultFinal = true
4563        });
4564    
4565        runScript({
4566            .code = R"NKSP_CODE(
4567    on init
4568      exit(0 and 0)
4569    end on
4570    )NKSP_CODE",
4571            .expectExitResultFinal = false
4572        });
4573    
4574      #if !SILENT_TEST      #if !SILENT_TEST
4575      std::cout << std::endl;      std::cout << std::endl;
4576      #endif      #endif
# Line 2013  end on Line 4670  end on
4670          .expectParseError = true // real numbers not allowed for this operator          .expectParseError = true // real numbers not allowed for this operator
4671      });      });
4672    
4673        // std unit tests ...
4674        // (not allowed for this operator)
4675    
4676        runScript({
4677            .code = R"NKSP_CODE(
4678    on init
4679      exit(1s or 0)
4680    end on
4681    )NKSP_CODE",
4682            .expectParseError = true // std units not allowed for this operator
4683        });
4684    
4685        runScript({
4686            .code = R"NKSP_CODE(
4687    on init
4688      exit(0 or 1s)
4689    end on
4690    )NKSP_CODE",
4691            .expectParseError = true // std units not allowed for this operator
4692        });
4693    
4694        // 'final' ('!') operator tests ...
4695    
4696        runScript({
4697            .code = R"NKSP_CODE(
4698    on init
4699      exit(!0 or !0)
4700    end on
4701    )NKSP_CODE",
4702            .expectExitResultFinal = true
4703        });
4704    
4705        runScript({
4706            .code = R"NKSP_CODE(
4707    on init
4708      exit(0 or 0)
4709    end on
4710    )NKSP_CODE",
4711            .expectExitResultFinal = false
4712        });
4713    
4714      #if !SILENT_TEST      #if !SILENT_TEST
4715      std::cout << std::endl;      std::cout << std::endl;
4716      #endif      #endif
# Line 2064  end on Line 4762  end on
4762          .expectParseError = true // real numbers not allowed for this operator          .expectParseError = true // real numbers not allowed for this operator
4763      });      });
4764    
4765        // std unit tests ...
4766        // (not allowed for this operator)
4767    
4768        runScript({
4769            .code = R"NKSP_CODE(
4770    on init
4771      exit(not 1s)
4772    end on
4773    )NKSP_CODE",
4774            .expectParseError = true // std units not allowed for this operator
4775        });
4776    
4777        // 'final' ('!') operator tests ...
4778    
4779        runScript({
4780            .code = R"NKSP_CODE(
4781    on init
4782      exit(not !1)
4783    end on
4784    )NKSP_CODE",
4785            .expectExitResultFinal = true
4786        });
4787    
4788        runScript({
4789            .code = R"NKSP_CODE(
4790    on init
4791      exit(not 1)
4792    end on
4793    )NKSP_CODE",
4794            .expectExitResultFinal = false
4795        });
4796    
4797      #if !SILENT_TEST      #if !SILENT_TEST
4798      std::cout << std::endl;      std::cout << std::endl;
4799      #endif      #endif
# Line 2127  end on Line 4857  end on
4857          .expectParseError = true // real numbers not allowed for this operator          .expectParseError = true // real numbers not allowed for this operator
4858      });      });
4859    
4860        // std unit tests ...
4861        // (not allowed for this operator)
4862    
4863        runScript({
4864            .code = R"NKSP_CODE(
4865    on init
4866      exit(1s .and. 1)
4867    end on
4868    )NKSP_CODE",
4869            .expectParseError = true // std units not allowed for this operator
4870        });
4871    
4872        runScript({
4873            .code = R"NKSP_CODE(
4874    on init
4875      exit(1 .and. 1s)
4876    end on
4877    )NKSP_CODE",
4878            .expectParseError = true // std units not allowed for this operator
4879        });
4880    
4881        // 'final' ('!') operator tests ...
4882    
4883        runScript({
4884            .code = R"NKSP_CODE(
4885    on init
4886      exit(!43 .and. !142)
4887    end on
4888    )NKSP_CODE",
4889            .expectIntExitResult = 10,
4890            .expectExitResultFinal = true
4891        });
4892    
4893        runScript({
4894            .code = R"NKSP_CODE(
4895    on init
4896      exit(43 .and. 142)
4897    end on
4898    )NKSP_CODE",
4899            .expectIntExitResult = 10,
4900            .expectExitResultFinal = false
4901        });
4902    
4903      #if !SILENT_TEST      #if !SILENT_TEST
4904      std::cout << std::endl;      std::cout << std::endl;
4905      #endif      #endif
# Line 2199  end on Line 4972  end on
4972          .expectParseError = true // real numbers not allowed for this operator          .expectParseError = true // real numbers not allowed for this operator
4973      });      });
4974    
4975        // std unit tests ...
4976        // (not allowed for this operator)
4977    
4978        runScript({
4979            .code = R"NKSP_CODE(
4980    on init
4981      exit(1s .or. 1)
4982    end on
4983    )NKSP_CODE",
4984            .expectParseError = true // std units not allowed for this operator
4985        });
4986    
4987        runScript({
4988            .code = R"NKSP_CODE(
4989    on init
4990      exit(1 .or. 1s)
4991    end on
4992    )NKSP_CODE",
4993            .expectParseError = true // std units not allowed for this operator
4994        });
4995    
4996        // 'final' ('!') operator tests ...
4997    
4998        runScript({
4999            .code = R"NKSP_CODE(
5000    on init
5001      exit(!43 .or. !142)
5002    end on
5003    )NKSP_CODE",
5004            .expectIntExitResult = 175,
5005            .expectExitResultFinal = true
5006        });
5007    
5008        runScript({
5009            .code = R"NKSP_CODE(
5010    on init
5011      exit(43 .or. 142)
5012    end on
5013    )NKSP_CODE",
5014            .expectIntExitResult = 175,
5015            .expectExitResultFinal = false
5016        });
5017    
5018      #if !SILENT_TEST      #if !SILENT_TEST
5019      std::cout << std::endl;      std::cout << std::endl;
5020      #endif      #endif
# Line 2259  end on Line 5075  end on
5075          .expectParseError = true // real numbers not allowed for this operator          .expectParseError = true // real numbers not allowed for this operator
5076      });      });
5077    
5078        // std unit tests ...
5079        // (not allowed for this operator)
5080    
5081        runScript({
5082            .code = R"NKSP_CODE(
5083    on init
5084      exit(.not. 1s)
5085    end on
5086    )NKSP_CODE",
5087            .expectParseError = true // std units not allowed for this operator
5088        });
5089    
5090        // 'final' ('!') operator tests ...
5091    
5092        runScript({
5093            .code = R"NKSP_CODE(
5094    on init
5095      exit(.not. !0)
5096    end on
5097    )NKSP_CODE",
5098            .expectIntExitResult = -1,
5099            .expectExitResultFinal = true
5100        });
5101    
5102        runScript({
5103            .code = R"NKSP_CODE(
5104    on init
5105      exit(.not. 0)
5106    end on
5107    )NKSP_CODE",
5108            .expectIntExitResult = -1,
5109            .expectExitResultFinal = false
5110        });
5111    
5112      #if !SILENT_TEST      #if !SILENT_TEST
5113      std::cout << std::endl;      std::cout << std::endl;
5114      #endif      #endif
# Line 2345  end on Line 5195  end on
5195          .expectRealExitResult = 20.8          .expectRealExitResult = 20.8
5196      });      });
5197    
5198        // std unit tests ...
5199    
5200        runScript({
5201            .code = R"NKSP_CODE(
5202    on init
5203      exit(4 * (2us + 3us) + 7ms)
5204    end on
5205    )NKSP_CODE",
5206            .expectIntExitResult = 7020,
5207            .expectExitResultUnitPrefix = { VM_MICRO },
5208            .expectExitResultUnit = VM_SECOND
5209        });
5210    
5211        runScript({
5212            .code = R"NKSP_CODE(
5213    on init
5214      declare $a := 4
5215      declare $c := 3us
5216      exit($a * (2us + $c) + 7ms)
5217    end on
5218    )NKSP_CODE",
5219            .expectIntExitResult = 7020,
5220            .expectExitResultUnitPrefix = { VM_MICRO },
5221            .expectExitResultUnit = VM_SECOND
5222        });
5223    
5224        runScript({
5225            .code = R"NKSP_CODE(
5226    on init
5227      declare $a := 4
5228      declare $b := 2us
5229      declare $c := 3us
5230      exit($a * ($b + $c) + 7ms)
5231    end on
5232    )NKSP_CODE",
5233            .expectIntExitResult = 7020,
5234            .expectExitResultUnitPrefix = { VM_MICRO },
5235            .expectExitResultUnit = VM_SECOND
5236        });
5237    
5238        runScript({
5239            .code = R"NKSP_CODE(
5240    on init
5241      declare $a := 4
5242      declare $b := 2us
5243      declare $c := 3us
5244      declare $d := 7ms
5245      exit($a * ($b + $c) + 7ms)
5246    end on
5247    )NKSP_CODE",
5248            .expectIntExitResult = 7020,
5249            .expectExitResultUnitPrefix = { VM_MICRO },
5250            .expectExitResultUnit = VM_SECOND
5251        });
5252    
5253        runScript({
5254            .code = R"NKSP_CODE(
5255    on init
5256      declare $c := 3us
5257      declare $a := 4
5258      declare $d := 7ms
5259      declare $b := 2us
5260      exit($a * ($b + $c) + 7ms)
5261    end on
5262    )NKSP_CODE",
5263            .expectIntExitResult = 7020,
5264            .expectExitResultUnitPrefix = { VM_MICRO },
5265            .expectExitResultUnit = VM_SECOND
5266        });
5267    
5268        runScript({
5269            .code = R"NKSP_CODE(
5270    on init
5271      exit(4.0 * (2.0mdB + 3.2mdB) / 2.0)
5272    end on
5273    )NKSP_CODE",
5274            .expectRealExitResult = 10.4,
5275            .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5276            .expectExitResultUnit = VM_BEL
5277        });
5278    
5279        runScript({
5280            .code = R"NKSP_CODE(
5281    on init
5282      declare ~a := 2.0mdB
5283      declare ~b := 3.2mdB
5284      exit(4.0 * (~a + ~b) / 2.0)
5285    end on
5286    )NKSP_CODE",
5287            .expectRealExitResult = 10.4,
5288            .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5289            .expectExitResultUnit = VM_BEL
5290        });
5291    
5292        runScript({
5293            .code = R"NKSP_CODE(
5294    on init
5295      declare ~b := 3.2mdB
5296      declare ~a := 2.0mdB
5297      exit(4.0 * (~a + ~b) / 2.0)
5298    end on
5299    )NKSP_CODE",
5300            .expectRealExitResult = 10.4,
5301            .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5302            .expectExitResultUnit = VM_BEL
5303        });
5304    
5305        runScript({
5306            .code = R"NKSP_CODE(
5307    on init
5308      declare ~a := 4.0
5309      declare ~b := 2.0mdB
5310      declare ~c := 3.2mdB
5311      declare ~d := 2.0
5312      exit((~a * (~b + ~c) / ~d) + 1.1mdB)
5313    end on
5314    )NKSP_CODE",
5315            .expectRealExitResult = 11.5,
5316            .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5317            .expectExitResultUnit = VM_BEL
5318        });
5319    
5320        runScript({
5321            .code = R"NKSP_CODE(
5322    on init
5323      declare ~c := 3.2mdB
5324      declare ~a := 4.0
5325      declare ~d := 2.0
5326      declare ~b := 2.0mdB
5327      exit(~a * (~b + ~c) / ~d + 1.1mdB)
5328    end on
5329    )NKSP_CODE",
5330            .expectRealExitResult = 11.5,
5331            .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5332            .expectExitResultUnit = VM_BEL
5333        });
5334    
5335        // 'final' ('!') operator tests ...
5336    
5337        runScript({
5338            .code = R"NKSP_CODE(
5339    on init
5340      declare $a := 4
5341      declare $b := !2us
5342      declare $c := 3us
5343      declare $d := 7ms
5344      exit($a * ($b + $c) + 7ms)
5345    end on
5346    )NKSP_CODE",
5347            .expectIntExitResult = 7020,
5348            .expectExitResultUnitPrefix = { VM_MICRO },
5349            .expectExitResultUnit = VM_SECOND,
5350            .expectExitResultFinal = true,
5351            .expectParseWarning = true // only one operand is defined as 'final', result will be final though
5352        });
5353    
5354        runScript({
5355            .code = R"NKSP_CODE(
5356    on init
5357      declare $a := 4
5358      declare $b := 2us
5359      declare $c := !3us
5360      declare $d := 7ms
5361      exit($a * ($b + $c) + 7ms)
5362    end on
5363    )NKSP_CODE",
5364            .expectIntExitResult = 7020,
5365            .expectExitResultUnitPrefix = { VM_MICRO },
5366            .expectExitResultUnit = VM_SECOND,
5367            .expectExitResultFinal = true,
5368            .expectParseWarning = true // only one operand is defined as 'final', result will be final though
5369        });
5370    
5371      #if !SILENT_TEST      #if !SILENT_TEST
5372      std::cout << std::endl;      std::cout << std::endl;
5373      #endif      #endif
# Line 2409  end on Line 5432  end on
5432      runScript({      runScript({
5433          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
5434  on init  on init
5435    declare $foo := min(1.0, 2.0)    declare ~foo := min(1.0, 2.0)
5436    exit($foo)    exit(~foo)
5437  end on  end on
5438  )NKSP_CODE",  )NKSP_CODE",
5439          .expectRealExitResult = 1.0          .expectRealExitResult = 1.0
# Line 2419  end on Line 5442  end on
5442      runScript({      runScript({
5443          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
5444  on init  on init
5445    declare $foo := min(-30.0, 4.0)    declare ~foo := min(-30.0, 4.0)
5446    exit($foo)    exit(~foo)
5447  end on  end on
5448  )NKSP_CODE",  )NKSP_CODE",
5449          .expectRealExitResult = -30.0          .expectRealExitResult = -30.0
# Line 2429  end on Line 5452  end on
5452      runScript({      runScript({
5453          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
5454  on init  on init
5455    declare $foo := min(1.1, 1.13)    declare ~foo := min(1.1, 1.13)
5456    exit($foo)    exit(~foo)
5457  end on  end on
5458  )NKSP_CODE",  )NKSP_CODE",
5459          .expectRealExitResult = 1.1          .expectRealExitResult = 1.1
# Line 2439  end on Line 5462  end on
5462      runScript({      runScript({
5463          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
5464  on init  on init
5465    declare $foo := min(1.13, 1.1)    declare ~foo := min(1.13, 1.1)
5466    exit($foo)    exit(~foo)
5467  end on  end on
5468  )NKSP_CODE",  )NKSP_CODE",
5469          .expectRealExitResult = 1.1          .expectRealExitResult = 1.1
# Line 2451  end on Line 5474  end on
5474      runScript({      runScript({
5475          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
5476  on init  on init
5477    declare $foo := min(1, 1.16)    declare ~foo := min(1, 1.16)
5478      exit(~foo)
5479    end on
5480    )NKSP_CODE",
5481            .expectRealExitResult = 1.0,
5482            .expectParseWarning = true // min() warns if data types of arguments not matching
5483        });
5484    
5485        runScript({
5486            .code = R"NKSP_CODE(
5487    on init
5488      declare ~foo := min(-3.92, 9)
5489      exit(~foo)
5490    end on
5491    )NKSP_CODE",
5492            .expectRealExitResult = -3.92,
5493            .expectParseWarning = true // min() warns if data types of arguments not matching
5494        });
5495    
5496        // std unit tests ...
5497    
5498        runScript({
5499            .code = R"NKSP_CODE(
5500    on init
5501      declare $foo := min(30ms,4s)
5502    exit($foo)    exit($foo)
5503  end on  end on
5504  )NKSP_CODE",  )NKSP_CODE",
5505          .expectRealExitResult = 1.0          .expectIntExitResult = 30,
5506            .expectExitResultUnitPrefix = { VM_MILLI },
5507            .expectExitResultUnit = VM_SECOND,
5508        });
5509    
5510        runScript({
5511            .code = R"NKSP_CODE(
5512    on init
5513      declare $foo := min(4s,30ms)
5514      exit($foo)
5515    end on
5516    )NKSP_CODE",
5517            .expectIntExitResult = 30,
5518            .expectExitResultUnitPrefix = { VM_MILLI },
5519            .expectExitResultUnit = VM_SECOND,
5520        });
5521    
5522        runScript({
5523            .code = R"NKSP_CODE(
5524    on init
5525      declare $foo := min(-30mdB,-4dB)
5526      exit($foo)
5527    end on
5528    )NKSP_CODE",
5529            .expectIntExitResult = -4,
5530            .expectExitResultUnitPrefix = { VM_DECI },
5531            .expectExitResultUnit = VM_BEL,
5532        });
5533    
5534        runScript({
5535            .code = R"NKSP_CODE(
5536    on init
5537      declare $foo := min(-4dB,-30mdB)
5538      exit($foo)
5539    end on
5540    )NKSP_CODE",
5541            .expectIntExitResult = -4,
5542            .expectExitResultUnitPrefix = { VM_DECI },
5543            .expectExitResultUnit = VM_BEL,
5544        });
5545    
5546        runScript({
5547            .code = R"NKSP_CODE(
5548    on init
5549      declare $foo := min(-4s,-30Hz)
5550      exit($foo)
5551    end on
5552    )NKSP_CODE",
5553            .expectParseError = true // min() requires arguments to have same unit type
5554        });
5555    
5556        runScript({
5557            .code = R"NKSP_CODE(
5558    on init
5559      declare $foo := min(-4s,-30)
5560      exit($foo)
5561    end on
5562    )NKSP_CODE",
5563            .expectParseError = true // min() requires arguments to have same unit type
5564        });
5565    
5566        runScript({
5567            .code = R"NKSP_CODE(
5568    on init
5569      declare $foo := min(-4,-30s)
5570      exit($foo)
5571    end on
5572    )NKSP_CODE",
5573            .expectParseError = true // min() requires arguments to have same unit type
5574        });
5575    
5576        runScript({
5577            .code = R"NKSP_CODE(
5578    on init
5579      declare ~foo := min(0.9s,1.0s)
5580      exit(~foo)
5581    end on
5582    )NKSP_CODE",
5583            .expectRealExitResult = 0.9,
5584            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
5585            .expectExitResultUnit = VM_SECOND,
5586        });
5587    
5588        // 'final' ('!') operator tests ...
5589    
5590        runScript({
5591            .code = R"NKSP_CODE(
5592    on init
5593      declare $foo := min(!30,!4)
5594      exit($foo)
5595    end on
5596    )NKSP_CODE",
5597            .expectIntExitResult = 4,
5598            .expectExitResultFinal = true
5599        });
5600    
5601        runScript({
5602            .code = R"NKSP_CODE(
5603    on init
5604      declare $foo := min(30,4)
5605      exit($foo)
5606    end on
5607    )NKSP_CODE",
5608            .expectIntExitResult = 4,
5609            .expectExitResultFinal = false
5610        });
5611    
5612        runScript({
5613            .code = R"NKSP_CODE(
5614    on init
5615      declare $foo := min(30,!4)
5616      exit($foo)
5617    end on
5618    )NKSP_CODE",
5619            .expectIntExitResult = 4,
5620            .expectExitResultFinal = true,
5621            .expectParseWarning = true // min() warns if only one argument is 'final'
5622      });      });
5623    
5624      runScript({      runScript({
5625          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
5626  on init  on init
5627    declare $foo := min(-3.92, 9)    declare $foo := min(!30,4)
5628    exit($foo)    exit($foo)
5629  end on  end on
5630  )NKSP_CODE",  )NKSP_CODE",
5631          .expectRealExitResult = -3.92          .expectIntExitResult = 4,
5632            .expectExitResultFinal = true,
5633            .expectParseWarning = true // min() warns if only one argument is 'final'
5634        });
5635    
5636        runScript({
5637            .code = R"NKSP_CODE(
5638    on init
5639      declare ~foo := min(!12.1,!12.2)
5640      exit(~foo)
5641    end on
5642    )NKSP_CODE",
5643            .expectRealExitResult = 12.1,
5644            .expectExitResultFinal = true
5645        });
5646    
5647        runScript({
5648            .code = R"NKSP_CODE(
5649    on init
5650      declare ~foo := min(12.1,12.2)
5651      exit(~foo)
5652    end on
5653    )NKSP_CODE",
5654            .expectRealExitResult = 12.1,
5655            .expectExitResultFinal = false
5656        });
5657    
5658        runScript({
5659            .code = R"NKSP_CODE(
5660    on init
5661      declare ~foo := min(!12.1,12.2)
5662      exit(~foo)
5663    end on
5664    )NKSP_CODE",
5665            .expectRealExitResult = 12.1,
5666            .expectExitResultFinal = true,
5667            .expectParseWarning = true // min() warns if only one argument is 'final'
5668        });
5669    
5670        runScript({
5671            .code = R"NKSP_CODE(
5672    on init
5673      declare ~foo := min(12.1,!12.2)
5674      exit(~foo)
5675    end on
5676    )NKSP_CODE",
5677            .expectRealExitResult = 12.1,
5678            .expectExitResultFinal = true,
5679            .expectParseWarning = true // min() warns if only one argument is 'final'
5680      });      });
5681    
5682      #if !SILENT_TEST      #if !SILENT_TEST
# Line 2532  end on Line 5743  end on
5743      runScript({      runScript({
5744          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
5745  on init  on init
5746    declare $foo := max(1.0, 2.0)    declare ~foo := max(1.0, 2.0)
5747    exit($foo)    exit(~foo)
5748  end on  end on
5749  )NKSP_CODE",  )NKSP_CODE",
5750          .expectRealExitResult = 2.0          .expectRealExitResult = 2.0
# Line 2542  end on Line 5753  end on
5753      runScript({      runScript({
5754          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
5755  on init  on init
5756    declare $foo := max(-30.0, 4.0)    declare ~foo := max(-30.0, 4.0)
5757    exit($foo)    exit(~foo)
5758  end on  end on
5759  )NKSP_CODE",  )NKSP_CODE",
5760          .expectRealExitResult = 4.0          .expectRealExitResult = 4.0
# Line 2552  end on Line 5763  end on
5763      runScript({      runScript({
5764          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
5765  on init  on init
5766    declare $foo := max(1.1, 1.13)    declare ~foo := max(1.1, 1.13)
5767    exit($foo)    exit(~foo)
5768  end on  end on
5769  )NKSP_CODE",  )NKSP_CODE",
5770          .expectRealExitResult = 1.13          .expectRealExitResult = 1.13
# Line 2562  end on Line 5773  end on
5773      runScript({      runScript({
5774          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
5775  on init  on init
5776    declare $foo := max(1.13, 1.1)    declare ~foo := max(1.13, 1.1)
5777    exit($foo)    exit(~foo)
5778  end on  end on
5779  )NKSP_CODE",  )NKSP_CODE",
5780          .expectRealExitResult = 1.13          .expectRealExitResult = 1.13
# Line 2574  end on Line 5785  end on
5785      runScript({      runScript({
5786          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
5787  on init  on init
5788    declare $foo := max(1, 1.16)    declare ~foo := max(1, 1.16)
5789      exit(~foo)
5790    end on
5791    )NKSP_CODE",
5792            .expectRealExitResult = 1.16,
5793            .expectParseWarning = true // max() warns if data types of arguments not matching
5794        });
5795    
5796        runScript({
5797            .code = R"NKSP_CODE(
5798    on init
5799      declare ~foo := max(-3.92, 9)
5800      exit(~foo)
5801    end on
5802    )NKSP_CODE",
5803            .expectRealExitResult = 9.0,
5804            .expectParseWarning = true // max() warns if data types of arguments not matching
5805        });
5806    
5807        // std unit tests ...
5808    
5809        runScript({
5810            .code = R"NKSP_CODE(
5811    on init
5812      declare $foo := max(30ms,4s)
5813      exit($foo)
5814    end on
5815    )NKSP_CODE",
5816            .expectIntExitResult = 4,
5817            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
5818            .expectExitResultUnit = VM_SECOND,
5819        });
5820    
5821        runScript({
5822            .code = R"NKSP_CODE(
5823    on init
5824      declare $foo := max(4s,30ms)
5825      exit($foo)
5826    end on
5827    )NKSP_CODE",
5828            .expectIntExitResult = 4,
5829            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
5830            .expectExitResultUnit = VM_SECOND,
5831        });
5832    
5833        runScript({
5834            .code = R"NKSP_CODE(
5835    on init
5836      declare $foo := max(-30mdB,-4dB)
5837      exit($foo)
5838    end on
5839    )NKSP_CODE",
5840            .expectIntExitResult = -30,
5841            .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5842            .expectExitResultUnit = VM_BEL,
5843        });
5844    
5845        runScript({
5846            .code = R"NKSP_CODE(
5847    on init
5848      declare $foo := max(-4dB,-30mdB)
5849      exit($foo)
5850    end on
5851    )NKSP_CODE",
5852            .expectIntExitResult = -30,
5853            .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5854            .expectExitResultUnit = VM_BEL,
5855        });
5856    
5857        runScript({
5858            .code = R"NKSP_CODE(
5859    on init
5860      declare $foo := max(-4s,-30Hz)
5861      exit($foo)
5862    end on
5863    )NKSP_CODE",
5864            .expectParseError = true // max() requires arguments to have same unit type
5865        });
5866    
5867        runScript({
5868            .code = R"NKSP_CODE(
5869    on init
5870      declare $foo := max(-4s,-30)
5871      exit($foo)
5872    end on
5873    )NKSP_CODE",
5874            .expectParseError = true // max() requires arguments to have same unit type
5875        });
5876    
5877        runScript({
5878            .code = R"NKSP_CODE(
5879    on init
5880      declare $foo := max(-4,-30s)
5881      exit($foo)
5882    end on
5883    )NKSP_CODE",
5884            .expectParseError = true // max() requires arguments to have same unit type
5885        });
5886    
5887        runScript({
5888            .code = R"NKSP_CODE(
5889    on init
5890      declare ~foo := max(0.9s,1.0s)
5891      exit(~foo)
5892    end on
5893    )NKSP_CODE",
5894            .expectRealExitResult = 1.0,
5895            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
5896            .expectExitResultUnit = VM_SECOND,
5897        });
5898    
5899        // 'final' ('!') operator tests ...
5900    
5901        runScript({
5902            .code = R"NKSP_CODE(
5903    on init
5904      declare $foo := max(!30,!4)
5905      exit($foo)
5906    end on
5907    )NKSP_CODE",
5908            .expectIntExitResult = 30,
5909            .expectExitResultFinal = true
5910        });
5911    
5912        runScript({
5913            .code = R"NKSP_CODE(
5914    on init
5915      declare $foo := max(30,4)
5916    exit($foo)    exit($foo)
5917  end on  end on
5918  )NKSP_CODE",  )NKSP_CODE",
5919          .expectRealExitResult = 1.16          .expectIntExitResult = 30,
5920            .expectExitResultFinal = false
5921      });      });
5922    
5923      runScript({      runScript({
5924          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
5925  on init  on init
5926    declare $foo := max(-3.92, 9)    declare $foo := max(30,!4)
5927    exit($foo)    exit($foo)
5928  end on  end on
5929  )NKSP_CODE",  )NKSP_CODE",
5930          .expectRealExitResult = 9.0          .expectIntExitResult = 30,
5931            .expectExitResultFinal = true,
5932            .expectParseWarning = true // max() warns if only one argument is 'final'
5933        });
5934    
5935        runScript({
5936            .code = R"NKSP_CODE(
5937    on init
5938      declare $foo := max(!30,4)
5939      exit($foo)
5940    end on
5941    )NKSP_CODE",
5942            .expectIntExitResult = 30,
5943            .expectExitResultFinal = true,
5944            .expectParseWarning = true // max() warns if only one argument is 'final'
5945        });
5946    
5947        runScript({
5948            .code = R"NKSP_CODE(
5949    on init
5950      declare ~foo := max(!12.1,!12.2)
5951      exit(~foo)
5952    end on
5953    )NKSP_CODE",
5954            .expectRealExitResult = 12.2,
5955            .expectExitResultFinal = true
5956        });
5957    
5958        runScript({
5959            .code = R"NKSP_CODE(
5960    on init
5961      declare ~foo := max(12.1,12.2)
5962      exit(~foo)
5963    end on
5964    )NKSP_CODE",
5965            .expectRealExitResult = 12.2,
5966            .expectExitResultFinal = false
5967        });
5968    
5969        runScript({
5970            .code = R"NKSP_CODE(
5971    on init
5972      declare ~foo := max(!12.1,12.2)
5973      exit(~foo)
5974    end on
5975    )NKSP_CODE",
5976            .expectRealExitResult = 12.2,
5977            .expectExitResultFinal = true,
5978            .expectParseWarning = true // max() warns if only one argument is 'final'
5979        });
5980    
5981        runScript({
5982            .code = R"NKSP_CODE(
5983    on init
5984      declare ~foo := max(12.1,!12.2)
5985      exit(~foo)
5986    end on
5987    )NKSP_CODE",
5988            .expectRealExitResult = 12.2,
5989            .expectExitResultFinal = true,
5990            .expectParseWarning = true // max() warns if only one argument is 'final'
5991      });      });
5992    
5993      #if !SILENT_TEST      #if !SILENT_TEST
# Line 2684  end on Line 6083  end on
6083          .expectRealExitResult = 23.11          .expectRealExitResult = 23.11
6084      });      });
6085    
6086        // std unit tests ...
6087    
6088        runScript({
6089            .code = R"NKSP_CODE(
6090    on init
6091      declare $foo := abs(-23kHz)
6092      exit($foo)
6093    end on
6094    )NKSP_CODE",
6095            .expectIntExitResult = 23,
6096            .expectExitResultUnitPrefix = { VM_KILO },
6097            .expectExitResultUnit = VM_HERTZ
6098        });
6099    
6100        runScript({
6101            .code = R"NKSP_CODE(
6102    on init
6103      declare ~foo := abs(-23.4kHz)
6104      exit(~foo)
6105    end on
6106    )NKSP_CODE",
6107            .expectRealExitResult = 23.4,
6108            .expectExitResultUnitPrefix = { VM_KILO },
6109            .expectExitResultUnit = VM_HERTZ
6110        });
6111    
6112        // 'final' ('!') operator tests ...
6113    
6114        runScript({
6115            .code = R"NKSP_CODE(
6116    on init
6117      declare $foo := abs(!-23)
6118      exit($foo)
6119    end on
6120    )NKSP_CODE",
6121            .expectIntExitResult = 23,
6122            .expectExitResultFinal = true
6123        });
6124    
6125        runScript({
6126            .code = R"NKSP_CODE(
6127    on init
6128      declare $foo := abs(-23)
6129      exit($foo)
6130    end on
6131    )NKSP_CODE",
6132            .expectIntExitResult = 23,
6133            .expectExitResultFinal = false
6134        });
6135    
6136        runScript({
6137            .code = R"NKSP_CODE(
6138    on init
6139      declare ~foo := abs(!-23.2)
6140      exit(~foo)
6141    end on
6142    )NKSP_CODE",
6143            .expectRealExitResult = 23.2,
6144            .expectExitResultFinal = true
6145        });
6146    
6147        runScript({
6148            .code = R"NKSP_CODE(
6149    on init
6150      declare ~foo := abs(-23.9)
6151      exit(~foo)
6152    end on
6153    )NKSP_CODE",
6154            .expectRealExitResult = 23.9,
6155            .expectExitResultFinal = false
6156        });
6157    
6158      #if !SILENT_TEST      #if !SILENT_TEST
6159      std::cout << std::endl;      std::cout << std::endl;
6160      #endif      #endif
# Line 2694  static void testBuiltInIncFunction() { Line 6165  static void testBuiltInIncFunction() {
6165      std::cout << "UNIT TEST: built-in inc() function\n";      std::cout << "UNIT TEST: built-in inc() function\n";
6166      #endif      #endif
6167    
6168        // integer tests ...
6169    
6170      runScript({      runScript({
6171          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
6172  on init  on init
# Line 2729  end on Line 6202  end on
6202          .expectIntExitResult = 7          .expectIntExitResult = 7
6203      });      });
6204    
6205        // std unit tests ...
6206    
6207        runScript({
6208            .code = R"NKSP_CODE(
6209    on init
6210      declare $foo := 53mdB
6211      inc($foo)
6212      exit( inc($foo) )
6213    end on
6214    )NKSP_CODE",
6215            .expectIntExitResult = 55,
6216            .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
6217            .expectExitResultUnit = VM_BEL,
6218            .expectParseWarning = true // inc() warns if argument has a unit
6219        });
6220    
6221        // 'final' ('!') operator tests ...
6222    
6223        runScript({
6224            .code = R"NKSP_CODE(
6225    on init
6226      declare $foo := !53
6227      inc($foo)
6228      exit( inc($foo) )
6229    end on
6230    )NKSP_CODE",
6231            .expectIntExitResult = 55,
6232            .expectExitResultFinal = true
6233        });
6234    
6235        runScript({
6236            .code = R"NKSP_CODE(
6237    on init
6238      declare $foo := 53
6239      inc($foo)
6240      exit( inc($foo) )
6241    end on
6242    )NKSP_CODE",
6243            .expectIntExitResult = 55,
6244            .expectExitResultFinal = false
6245        });
6246    
6247        runScript({
6248            .code = R"NKSP_CODE(
6249    on init
6250      declare $foo := 53
6251      inc($foo)
6252      exit( !inc($foo) )
6253    end on
6254    )NKSP_CODE",
6255            .expectIntExitResult = 55,
6256            .expectExitResultFinal = true
6257        });
6258    
6259      #if !SILENT_TEST      #if !SILENT_TEST
6260      std::cout << std::endl;      std::cout << std::endl;
6261      #endif      #endif
# Line 2739  static void testBuiltInDecFunction() { Line 6266  static void testBuiltInDecFunction() {
6266      std::cout << "UNIT TEST: built-in dec() function\n";      std::cout << "UNIT TEST: built-in dec() function\n";
6267      #endif      #endif
6268    
6269        // integer tests ...
6270    
6271      runScript({      runScript({
6272          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
6273  on init  on init
# Line 2774  end on Line 6303  end on
6303          .expectIntExitResult = 3          .expectIntExitResult = 3
6304      });      });
6305    
6306        // std unit tests ...
6307    
6308        runScript({
6309            .code = R"NKSP_CODE(
6310    on init
6311      declare $foo := 53mdB
6312      dec($foo)
6313      exit( dec($foo) )
6314    end on
6315    )NKSP_CODE",
6316            .expectIntExitResult = 51,
6317            .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
6318            .expectExitResultUnit = VM_BEL,
6319            .expectParseWarning = true // dec() warns if argument has a unit
6320        });
6321    
6322        // 'final' ('!') operator tests ...
6323    
6324        runScript({
6325            .code = R"NKSP_CODE(
6326    on init
6327      declare $foo := !53
6328      dec($foo)
6329      exit( dec($foo) )
6330    end on
6331    )NKSP_CODE",
6332            .expectIntExitResult = 51,
6333            .expectExitResultFinal = true
6334        });
6335    
6336        runScript({
6337            .code = R"NKSP_CODE(
6338    on init
6339      declare $foo := 53
6340      dec($foo)
6341      exit( dec($foo) )
6342    end on
6343    )NKSP_CODE",
6344            .expectIntExitResult = 51,
6345            .expectExitResultFinal = false
6346        });
6347    
6348        runScript({
6349            .code = R"NKSP_CODE(
6350    on init
6351      declare $foo := 53
6352      dec($foo)
6353      exit( !dec($foo) )
6354    end on
6355    )NKSP_CODE",
6356            .expectIntExitResult = 51,
6357            .expectExitResultFinal = true
6358        });
6359    
6360      #if !SILENT_TEST      #if !SILENT_TEST
6361      std::cout << std::endl;      std::cout << std::endl;
6362      #endif      #endif
# Line 2784  static void testBuiltInInRangeFunction() Line 6367  static void testBuiltInInRangeFunction()
6367      std::cout << "UNIT TEST: built-in in_range() function\n";      std::cout << "UNIT TEST: built-in in_range() function\n";
6368      #endif      #endif
6369    
6370        // integer tests ...
6371    
6372      runScript({      runScript({
6373          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
6374  on init  on init
# Line 2865  end on Line 6450  end on
6450          .expectBoolExitResult = false          .expectBoolExitResult = false
6451      });      });
6452    
6453        // real number tests ...
6454    
6455        runScript({
6456            .code = R"NKSP_CODE(
6457    on init
6458      exit( in_range(12.2,12.1,12.9) )
6459    end on
6460    )NKSP_CODE",
6461            .expectBoolExitResult = true
6462        });
6463    
6464        runScript({
6465            .code = R"NKSP_CODE(
6466    on init
6467      exit( in_range(12.2,12.9,12.1) )
6468    end on
6469    )NKSP_CODE",
6470            .expectBoolExitResult = true
6471        });
6472    
6473        runScript({
6474            .code = R"NKSP_CODE(
6475    on init
6476      exit( in_range(12.0,12.1,12.9) )
6477    end on
6478    )NKSP_CODE",
6479            .expectBoolExitResult = false
6480        });
6481    
6482        runScript({
6483            .code = R"NKSP_CODE(
6484    on init
6485      exit( in_range(12.0,12.9,12.1) )
6486    end on
6487    )NKSP_CODE",
6488            .expectBoolExitResult = false
6489        });
6490    
6491        runScript({
6492            .code = R"NKSP_CODE(
6493    on init
6494      exit( in_range(0.0,-0.3,0.3) )
6495    end on
6496    )NKSP_CODE",
6497            .expectBoolExitResult = true
6498        });
6499    
6500        runScript({
6501            .code = R"NKSP_CODE(
6502    on init
6503      exit( in_range(-0.34,-0.3,0.3) )
6504    end on
6505    )NKSP_CODE",
6506            .expectBoolExitResult = false
6507        });
6508    
6509        runScript({
6510            .code = R"NKSP_CODE(
6511    on init
6512      exit( in_range(0.34,-0.3,0.3) )
6513    end on
6514    )NKSP_CODE",
6515            .expectBoolExitResult = false
6516        });
6517    
6518        runScript({
6519            .code = R"NKSP_CODE(
6520    on init
6521      exit( in_range(-0.3,-0.3,0.3) )
6522    end on
6523    )NKSP_CODE",
6524            .expectBoolExitResult = true
6525        });
6526    
6527        runScript({
6528            .code = R"NKSP_CODE(
6529    on init
6530      exit( in_range(0.3,-0.3,0.3) )
6531    end on
6532    )NKSP_CODE",
6533            .expectBoolExitResult = true
6534        });
6535    
6536        // mixed type tests ...
6537    
6538        runScript({
6539            .code = R"NKSP_CODE(
6540    on init
6541      exit( in_range(4.0,-5,5) )
6542    end on
6543    )NKSP_CODE",
6544            .expectBoolExitResult = true,
6545            .expectParseWarning = true // in_range() warns if not all arguments are of same type
6546        });
6547    
6548        runScript({
6549            .code = R"NKSP_CODE(
6550    on init
6551      exit( in_range(5,-5,5.0) )
6552    end on
6553    )NKSP_CODE",
6554            .expectBoolExitResult = true,
6555            .expectParseWarning = true // in_range() warns if not all arguments are of same type
6556        });
6557    
6558        runScript({
6559            .code = R"NKSP_CODE(
6560    on init
6561      exit( in_range(-5,-5.0,5) )
6562    end on
6563    )NKSP_CODE",
6564            .expectBoolExitResult = true,
6565            .expectParseWarning = true // in_range() warns if not all arguments are of same type
6566        });
6567    
6568        // std unit tests ...
6569    
6570        runScript({
6571            .code = R"NKSP_CODE(
6572    on init
6573      exit( in_range(4000Hz,3kHz,5kHz) )
6574    end on
6575    )NKSP_CODE",
6576            .expectBoolExitResult = true,
6577            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6578            .expectExitResultUnit = VM_NO_UNIT
6579        });
6580    
6581        runScript({
6582            .code = R"NKSP_CODE(
6583    on init
6584      exit( in_range(5000Hz,3kHz,5kHz) )
6585    end on
6586    )NKSP_CODE",
6587            .expectBoolExitResult = true,
6588            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6589            .expectExitResultUnit = VM_NO_UNIT
6590        });
6591    
6592        runScript({
6593            .code = R"NKSP_CODE(
6594    on init
6595      exit( in_range(5001Hz,3kHz,5kHz) )
6596    end on
6597    )NKSP_CODE",
6598            .expectBoolExitResult = false,
6599            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6600            .expectExitResultUnit = VM_NO_UNIT
6601        });
6602    
6603        runScript({
6604            .code = R"NKSP_CODE(
6605    on init
6606      exit( in_range(3000Hz,3kHz,5kHz) )
6607    end on
6608    )NKSP_CODE",
6609            .expectBoolExitResult = true,
6610            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6611            .expectExitResultUnit = VM_NO_UNIT
6612        });
6613    
6614        runScript({
6615            .code = R"NKSP_CODE(
6616    on init
6617      exit( in_range(2999Hz,3kHz,5kHz) )
6618    end on
6619    )NKSP_CODE",
6620            .expectBoolExitResult = false,
6621            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6622            .expectExitResultUnit = VM_NO_UNIT
6623        });
6624    
6625        runScript({
6626            .code = R"NKSP_CODE(
6627    on init
6628      exit( in_range(0.003s,3000.0us,5ms) )
6629    end on
6630    )NKSP_CODE",
6631            .expectBoolExitResult = true,
6632            .expectParseWarning = true, // in_range() warns if not all arguments are of same type
6633            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6634            .expectExitResultUnit = VM_NO_UNIT
6635        });
6636    
6637        runScript({
6638            .code = R"NKSP_CODE(
6639    on init
6640      exit( in_range(0.005s,3000.0us,5ms) )
6641    end on
6642    )NKSP_CODE",
6643            .expectBoolExitResult = true,
6644            .expectParseWarning = true, // in_range() warns if not all arguments are of same type,
6645            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6646            .expectExitResultUnit = VM_NO_UNIT
6647        });
6648    
6649        runScript({
6650            .code = R"NKSP_CODE(
6651    on init
6652      exit( in_range(0.0051s,3000.0us,5ms) )
6653    end on
6654    )NKSP_CODE",
6655            .expectBoolExitResult = false,
6656            .expectParseWarning = true, // in_range() warns if not all arguments are of same type
6657            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6658            .expectExitResultUnit = VM_NO_UNIT
6659        });
6660    
6661        runScript({
6662            .code = R"NKSP_CODE(
6663    on init
6664      exit( in_range(3s,2Hz,5Hz) )
6665    end on
6666    )NKSP_CODE",
6667            .expectParseError = true // in_range() throws error if not all arguments' unit types equal,
6668        });
6669    
6670        runScript({
6671            .code = R"NKSP_CODE(
6672    on init
6673      exit( in_range(3Hz,2s,5Hz) )
6674    end on
6675    )NKSP_CODE",
6676            .expectParseError = true // in_range() throws error if not all arguments' unit types equal
6677        });
6678    
6679        runScript({
6680            .code = R"NKSP_CODE(
6681    on init
6682      exit( in_range(3Hz,2Hz,5s) )
6683    end on
6684    )NKSP_CODE",
6685            .expectParseError = true // in_range() throws error if not all arguments' unit types equal
6686        });
6687    
6688        // 'final' ('!') operator tests ...
6689        // (result should always be NOT final)
6690    
6691        runScript({
6692            .code = R"NKSP_CODE(
6693    on init
6694      exit( in_range(!9,!4,!9) )
6695    end on
6696    )NKSP_CODE",
6697            .expectBoolExitResult = true,
6698            .expectExitResultFinal = false
6699        });
6700    
6701      #if !SILENT_TEST      #if !SILENT_TEST
6702      std::cout << std::endl;      std::cout << std::endl;
6703      #endif      #endif
# Line 2875  static void testBuiltInRandomFunction() Line 6708  static void testBuiltInRandomFunction()
6708      std::cout << "UNIT TEST: built-in random() function\n";      std::cout << "UNIT TEST: built-in random() function\n";
6709      #endif      #endif
6710    
6711        // integer tests ...
6712    
6713        runScript({
6714            .code = R"NKSP_CODE(
6715    on init
6716      exit( random(-5,5) )
6717    end on
6718    )NKSP_CODE",
6719            .expectExitResultIsInt = true // only check type, exact value is irrelevant here
6720        });
6721    
6722      for (int run = 0; run < 20; ++run) {      for (int run = 0; run < 20; ++run) {
6723          runScript({          runScript({
6724              .code = R"NKSP_CODE(              .code = R"NKSP_CODE(
# Line 2887  end on Line 6731  end on
6731          });          });
6732      }      }
6733    
6734        // real number tests ...
6735    
6736        runScript({
6737            .code = R"NKSP_CODE(
6738    on init
6739      exit( random(-0.5,0.5) )
6740    end on
6741    )NKSP_CODE",
6742            .expectExitResultIsReal = true // only check type, exact value is irrelevant here
6743        });
6744    
6745        runScript({
6746            .code = R"NKSP_CODE(
6747    on init
6748      declare ~foo := random(-5.0,5.0)
6749      exit(~foo)
6750    end on
6751    )NKSP_CODE",
6752            .expectExitResultIsReal = true // only check type, exact value is irrelevant here
6753        });
6754    
6755        for (int run = 0; run < 20; ++run) {
6756            runScript({
6757                .code = R"NKSP_CODE(
6758    on init
6759      declare ~foo := random(-0.5,0.5)
6760      exit( in_range(~foo,-0.5,0.5) )
6761    end on
6762    )NKSP_CODE",
6763                .expectBoolExitResult = true
6764            });
6765        }
6766    
6767        for (int run = 0; run < 20; ++run) {
6768            runScript({
6769                .code = R"NKSP_CODE(
6770    on init
6771      declare ~foo := random(-5.0,12.0)
6772      exit( in_range(~foo,-5.0,12.0) )
6773    end on
6774    )NKSP_CODE",
6775                .expectBoolExitResult = true
6776            });
6777        }
6778    
6779        for (int run = 0; run < 20; ++run) {
6780            runScript({
6781                .code = R"NKSP_CODE(
6782    on init
6783      declare ~foo := random(23.3,98.4)
6784      exit( in_range(~foo,23.3,98.4) )
6785    end on
6786    )NKSP_CODE",
6787                .expectBoolExitResult = true
6788            });
6789        }
6790    
6791        // std unit tests ...
6792    
6793        runScript({
6794            .code = R"NKSP_CODE(
6795    on init
6796      exit( random(-5Hz,5Hz) )
6797    end on
6798    )NKSP_CODE",
6799            .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
6800            .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6801            .expectExitResultUnit = VM_HERTZ
6802        });
6803    
6804        for (int run = 0; run < 20; ++run) {
6805            runScript({
6806                .code = R"NKSP_CODE(
6807    on init
6808      declare $foo := random(-5Hz,5Hz)
6809      exit( in_range($foo,-5Hz,5Hz) )
6810    end on
6811    )NKSP_CODE",
6812                .expectBoolExitResult = true
6813            });
6814        }
6815    
6816        runScript({
6817            .code = R"NKSP_CODE(
6818    on init
6819      exit( random(5us,1ms) )
6820    end on
6821    )NKSP_CODE",
6822            .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
6823            .expectExitResultUnitPrefix = { VM_MICRO },
6824            .expectExitResultUnit = VM_SECOND
6825        });
6826    
6827        for (int run = 0; run < 20; ++run) {
6828            runScript({
6829                .code = R"NKSP_CODE(
6830    on init
6831      declare $foo := random(5us,1ms)
6832      exit( in_range($foo,5us,1ms) )
6833    end on
6834    )NKSP_CODE",
6835                .expectBoolExitResult = true
6836            });
6837        }
6838    
6839        runScript({
6840            .code = R"NKSP_CODE(
6841    on init
6842      exit( random(1ms,5000us) )
6843    end on
6844    )NKSP_CODE",
6845            .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
6846            .expectExitResultUnitPrefix = { VM_MICRO },
6847            .expectExitResultUnit = VM_SECOND
6848        });
6849    
6850        for (int run = 0; run < 20; ++run) {
6851            runScript({
6852                .code = R"NKSP_CODE(
6853    on init
6854      declare $foo := random(1ms,5000us)
6855      exit( in_range($foo,1ms,5000us) )
6856    end on
6857    )NKSP_CODE",
6858                .expectBoolExitResult = true
6859            });
6860        }
6861    
6862        runScript({
6863            .code = R"NKSP_CODE(
6864    on init
6865      exit( random(1kHz,20kHz) )
6866    end on
6867    )NKSP_CODE",
6868            .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
6869            .expectExitResultUnitPrefix = { VM_KILO },
6870            .expectExitResultUnit = VM_HERTZ
6871        });
6872    
6873        for (int run = 0; run < 20; ++run) {
6874            runScript({
6875                .code = R"NKSP_CODE(
6876    on init
6877      declare $foo := random(1kHz,20kHz)
6878      exit( in_range($foo,1kHz,20kHz) )
6879    end on
6880    )NKSP_CODE",
6881                .expectBoolExitResult = true
6882            });
6883        }
6884    
6885        runScript({
6886            .code = R"NKSP_CODE(
6887    on init
6888      exit( random(1.2us,3.5us) )
6889    end on
6890    )NKSP_CODE",
6891            .expectExitResultIsReal = true, // only check type, exact value is irrelevant here
6892            .expectExitResultUnitPrefix = { VM_MICRO },
6893            .expectExitResultUnit = VM_SECOND
6894        });
6895    
6896        for (int run = 0; run < 20; ++run) {
6897            runScript({
6898                .code = R"NKSP_CODE(
6899    on init
6900      declare ~foo := random(1.2us,3.5us)
6901      exit( in_range(~foo,1.2us,3.5us) )
6902    end on
6903    )NKSP_CODE",
6904                .expectBoolExitResult = true
6905            });
6906        }
6907    
6908        runScript({
6909            .code = R"NKSP_CODE(
6910    on init
6911      exit( random(5.2us,1.1ms) )
6912    end on
6913    )NKSP_CODE",
6914            .expectExitResultIsReal = true, // only check type, exact value is irrelevant here
6915            .expectExitResultUnitPrefix = { VM_MICRO },
6916            .expectExitResultUnit = VM_SECOND
6917        });
6918    
6919        for (int run = 0; run < 20; ++run) {
6920            runScript({
6921                .code = R"NKSP_CODE(
6922    on init
6923      declare ~foo := random(5.2us,1.1ms)
6924      exit( in_range(~foo,5.2us,1.1ms) )
6925    end on
6926    )NKSP_CODE",
6927                .expectBoolExitResult = true
6928            });
6929        }
6930    
6931        runScript({
6932            .code = R"NKSP_CODE(
6933    on init
6934      exit( random(1Hz,12s) )
6935    end on
6936    )NKSP_CODE",
6937            .expectParseError = true // random() throws error if arguments' unit types don't match
6938        });
6939    
6940        runScript({
6941            .code = R"NKSP_CODE(
6942    on init
6943      exit( random(1,12s) )
6944    end on
6945    )NKSP_CODE",
6946            .expectParseError = true // random() throws error if arguments' unit types don't match
6947        });
6948    
6949        runScript({
6950            .code = R"NKSP_CODE(
6951    on init
6952      exit( random(1s,12) )
6953    end on
6954    )NKSP_CODE",
6955            .expectParseError = true // random() throws error if arguments' unit types don't match
6956        });
6957    
6958        // 'final' ('!') operator tests ...
6959    
6960        runScript({
6961            .code = R"NKSP_CODE(
6962    on init
6963      exit( random(!1,!12) )
6964    end on
6965    )NKSP_CODE",
6966            .expectExitResultFinal = true
6967        });
6968    
6969        runScript({
6970            .code = R"NKSP_CODE(
6971    on init
6972      exit( random(1,12) )
6973    end on
6974    )NKSP_CODE",
6975            .expectExitResultFinal = false
6976        });
6977    
6978        runScript({
6979            .code = R"NKSP_CODE(
6980    on init
6981      exit( random(!1,12) )
6982    end on
6983    )NKSP_CODE",
6984            .expectExitResultFinal = true,
6985            .expectParseWarning = true // random() warns if only one argument is 'final'
6986        });
6987    
6988        runScript({
6989            .code = R"NKSP_CODE(
6990    on init
6991      exit( random(1,!12) )
6992    end on
6993    )NKSP_CODE",
6994            .expectExitResultFinal = true,
6995            .expectParseWarning = true // random() warns if only one argument is 'final'
6996        });
6997    
6998      #if !SILENT_TEST      #if !SILENT_TEST
6999      std::cout << std::endl;      std::cout << std::endl;
7000      #endif      #endif
# Line 3017  end on Line 7125  end on
7125          .expectRealExitResult = 23.0          .expectRealExitResult = 23.0
7126      });      });
7127    
7128        // std unit tests ...
7129    
7130        runScript({
7131            .code = R"NKSP_CODE(
7132    on init
7133      exit( int_to_real(-58mdB) )
7134    end on
7135    )NKSP_CODE",
7136            .expectRealExitResult = -58.0,
7137            .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7138            .expectExitResultUnit = VM_BEL
7139        });
7140    
7141        runScript({
7142            .code = R"NKSP_CODE(
7143    on init
7144      declare $foo := -58mdB
7145      exit( int_to_real($foo) )
7146    end on
7147    )NKSP_CODE",
7148            .expectRealExitResult = -58.0,
7149            .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7150            .expectExitResultUnit = VM_BEL
7151        });
7152    
7153        // 'final' ('!') operator tests ...
7154    
7155        runScript({
7156            .code = R"NKSP_CODE(
7157    on init
7158      declare $foo := !-58
7159      exit( int_to_real($foo) )
7160    end on
7161    )NKSP_CODE",
7162            .expectRealExitResult = -58.0,
7163            .expectExitResultFinal = true
7164        });
7165    
7166        runScript({
7167            .code = R"NKSP_CODE(
7168    on init
7169      declare $foo := -58
7170      exit( int_to_real($foo) )
7171    end on
7172    )NKSP_CODE",
7173            .expectRealExitResult = -58.0,
7174            .expectExitResultFinal = false
7175        });
7176    
7177      #if !SILENT_TEST      #if !SILENT_TEST
7178      std::cout << std::endl;      std::cout << std::endl;
7179      #endif      #endif
# Line 3046  end on Line 7203  end on
7203          .expectRealExitResult = 23.0          .expectRealExitResult = 23.0
7204      });      });
7205    
7206        // std unit tests ...
7207    
7208        runScript({
7209            .code = R"NKSP_CODE(
7210    on init
7211      exit( real(-58mdB) )
7212    end on
7213    )NKSP_CODE",
7214            .expectRealExitResult = -58.0,
7215            .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7216            .expectExitResultUnit = VM_BEL
7217        });
7218    
7219        runScript({
7220            .code = R"NKSP_CODE(
7221    on init
7222      declare $foo := -58mdB
7223      exit( real($foo) )
7224    end on
7225    )NKSP_CODE",
7226            .expectRealExitResult = -58.0,
7227            .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7228            .expectExitResultUnit = VM_BEL
7229        });
7230    
7231        // 'final' ('!') operator tests ...
7232    
7233        runScript({
7234            .code = R"NKSP_CODE(
7235    on init
7236      declare $foo := !-58
7237      exit( real($foo) )
7238    end on
7239    )NKSP_CODE",
7240            .expectRealExitResult = -58.0,
7241            .expectExitResultFinal = true
7242        });
7243    
7244        runScript({
7245            .code = R"NKSP_CODE(
7246    on init
7247      declare $foo := -58
7248      exit( real($foo) )
7249    end on
7250    )NKSP_CODE",
7251            .expectRealExitResult = -58.0,
7252            .expectExitResultFinal = false
7253        });
7254    
7255      #if !SILENT_TEST      #if !SILENT_TEST
7256      std::cout << std::endl;      std::cout << std::endl;
7257      #endif      #endif
# Line 3075  end on Line 7281  end on
7281          .expectIntExitResult = 8          .expectIntExitResult = 8
7282      });      });
7283    
7284        // std unit tests ...
7285    
7286        runScript({
7287            .code = R"NKSP_CODE(
7288    on init
7289      declare ~foo := 8.9mdB
7290      exit( real_to_int(~foo) )
7291    end on
7292    )NKSP_CODE",
7293            .expectIntExitResult = 8,
7294            .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7295            .expectExitResultUnit = VM_BEL
7296        });
7297    
7298        // 'final' ('!') operator tests ...
7299    
7300        runScript({
7301            .code = R"NKSP_CODE(
7302    on init
7303      declare ~foo := !8.9
7304      exit( real_to_int(~foo) )
7305    end on
7306    )NKSP_CODE",
7307            .expectIntExitResult = 8,
7308            .expectExitResultFinal = true
7309        });
7310    
7311        runScript({
7312            .code = R"NKSP_CODE(
7313    on init
7314      declare ~foo := 8.9
7315      exit( real_to_int(~foo) )
7316    end on
7317    )NKSP_CODE",
7318            .expectIntExitResult = 8,
7319            .expectExitResultFinal = false
7320        });
7321    
7322      #if !SILENT_TEST      #if !SILENT_TEST
7323      std::cout << std::endl;      std::cout << std::endl;
7324      #endif      #endif
# Line 3104  end on Line 7348  end on
7348          .expectIntExitResult = 8          .expectIntExitResult = 8
7349      });      });
7350    
7351        // std unit tests ...
7352    
7353        runScript({
7354            .code = R"NKSP_CODE(
7355    on init
7356      declare ~foo := 8.9mdB
7357      exit( int(~foo) )
7358    end on
7359    )NKSP_CODE",
7360            .expectIntExitResult = 8,
7361            .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7362            .expectExitResultUnit = VM_BEL
7363        });
7364    
7365        // 'final' ('!') operator tests ...
7366    
7367        runScript({
7368            .code = R"NKSP_CODE(
7369    on init
7370      declare ~foo := !8.9
7371      exit( int(~foo) )
7372    end on
7373    )NKSP_CODE",
7374            .expectIntExitResult = 8,
7375            .expectExitResultFinal = true
7376        });
7377    
7378        runScript({
7379            .code = R"NKSP_CODE(
7380    on init
7381      declare ~foo := 8.9
7382      exit( int(~foo) )
7383    end on
7384    )NKSP_CODE",
7385            .expectIntExitResult = 8,
7386            .expectExitResultFinal = false
7387        });
7388    
7389      #if !SILENT_TEST      #if !SILENT_TEST
7390      std::cout << std::endl;      std::cout << std::endl;
7391      #endif      #endif
# Line 3114  static void testBuiltInArrayEqualFunctio Line 7396  static void testBuiltInArrayEqualFunctio
7396      std::cout << "UNIT TEST: built-in array_equal() function\n";      std::cout << "UNIT TEST: built-in array_equal() function\n";
7397      #endif      #endif
7398    
7399        // integer array tests ...
7400    
7401      runScript({      runScript({
7402          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
7403  on init  on init
# Line 3166  on init Line 7450  on init
7450    exit( array_equal(%foo, %bar) )    exit( array_equal(%foo, %bar) )
7451  end on  end on
7452  )NKSP_CODE",  )NKSP_CODE",
7453            .expectBoolExitResult = false,
7454            .expectParseWarning = true // array_equal() warns if array sizes do not match
7455        });
7456    
7457        // real number array tests ...
7458    
7459        runScript({
7460            .code = R"NKSP_CODE(
7461    on init
7462      declare ?foo[3] := ( 1.0, 2.0, 3.0 )
7463      declare ?bar[3] := ( 1.0, 2.0, 3.0 )
7464      exit( array_equal(?foo, ?bar) )
7465    end on
7466    )NKSP_CODE",
7467            .expectBoolExitResult = true
7468        });
7469    
7470        runScript({
7471            .code = R"NKSP_CODE(
7472    on init
7473      declare ?foo[3] := ( 1.0, 1.1, 3.4 )
7474      declare ?bar[3] := ( 1.0, 1.1, 3.4 )
7475      exit( array_equal(?foo, ?bar) )
7476    end on
7477    )NKSP_CODE",
7478            .expectBoolExitResult = true
7479        });
7480    
7481        runScript({
7482            .code = R"NKSP_CODE(
7483    on init
7484      declare ?foo[3] := ( 1.0, 1.1, 3.4 )
7485      declare ?bar[3] := ( 1.0, 1.2, 3.4 )
7486      exit( array_equal(?foo, ?bar) )
7487    end on
7488    )NKSP_CODE",
7489            .expectBoolExitResult = false
7490        });
7491    
7492        runScript({
7493            .code = R"NKSP_CODE(
7494    on init
7495      declare ?foo[3] := ( 1.0, 1.1, 3.4 )
7496      declare ?bar[2] := ( 1.0, 1.1 )
7497      exit( array_equal(?foo, ?bar) )
7498    end on
7499    )NKSP_CODE",
7500            .expectBoolExitResult = false,
7501            .expectParseWarning = true // array_equal() warns if array sizes do not match
7502        });
7503    
7504        // std unit tests ...
7505        // (only metric prefixes allowed, unit types are prohibited for arrays ATM)
7506    
7507        runScript({
7508            .code = R"NKSP_CODE(
7509    on init
7510      declare %foo[3] := ( 1, 1s, 1 )
7511      declare %bar[3] := ( 1, 1,  1 )
7512      exit( array_equal(%foo, %bar) )
7513    end on
7514    )NKSP_CODE",
7515            .expectParseError = true // see comment above
7516        });
7517    
7518        runScript({
7519            .code = R"NKSP_CODE(
7520    on init
7521      declare %foo[3] := ( 1k, 1, 1m )
7522      declare %bar[3] := ( 1k, 1, 1m )
7523      exit( array_equal(%foo, %bar) )
7524    end on
7525    )NKSP_CODE",
7526            .expectBoolExitResult = true
7527        });
7528    
7529        runScript({
7530            .code = R"NKSP_CODE(
7531    on init
7532      declare %foo[3] := ( 1m, 1, 1k )
7533      declare %bar[3] := ( 1k, 1, 1m )
7534      exit( array_equal(%foo, %bar) )
7535    end on
7536    )NKSP_CODE",
7537            .expectBoolExitResult = false
7538        });
7539    
7540        runScript({
7541            .code = R"NKSP_CODE(
7542    on init
7543      declare %foo[3] := ( 1, 1k, 1 )
7544      declare %bar[3] := ( 1, 1,  1 )
7545      exit( array_equal(%foo, %bar) )
7546    end on
7547    )NKSP_CODE",
7548            .expectBoolExitResult = false
7549        });
7550    
7551        runScript({
7552            .code = R"NKSP_CODE(
7553    on init
7554      declare %foo[3] := ( 1, 1k, 1 )
7555      declare %bar[3] := ( 1, 1000, 1 )
7556      exit( array_equal(%foo, %bar) )
7557    end on
7558    )NKSP_CODE",
7559            .expectBoolExitResult = true
7560        });
7561    
7562        runScript({
7563            .code = R"NKSP_CODE(
7564    on init
7565      declare %foo[3] := ( 1, 2, 3000 )
7566      declare %bar[3] := ( 1, 2, 3k )
7567      exit( array_equal(%foo, %bar) )
7568    end on
7569    )NKSP_CODE",
7570            .expectBoolExitResult = true
7571        });
7572    
7573        runScript({
7574            .code = R"NKSP_CODE(
7575    on init
7576      declare %foo[3] := ( 1, 2, 3m )
7577      declare %bar[3] := ( 1, 2, 3k )
7578      exit( array_equal(%foo, %bar) )
7579    end on
7580    )NKSP_CODE",
7581            .expectBoolExitResult = false
7582        });
7583    
7584        runScript({
7585            .code = R"NKSP_CODE(
7586    on init
7587      declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
7588      declare ?bar[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
7589      exit( array_equal(?foo, ?bar) )
7590    end on
7591    )NKSP_CODE",
7592            .expectBoolExitResult = true
7593        });
7594    
7595        runScript({
7596            .code = R"NKSP_CODE(
7597    on init
7598      declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
7599      declare ?bar[4] := ( 1.0, 1.0 , 1.1m, 3.4k )
7600      exit( array_equal(?foo, ?bar) )
7601    end on
7602    )NKSP_CODE",
7603            .expectBoolExitResult = false
7604        });
7605    
7606        runScript({
7607            .code = R"NKSP_CODE(
7608    on init
7609      declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
7610      declare ?bar[4] := ( 1.0, 1.0m, 1.1k, 3.4k )
7611      exit( array_equal(?foo, ?bar) )
7612    end on
7613    )NKSP_CODE",
7614            .expectBoolExitResult = false
7615        });
7616    
7617        runScript({
7618            .code = R"NKSP_CODE(
7619    on init
7620      declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
7621      declare ?bar[4] := ( 1.0, 1.0m, 1.1m, 3.4u )
7622      exit( array_equal(?foo, ?bar) )
7623    end on
7624    )NKSP_CODE",
7625            .expectBoolExitResult = false
7626        });
7627    
7628        runScript({
7629            .code = R"NKSP_CODE(
7630    on init
7631      declare ?foo[3] := ( 1.0, 1.0k, 1.1m )
7632      declare ?bar[3] := ( 1.0, 1000.0, 1.1m )
7633      exit( array_equal(?foo, ?bar) )
7634    end on
7635    )NKSP_CODE",
7636            .expectBoolExitResult = true
7637        });
7638    
7639        runScript({
7640            .code = R"NKSP_CODE(
7641    on init
7642      declare ?foo[3] := ( 1.0, 1.0k, 1.1u )
7643      declare ?bar[3] := ( 1.0, 1000.0, 0.0011m )
7644      exit( array_equal(?foo, ?bar) )
7645    end on
7646    )NKSP_CODE",
7647            .expectBoolExitResult = true
7648        });
7649    
7650        runScript({
7651            .code = R"NKSP_CODE(
7652    on init
7653      declare ?foo[3] := ( 1.0, 1.0k, 1.1u )
7654      declare ?bar[3] := ( 1.0, 1000.0, 0.0016m )
7655      exit( array_equal(?foo, ?bar) )
7656    end on
7657    )NKSP_CODE",
7658          .expectBoolExitResult = false          .expectBoolExitResult = false
7659      });      });
7660    
7661        // 'final' ('!') operator tests ...
7662        // (currently prohibited for arrays)
7663    
7664        runScript({
7665            .code = R"NKSP_CODE(
7666    on init
7667      declare %foo[3] := ( !1, !1, !1 )
7668      declare %bar[3] := ( !1, !1, !1 )
7669      exit( array_equal(%foo, %bar) )
7670    end on
7671    )NKSP_CODE",
7672            .expectParseError = true // see comment above
7673        });
7674    
7675        runScript({
7676            .code = R"NKSP_CODE(
7677    on init
7678      declare ?foo[3] := ( !1.0, !1.0, !1.0 )
7679      declare ?bar[3] := ( !1.0, !1.0, !1.0 )
7680      exit( array_equal(?foo, ?bar) )
7681    end on
7682    )NKSP_CODE",
7683            .expectParseError = true // see comment above
7684        });
7685    
7686      #if !SILENT_TEST      #if !SILENT_TEST
7687      std::cout << std::endl;      std::cout << std::endl;
7688      #endif      #endif
# Line 3179  static void testBuiltInSortFunction() { Line 7693  static void testBuiltInSortFunction() {
7693      std::cout << "UNIT TEST: built-in sort() function\n";      std::cout << "UNIT TEST: built-in sort() function\n";
7694      #endif      #endif
7695    
7696        // integer array tests ...
7697    
7698      runScript({      runScript({
7699          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
7700  on init  on init
# Line 3203  end on Line 7719  end on
7719          .expectBoolExitResult = true          .expectBoolExitResult = true
7720      });      });
7721    
7722        runScript({
7723            .code = R"NKSP_CODE(
7724    on init
7725      declare %input[6] := ( 1, 80, 120, 40, 3000, 20 )
7726      declare %expected[6] := ( 1, 20, 40, 80, 120, 3000  )
7727      sort(%input, 0)
7728      exit( array_equal(%input, %expected) )
7729    end on
7730    )NKSP_CODE",
7731            .expectBoolExitResult = true
7732        });
7733    
7734        // real number array tests ...
7735    
7736        runScript({
7737            .code = R"NKSP_CODE(
7738    on init
7739      declare ?input[4] := ( 1.4, 1.0, 13.4, 2.7 )
7740      declare ?expected[4] := ( 1.0, 1.4, 2.7, 13.4 )
7741      sort(?input, 0)
7742      exit( array_equal(?input, ?expected) )
7743    end on
7744    )NKSP_CODE",
7745            .expectBoolExitResult = true
7746        });
7747    
7748        runScript({
7749            .code = R"NKSP_CODE(
7750    on init
7751      declare ?input[4] := ( 1.4, 1.0, 13.4, 2.7 )
7752      declare ?expected[4] := ( 13.4, 2.7, 1.4, 1.0 )
7753      sort(?input, 1)
7754      exit( array_equal(?input, ?expected) )
7755    end on
7756    )NKSP_CODE",
7757            .expectBoolExitResult = true
7758        });
7759    
7760        // std unit tests ...
7761        // (only metric prefixes are allowed for arrays ATM)
7762    
7763        runScript({
7764            .code = R"NKSP_CODE(
7765    on init
7766      declare %input[3] := ( 1k, 6, 900 )
7767      declare %expected[3] := ( 6, 900, 1k )
7768      sort(%input, 0)
7769      exit( array_equal(%input, %expected) )
7770    end on
7771    )NKSP_CODE",
7772            .expectBoolExitResult = true
7773        });
7774    
7775        runScript({
7776            .code = R"NKSP_CODE(
7777    on init
7778      declare %input[3] := ( 900, 1k, 6 )
7779      declare %expected[3] := ( 1k, 900, 6 )
7780      sort(%input, 1)
7781      exit( array_equal(%input, %expected) )
7782    end on
7783    )NKSP_CODE",
7784            .expectBoolExitResult = true
7785        });
7786    
7787        runScript({
7788            .code = R"NKSP_CODE(
7789    on init
7790      declare %input[6] := ( 1k, 8m, 4k, 12000u, 3000u, 1000u )
7791      declare %expected[6] := ( 1000u, 3000u, 8m, 12000u, 1k, 4k )
7792      sort(%input, 0)
7793      exit( array_equal(%input, %expected) )
7794    end on
7795    )NKSP_CODE",
7796            .expectBoolExitResult = true
7797        });
7798    
7799        runScript({
7800            .code = R"NKSP_CODE(
7801    on init
7802      declare ?input[3] := ( 1.0k, 6.0, 900.0 )
7803      declare ?expected[3] := ( 6.0, 900.0, 1.0k )
7804      sort(?input, 0)
7805      exit( array_equal(?input, ?expected) )
7806    end on
7807    )NKSP_CODE",
7808            .expectBoolExitResult = true
7809        });
7810    
7811        runScript({
7812            .code = R"NKSP_CODE(
7813    on init
7814      declare ?input[3] := ( 900.0, 1.0k, 6.0 )
7815      declare ?expected[3] := ( 1.0k, 900.0, 6.0 )
7816      sort(?input, 1)
7817      exit( array_equal(?input, ?expected) )
7818    end on
7819    )NKSP_CODE",
7820            .expectBoolExitResult = true
7821        });
7822    
7823        runScript({
7824            .code = R"NKSP_CODE(
7825    on init
7826      declare ?input[3] := ( 1.0k, 0.9k, 1.1k )
7827      declare ?expected[3] := ( 0.9k, 1.0k, 1.1k )
7828      sort(?input, 0)
7829      exit( array_equal(?input, ?expected) )
7830    end on
7831    )NKSP_CODE",
7832            .expectBoolExitResult = true
7833        });
7834    
7835        runScript({
7836            .code = R"NKSP_CODE(
7837    on init
7838      declare ?input[3] := ( 2.0m, 1000.1u, 1.0 )
7839      declare ?expected[3] := ( 1000.1u, 2.0m, 1.0 )
7840      sort(?input, 0)
7841      exit( array_equal(?input, ?expected) )
7842    end on
7843    )NKSP_CODE",
7844            .expectBoolExitResult = true
7845        });
7846    
7847        runScript({
7848            .code = R"NKSP_CODE(
7849    on init
7850      declare ?input[4] := ( 2.0m, 1000.1u, 1.0, 1400.0u )
7851      declare ?expected[4] := ( 1000.1u, 1400.0u, 2.0m, 1.0 )
7852      sort(?input, 0)
7853      exit( array_equal(?input, ?expected) )
7854    end on
7855    )NKSP_CODE",
7856            .expectBoolExitResult = true
7857        });
7858    
7859        runScript({
7860            .code = R"NKSP_CODE(
7861    on init
7862      declare ?input[4] := ( 2.0m, 1000.1u, 1.0, 1400.0u )
7863      declare ?expected[4] := ( 1.0, 2.0m, 1400.0u, 1000.1u )
7864      sort(?input, 1)
7865      exit( array_equal(?input, ?expected) )
7866    end on
7867    )NKSP_CODE",
7868            .expectBoolExitResult = true
7869        });
7870    
7871        runScript({
7872            .code = R"NKSP_CODE(
7873    on init
7874      declare ?input[6] := ( 0.9k, 8.0m, 1.1k, 12000.0u, 3000.0u, 1000.0u )
7875      declare ?expected[6] := ( 1000.0u, 3000.0u, 8.0m, 12000.0u, 0.9k, 1.1k )
7876      sort(?input, 0)
7877      exit( array_equal(?input, ?expected) )
7878    end on
7879    )NKSP_CODE",
7880            .expectBoolExitResult = true
7881        });
7882    
7883        runScript({
7884            .code = R"NKSP_CODE(
7885    on init
7886      declare ?input[6] := ( 0.9k, 8.0m, 1.1k, 12000.0u, 3000.0u, 1000.0u )
7887      declare ?expected[6] := ( 1.1k, 0.9k, 12000.0u, 8.0m, 3000.0u, 1000.0u )
7888      sort(?input, 1)
7889      exit( array_equal(?input, ?expected) )
7890    end on
7891    )NKSP_CODE",
7892            .expectBoolExitResult = true
7893        });
7894    
7895      #if !SILENT_TEST      #if !SILENT_TEST
7896      std::cout << std::endl;      std::cout << std::endl;
7897      #endif      #endif
# Line 3213  static void testBuiltInNumElementsFuncti Line 7902  static void testBuiltInNumElementsFuncti
7902      std::cout << "UNIT TEST: built-in num_elements() function\n";      std::cout << "UNIT TEST: built-in num_elements() function\n";
7903      #endif      #endif
7904    
7905        // integer array tests ...
7906    
7907      runScript({      runScript({
7908          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
7909  on init  on init
# Line 3243  end on Line 7934  end on
7934          .expectIntExitResult = 5          .expectIntExitResult = 5
7935      });      });
7936    
7937        // real array tests ...
7938    
7939        runScript({
7940            .code = R"NKSP_CODE(
7941    on init
7942      declare ?foo[3] := ( 19.0, 3.2, 6.5 )
7943      exit( num_elements(?foo) )
7944    end on
7945    )NKSP_CODE",
7946            .expectIntExitResult = 3
7947        });
7948    
7949        runScript({
7950            .code = R"NKSP_CODE(
7951    on init
7952      declare ?foo[1] := ( 19.0 )
7953      exit( num_elements(?foo) )
7954    end on
7955    )NKSP_CODE",
7956            .expectIntExitResult = 1
7957        });
7958    
7959        runScript({
7960            .code = R"NKSP_CODE(
7961    on init
7962      declare ?foo[5] := ( 1.1, 2.2, 3.3, 4.4, 5.5 )
7963      exit( num_elements(?foo) )
7964    end on
7965    )NKSP_CODE",
7966            .expectIntExitResult = 5
7967        });
7968    
7969      #if !SILENT_TEST      #if !SILENT_TEST
7970      std::cout << std::endl;      std::cout << std::endl;
7971      #endif      #endif
# Line 3253  static void testBuiltInSearchFunction() Line 7976  static void testBuiltInSearchFunction()
7976      std::cout << "UNIT TEST: built-in search() function\n";      std::cout << "UNIT TEST: built-in search() function\n";
7977      #endif      #endif
7978    
7979        // integer array tests ...
7980    
7981      runScript({      runScript({
7982          .code = R"NKSP_CODE(          .code = R"NKSP_CODE(
7983  on init  on init
# Line 3291  on init Line 8016  on init
8016  end on  end on
8017  )NKSP_CODE",  )NKSP_CODE",
8018          .expectIntExitResult = -1          .expectIntExitResult = -1
8019        });
8020    
8021        // real array tests ...
8022    
8023        runScript({
8024            .code = R"NKSP_CODE(
8025    on init
8026      declare ?foo[3] := ( 19.12, 3.45, 6.89 )
8027      exit( search(?foo, 19.12) )
8028    end on
8029    )NKSP_CODE",
8030            .expectIntExitResult = 0
8031        });
8032    
8033        runScript({
8034            .code = R"NKSP_CODE(
8035    on init
8036      declare ?foo[3] := ( 19.12, 3.45, 6.89 )
8037      exit( search(?foo, 3.45) )
8038    end on
8039    )NKSP_CODE",
8040            .expectIntExitResult = 1
8041        });
8042    
8043        runScript({
8044            .code = R"NKSP_CODE(
8045    on init
8046      declare ?foo[3] := ( 19.12, 3.45, 6.89 )
8047      exit( search(?foo, 6.89) )
8048    end on
8049    )NKSP_CODE",
8050            .expectIntExitResult = 2
8051        });
8052    
8053        runScript({
8054            .code = R"NKSP_CODE(
8055    on init
8056      declare ?foo[3] := ( 19.12, 3.45, 6.89 )
8057      exit( search(?foo, 6.99) )
8058    end on
8059    )NKSP_CODE",
8060            .expectIntExitResult = -1
8061      });      });
8062    
8063      #if !SILENT_TEST      #if !SILENT_TEST

Legend:
Removed from v.3577  
changed lines
  Added in v.3586

  ViewVC Help
Powered by ViewVC