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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3727 - (hide annotations) (download)
Mon Jan 27 16:34:44 2020 UTC (4 years, 4 months ago) by schoenebeck
File size: 220734 byte(s)
Tests: Added thorough NKSP test cases for variable declarations.

1 schoenebeck 3551 /*
2 schoenebeck 3727 * Copyright (c) 2019 - 2020 Christian Schoenebeck
3 schoenebeck 3551 *
4     * http://www.linuxsampler.org
5     *
6     * This file is part of LinuxSampler and released under the same terms.
7     * See README file for details.
8     */
9    
10     // This file contains automated test cases against the NKSP real-time
11     // instrument script engine.
12    
13     #include "../../common/global.h"
14     #include "../../common/optional.h"
15 schoenebeck 3575 #include "../../common/RTMath.h"
16 schoenebeck 3551 #include "../ScriptVM.h"
17     #include "../common.h"
18     #include <sstream>
19     #include <stdlib.h>
20     #include <time.h>
21     #include <assert.h>
22     #include <functional>
23    
24     #ifndef TEST_ASSERT
25     # define TEST_ASSERT assert
26     #endif
27    
28     using namespace LinuxSampler;
29     using namespace std;
30    
31     struct RunScriptOpt {
32     String code;
33     bool expectParseError;
34 schoenebeck 3581 bool expectParseWarning;
35 schoenebeck 3551 bool expectRuntimeError;
36     bool expectNoExitResult;
37 schoenebeck 3581 bool expectExitResultIsInt;
38     bool expectExitResultIsReal;
39 schoenebeck 3551 bool prohibitExitFunctionArguments;
40 schoenebeck 3575 optional<vmint> expectIntExitResult;
41 schoenebeck 3551 optional<bool> expectBoolExitResult;
42 schoenebeck 3575 optional<vmfloat> expectRealExitResult;
43 schoenebeck 3551 optional<String> expectStringExitResult;
44 schoenebeck 3581 vector<MetricPrefix_t> expectExitResultUnitPrefix;
45     optional<StdUnit_t> expectExitResultUnit;
46     optional<bool> expectExitResultFinal;
47 schoenebeck 3551 };
48    
49     static void runScript(const RunScriptOpt& opt) {
50     ScriptVM vm;
51     vm.setAutoSuspendEnabled(false);
52     if (!opt.prohibitExitFunctionArguments)
53     vm.setExitResultEnabled(true);
54     unique_ptr<VMParserContext> parserCtx(
55     vm.loadScript(opt.code)
56     );
57     vector<ParserIssue> errors = parserCtx->errors();
58 schoenebeck 3581 vector<ParserIssue> warnings = parserCtx->warnings();
59 schoenebeck 3551 if (opt.expectParseError) {
60     TEST_ASSERT(!errors.empty());
61     return;
62     } else {
63     for (ParserIssue& err : errors) {
64     err.dump();
65     }
66     TEST_ASSERT(errors.empty());
67     }
68 schoenebeck 3581 if (opt.expectParseWarning) {
69     TEST_ASSERT(!warnings.empty());
70     } else {
71     for (ParserIssue& wrn : warnings) {
72     wrn.dump();
73     }
74     }
75 schoenebeck 3551 TEST_ASSERT(parserCtx->eventHandler(0));
76     unique_ptr<VMExecContext> execCtx(
77     vm.createExecContext(&*parserCtx)
78     );
79     for (int i = 0; parserCtx->eventHandler(i); ++i) {
80     VMEventHandler* handler = parserCtx->eventHandler(i);
81     VMExecStatus_t result = vm.exec(&*parserCtx, &*execCtx, handler);
82     if (opt.expectRuntimeError) {
83     TEST_ASSERT(result & VM_EXEC_ERROR);
84     } else {
85     TEST_ASSERT(!(result & VM_EXEC_ERROR));
86     }
87     if (opt.expectNoExitResult) {
88     VMExpr* resExpr = execCtx->exitResult();
89     TEST_ASSERT(!resExpr);
90     }
91 schoenebeck 3581 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 schoenebeck 3551 if (opt.expectIntExitResult) {
102     VMExpr* resExpr = execCtx->exitResult();
103     TEST_ASSERT(resExpr);
104     TEST_ASSERT(resExpr->exprType() == INT_EXPR);
105     TEST_ASSERT(resExpr->asInt()->evalInt() == *opt.expectIntExitResult);
106     }
107 schoenebeck 3575 if (opt.expectRealExitResult) {
108     VMExpr* resExpr = execCtx->exitResult();
109     TEST_ASSERT(resExpr);
110     TEST_ASSERT(resExpr->exprType() == REAL_EXPR);
111     if (sizeof(vmfloat) == sizeof(float)) {
112     TEST_ASSERT(RTMath::fEqual32(resExpr->asReal()->evalReal(), *opt.expectRealExitResult));
113     } else {
114     TEST_ASSERT(RTMath::fEqual64(resExpr->asReal()->evalReal(), *opt.expectRealExitResult));
115     }
116     }
117 schoenebeck 3551 if (opt.expectBoolExitResult) {
118     VMExpr* resExpr = execCtx->exitResult();
119     TEST_ASSERT(resExpr);
120     TEST_ASSERT(resExpr->exprType() == INT_EXPR);
121     TEST_ASSERT(bool(resExpr->asInt()->evalInt()) == *opt.expectBoolExitResult);
122     }
123     if (opt.expectStringExitResult) {
124     VMExpr* resExpr = execCtx->exitResult();
125     TEST_ASSERT(resExpr);
126     TEST_ASSERT(resExpr->exprType() == STRING_EXPR);
127     TEST_ASSERT(resExpr->asString()->evalStr() == *opt.expectStringExitResult);
128     }
129 schoenebeck 3581 if (opt.expectExitResultUnit) {
130     VMExpr* resExpr = execCtx->exitResult();
131     TEST_ASSERT(resExpr);
132 schoenebeck 3582 VMNumberExpr* numberExpr = resExpr->asNumber();
133 schoenebeck 3581 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 schoenebeck 3582 VMNumberExpr* numberExpr = resExpr->asNumber();
140 schoenebeck 3581 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 schoenebeck 3582 VMNumberExpr* numberExpr = resExpr->asNumber();
156 schoenebeck 3581 TEST_ASSERT(numberExpr);
157     TEST_ASSERT(numberExpr->isFinal() == *opt.expectExitResultFinal);
158     }
159 schoenebeck 3551 }
160     }
161    
162     static void testBuiltInExitFunction() {
163     #if !SILENT_TEST
164     std::cout << "UNIT TEST: built-in exit() function\n";
165     #endif
166    
167     runScript({
168     .code = R"NKSP_CODE(
169     on init
170     end on
171     )NKSP_CODE",
172     .expectNoExitResult = true
173     });
174    
175     runScript({
176     .code = R"NKSP_CODE(
177     on init
178     exit
179     end on
180     )NKSP_CODE",
181     .expectNoExitResult = true
182     });
183    
184     runScript({
185     .code = R"NKSP_CODE(
186     on init
187     exit()
188     end on
189     )NKSP_CODE",
190     .expectNoExitResult = true
191     });
192    
193 schoenebeck 3575 // integer tests ...
194    
195 schoenebeck 3551 runScript({
196     .code = R"NKSP_CODE(
197     on init
198     exit(42)
199     end on
200     )NKSP_CODE",
201     .expectIntExitResult = 42
202     });
203    
204     runScript({
205     .code = R"NKSP_CODE(
206     on init
207     declare $foo := 1
208     if ($foo)
209     exit(21)
210     end if
211     end on
212     )NKSP_CODE",
213     .expectIntExitResult = 21
214     });
215    
216     runScript({
217     .code = R"NKSP_CODE(
218     on init
219     declare $foo := 0
220     if ($foo)
221     exit(21)
222     end if
223     exit(99)
224     end on
225     )NKSP_CODE",
226     .expectIntExitResult = 99
227     });
228    
229 schoenebeck 3575 // string tests ...
230    
231 schoenebeck 3551 runScript({
232     .code = R"NKSP_CODE(
233     on init
234     exit("fourtytwo!")
235     end on
236     )NKSP_CODE",
237     .expectStringExitResult = "fourtytwo!"
238     });
239    
240     // in production environment we prohibit the built-in exit() function to
241     // accept any arguments
242     runScript({
243     .code = R"NKSP_CODE(
244     on init
245     exit(42)
246     end on
247     )NKSP_CODE",
248     .expectParseError = true, // see comment above why
249     .prohibitExitFunctionArguments = true // simulate production environment
250     });
251    
252 schoenebeck 3575 // real number tests ...
253    
254     runScript({
255     .code = R"NKSP_CODE(
256     on init
257     exit(3.14)
258     end on
259     )NKSP_CODE",
260     .expectRealExitResult = 3.14
261     });
262    
263     runScript({
264     .code = R"NKSP_CODE(
265     on init
266     declare $foo := 1
267     if ($foo)
268     exit(3.14)
269     end if
270     end on
271     )NKSP_CODE",
272     .expectRealExitResult = 3.14
273     });
274    
275     runScript({
276     .code = R"NKSP_CODE(
277     on init
278     declare $foo := 0
279     if ($foo)
280     exit(3.14)
281     end if
282     exit(6.9)
283     end on
284     )NKSP_CODE",
285     .expectRealExitResult = 6.9
286     });
287    
288 schoenebeck 3586 // 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 schoenebeck 3581 // 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 schoenebeck 3551 #if !SILENT_TEST
1010     std::cout << std::endl;
1011     #endif
1012     }
1013    
1014     static void testStringConcatOperator() {
1015     #if !SILENT_TEST
1016     std::cout << "UNIT TEST: string concatenation (&) operator\n";
1017     #endif
1018    
1019 schoenebeck 3581 // strings only tests ...
1020    
1021 schoenebeck 3551 runScript({
1022     .code = R"NKSP_CODE(
1023     on init
1024     declare @s := "foo" & " bar"
1025     exit(@s)
1026     end on
1027     )NKSP_CODE",
1028     .expectStringExitResult = "foo bar"
1029     });
1030    
1031 schoenebeck 3581 // integer tests ...
1032    
1033 schoenebeck 3551 runScript({
1034     .code = R"NKSP_CODE(
1035     on init
1036     declare @s := "foo" & " bar" & " " & 123
1037     exit(@s)
1038     end on
1039     )NKSP_CODE",
1040     .expectStringExitResult = "foo bar 123"
1041     });
1042    
1043     runScript({
1044     .code = R"NKSP_CODE(
1045     on init
1046     declare $i := 123
1047     declare @s := "foo" & " bar" & " " & $i
1048     exit(@s)
1049     end on
1050     )NKSP_CODE",
1051     .expectStringExitResult = "foo bar 123"
1052     });
1053    
1054 schoenebeck 3581 // 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 schoenebeck 3551 #if !SILENT_TEST
1168     std::cout << std::endl;
1169     #endif
1170     }
1171    
1172 schoenebeck 3575 static void testNegOperator() {
1173     #if !SILENT_TEST
1174     std::cout << "UNIT TEST: negate (-) operator\n";
1175     #endif
1176    
1177     // integer tests ...
1178    
1179     runScript({
1180     .code = R"NKSP_CODE(
1181     on init
1182     exit(-87)
1183     end on
1184     )NKSP_CODE",
1185     .expectIntExitResult = -87
1186     });
1187    
1188     runScript({
1189     .code = R"NKSP_CODE(
1190     on init
1191     declare $foo := -87
1192     exit(-$foo)
1193     end on
1194     )NKSP_CODE",
1195     .expectIntExitResult = 87
1196     });
1197    
1198     // real number tests ...
1199    
1200     runScript({
1201     .code = R"NKSP_CODE(
1202     on init
1203     exit(-99.3)
1204     end on
1205     )NKSP_CODE",
1206     .expectRealExitResult = -99.3
1207     });
1208    
1209     runScript({
1210     .code = R"NKSP_CODE(
1211     on init
1212     declare ~foo := -99.3
1213     exit(-~foo)
1214     end on
1215     )NKSP_CODE",
1216     .expectRealExitResult = 99.3
1217     });
1218    
1219 schoenebeck 3581 // 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 schoenebeck 3592 //TODO: the following are unary '+' operator tests which should be moved to their own function (lazy me).
1258    
1259     runScript({
1260     .code = R"NKSP_CODE(
1261     on init
1262     exit(+54)
1263     end on
1264     )NKSP_CODE",
1265     .expectIntExitResult = 54
1266     });
1267    
1268     runScript({
1269     .code = R"NKSP_CODE(
1270     on init
1271     declare $foo := +54
1272     exit( $foo )
1273     end on
1274     )NKSP_CODE",
1275     .expectIntExitResult = 54
1276     });
1277    
1278     runScript({
1279     .code = R"NKSP_CODE(
1280     on init
1281     exit(+0.45)
1282     end on
1283     )NKSP_CODE",
1284     .expectRealExitResult = 0.45
1285     });
1286    
1287     runScript({
1288     .code = R"NKSP_CODE(
1289     on init
1290     declare ~foo := +0.29
1291     exit( ~foo )
1292     end on
1293     )NKSP_CODE",
1294     .expectRealExitResult = 0.29
1295     });
1296    
1297 schoenebeck 3575 #if !SILENT_TEST
1298     std::cout << std::endl;
1299     #endif
1300     }
1301    
1302 schoenebeck 3551 static void testPlusOperator() {
1303     #if !SILENT_TEST
1304     std::cout << "UNIT TEST: plus (+) operator\n";
1305     #endif
1306    
1307 schoenebeck 3575 // integer tests ...
1308    
1309 schoenebeck 3551 runScript({
1310     .code = R"NKSP_CODE(
1311     on init
1312     exit(4 + 3)
1313     end on
1314     )NKSP_CODE",
1315     .expectIntExitResult = 7
1316     });
1317    
1318     runScript({
1319     .code = R"NKSP_CODE(
1320     on init
1321     exit(42 + 145)
1322     end on
1323     )NKSP_CODE",
1324     .expectIntExitResult = 187
1325     });
1326    
1327     runScript({
1328     .code = R"NKSP_CODE(
1329     on init
1330     exit(-4 + 2)
1331     end on
1332     )NKSP_CODE",
1333     .expectIntExitResult = -2
1334     });
1335    
1336 schoenebeck 3575 // real number tests ...
1337    
1338     runScript({
1339     .code = R"NKSP_CODE(
1340     on init
1341     exit(4.0 + 3.0)
1342     end on
1343     )NKSP_CODE",
1344     .expectRealExitResult = 7.0
1345     });
1346    
1347     runScript({
1348     .code = R"NKSP_CODE(
1349     on init
1350     exit(42.3 + 145.2)
1351     end on
1352     )NKSP_CODE",
1353     .expectRealExitResult = 187.5
1354     });
1355    
1356     runScript({
1357     .code = R"NKSP_CODE(
1358     on init
1359     exit(-4.0 + 2.2)
1360     end on
1361     )NKSP_CODE",
1362     .expectRealExitResult = -1.8
1363     });
1364    
1365 schoenebeck 3581 // std unit tests ...
1366    
1367     runScript({
1368     .code = R"NKSP_CODE(
1369     on init
1370     exit(42ms + 145ms)
1371     end on
1372     )NKSP_CODE",
1373     .expectIntExitResult = 187,
1374     .expectExitResultUnitPrefix = { VM_MILLI },
1375     .expectExitResultUnit = VM_SECOND
1376     });
1377    
1378     runScript({
1379     .code = R"NKSP_CODE(
1380     on init
1381     exit(1s + 145ms)
1382     end on
1383     )NKSP_CODE",
1384     .expectIntExitResult = 1145,
1385     .expectExitResultUnitPrefix = { VM_MILLI },
1386     .expectExitResultUnit = VM_SECOND
1387     });
1388    
1389     runScript({
1390     .code = R"NKSP_CODE(
1391     on init
1392     exit(42ms + 145)
1393     end on
1394     )NKSP_CODE",
1395     .expectParseError = true // units must match for + operator
1396     });
1397    
1398     runScript({
1399     .code = R"NKSP_CODE(
1400     on init
1401     exit(42 + 145ms)
1402     end on
1403     )NKSP_CODE",
1404     .expectParseError = true // units must match for + operator
1405     });
1406    
1407     runScript({
1408     .code = R"NKSP_CODE(
1409     on init
1410     exit(42Hz + 145s)
1411     end on
1412     )NKSP_CODE",
1413     .expectParseError = true // units must match for + operator
1414     });
1415    
1416     runScript({
1417     .code = R"NKSP_CODE(
1418     on init
1419     exit(42.1ms + 145.3ms)
1420     end on
1421     )NKSP_CODE",
1422     .expectRealExitResult = 187.4,
1423     .expectExitResultUnitPrefix = { VM_MILLI },
1424     .expectExitResultUnit = VM_SECOND
1425     });
1426    
1427     runScript({
1428     .code = R"NKSP_CODE(
1429     on init
1430     exit(1.1s + 145.0ms)
1431     end on
1432     )NKSP_CODE",
1433     .expectRealExitResult = 1245.0,
1434     .expectExitResultUnitPrefix = { VM_MILLI },
1435     .expectExitResultUnit = VM_SECOND
1436     });
1437    
1438     runScript({
1439     .code = R"NKSP_CODE(
1440     on init
1441     exit(42.1ms + 145.3)
1442     end on
1443     )NKSP_CODE",
1444     .expectParseError = true // units must match for + operator
1445     });
1446    
1447     runScript({
1448     .code = R"NKSP_CODE(
1449     on init
1450     exit(42.0 + 145.0ms)
1451     end on
1452     )NKSP_CODE",
1453     .expectParseError = true // units must match for + operator
1454     });
1455    
1456     runScript({
1457     .code = R"NKSP_CODE(
1458     on init
1459     exit(42.0Hz + 145.0s)
1460     end on
1461     )NKSP_CODE",
1462     .expectParseError = true // units must match for + operator
1463     });
1464    
1465     // 'final' ('!') operator tests ...
1466    
1467     runScript({
1468     .code = R"NKSP_CODE(
1469     on init
1470     exit(!4 + !3)
1471     end on
1472     )NKSP_CODE",
1473     .expectIntExitResult = 7,
1474     .expectExitResultFinal = true
1475     });
1476    
1477     runScript({
1478     .code = R"NKSP_CODE(
1479     on init
1480     exit(4 + 3)
1481     end on
1482     )NKSP_CODE",
1483     .expectIntExitResult = 7,
1484     .expectExitResultFinal = false
1485     });
1486    
1487     runScript({
1488     .code = R"NKSP_CODE(
1489     on init
1490     exit(!4.1 + !3.3)
1491     end on
1492     )NKSP_CODE",
1493     .expectRealExitResult = 7.4,
1494     .expectExitResultFinal = true
1495     });
1496    
1497     runScript({
1498     .code = R"NKSP_CODE(
1499     on init
1500     exit(4.1 + 3.3)
1501     end on
1502     )NKSP_CODE",
1503     .expectRealExitResult = 7.4,
1504     .expectExitResultFinal = false
1505     });
1506    
1507 schoenebeck 3551 #if !SILENT_TEST
1508     std::cout << std::endl;
1509     #endif
1510     }
1511    
1512     static void testMinusOperator() {
1513     #if !SILENT_TEST
1514     std::cout << "UNIT TEST: minus (-) operator\n";
1515     #endif
1516    
1517 schoenebeck 3575 // integer tests ...
1518    
1519 schoenebeck 3551 runScript({
1520     .code = R"NKSP_CODE(
1521     on init
1522     exit(4 - 3)
1523     end on
1524     )NKSP_CODE",
1525     .expectIntExitResult = 1
1526     });
1527    
1528     runScript({
1529     .code = R"NKSP_CODE(
1530     on init
1531     exit(139 - 74)
1532     end on
1533     )NKSP_CODE",
1534     .expectIntExitResult = 65
1535     });
1536    
1537     runScript({
1538     .code = R"NKSP_CODE(
1539     on init
1540     exit(3 - 9)
1541     end on
1542     )NKSP_CODE",
1543     .expectIntExitResult = -6
1544     });
1545    
1546     runScript({
1547     .code = R"NKSP_CODE(
1548     on init
1549     exit(-3 - 18)
1550     end on
1551     )NKSP_CODE",
1552     .expectIntExitResult = -21
1553     });
1554    
1555 schoenebeck 3575 // real number tests ...
1556    
1557     runScript({
1558     .code = R"NKSP_CODE(
1559     on init
1560     exit(4.0 - 0.2)
1561     end on
1562     )NKSP_CODE",
1563     .expectRealExitResult = 3.8
1564     });
1565    
1566     runScript({
1567     .code = R"NKSP_CODE(
1568     on init
1569     exit(3.1 - 9.65)
1570     end on
1571     )NKSP_CODE",
1572     .expectRealExitResult = -6.55
1573     });
1574    
1575     runScript({
1576     .code = R"NKSP_CODE(
1577     on init
1578     exit(-3.0 - 18.1)
1579     end on
1580     )NKSP_CODE",
1581     .expectRealExitResult = -21.1
1582     });
1583    
1584 schoenebeck 3581 // std unit tests ...
1585    
1586     runScript({
1587     .code = R"NKSP_CODE(
1588     on init
1589     exit(1000ms - 145ms)
1590     end on
1591     )NKSP_CODE",
1592     .expectIntExitResult = 855,
1593     .expectExitResultUnitPrefix = { VM_MILLI },
1594     .expectExitResultUnit = VM_SECOND
1595     });
1596    
1597     runScript({
1598     .code = R"NKSP_CODE(
1599     on init
1600     exit(1s - 145ms)
1601     end on
1602     )NKSP_CODE",
1603     .expectIntExitResult = 855,
1604     .expectExitResultUnitPrefix = { VM_MILLI },
1605     .expectExitResultUnit = VM_SECOND
1606     });
1607    
1608     runScript({
1609     .code = R"NKSP_CODE(
1610     on init
1611     exit(1s - 145)
1612     end on
1613     )NKSP_CODE",
1614     .expectParseError = true // units must match for - operator
1615     });
1616    
1617     runScript({
1618     .code = R"NKSP_CODE(
1619     on init
1620     exit(1 - 145s)
1621     end on
1622     )NKSP_CODE",
1623     .expectParseError = true // units must match for - operator
1624     });
1625    
1626     runScript({
1627     .code = R"NKSP_CODE(
1628     on init
1629     exit(1ms - 145mB)
1630     end on
1631     )NKSP_CODE",
1632     .expectParseError = true // units must match for - operator
1633     });
1634    
1635     runScript({
1636     .code = R"NKSP_CODE(
1637     on init
1638     exit(1.0ms - 0.1ms)
1639     end on
1640     )NKSP_CODE",
1641     .expectRealExitResult = 0.9,
1642     .expectExitResultUnitPrefix = { VM_MILLI },
1643     .expectExitResultUnit = VM_SECOND
1644     });
1645    
1646     runScript({
1647     .code = R"NKSP_CODE(
1648     on init
1649     exit(1.1s - 106.0ms)
1650     end on
1651     )NKSP_CODE",
1652     .expectRealExitResult = 994.0,
1653     .expectExitResultUnitPrefix = { VM_MILLI },
1654     .expectExitResultUnit = VM_SECOND
1655     });
1656    
1657     runScript({
1658     .code = R"NKSP_CODE(
1659     on init
1660     exit(1100.0ms - 0.106s)
1661     end on
1662     )NKSP_CODE",
1663     .expectRealExitResult = 994.0,
1664     .expectExitResultUnitPrefix = { VM_MILLI },
1665     .expectExitResultUnit = VM_SECOND
1666     });
1667    
1668     runScript({
1669     .code = R"NKSP_CODE(
1670     on init
1671     exit(1.0s - 145.0)
1672     end on
1673     )NKSP_CODE",
1674     .expectParseError = true // units must match for - operator
1675     });
1676    
1677     runScript({
1678     .code = R"NKSP_CODE(
1679     on init
1680     exit(1.0 - 145.0s)
1681     end on
1682     )NKSP_CODE",
1683     .expectParseError = true // units must match for - operator
1684     });
1685    
1686     runScript({
1687     .code = R"NKSP_CODE(
1688     on init
1689     exit(1.0ms - 145.0mB)
1690     end on
1691     )NKSP_CODE",
1692     .expectParseError = true // units must match for - operator
1693     });
1694    
1695     // 'final' ('!') operator tests ...
1696    
1697     runScript({
1698     .code = R"NKSP_CODE(
1699     on init
1700     exit(!5 - !3)
1701     end on
1702     )NKSP_CODE",
1703     .expectIntExitResult = 2,
1704     .expectExitResultFinal = true
1705     });
1706    
1707     runScript({
1708     .code = R"NKSP_CODE(
1709     on init
1710     exit(5 - 3)
1711     end on
1712     )NKSP_CODE",
1713     .expectIntExitResult = 2,
1714     .expectExitResultFinal = false
1715     });
1716    
1717     runScript({
1718     .code = R"NKSP_CODE(
1719     on init
1720     exit(!5.9 - !3.3)
1721     end on
1722     )NKSP_CODE",
1723     .expectRealExitResult = 2.6,
1724     .expectExitResultFinal = true
1725     });
1726    
1727     runScript({
1728     .code = R"NKSP_CODE(
1729     on init
1730     exit(5.9 - 3.3)
1731     end on
1732     )NKSP_CODE",
1733     .expectRealExitResult = 2.6,
1734     .expectExitResultFinal = false
1735     });
1736    
1737 schoenebeck 3551 #if !SILENT_TEST
1738     std::cout << std::endl;
1739     #endif
1740     }
1741    
1742     static void testModuloOperator() {
1743     #if !SILENT_TEST
1744     std::cout << "UNIT TEST: modulo (mod) operator\n";
1745     #endif
1746    
1747 schoenebeck 3575 // integer tests ...
1748    
1749 schoenebeck 3551 runScript({
1750     .code = R"NKSP_CODE(
1751     on init
1752     exit(10 mod 8)
1753     end on
1754     )NKSP_CODE",
1755     .expectIntExitResult = 2
1756     });
1757    
1758 schoenebeck 3575 runScript({
1759     .code = R"NKSP_CODE(
1760     on init
1761     declare $a := 10
1762     declare $b := 8
1763     exit($a mod $b)
1764     end on
1765     )NKSP_CODE",
1766     .expectIntExitResult = 2
1767     });
1768    
1769     // real number tests ...
1770     // (mod operator prohibits real numbers ATM)
1771    
1772     runScript({
1773     .code = R"NKSP_CODE(
1774     on init
1775     exit(10.0 mod 8.0)
1776     end on
1777     )NKSP_CODE",
1778     .expectParseError = true // mod operator prohibits real numbers ATM
1779     });
1780    
1781     runScript({
1782     .code = R"NKSP_CODE(
1783     on init
1784     exit(10 mod 8.0)
1785     end on
1786     )NKSP_CODE",
1787     .expectParseError = true // mod operator prohibits real numbers ATM
1788     });
1789    
1790     runScript({
1791     .code = R"NKSP_CODE(
1792     on init
1793     exit(10.0 mod 8)
1794     end on
1795     )NKSP_CODE",
1796     .expectParseError = true // mod operator prohibits real numbers ATM
1797     });
1798    
1799     runScript({
1800     .code = R"NKSP_CODE(
1801     on init
1802     declare ~a := 10.0
1803     declare ~b := 8.0
1804     exit(~a mod ~b)
1805     end on
1806     )NKSP_CODE",
1807     .expectParseError = true // mod operator prohibits real numbers ATM
1808     });
1809    
1810 schoenebeck 3581 // std unit tests ...
1811    
1812     runScript({
1813     .code = R"NKSP_CODE(
1814     on init
1815     exit(10s mod 8)
1816     end on
1817     )NKSP_CODE",
1818     .expectParseError = true // mod operator prohibits std units ATM
1819     });
1820    
1821     runScript({
1822     .code = R"NKSP_CODE(
1823     on init
1824     exit(10 mod 8s)
1825     end on
1826     )NKSP_CODE",
1827     .expectParseError = true // mod operator prohibits std units ATM
1828     });
1829    
1830     runScript({
1831     .code = R"NKSP_CODE(
1832     on init
1833     exit(10s mod 8s)
1834     end on
1835     )NKSP_CODE",
1836     .expectParseError = true // mod operator prohibits std units ATM
1837     });
1838    
1839     // 'final' ('!') operator tests ...
1840    
1841     runScript({
1842     .code = R"NKSP_CODE(
1843     on init
1844     exit(!10 mod !8)
1845     end on
1846     )NKSP_CODE",
1847     .expectIntExitResult = 2,
1848     .expectExitResultFinal = true
1849     });
1850    
1851     runScript({
1852     .code = R"NKSP_CODE(
1853     on init
1854     exit(10 mod 8)
1855     end on
1856     )NKSP_CODE",
1857     .expectIntExitResult = 2,
1858     .expectExitResultFinal = false
1859     });
1860    
1861 schoenebeck 3551 #if !SILENT_TEST
1862     std::cout << std::endl;
1863     #endif
1864     }
1865    
1866     static void testMultiplyOperator() {
1867     #if !SILENT_TEST
1868     std::cout << "UNIT TEST: multiply (*) operator\n";
1869     #endif
1870    
1871 schoenebeck 3575 // integer tests ...
1872    
1873 schoenebeck 3551 runScript({
1874     .code = R"NKSP_CODE(
1875     on init
1876     exit(10 * 8)
1877     end on
1878     )NKSP_CODE",
1879     .expectIntExitResult = 80
1880     });
1881    
1882     runScript({
1883     .code = R"NKSP_CODE(
1884     on init
1885     exit(-3 * -4)
1886     end on
1887     )NKSP_CODE",
1888     .expectIntExitResult = 12
1889     });
1890    
1891     runScript({
1892     .code = R"NKSP_CODE(
1893     on init
1894     exit(-52 * 63)
1895     end on
1896     )NKSP_CODE",
1897     .expectIntExitResult = -3276
1898     });
1899    
1900     runScript({
1901     .code = R"NKSP_CODE(
1902     on init
1903     exit(123 * -59)
1904     end on
1905     )NKSP_CODE",
1906     .expectIntExitResult = -7257
1907     });
1908    
1909 schoenebeck 3575 // real number tests ...
1910    
1911     runScript({
1912     .code = R"NKSP_CODE(
1913     on init
1914     exit(10.2 * 8.4)
1915     end on
1916     )NKSP_CODE",
1917     .expectRealExitResult = 85.68
1918     });
1919    
1920     runScript({
1921     .code = R"NKSP_CODE(
1922     on init
1923     exit(10.0 * -3.33)
1924     end on
1925     )NKSP_CODE",
1926     .expectRealExitResult = -33.3
1927     });
1928    
1929     runScript({
1930     .code = R"NKSP_CODE(
1931     on init
1932     exit(-3.33 * 10.0)
1933     end on
1934     )NKSP_CODE",
1935     .expectRealExitResult = -33.3
1936     });
1937    
1938     runScript({
1939     .code = R"NKSP_CODE(
1940     on init
1941     exit(-3.33 * -10.0)
1942     end on
1943     )NKSP_CODE",
1944     .expectRealExitResult = 33.3
1945     });
1946    
1947     // mixed type tests ...
1948     // (mixed int * real forbidden ATM)
1949    
1950     runScript({
1951     .code = R"NKSP_CODE(
1952     on init
1953     exit(2 * 3.0)
1954     end on
1955     )NKSP_CODE",
1956     .expectParseError = true // mixed int * real forbidden ATM
1957     });
1958    
1959     runScript({
1960     .code = R"NKSP_CODE(
1961     on init
1962     exit(2.0 * 3)
1963     end on
1964     )NKSP_CODE",
1965     .expectParseError = true // mixed int * real forbidden ATM
1966     });
1967    
1968 schoenebeck 3581 // std unit tests ...
1969    
1970     runScript({
1971     .code = R"NKSP_CODE(
1972     on init
1973     exit(10ms * 8)
1974     end on
1975     )NKSP_CODE",
1976     .expectIntExitResult = 80,
1977     .expectExitResultUnitPrefix = { VM_MILLI },
1978     .expectExitResultUnit = VM_SECOND
1979     });
1980    
1981     runScript({
1982     .code = R"NKSP_CODE(
1983     on init
1984     exit(10 * 8ms)
1985     end on
1986     )NKSP_CODE",
1987     .expectIntExitResult = 80,
1988     .expectExitResultUnitPrefix = { VM_MILLI },
1989     .expectExitResultUnit = VM_SECOND
1990     });
1991    
1992     runScript({
1993     .code = R"NKSP_CODE(
1994     on init
1995     exit(10s * 8s)
1996     end on
1997     )NKSP_CODE",
1998     .expectParseError = true // units on both sides not allowed for * ATM
1999     });
2000    
2001     runScript({
2002     .code = R"NKSP_CODE(
2003     on init
2004     exit(10cs * 8d)
2005     end on
2006     )NKSP_CODE",
2007     .expectIntExitResult = 80,
2008     .expectExitResultUnitPrefix = { VM_MILLI },
2009     .expectExitResultUnit = VM_SECOND
2010     });
2011    
2012     runScript({
2013     .code = R"NKSP_CODE(
2014     on init
2015     exit(10m * 8ms)
2016     end on
2017     )NKSP_CODE",
2018     .expectIntExitResult = 80,
2019     .expectExitResultUnitPrefix = { VM_MICRO },
2020     .expectExitResultUnit = VM_SECOND
2021     });
2022    
2023     runScript({
2024     .code = R"NKSP_CODE(
2025     on init
2026     exit(10ms * 8k)
2027     end on
2028     )NKSP_CODE",
2029     .expectIntExitResult = 80,
2030     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
2031     .expectExitResultUnit = VM_SECOND
2032     });
2033    
2034     runScript({
2035     .code = R"NKSP_CODE(
2036     on init
2037     exit(10.1ms * 8.0)
2038     end on
2039     )NKSP_CODE",
2040     .expectRealExitResult = 80.8,
2041     .expectExitResultUnitPrefix = { VM_MILLI },
2042     .expectExitResultUnit = VM_SECOND
2043     });
2044    
2045     runScript({
2046     .code = R"NKSP_CODE(
2047     on init
2048     exit(10.1 * 8.0ms)
2049     end on
2050     )NKSP_CODE",
2051     .expectRealExitResult = 80.8,
2052     .expectExitResultUnitPrefix = { VM_MILLI },
2053     .expectExitResultUnit = VM_SECOND
2054     });
2055    
2056     runScript({
2057     .code = R"NKSP_CODE(
2058     on init
2059     exit(10.0s * 8.0s)
2060     end on
2061     )NKSP_CODE",
2062     .expectParseError = true // units on both sides not allowed for * ATM
2063     });
2064    
2065     runScript({
2066     .code = R"NKSP_CODE(
2067     on init
2068     exit(10.1ds * 8.0c)
2069     end on
2070     )NKSP_CODE",
2071     .expectRealExitResult = 80.8,
2072     .expectExitResultUnitPrefix = { VM_MILLI },
2073     .expectExitResultUnit = VM_SECOND
2074     });
2075    
2076     runScript({
2077     .code = R"NKSP_CODE(
2078     on init
2079     exit(10.1m * 8.0ms)
2080     end on
2081     )NKSP_CODE",
2082     .expectRealExitResult = 80.8,
2083     .expectExitResultUnitPrefix = { VM_MICRO },
2084     .expectExitResultUnit = VM_SECOND
2085     });
2086    
2087     runScript({
2088     .code = R"NKSP_CODE(
2089     on init
2090     exit(10.1m * 8.0ks)
2091     end on
2092     )NKSP_CODE",
2093     .expectRealExitResult = 80.8,
2094     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
2095     .expectExitResultUnit = VM_SECOND
2096     });
2097    
2098     // 'final' ('!') operator tests ...
2099    
2100     runScript({
2101     .code = R"NKSP_CODE(
2102     on init
2103     exit(!10 * !8)
2104     end on
2105     )NKSP_CODE",
2106     .expectIntExitResult = 80,
2107     .expectExitResultFinal = true
2108     });
2109    
2110     runScript({
2111     .code = R"NKSP_CODE(
2112     on init
2113     exit(10 * 8)
2114     end on
2115     )NKSP_CODE",
2116     .expectIntExitResult = 80,
2117     .expectExitResultFinal = false
2118     });
2119    
2120     runScript({
2121     .code = R"NKSP_CODE(
2122     on init
2123     exit(!10 * 8)
2124     end on
2125     )NKSP_CODE",
2126     .expectIntExitResult = 80,
2127     .expectExitResultFinal = true,
2128     .expectParseWarning = true // since final only on one side, result will be final though
2129     });
2130    
2131     runScript({
2132     .code = R"NKSP_CODE(
2133     on init
2134     exit(10 * !8)
2135     end on
2136     )NKSP_CODE",
2137     .expectIntExitResult = 80,
2138     .expectExitResultFinal = true,
2139     .expectParseWarning = true // since final only on one side, result will be final though
2140     });
2141    
2142     runScript({
2143     .code = R"NKSP_CODE(
2144     on init
2145     exit(!10.1 * !8.0)
2146     end on
2147     )NKSP_CODE",
2148     .expectRealExitResult = 80.8,
2149     .expectExitResultFinal = true
2150     });
2151    
2152     runScript({
2153     .code = R"NKSP_CODE(
2154     on init
2155     exit(10.1 * 8.0)
2156     end on
2157     )NKSP_CODE",
2158     .expectRealExitResult = 80.8,
2159     .expectExitResultFinal = false
2160     });
2161    
2162     runScript({
2163     .code = R"NKSP_CODE(
2164     on init
2165     exit(!10.1 * 8.0)
2166     end on
2167     )NKSP_CODE",
2168     .expectRealExitResult = 80.8,
2169     .expectExitResultFinal = true,
2170     .expectParseWarning = true // since final only on one side, result will be final though
2171     });
2172    
2173     runScript({
2174     .code = R"NKSP_CODE(
2175     on init
2176     exit(10.1 * !8.0)
2177     end on
2178     )NKSP_CODE",
2179     .expectRealExitResult = 80.8,
2180     .expectExitResultFinal = true,
2181     .expectParseWarning = true // since final only on one side, result will be final though
2182     });
2183    
2184 schoenebeck 3551 #if !SILENT_TEST
2185     std::cout << std::endl;
2186     #endif
2187     }
2188    
2189     static void testDivideOperator() {
2190     #if !SILENT_TEST
2191     std::cout << "UNIT TEST: divide (/) operator\n";
2192     #endif
2193    
2194 schoenebeck 3575 // integer tests ...
2195    
2196 schoenebeck 3551 runScript({
2197     .code = R"NKSP_CODE(
2198     on init
2199     exit(9 / 3)
2200     end on
2201     )NKSP_CODE",
2202     .expectIntExitResult = 3
2203     });
2204    
2205     runScript({
2206     .code = R"NKSP_CODE(
2207     on init
2208     exit(-27 / 3)
2209     end on
2210     )NKSP_CODE",
2211     .expectIntExitResult = -9
2212     });
2213    
2214     runScript({
2215     .code = R"NKSP_CODE(
2216     on init
2217     exit(35 / -5)
2218     end on
2219     )NKSP_CODE",
2220     .expectIntExitResult = -7
2221     });
2222    
2223     runScript({
2224     .code = R"NKSP_CODE(
2225     on init
2226     exit(39 / -5)
2227     end on
2228     )NKSP_CODE",
2229     .expectIntExitResult = -7
2230     });
2231    
2232 schoenebeck 3575 // real number tests ...
2233    
2234     runScript({
2235     .code = R"NKSP_CODE(
2236     on init
2237     exit(9.0 / 10.0)
2238     end on
2239     )NKSP_CODE",
2240     .expectRealExitResult = 0.9
2241     });
2242    
2243     runScript({
2244     .code = R"NKSP_CODE(
2245     on init
2246     exit(-9.0 / 10.0)
2247     end on
2248     )NKSP_CODE",
2249     .expectRealExitResult = -0.9
2250     });
2251    
2252     runScript({
2253     .code = R"NKSP_CODE(
2254     on init
2255     exit(9.0 / -10.0)
2256     end on
2257     )NKSP_CODE",
2258     .expectRealExitResult = -0.9
2259     });
2260    
2261     runScript({
2262     .code = R"NKSP_CODE(
2263     on init
2264     exit(-9.0 / -10.0)
2265     end on
2266     )NKSP_CODE",
2267     .expectRealExitResult = 0.9
2268     });
2269    
2270     // mixed type tests ...
2271     // (mixed int / real forbidden ATM)
2272    
2273     runScript({
2274     .code = R"NKSP_CODE(
2275     on init
2276     exit(9 / 10.0)
2277     end on
2278     )NKSP_CODE",
2279     .expectParseError = true // mixed int / real forbidden ATM
2280     });
2281    
2282     runScript({
2283     .code = R"NKSP_CODE(
2284     on init
2285     exit(9.0 / 10)
2286     end on
2287     )NKSP_CODE",
2288     .expectParseError = true // mixed int / real forbidden ATM
2289     });
2290    
2291 schoenebeck 3581 // std unit tests ...
2292    
2293     runScript({
2294     .code = R"NKSP_CODE(
2295     on init
2296     exit(-27us / 3)
2297     end on
2298     )NKSP_CODE",
2299     .expectIntExitResult = -9,
2300     .expectExitResultUnitPrefix = { VM_MICRO },
2301     .expectExitResultUnit = VM_SECOND
2302     });
2303    
2304     runScript({
2305     .code = R"NKSP_CODE(
2306     on init
2307     exit(-27mdB / 3mdB)
2308     end on
2309     )NKSP_CODE",
2310     .expectIntExitResult = -9,
2311     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
2312     .expectExitResultUnit = VM_NO_UNIT
2313     });
2314    
2315     runScript({
2316     .code = R"NKSP_CODE(
2317     on init
2318     exit(-27s / 3m)
2319     end on
2320     )NKSP_CODE",
2321     .expectIntExitResult = -9,
2322     .expectExitResultUnitPrefix = { VM_KILO },
2323     .expectExitResultUnit = VM_SECOND
2324     });
2325    
2326     runScript({
2327     .code = R"NKSP_CODE(
2328     on init
2329     exit(-27us / 3m)
2330     end on
2331     )NKSP_CODE",
2332     .expectIntExitResult = -9,
2333     .expectExitResultUnitPrefix = { VM_MILLI },
2334     .expectExitResultUnit = VM_SECOND
2335     });
2336    
2337     runScript({
2338     .code = R"NKSP_CODE(
2339     on init
2340     exit(-27 / 3s)
2341     end on
2342     )NKSP_CODE",
2343     .expectParseError = true // illegal unit type arrangement for divisions
2344     });
2345    
2346     runScript({
2347     .code = R"NKSP_CODE(
2348     on init
2349     exit(-27s / 3Hz)
2350     end on
2351     )NKSP_CODE",
2352     .expectParseError = true // unit types are not matching
2353     });
2354    
2355     // 'final' ('!') operator tests ...
2356    
2357     runScript({
2358     .code = R"NKSP_CODE(
2359     on init
2360     exit(!-27 / !3)
2361     end on
2362     )NKSP_CODE",
2363     .expectIntExitResult = -9,
2364     .expectExitResultFinal = true
2365     });
2366    
2367     runScript({
2368     .code = R"NKSP_CODE(
2369     on init
2370     exit(-27 / 3)
2371     end on
2372     )NKSP_CODE",
2373     .expectIntExitResult = -9,
2374     .expectExitResultFinal = false
2375     });
2376    
2377     runScript({
2378     .code = R"NKSP_CODE(
2379     on init
2380     exit(!-27 / 3)
2381     end on
2382     )NKSP_CODE",
2383     .expectIntExitResult = -9,
2384     .expectExitResultFinal = true,
2385     .expectParseWarning = true // final only on one side, result will be final though
2386     });
2387    
2388     runScript({
2389     .code = R"NKSP_CODE(
2390     on init
2391     exit(-27 / !3)
2392     end on
2393     )NKSP_CODE",
2394     .expectIntExitResult = -9,
2395     .expectExitResultFinal = true,
2396     .expectParseWarning = true // final only on one side, result will be final though
2397     });
2398    
2399 schoenebeck 3551 #if !SILENT_TEST
2400     std::cout << std::endl;
2401     #endif
2402     }
2403    
2404     static void testSmallerThanOperator() {
2405     #if !SILENT_TEST
2406     std::cout << "UNIT TEST: smaller than (<) operator\n";
2407     #endif
2408    
2409 schoenebeck 3575 // integer tests ...
2410    
2411 schoenebeck 3551 runScript({
2412     .code = R"NKSP_CODE(
2413     on init
2414     exit(3 < 4)
2415     end on
2416     )NKSP_CODE",
2417     .expectBoolExitResult = true
2418     });
2419    
2420     runScript({
2421     .code = R"NKSP_CODE(
2422     on init
2423     exit(4 < 3)
2424     end on
2425     )NKSP_CODE",
2426     .expectBoolExitResult = false
2427     });
2428    
2429     runScript({
2430     .code = R"NKSP_CODE(
2431     on init
2432     exit(-4 < 3)
2433     end on
2434     )NKSP_CODE",
2435     .expectBoolExitResult = true
2436     });
2437    
2438     runScript({
2439     .code = R"NKSP_CODE(
2440     on init
2441     exit(3 < -4)
2442     end on
2443     )NKSP_CODE",
2444     .expectBoolExitResult = false
2445     });
2446    
2447     runScript({
2448     .code = R"NKSP_CODE(
2449     on init
2450     exit(123 < -45)
2451     end on
2452     )NKSP_CODE",
2453     .expectBoolExitResult = false
2454     });
2455    
2456     runScript({
2457     .code = R"NKSP_CODE(
2458     on init
2459     exit(-45 < 123)
2460     end on
2461     )NKSP_CODE",
2462     .expectBoolExitResult = true
2463     });
2464    
2465 schoenebeck 3575 // real number tests ...
2466    
2467     runScript({
2468     .code = R"NKSP_CODE(
2469     on init
2470     exit(3.0 < 4.0)
2471     end on
2472     )NKSP_CODE",
2473     .expectBoolExitResult = true
2474     });
2475    
2476     runScript({
2477     .code = R"NKSP_CODE(
2478     on init
2479     exit(4.0 < 3.0)
2480     end on
2481     )NKSP_CODE",
2482     .expectBoolExitResult = false
2483     });
2484    
2485     runScript({
2486     .code = R"NKSP_CODE(
2487     on init
2488     exit(1.2 < 1.23)
2489     end on
2490     )NKSP_CODE",
2491     .expectBoolExitResult = true
2492     });
2493    
2494     runScript({
2495     .code = R"NKSP_CODE(
2496     on init
2497     exit(1.23 < 1.2)
2498     end on
2499     )NKSP_CODE",
2500     .expectBoolExitResult = false
2501     });
2502    
2503     runScript({
2504     .code = R"NKSP_CODE(
2505     on init
2506     exit(-4.0 < 3.0)
2507     end on
2508     )NKSP_CODE",
2509     .expectBoolExitResult = true
2510     });
2511    
2512     runScript({
2513     .code = R"NKSP_CODE(
2514     on init
2515     exit(3.0 < -4.0)
2516     end on
2517     )NKSP_CODE",
2518     .expectBoolExitResult = false
2519     });
2520    
2521     runScript({
2522     .code = R"NKSP_CODE(
2523     on init
2524     exit(123.0 < -45.0)
2525     end on
2526     )NKSP_CODE",
2527     .expectBoolExitResult = false
2528     });
2529    
2530     runScript({
2531     .code = R"NKSP_CODE(
2532     on init
2533     exit(-45.0 < 123.0)
2534     end on
2535     )NKSP_CODE",
2536     .expectBoolExitResult = true
2537     });
2538    
2539     // mixed type tests ...
2540    
2541     runScript({
2542     .code = R"NKSP_CODE(
2543     on init
2544     exit(9 < 9.1)
2545     end on
2546     )NKSP_CODE",
2547     .expectBoolExitResult = true
2548     });
2549    
2550     runScript({
2551     .code = R"NKSP_CODE(
2552     on init
2553     exit(9.1 < 9)
2554     end on
2555     )NKSP_CODE",
2556     .expectBoolExitResult = false
2557     });
2558    
2559 schoenebeck 3581 // std unit tests ...
2560    
2561     runScript({
2562     .code = R"NKSP_CODE(
2563     on init
2564     exit(13ms < 14ms)
2565     end on
2566     )NKSP_CODE",
2567     .expectBoolExitResult = true
2568     });
2569    
2570     runScript({
2571     .code = R"NKSP_CODE(
2572     on init
2573     exit(14ms < 13ms)
2574     end on
2575     )NKSP_CODE",
2576     .expectBoolExitResult = false
2577     });
2578    
2579     runScript({
2580     .code = R"NKSP_CODE(
2581     on init
2582     exit(1s < 990ms)
2583     end on
2584     )NKSP_CODE",
2585     .expectBoolExitResult = false
2586     });
2587    
2588     runScript({
2589     .code = R"NKSP_CODE(
2590     on init
2591     exit(990ms < 1s)
2592     end on
2593     )NKSP_CODE",
2594     .expectBoolExitResult = true
2595     });
2596    
2597     runScript({
2598     .code = R"NKSP_CODE(
2599     on init
2600     exit(1000ms < 1s)
2601     end on
2602     )NKSP_CODE",
2603     .expectBoolExitResult = false
2604     });
2605    
2606     runScript({
2607     .code = R"NKSP_CODE(
2608     on init
2609     exit(1s < 1000ms)
2610     end on
2611     )NKSP_CODE",
2612     .expectBoolExitResult = false
2613     });
2614    
2615     runScript({
2616     .code = R"NKSP_CODE(
2617     on init
2618     exit(1s < 1)
2619     end on
2620     )NKSP_CODE",
2621     .expectParseError = true // units on both sides must match
2622     });
2623    
2624     runScript({
2625     .code = R"NKSP_CODE(
2626     on init
2627     exit(1 < 1s)
2628     end on
2629     )NKSP_CODE",
2630     .expectParseError = true // units on both sides must match
2631     });
2632    
2633     runScript({
2634     .code = R"NKSP_CODE(
2635     on init
2636     exit(1Hz < 1B)
2637     end on
2638     )NKSP_CODE",
2639     .expectParseError = true // units on both sides must match
2640     });
2641    
2642     runScript({
2643     .code = R"NKSP_CODE(
2644     on init
2645     exit(13.0ms < 13.1ms)
2646     end on
2647     )NKSP_CODE",
2648     .expectBoolExitResult = true
2649     });
2650    
2651     runScript({
2652     .code = R"NKSP_CODE(
2653     on init
2654     exit(13.1ms < 13.0ms)
2655     end on
2656     )NKSP_CODE",
2657     .expectBoolExitResult = false
2658     });
2659    
2660     runScript({
2661     .code = R"NKSP_CODE(
2662     on init
2663     exit(0.9s < 600.0ms)
2664     end on
2665     )NKSP_CODE",
2666     .expectBoolExitResult = false
2667     });
2668    
2669     runScript({
2670     .code = R"NKSP_CODE(
2671     on init
2672     exit(600.0ms < 0.9s)
2673     end on
2674     )NKSP_CODE",
2675     .expectBoolExitResult = true
2676     });
2677    
2678     runScript({
2679     .code = R"NKSP_CODE(
2680     on init
2681     exit(5.1kHz < 5100.0Hz)
2682     end on
2683     )NKSP_CODE",
2684     .expectBoolExitResult = false
2685     });
2686    
2687     runScript({
2688     .code = R"NKSP_CODE(
2689     on init
2690     exit(5100.0Hz < 5.1kHz)
2691     end on
2692     )NKSP_CODE",
2693     .expectBoolExitResult = false
2694     });
2695    
2696     runScript({
2697     .code = R"NKSP_CODE(
2698     on init
2699     exit(1.0Hz < 1.1)
2700     end on
2701     )NKSP_CODE",
2702     .expectParseError = true // units on both sides must match
2703     });
2704    
2705     runScript({
2706     .code = R"NKSP_CODE(
2707     on init
2708     exit(1.2 < 1.34mdB)
2709     end on
2710     )NKSP_CODE",
2711     .expectParseError = true // units on both sides must match
2712     });
2713    
2714     runScript({
2715     .code = R"NKSP_CODE(
2716     on init
2717     exit(9.23us < 3.14kHz)
2718     end on
2719     )NKSP_CODE",
2720     .expectParseError = true // units on both sides must match
2721     });
2722    
2723     // 'final' ('!') operator tests ...
2724     // (should always yield in false for relation operators)
2725    
2726     runScript({
2727     .code = R"NKSP_CODE(
2728     on init
2729     exit(!-4 < !3)
2730     end on
2731     )NKSP_CODE",
2732     .expectBoolExitResult = true,
2733     .expectExitResultFinal = false
2734     });
2735    
2736     runScript({
2737     .code = R"NKSP_CODE(
2738     on init
2739     exit(-4 < 3)
2740     end on
2741     )NKSP_CODE",
2742     .expectBoolExitResult = true,
2743     .expectExitResultFinal = false
2744     });
2745    
2746 schoenebeck 3551 #if !SILENT_TEST
2747     std::cout << std::endl;
2748     #endif
2749     }
2750    
2751     static void testGreaterThanOperator() {
2752     #if !SILENT_TEST
2753     std::cout << "UNIT TEST: greater than (>) operator\n";
2754     #endif
2755    
2756 schoenebeck 3575 // integer tests ...
2757    
2758 schoenebeck 3551 runScript({
2759     .code = R"NKSP_CODE(
2760     on init
2761     exit(3 > 4)
2762     end on
2763     )NKSP_CODE",
2764     .expectBoolExitResult = false
2765     });
2766    
2767     runScript({
2768     .code = R"NKSP_CODE(
2769     on init
2770     exit(4 > 3)
2771     end on
2772     )NKSP_CODE",
2773     .expectBoolExitResult = true
2774     });
2775    
2776     runScript({
2777     .code = R"NKSP_CODE(
2778     on init
2779     exit(-4 > 3)
2780     end on
2781     )NKSP_CODE",
2782     .expectBoolExitResult = false
2783     });
2784    
2785     runScript({
2786     .code = R"NKSP_CODE(
2787     on init
2788     exit(3 > -4)
2789     end on
2790     )NKSP_CODE",
2791     .expectBoolExitResult = true
2792     });
2793    
2794     runScript({
2795     .code = R"NKSP_CODE(
2796     on init
2797     exit(123 > -45)
2798     end on
2799     )NKSP_CODE",
2800     .expectBoolExitResult = true
2801     });
2802    
2803     runScript({
2804     .code = R"NKSP_CODE(
2805     on init
2806     exit(-45 > 123)
2807     end on
2808     )NKSP_CODE",
2809     .expectBoolExitResult = false
2810     });
2811    
2812 schoenebeck 3575 // real number tests ...
2813    
2814     runScript({
2815     .code = R"NKSP_CODE(
2816     on init
2817     exit(3.0 > 4.0)
2818     end on
2819     )NKSP_CODE",
2820     .expectBoolExitResult = false
2821     });
2822    
2823     runScript({
2824     .code = R"NKSP_CODE(
2825     on init
2826     exit(4.0 > 3.0)
2827     end on
2828     )NKSP_CODE",
2829     .expectBoolExitResult = true
2830     });
2831    
2832     runScript({
2833     .code = R"NKSP_CODE(
2834     on init
2835     exit(1.2 > 1.23)
2836     end on
2837     )NKSP_CODE",
2838     .expectBoolExitResult = false
2839     });
2840    
2841     runScript({
2842     .code = R"NKSP_CODE(
2843     on init
2844     exit(1.23 > 1.2)
2845     end on
2846     )NKSP_CODE",
2847     .expectBoolExitResult = true
2848     });
2849    
2850     runScript({
2851     .code = R"NKSP_CODE(
2852     on init
2853     exit(-4.0 > 3.0)
2854     end on
2855     )NKSP_CODE",
2856     .expectBoolExitResult = false
2857     });
2858    
2859     runScript({
2860     .code = R"NKSP_CODE(
2861     on init
2862     exit(3.0 > -4.0)
2863     end on
2864     )NKSP_CODE",
2865     .expectBoolExitResult = true
2866     });
2867    
2868     runScript({
2869     .code = R"NKSP_CODE(
2870     on init
2871     exit(123.0 > -45.0)
2872     end on
2873     )NKSP_CODE",
2874     .expectBoolExitResult = true
2875     });
2876    
2877     runScript({
2878     .code = R"NKSP_CODE(
2879     on init
2880     exit(-45.0 > 123.0)
2881     end on
2882     )NKSP_CODE",
2883     .expectBoolExitResult = false
2884     });
2885    
2886     // mixed type tests ...
2887    
2888     runScript({
2889     .code = R"NKSP_CODE(
2890     on init
2891     exit(9 > 9.1)
2892     end on
2893     )NKSP_CODE",
2894     .expectBoolExitResult = false
2895     });
2896    
2897     runScript({
2898     .code = R"NKSP_CODE(
2899     on init
2900     exit(9.1 > 9)
2901     end on
2902     )NKSP_CODE",
2903     .expectBoolExitResult = true
2904     });
2905    
2906 schoenebeck 3581 // std unit tests ...
2907    
2908     runScript({
2909     .code = R"NKSP_CODE(
2910     on init
2911     exit(13ms > 14ms)
2912     end on
2913     )NKSP_CODE",
2914     .expectBoolExitResult = false
2915     });
2916    
2917     runScript({
2918     .code = R"NKSP_CODE(
2919     on init
2920     exit(14ms > 13ms)
2921     end on
2922     )NKSP_CODE",
2923     .expectBoolExitResult = true
2924     });
2925    
2926     runScript({
2927     .code = R"NKSP_CODE(
2928     on init
2929     exit(1s > 990ms)
2930     end on
2931     )NKSP_CODE",
2932     .expectBoolExitResult = true
2933     });
2934    
2935     runScript({
2936     .code = R"NKSP_CODE(
2937     on init
2938     exit(990ms > 1s)
2939     end on
2940     )NKSP_CODE",
2941     .expectBoolExitResult = false
2942     });
2943    
2944     runScript({
2945     .code = R"NKSP_CODE(
2946     on init
2947     exit(1000ms > 1s)
2948     end on
2949     )NKSP_CODE",
2950     .expectBoolExitResult = false
2951     });
2952    
2953     runScript({
2954     .code = R"NKSP_CODE(
2955     on init
2956     exit(1s > 1000ms)
2957     end on
2958     )NKSP_CODE",
2959     .expectBoolExitResult = false
2960     });
2961    
2962     runScript({
2963     .code = R"NKSP_CODE(
2964     on init
2965     exit(1s > 1)
2966     end on
2967     )NKSP_CODE",
2968     .expectParseError = true // units on both sides must match
2969     });
2970    
2971     runScript({
2972     .code = R"NKSP_CODE(
2973     on init
2974     exit(1 > 1s)
2975     end on
2976     )NKSP_CODE",
2977     .expectParseError = true // units on both sides must match
2978     });
2979    
2980     runScript({
2981     .code = R"NKSP_CODE(
2982     on init
2983     exit(1Hz > 1B)
2984     end on
2985     )NKSP_CODE",
2986     .expectParseError = true // units on both sides must match
2987     });
2988    
2989     runScript({
2990     .code = R"NKSP_CODE(
2991     on init
2992     exit(13.0ms > 13.1ms)
2993     end on
2994     )NKSP_CODE",
2995     .expectBoolExitResult = false
2996     });
2997    
2998     runScript({
2999     .code = R"NKSP_CODE(
3000     on init
3001     exit(13.1ms > 13.0ms)
3002     end on
3003     )NKSP_CODE",
3004     .expectBoolExitResult = true
3005     });
3006    
3007     runScript({
3008     .code = R"NKSP_CODE(
3009     on init
3010     exit(0.9s > 600.0ms)
3011     end on
3012     )NKSP_CODE",
3013     .expectBoolExitResult = true
3014     });
3015    
3016     runScript({
3017     .code = R"NKSP_CODE(
3018     on init
3019     exit(600.0ms > 0.9s)
3020     end on
3021     )NKSP_CODE",
3022     .expectBoolExitResult = false
3023     });
3024    
3025     runScript({
3026     .code = R"NKSP_CODE(
3027     on init
3028     exit(5.1kHz > 5100.0Hz)
3029     end on
3030     )NKSP_CODE",
3031     .expectBoolExitResult = false
3032     });
3033    
3034     runScript({
3035     .code = R"NKSP_CODE(
3036     on init
3037     exit(5100.0Hz > 5.1kHz)
3038     end on
3039     )NKSP_CODE",
3040     .expectBoolExitResult = false
3041     });
3042    
3043     runScript({
3044     .code = R"NKSP_CODE(
3045     on init
3046     exit(1.0Hz > 1.1)
3047     end on
3048     )NKSP_CODE",
3049     .expectParseError = true // units on both sides must match
3050     });
3051    
3052     runScript({
3053     .code = R"NKSP_CODE(
3054     on init
3055     exit(1.2 > 1.34mdB)
3056     end on
3057     )NKSP_CODE",
3058     .expectParseError = true // units on both sides must match
3059     });
3060    
3061     runScript({
3062     .code = R"NKSP_CODE(
3063     on init
3064     exit(9.23us > 3.14kHz)
3065     end on
3066     )NKSP_CODE",
3067     .expectParseError = true // units on both sides must match
3068     });
3069    
3070     // 'final' ('!') operator tests ...
3071     // (should always yield in false for relation operators)
3072    
3073     runScript({
3074     .code = R"NKSP_CODE(
3075     on init
3076     exit(!-4 > !3)
3077     end on
3078     )NKSP_CODE",
3079     .expectBoolExitResult = false,
3080     .expectExitResultFinal = false
3081     });
3082    
3083     runScript({
3084     .code = R"NKSP_CODE(
3085     on init
3086     exit(-4 > 3)
3087     end on
3088     )NKSP_CODE",
3089     .expectBoolExitResult = false,
3090     .expectExitResultFinal = false
3091     });
3092    
3093 schoenebeck 3551 #if !SILENT_TEST
3094     std::cout << std::endl;
3095     #endif
3096     }
3097    
3098     static void testSmallerOrEqualOperator() {
3099     #if !SILENT_TEST
3100     std::cout << "UNIT TEST: smaller-or-equal (<=) operator\n";
3101     #endif
3102    
3103 schoenebeck 3575 // integer tests ...
3104    
3105 schoenebeck 3551 runScript({
3106     .code = R"NKSP_CODE(
3107     on init
3108     exit(3 <= 3)
3109     end on
3110     )NKSP_CODE",
3111     .expectBoolExitResult = true
3112     });
3113    
3114     runScript({
3115     .code = R"NKSP_CODE(
3116     on init
3117     exit(4 <= 4)
3118     end on
3119     )NKSP_CODE",
3120     .expectBoolExitResult = true
3121     });
3122    
3123     runScript({
3124     .code = R"NKSP_CODE(
3125     on init
3126     exit(-23 <= -23)
3127     end on
3128     )NKSP_CODE",
3129     .expectBoolExitResult = true
3130     });
3131    
3132     runScript({
3133     .code = R"NKSP_CODE(
3134     on init
3135     exit(23 <= -23)
3136     end on
3137     )NKSP_CODE",
3138     .expectBoolExitResult = false
3139     });
3140    
3141     runScript({
3142     .code = R"NKSP_CODE(
3143     on init
3144     exit(3 <= 4)
3145     end on
3146     )NKSP_CODE",
3147     .expectBoolExitResult = true
3148     });
3149    
3150     runScript({
3151     .code = R"NKSP_CODE(
3152     on init
3153     exit(4 <= 3)
3154     end on
3155     )NKSP_CODE",
3156     .expectBoolExitResult = false
3157     });
3158    
3159     runScript({
3160     .code = R"NKSP_CODE(
3161     on init
3162     exit(-4 <= 3)
3163     end on
3164     )NKSP_CODE",
3165     .expectBoolExitResult = true
3166     });
3167    
3168     runScript({
3169     .code = R"NKSP_CODE(
3170     on init
3171     exit(3 <= -4)
3172     end on
3173     )NKSP_CODE",
3174     .expectBoolExitResult = false
3175     });
3176    
3177     runScript({
3178     .code = R"NKSP_CODE(
3179     on init
3180     exit(123 <= -45)
3181     end on
3182     )NKSP_CODE",
3183     .expectBoolExitResult = false
3184     });
3185    
3186     runScript({
3187     .code = R"NKSP_CODE(
3188     on init
3189     exit(-45 <= 123)
3190     end on
3191     )NKSP_CODE",
3192     .expectBoolExitResult = true
3193     });
3194    
3195 schoenebeck 3575 // real number tests ...
3196    
3197     runScript({
3198     .code = R"NKSP_CODE(
3199     on init
3200     exit(3.0 <= 3.0)
3201     end on
3202     )NKSP_CODE",
3203     .expectBoolExitResult = true
3204     });
3205    
3206     runScript({
3207     .code = R"NKSP_CODE(
3208     on init
3209     exit(4.33 <= 4.33)
3210     end on
3211     )NKSP_CODE",
3212     .expectBoolExitResult = true
3213     });
3214    
3215     runScript({
3216     .code = R"NKSP_CODE(
3217     on init
3218     exit(-23.1 <= -23.1)
3219     end on
3220     )NKSP_CODE",
3221     .expectBoolExitResult = true
3222     });
3223    
3224     runScript({
3225     .code = R"NKSP_CODE(
3226     on init
3227     exit(23.3 <= -23.3)
3228     end on
3229     )NKSP_CODE",
3230     .expectBoolExitResult = false
3231     });
3232    
3233     runScript({
3234     .code = R"NKSP_CODE(
3235     on init
3236     exit(3.0 <= 4.0)
3237     end on
3238     )NKSP_CODE",
3239     .expectBoolExitResult = true
3240     });
3241    
3242     runScript({
3243     .code = R"NKSP_CODE(
3244     on init
3245     exit(4.0 <= 3.0)
3246     end on
3247     )NKSP_CODE",
3248     .expectBoolExitResult = false
3249     });
3250    
3251     runScript({
3252     .code = R"NKSP_CODE(
3253     on init
3254     exit(-4.0 <= 3.0)
3255     end on
3256     )NKSP_CODE",
3257     .expectBoolExitResult = true
3258     });
3259    
3260     runScript({
3261     .code = R"NKSP_CODE(
3262     on init
3263     exit(3.0 <= -4.0)
3264     end on
3265     )NKSP_CODE",
3266     .expectBoolExitResult = false
3267     });
3268    
3269     runScript({
3270     .code = R"NKSP_CODE(
3271     on init
3272     exit(123.0 <= -45.0)
3273     end on
3274     )NKSP_CODE",
3275     .expectBoolExitResult = false
3276     });
3277    
3278     runScript({
3279     .code = R"NKSP_CODE(
3280     on init
3281     exit(-45.0 <= 123.0)
3282     end on
3283     )NKSP_CODE",
3284     .expectBoolExitResult = true
3285     });
3286    
3287     // mixed type tests ...
3288    
3289     runScript({
3290     .code = R"NKSP_CODE(
3291     on init
3292     exit(9 <= 9.1)
3293     end on
3294     )NKSP_CODE",
3295     .expectBoolExitResult = true
3296     });
3297    
3298     runScript({
3299     .code = R"NKSP_CODE(
3300     on init
3301     exit(9.1 <= 9)
3302     end on
3303     )NKSP_CODE",
3304     .expectBoolExitResult = false
3305     });
3306    
3307     runScript({
3308     .code = R"NKSP_CODE(
3309     on init
3310     exit(9 <= 9.0)
3311     end on
3312     )NKSP_CODE",
3313     .expectBoolExitResult = true
3314     });
3315    
3316     runScript({
3317     .code = R"NKSP_CODE(
3318     on init
3319     exit(9.0 <= 9)
3320     end on
3321     )NKSP_CODE",
3322     .expectBoolExitResult = true
3323     });
3324    
3325 schoenebeck 3581 // std unit tests ...
3326    
3327     runScript({
3328     .code = R"NKSP_CODE(
3329     on init
3330     exit(13ms <= 14ms)
3331     end on
3332     )NKSP_CODE",
3333     .expectBoolExitResult = true
3334     });
3335    
3336     runScript({
3337     .code = R"NKSP_CODE(
3338     on init
3339     exit(14ms <= 13ms)
3340     end on
3341     )NKSP_CODE",
3342     .expectBoolExitResult = false
3343     });
3344    
3345     runScript({
3346     .code = R"NKSP_CODE(
3347     on init
3348     exit(1s <= 990ms)
3349     end on
3350     )NKSP_CODE",
3351     .expectBoolExitResult = false
3352     });
3353    
3354     runScript({
3355     .code = R"NKSP_CODE(
3356     on init
3357     exit(990ms <= 1s)
3358     end on
3359     )NKSP_CODE",
3360     .expectBoolExitResult = true
3361     });
3362    
3363     runScript({
3364     .code = R"NKSP_CODE(
3365     on init
3366     exit(1000ms <= 1s)
3367     end on
3368     )NKSP_CODE",
3369     .expectBoolExitResult = true
3370     });
3371    
3372     runScript({
3373     .code = R"NKSP_CODE(
3374     on init
3375     exit(1s <= 1000ms)
3376     end on
3377     )NKSP_CODE",
3378     .expectBoolExitResult = true
3379     });
3380    
3381     runScript({
3382     .code = R"NKSP_CODE(
3383     on init
3384     exit(1s <= 1)
3385     end on
3386     )NKSP_CODE",
3387     .expectParseError = true // units on both sides must match
3388     });
3389    
3390     runScript({
3391     .code = R"NKSP_CODE(
3392     on init
3393     exit(1 <= 1s)
3394     end on
3395     )NKSP_CODE",
3396     .expectParseError = true // units on both sides must match
3397     });
3398    
3399     runScript({
3400     .code = R"NKSP_CODE(
3401     on init
3402     exit(1Hz <= 1B)
3403     end on
3404     )NKSP_CODE",
3405     .expectParseError = true // units on both sides must match
3406     });
3407    
3408     runScript({
3409     .code = R"NKSP_CODE(
3410     on init
3411     exit(13.0ms <= 13.1ms)
3412     end on
3413     )NKSP_CODE",
3414     .expectBoolExitResult = true
3415     });
3416    
3417     runScript({
3418     .code = R"NKSP_CODE(
3419     on init
3420     exit(13.1ms <= 13.0ms)
3421     end on
3422     )NKSP_CODE",
3423     .expectBoolExitResult = false
3424     });
3425    
3426     runScript({
3427     .code = R"NKSP_CODE(
3428     on init
3429     exit(0.9s <= 600.0ms)
3430     end on
3431     )NKSP_CODE",
3432     .expectBoolExitResult = false
3433     });
3434    
3435     runScript({
3436     .code = R"NKSP_CODE(
3437     on init
3438     exit(600.0ms <= 0.9s)
3439     end on
3440     )NKSP_CODE",
3441     .expectBoolExitResult = true
3442     });
3443    
3444     runScript({
3445     .code = R"NKSP_CODE(
3446     on init
3447     exit(5.1kHz <= 5100.0Hz)
3448     end on
3449     )NKSP_CODE",
3450     .expectBoolExitResult = true
3451     });
3452    
3453     runScript({
3454     .code = R"NKSP_CODE(
3455     on init
3456     exit(5100.0Hz <= 5.1kHz)
3457     end on
3458     )NKSP_CODE",
3459     .expectBoolExitResult = true
3460     });
3461    
3462     runScript({
3463     .code = R"NKSP_CODE(
3464     on init
3465     exit(1.0Hz <= 1.1)
3466     end on
3467     )NKSP_CODE",
3468     .expectParseError = true // units on both sides must match
3469     });
3470    
3471     runScript({
3472     .code = R"NKSP_CODE(
3473     on init
3474     exit(1.2 <= 1.34mdB)
3475     end on
3476     )NKSP_CODE",
3477     .expectParseError = true // units on both sides must match
3478     });
3479    
3480     runScript({
3481     .code = R"NKSP_CODE(
3482     on init
3483     exit(9.23us <= 3.14kHz)
3484     end on
3485     )NKSP_CODE",
3486     .expectParseError = true // units on both sides must match
3487     });
3488    
3489     // 'final' ('!') operator tests ...
3490     // (should always yield in false for relation operators)
3491    
3492     runScript({
3493     .code = R"NKSP_CODE(
3494     on init
3495     exit(!-4 <= !3)
3496     end on
3497     )NKSP_CODE",
3498     .expectBoolExitResult = true,
3499     .expectExitResultFinal = false
3500     });
3501    
3502     runScript({
3503     .code = R"NKSP_CODE(
3504     on init
3505     exit(-4 <= 3)
3506     end on
3507     )NKSP_CODE",
3508     .expectBoolExitResult = true,
3509     .expectExitResultFinal = false
3510     });
3511    
3512 schoenebeck 3551 #if !SILENT_TEST
3513     std::cout << std::endl;
3514     #endif
3515     }
3516    
3517     static void testGreaterOrEqualOperator() {
3518     #if !SILENT_TEST
3519     std::cout << "UNIT TEST: greater-or-equal (>=) operator\n";
3520     #endif
3521    
3522 schoenebeck 3575 // integer tests ...
3523    
3524 schoenebeck 3551 runScript({
3525     .code = R"NKSP_CODE(
3526     on init
3527     exit(3 >= 3)
3528     end on
3529     )NKSP_CODE",
3530     .expectBoolExitResult = true
3531     });
3532    
3533     runScript({
3534     .code = R"NKSP_CODE(
3535     on init
3536     exit(4 >= 4)
3537     end on
3538     )NKSP_CODE",
3539     .expectBoolExitResult = true
3540     });
3541    
3542     runScript({
3543     .code = R"NKSP_CODE(
3544     on init
3545     exit(-23 >= -23)
3546     end on
3547     )NKSP_CODE",
3548     .expectBoolExitResult = true
3549     });
3550    
3551     runScript({
3552     .code = R"NKSP_CODE(
3553     on init
3554     exit(23 >= -23)
3555     end on
3556     )NKSP_CODE",
3557     .expectBoolExitResult = true
3558     });
3559    
3560     runScript({
3561     .code = R"NKSP_CODE(
3562     on init
3563     exit(3 >= 4)
3564     end on
3565     )NKSP_CODE",
3566     .expectBoolExitResult = false
3567     });
3568    
3569     runScript({
3570     .code = R"NKSP_CODE(
3571     on init
3572     exit(4 >= 3)
3573     end on
3574     )NKSP_CODE",
3575     .expectBoolExitResult = true
3576     });
3577    
3578     runScript({
3579     .code = R"NKSP_CODE(
3580     on init
3581     exit(-4 >= 3)
3582     end on
3583     )NKSP_CODE",
3584     .expectBoolExitResult = false
3585     });
3586    
3587     runScript({
3588     .code = R"NKSP_CODE(
3589     on init
3590     exit(3 >= -4)
3591     end on
3592     )NKSP_CODE",
3593     .expectBoolExitResult = true
3594     });
3595    
3596     runScript({
3597     .code = R"NKSP_CODE(
3598     on init
3599     exit(123 >= -45)
3600     end on
3601     )NKSP_CODE",
3602     .expectBoolExitResult = true
3603     });
3604    
3605     runScript({
3606     .code = R"NKSP_CODE(
3607     on init
3608     exit(-45 >= 123)
3609     end on
3610     )NKSP_CODE",
3611     .expectBoolExitResult = false
3612     });
3613    
3614 schoenebeck 3575 // real number tests ...
3615    
3616     runScript({
3617     .code = R"NKSP_CODE(
3618     on init
3619     exit(3.0 >= 3.0)
3620     end on
3621     )NKSP_CODE",
3622     .expectBoolExitResult = true
3623     });
3624    
3625     runScript({
3626     .code = R"NKSP_CODE(
3627     on init
3628     exit(3.1 >= 3.1)
3629     end on
3630     )NKSP_CODE",
3631     .expectBoolExitResult = true
3632     });
3633    
3634     runScript({
3635     .code = R"NKSP_CODE(
3636     on init
3637     exit(3.1 >= 3.0)
3638     end on
3639     )NKSP_CODE",
3640     .expectBoolExitResult = true
3641     });
3642    
3643     runScript({
3644     .code = R"NKSP_CODE(
3645     on init
3646     exit(3.0 >= 3.1)
3647     end on
3648     )NKSP_CODE",
3649     .expectBoolExitResult = false
3650     });
3651    
3652     runScript({
3653     .code = R"NKSP_CODE(
3654     on init
3655     exit(-23.33 >= -23.33)
3656     end on
3657     )NKSP_CODE",
3658     .expectBoolExitResult = true
3659     });
3660    
3661     runScript({
3662     .code = R"NKSP_CODE(
3663     on init
3664     exit(23.0 >= -23.0)
3665     end on
3666     )NKSP_CODE",
3667     .expectBoolExitResult = true
3668     });
3669    
3670     runScript({
3671     .code = R"NKSP_CODE(
3672     on init
3673     exit(3.0 >= 4.0)
3674     end on
3675     )NKSP_CODE",
3676     .expectBoolExitResult = false
3677     });
3678    
3679     runScript({
3680     .code = R"NKSP_CODE(
3681     on init
3682     exit(4.0 >= 3.0)
3683     end on
3684     )NKSP_CODE",
3685     .expectBoolExitResult = true
3686     });
3687    
3688     runScript({
3689     .code = R"NKSP_CODE(
3690     on init
3691     exit(-4.0 >= 3.0)
3692     end on
3693     )NKSP_CODE",
3694     .expectBoolExitResult = false
3695     });
3696    
3697     runScript({
3698     .code = R"NKSP_CODE(
3699     on init
3700     exit(3.0 >= -4.0)
3701     end on
3702     )NKSP_CODE",
3703     .expectBoolExitResult = true
3704     });
3705    
3706     runScript({
3707     .code = R"NKSP_CODE(
3708     on init
3709     exit(123.0 >= -45.0)
3710     end on
3711     )NKSP_CODE",
3712     .expectBoolExitResult = true
3713     });
3714    
3715     runScript({
3716     .code = R"NKSP_CODE(
3717     on init
3718     exit(-45.0 >= 123.0)
3719     end on
3720     )NKSP_CODE",
3721     .expectBoolExitResult = false
3722     });
3723    
3724     // mixed type tests ...
3725    
3726     runScript({
3727     .code = R"NKSP_CODE(
3728     on init
3729     exit(9 >= 9.1)
3730     end on
3731     )NKSP_CODE",
3732     .expectBoolExitResult = false
3733     });
3734    
3735     runScript({
3736     .code = R"NKSP_CODE(
3737     on init
3738     exit(9.1 >= 9)
3739     end on
3740     )NKSP_CODE",
3741     .expectBoolExitResult = true
3742     });
3743    
3744     runScript({
3745     .code = R"NKSP_CODE(
3746     on init
3747     exit(9 >= 9.0)
3748     end on
3749     )NKSP_CODE",
3750     .expectBoolExitResult = true
3751     });
3752    
3753     runScript({
3754     .code = R"NKSP_CODE(
3755     on init
3756     exit(9.0 >= 9)
3757     end on
3758     )NKSP_CODE",
3759     .expectBoolExitResult = true
3760     });
3761    
3762 schoenebeck 3581 // std unit tests ...
3763    
3764     runScript({
3765     .code = R"NKSP_CODE(
3766     on init
3767     exit(13ms >= 14ms)
3768     end on
3769     )NKSP_CODE",
3770     .expectBoolExitResult = false
3771     });
3772    
3773     runScript({
3774     .code = R"NKSP_CODE(
3775     on init
3776     exit(14ms >= 13ms)
3777     end on
3778     )NKSP_CODE",
3779     .expectBoolExitResult = true
3780     });
3781    
3782     runScript({
3783     .code = R"NKSP_CODE(
3784     on init
3785     exit(1s >= 990ms)
3786     end on
3787     )NKSP_CODE",
3788     .expectBoolExitResult = true
3789     });
3790    
3791     runScript({
3792     .code = R"NKSP_CODE(
3793     on init
3794     exit(990ms >= 1s)
3795     end on
3796     )NKSP_CODE",
3797     .expectBoolExitResult = false
3798     });
3799    
3800     runScript({
3801     .code = R"NKSP_CODE(
3802     on init
3803     exit(1000ms >= 1s)
3804     end on
3805     )NKSP_CODE",
3806     .expectBoolExitResult = true
3807     });
3808    
3809     runScript({
3810     .code = R"NKSP_CODE(
3811     on init
3812     exit(1s >= 1000ms)
3813     end on
3814     )NKSP_CODE",
3815     .expectBoolExitResult = true
3816     });
3817    
3818     runScript({
3819     .code = R"NKSP_CODE(
3820     on init
3821     exit(1s >= 1)
3822     end on
3823     )NKSP_CODE",
3824     .expectParseError = true // units on both sides must match
3825     });
3826    
3827     runScript({
3828     .code = R"NKSP_CODE(
3829     on init
3830     exit(1 >= 1s)
3831     end on
3832     )NKSP_CODE",
3833     .expectParseError = true // units on both sides must match
3834     });
3835    
3836     runScript({
3837     .code = R"NKSP_CODE(
3838     on init
3839     exit(1Hz >= 1B)
3840     end on
3841     )NKSP_CODE",
3842     .expectParseError = true // units on both sides must match
3843     });
3844    
3845     runScript({
3846     .code = R"NKSP_CODE(
3847     on init
3848     exit(13.0ms >= 13.1ms)
3849     end on
3850     )NKSP_CODE",
3851     .expectBoolExitResult = false
3852     });
3853    
3854     runScript({
3855     .code = R"NKSP_CODE(
3856     on init
3857     exit(13.1ms >= 13.0ms)
3858     end on
3859     )NKSP_CODE",
3860     .expectBoolExitResult = true
3861     });
3862    
3863     runScript({
3864     .code = R"NKSP_CODE(
3865     on init
3866     exit(0.9s >= 600.0ms)
3867     end on
3868     )NKSP_CODE",
3869     .expectBoolExitResult = true
3870     });
3871    
3872     runScript({
3873     .code = R"NKSP_CODE(
3874     on init
3875     exit(600.0ms >= 0.9s)
3876     end on
3877     )NKSP_CODE",
3878     .expectBoolExitResult = false
3879     });
3880    
3881     runScript({
3882     .code = R"NKSP_CODE(
3883     on init
3884     exit(5.1kHz >= 5100.0Hz)
3885     end on
3886     )NKSP_CODE",
3887     .expectBoolExitResult = true
3888     });
3889    
3890     runScript({
3891     .code = R"NKSP_CODE(
3892     on init
3893     exit(5100.0Hz >= 5.1kHz)
3894     end on
3895     )NKSP_CODE",
3896     .expectBoolExitResult = true
3897     });
3898    
3899     runScript({
3900     .code = R"NKSP_CODE(
3901     on init
3902     exit(1.0Hz >= 1.1)
3903     end on
3904     )NKSP_CODE",
3905     .expectParseError = true // units on both sides must match
3906     });
3907    
3908     runScript({
3909     .code = R"NKSP_CODE(
3910     on init
3911     exit(1.2 >= 1.34mdB)
3912     end on
3913     )NKSP_CODE",
3914     .expectParseError = true // units on both sides must match
3915     });
3916    
3917     runScript({
3918     .code = R"NKSP_CODE(
3919     on init
3920     exit(9.23us >= 3.14kHz)
3921     end on
3922     )NKSP_CODE",
3923     .expectParseError = true // units on both sides must match
3924     });
3925    
3926     // 'final' ('!') operator tests ...
3927     // (should always yield in false for relation operators)
3928    
3929     runScript({
3930     .code = R"NKSP_CODE(
3931     on init
3932     exit(!-4 >= !3)
3933     end on
3934     )NKSP_CODE",
3935     .expectBoolExitResult = false,
3936     .expectExitResultFinal = false
3937     });
3938    
3939     runScript({
3940     .code = R"NKSP_CODE(
3941     on init
3942     exit(-4 >= 3)
3943     end on
3944     )NKSP_CODE",
3945     .expectBoolExitResult = false,
3946     .expectExitResultFinal = false
3947     });
3948    
3949 schoenebeck 3551 #if !SILENT_TEST
3950     std::cout << std::endl;
3951     #endif
3952     }
3953    
3954     static void testEqualOperator() {
3955     #if !SILENT_TEST
3956     std::cout << "UNIT TEST: equal (=) operator\n";
3957     #endif
3958    
3959 schoenebeck 3575 // integer tests ...
3960    
3961 schoenebeck 3551 runScript({
3962     .code = R"NKSP_CODE(
3963     on init
3964     exit(3 = 3)
3965     end on
3966     )NKSP_CODE",
3967     .expectBoolExitResult = true
3968     });
3969    
3970     runScript({
3971     .code = R"NKSP_CODE(
3972     on init
3973     exit(4 = 4)
3974     end on
3975     )NKSP_CODE",
3976     .expectBoolExitResult = true
3977     });
3978    
3979     runScript({
3980     .code = R"NKSP_CODE(
3981     on init
3982     exit(3 = 4)
3983     end on
3984     )NKSP_CODE",
3985     .expectBoolExitResult = false
3986     });
3987    
3988     runScript({
3989     .code = R"NKSP_CODE(
3990     on init
3991     exit(23 = -23)
3992     end on
3993     )NKSP_CODE",
3994     .expectBoolExitResult = false
3995     });
3996    
3997 schoenebeck 3575 // real number tests ...
3998    
3999     runScript({
4000     .code = R"NKSP_CODE(
4001     on init
4002     exit(3.0 = 3.0)
4003     end on
4004     )NKSP_CODE",
4005     .expectBoolExitResult = true
4006     });
4007    
4008     runScript({
4009     .code = R"NKSP_CODE(
4010     on init
4011     exit(4.33 = 4.33)
4012     end on
4013     )NKSP_CODE",
4014     .expectBoolExitResult = true
4015     });
4016    
4017     runScript({
4018     .code = R"NKSP_CODE(
4019     on init
4020     exit(4.31 = 4.35)
4021     end on
4022     )NKSP_CODE",
4023     .expectBoolExitResult = false
4024     });
4025    
4026     runScript({
4027     .code = R"NKSP_CODE(
4028     on init
4029     exit(3.0 = 4.0)
4030     end on
4031     )NKSP_CODE",
4032     .expectBoolExitResult = false
4033     });
4034    
4035     runScript({
4036     .code = R"NKSP_CODE(
4037     on init
4038     exit(23.0 = -23.0)
4039     end on
4040     )NKSP_CODE",
4041     .expectBoolExitResult = false
4042     });
4043    
4044 schoenebeck 3581 // deal with inaccuracy of float point
4045     runScript({
4046     .code = R"NKSP_CODE(
4047     on init
4048     declare ~a := 0.165
4049     declare ~b := 0.185
4050     declare ~x := 0.1
4051     declare ~y := 0.25
4052     exit(~a + ~b = ~x + ~y) { both sides should actually be 0.35, they slightly deviate both though }
4053     end on
4054     )NKSP_CODE",
4055     .expectBoolExitResult = true // our implementation of real number equal comparison should take care about floating point tolerance
4056     });
4057    
4058     // deal with inaccuracy of float point
4059     runScript({
4060     .code = R"NKSP_CODE(
4061     on init
4062     declare ~a := 0.166
4063     declare ~b := 0.185
4064     declare ~x := 0.1
4065     declare ~y := 0.25
4066     exit(~a + ~b = ~x + ~y) { left side approx. 0.351, right side approx. 0.35 }
4067     end on
4068     )NKSP_CODE",
4069     .expectBoolExitResult = false
4070     });
4071    
4072 schoenebeck 3575 // mixed type tests ...
4073    
4074     runScript({
4075     .code = R"NKSP_CODE(
4076     on init
4077     exit(23 = 23.0)
4078     end on
4079     )NKSP_CODE",
4080     .expectBoolExitResult = true
4081     });
4082    
4083     runScript({
4084     .code = R"NKSP_CODE(
4085     on init
4086     exit(23.0 = 23)
4087     end on
4088     )NKSP_CODE",
4089     .expectBoolExitResult = true
4090     });
4091    
4092     runScript({
4093     .code = R"NKSP_CODE(
4094     on init
4095     exit(23 = 23.1)
4096     end on
4097     )NKSP_CODE",
4098     .expectBoolExitResult = false
4099     });
4100    
4101     runScript({
4102     .code = R"NKSP_CODE(
4103     on init
4104     exit(23.1 = 23)
4105     end on
4106     )NKSP_CODE",
4107     .expectBoolExitResult = false
4108     });
4109    
4110 schoenebeck 3581 // std unit tests ...
4111    
4112     runScript({
4113     .code = R"NKSP_CODE(
4114     on init
4115     exit(13ms = 14ms)
4116     end on
4117     )NKSP_CODE",
4118     .expectBoolExitResult = false
4119     });
4120    
4121     runScript({
4122     .code = R"NKSP_CODE(
4123     on init
4124     exit(14ms = 13ms)
4125     end on
4126     )NKSP_CODE",
4127     .expectBoolExitResult = false
4128     });
4129    
4130     runScript({
4131     .code = R"NKSP_CODE(
4132     on init
4133     exit(1s = 1ms)
4134     end on
4135     )NKSP_CODE",
4136     .expectBoolExitResult = false
4137     });
4138    
4139     runScript({
4140     .code = R"NKSP_CODE(
4141     on init
4142     exit(1ms = 1s)
4143     end on
4144     )NKSP_CODE",
4145     .expectBoolExitResult = false
4146     });
4147    
4148     runScript({
4149     .code = R"NKSP_CODE(
4150     on init
4151     exit(3.14kHz = 3140Hz)
4152     end on
4153     )NKSP_CODE",
4154     .expectBoolExitResult = true
4155     });
4156    
4157     runScript({
4158     .code = R"NKSP_CODE(
4159     on init
4160     exit(3140Hz = 3.14kHz)
4161     end on
4162     )NKSP_CODE",
4163     .expectBoolExitResult = true
4164     });
4165    
4166     runScript({
4167     .code = R"NKSP_CODE(
4168     on init
4169     exit(1s = 1)
4170     end on
4171     )NKSP_CODE",
4172     .expectParseError = true // units on both sides must match
4173     });
4174    
4175     runScript({
4176     .code = R"NKSP_CODE(
4177     on init
4178     exit(1 = 1s)
4179     end on
4180     )NKSP_CODE",
4181     .expectParseError = true // units on both sides must match
4182     });
4183    
4184     runScript({
4185     .code = R"NKSP_CODE(
4186     on init
4187     exit(1Hz = 1B)
4188     end on
4189     )NKSP_CODE",
4190     .expectParseError = true // units on both sides must match
4191     });
4192    
4193     // 'final' ('!') operator tests ...
4194     // (should always yield in false for relation operators)
4195    
4196     runScript({
4197     .code = R"NKSP_CODE(
4198     on init
4199     exit(!-4 = !3)
4200     end on
4201     )NKSP_CODE",
4202     .expectBoolExitResult = false,
4203     .expectExitResultFinal = false
4204     });
4205    
4206     runScript({
4207     .code = R"NKSP_CODE(
4208     on init
4209     exit(-4 = 3)
4210     end on
4211     )NKSP_CODE",
4212     .expectBoolExitResult = false,
4213     .expectExitResultFinal = false
4214     });
4215    
4216 schoenebeck 3551 #if !SILENT_TEST
4217     std::cout << std::endl;
4218     #endif
4219     }
4220    
4221     static void testUnequalOperator() {
4222     #if !SILENT_TEST
4223     std::cout << "UNIT TEST: unequal (#) operator\n";
4224     #endif
4225    
4226 schoenebeck 3575 // integer tests ...
4227    
4228 schoenebeck 3551 runScript({
4229     .code = R"NKSP_CODE(
4230     on init
4231     exit(3 # 3)
4232     end on
4233     )NKSP_CODE",
4234     .expectBoolExitResult = false
4235     });
4236    
4237     runScript({
4238     .code = R"NKSP_CODE(
4239     on init
4240     exit(4 # 4)
4241     end on
4242     )NKSP_CODE",
4243     .expectBoolExitResult = false
4244     });
4245    
4246     runScript({
4247     .code = R"NKSP_CODE(
4248     on init
4249     exit(3 # 4)
4250     end on
4251     )NKSP_CODE",
4252     .expectBoolExitResult = true
4253     });
4254    
4255     runScript({
4256     .code = R"NKSP_CODE(
4257     on init
4258     exit(23 # -23)
4259     end on
4260     )NKSP_CODE",
4261     .expectBoolExitResult = true
4262     });
4263    
4264 schoenebeck 3575 // real number tests ...
4265    
4266     runScript({
4267     .code = R"NKSP_CODE(
4268     on init
4269     exit(3.0 # 3.0)
4270     end on
4271     )NKSP_CODE",
4272     .expectBoolExitResult = false
4273     });
4274    
4275     runScript({
4276     .code = R"NKSP_CODE(
4277     on init
4278     exit(3.14 # 3.14)
4279     end on
4280     )NKSP_CODE",
4281     .expectBoolExitResult = false
4282     });
4283    
4284     runScript({
4285     .code = R"NKSP_CODE(
4286     on init
4287     exit(3.19 # 3.12)
4288     end on
4289     )NKSP_CODE",
4290     .expectBoolExitResult = true
4291     });
4292    
4293     runScript({
4294     .code = R"NKSP_CODE(
4295     on init
4296     exit(23.0 # -23.0)
4297     end on
4298     )NKSP_CODE",
4299     .expectBoolExitResult = true
4300     });
4301    
4302 schoenebeck 3581 // deal with inaccuracy of float point
4303     runScript({
4304     .code = R"NKSP_CODE(
4305     on init
4306     declare ~a := 0.165
4307     declare ~b := 0.185
4308     declare ~x := 0.1
4309     declare ~y := 0.25
4310     exit(~a + ~b # ~x + ~y) { both sides should actually be 0.35, they slightly deviate both though }
4311     end on
4312     )NKSP_CODE",
4313     .expectBoolExitResult = false // our implementation of real number unequal comparison should take care about floating point tolerance
4314     });
4315    
4316     // deal with inaccuracy of float point
4317     runScript({
4318     .code = R"NKSP_CODE(
4319     on init
4320     declare ~a := 0.166
4321     declare ~b := 0.185
4322     declare ~x := 0.1
4323     declare ~y := 0.25
4324     exit(~a + ~b # ~x + ~y) { left side approx. 0.351, right side approx. 0.35 }
4325     end on
4326     )NKSP_CODE",
4327     .expectBoolExitResult = true
4328     });
4329    
4330 schoenebeck 3575 // mixed type tests ...
4331    
4332     runScript({
4333     .code = R"NKSP_CODE(
4334     on init
4335     exit(3 # 3.0)
4336     end on
4337     )NKSP_CODE",
4338     .expectBoolExitResult = false
4339     });
4340    
4341     runScript({
4342     .code = R"NKSP_CODE(
4343     on init
4344     exit(3.0 # 3)
4345     end on
4346     )NKSP_CODE",
4347     .expectBoolExitResult = false
4348     });
4349    
4350     runScript({
4351     .code = R"NKSP_CODE(
4352     on init
4353     exit(3.1 # 3)
4354     end on
4355     )NKSP_CODE",
4356     .expectBoolExitResult = true
4357     });
4358    
4359     runScript({
4360     .code = R"NKSP_CODE(
4361     on init
4362     exit(3 # 3.1)
4363     end on
4364     )NKSP_CODE",
4365     .expectBoolExitResult = true
4366     });
4367    
4368 schoenebeck 3581 // std unit tests ...
4369    
4370     runScript({
4371     .code = R"NKSP_CODE(
4372     on init
4373     exit(13ms # 14ms)
4374     end on
4375     )NKSP_CODE",
4376     .expectBoolExitResult = true
4377     });
4378    
4379     runScript({
4380     .code = R"NKSP_CODE(
4381     on init
4382     exit(14ms # 13ms)
4383     end on
4384     )NKSP_CODE",
4385     .expectBoolExitResult = true
4386     });
4387    
4388     runScript({
4389     .code = R"NKSP_CODE(
4390     on init
4391     exit(1s # 1ms)
4392     end on
4393     )NKSP_CODE",
4394     .expectBoolExitResult = true
4395     });
4396    
4397     runScript({
4398     .code = R"NKSP_CODE(
4399     on init
4400     exit(1ms # 1s)
4401     end on
4402     )NKSP_CODE",
4403     .expectBoolExitResult = true
4404     });
4405    
4406     runScript({
4407     .code = R"NKSP_CODE(
4408     on init
4409     exit(3.14kHz # 3140Hz)
4410     end on
4411     )NKSP_CODE",
4412     .expectBoolExitResult = false
4413     });
4414    
4415     runScript({
4416     .code = R"NKSP_CODE(
4417     on init
4418     exit(3140Hz # 3.14kHz)
4419     end on
4420     )NKSP_CODE",
4421     .expectBoolExitResult = false
4422     });
4423    
4424     runScript({
4425     .code = R"NKSP_CODE(
4426     on init
4427     exit(1s # 1)
4428     end on
4429     )NKSP_CODE",
4430     .expectParseError = true // units on both sides must match
4431     });
4432    
4433     runScript({
4434     .code = R"NKSP_CODE(
4435     on init
4436     exit(1 # 1s)
4437     end on
4438     )NKSP_CODE",
4439     .expectParseError = true // units on both sides must match
4440     });
4441    
4442     runScript({
4443     .code = R"NKSP_CODE(
4444     on init
4445     exit(1Hz # 1B)
4446     end on
4447     )NKSP_CODE",
4448     .expectParseError = true // units on both sides must match
4449     });
4450    
4451     // 'final' ('!') operator tests ...
4452     // (should always yield in false for relation operators)
4453    
4454     runScript({
4455     .code = R"NKSP_CODE(
4456     on init
4457     exit(!-4 # !3)
4458     end on
4459     )NKSP_CODE",
4460     .expectBoolExitResult = true,
4461     .expectExitResultFinal = false
4462     });
4463    
4464     runScript({
4465     .code = R"NKSP_CODE(
4466     on init
4467     exit(-4 # 3)
4468     end on
4469     )NKSP_CODE",
4470     .expectBoolExitResult = true,
4471     .expectExitResultFinal = false
4472     });
4473    
4474 schoenebeck 3551 #if !SILENT_TEST
4475     std::cout << std::endl;
4476     #endif
4477     }
4478    
4479     static void testLogicalAndOperator() {
4480     #if !SILENT_TEST
4481     std::cout << "UNIT TEST: logical and (and) operator\n";
4482     #endif
4483    
4484 schoenebeck 3575 // integer tests ...
4485    
4486 schoenebeck 3551 runScript({
4487     .code = R"NKSP_CODE(
4488     on init
4489     exit(1 and 1)
4490     end on
4491     )NKSP_CODE",
4492     .expectBoolExitResult = true
4493     });
4494    
4495     runScript({
4496     .code = R"NKSP_CODE(
4497     on init
4498     exit(1 and 2)
4499     end on
4500     )NKSP_CODE",
4501     .expectBoolExitResult = true
4502     });
4503    
4504     runScript({
4505     .code = R"NKSP_CODE(
4506     on init
4507     exit(1 and 3)
4508     end on
4509     )NKSP_CODE",
4510     .expectBoolExitResult = true
4511     });
4512    
4513     runScript({
4514     .code = R"NKSP_CODE(
4515     on init
4516     exit(1 and 0)
4517     end on
4518     )NKSP_CODE",
4519     .expectBoolExitResult = false
4520     });
4521    
4522     runScript({
4523     .code = R"NKSP_CODE(
4524     on init
4525     exit(0 and 1)
4526     end on
4527     )NKSP_CODE",
4528     .expectBoolExitResult = false
4529     });
4530    
4531     runScript({
4532     .code = R"NKSP_CODE(
4533     on init
4534     exit(0 and 0)
4535     end on
4536     )NKSP_CODE",
4537     .expectBoolExitResult = false
4538     });
4539    
4540 schoenebeck 3575 // real number tests ...
4541     // (not allowed for this operator)
4542    
4543     runScript({
4544     .code = R"NKSP_CODE(
4545     on init
4546     exit(1.0 and 1.0)
4547     end on
4548     )NKSP_CODE",
4549     .expectParseError = true // real numbers not allowed for this operator
4550     });
4551    
4552     // mixed type tests ...
4553     // (not allowed for this operator)
4554    
4555     runScript({
4556     .code = R"NKSP_CODE(
4557     on init
4558     exit(1.0 and 1)
4559     end on
4560     )NKSP_CODE",
4561     .expectParseError = true // real numbers not allowed for this operator
4562     });
4563    
4564     runScript({
4565     .code = R"NKSP_CODE(
4566     on init
4567     exit(1 and 1.0)
4568     end on
4569     )NKSP_CODE",
4570     .expectParseError = true // real numbers not allowed for this operator
4571     });
4572    
4573 schoenebeck 3581 // std unit tests ...
4574     // (not allowed for this operator)
4575    
4576     runScript({
4577     .code = R"NKSP_CODE(
4578     on init
4579     exit(1s and 0)
4580     end on
4581     )NKSP_CODE",
4582     .expectParseError = true // std units not allowed for this operator
4583     });
4584    
4585     runScript({
4586     .code = R"NKSP_CODE(
4587     on init
4588     exit(0 and 1s)
4589     end on
4590     )NKSP_CODE",
4591     .expectParseError = true // std units not allowed for this operator
4592     });
4593    
4594     // 'final' ('!') operator tests ...
4595    
4596     runScript({
4597     .code = R"NKSP_CODE(
4598     on init
4599     exit(!0 and !0)
4600     end on
4601     )NKSP_CODE",
4602     .expectExitResultFinal = true
4603     });
4604    
4605     runScript({
4606     .code = R"NKSP_CODE(
4607     on init
4608     exit(0 and 0)
4609     end on
4610     )NKSP_CODE",
4611     .expectExitResultFinal = false
4612     });
4613    
4614 schoenebeck 3551 #if !SILENT_TEST
4615     std::cout << std::endl;
4616     #endif
4617     }
4618    
4619     static void testLogicalOrOperator() {
4620     #if !SILENT_TEST
4621     std::cout << "UNIT TEST: logical or (or) operator\n";
4622     #endif
4623    
4624 schoenebeck 3575 // integer tests ...
4625    
4626 schoenebeck 3551 runScript({
4627     .code = R"NKSP_CODE(
4628     on init
4629     exit(1 or 1)
4630     end on
4631     )NKSP_CODE",
4632     .expectBoolExitResult = true
4633     });
4634    
4635     runScript({
4636     .code = R"NKSP_CODE(
4637     on init
4638     exit(1 or 2)
4639     end on
4640     )NKSP_CODE",
4641     .expectBoolExitResult = true
4642     });
4643    
4644     runScript({
4645     .code = R"NKSP_CODE(
4646     on init
4647     exit(1 or 3)
4648     end on
4649     )NKSP_CODE",
4650     .expectBoolExitResult = true
4651     });
4652    
4653     runScript({
4654     .code = R"NKSP_CODE(
4655     on init
4656     exit(1 or 0)
4657     end on
4658     )NKSP_CODE",
4659     .expectBoolExitResult = true
4660     });
4661    
4662     runScript({
4663     .code = R"NKSP_CODE(
4664     on init
4665     exit(0 or 1)
4666     end on
4667     )NKSP_CODE",
4668     .expectBoolExitResult = true
4669     });
4670    
4671     runScript({
4672     .code = R"NKSP_CODE(
4673     on init
4674     exit(0 or 0)
4675     end on
4676     )NKSP_CODE",
4677     .expectBoolExitResult = false
4678     });
4679    
4680 schoenebeck 3575 // real number tests ...
4681     // (not allowed for this operator)
4682    
4683     runScript({
4684     .code = R"NKSP_CODE(
4685     on init
4686     exit(1.0 or 1.0)
4687     end on
4688     )NKSP_CODE",
4689     .expectParseError = true // real numbers not allowed for this operator
4690     });
4691    
4692     // mixed type tests ...
4693     // (not allowed for this operator)
4694    
4695     runScript({
4696     .code = R"NKSP_CODE(
4697     on init
4698     exit(1.0 or 1)
4699     end on
4700     )NKSP_CODE",
4701     .expectParseError = true // real numbers not allowed for this operator
4702     });
4703    
4704     runScript({
4705     .code = R"NKSP_CODE(
4706     on init
4707     exit(1 or 1.0)
4708     end on
4709     )NKSP_CODE",
4710     .expectParseError = true // real numbers not allowed for this operator
4711     });
4712    
4713 schoenebeck 3581 // std unit tests ...
4714     // (not allowed for this operator)
4715    
4716     runScript({
4717     .code = R"NKSP_CODE(
4718     on init
4719     exit(1s or 0)
4720     end on
4721     )NKSP_CODE",
4722     .expectParseError = true // std units not allowed for this operator
4723     });
4724    
4725     runScript({
4726     .code = R"NKSP_CODE(
4727     on init
4728     exit(0 or 1s)
4729     end on
4730     )NKSP_CODE",
4731     .expectParseError = true // std units not allowed for this operator
4732     });
4733    
4734     // 'final' ('!') operator tests ...
4735    
4736     runScript({
4737     .code = R"NKSP_CODE(
4738     on init
4739     exit(!0 or !0)
4740     end on
4741     )NKSP_CODE",
4742     .expectExitResultFinal = true
4743     });
4744    
4745     runScript({
4746     .code = R"NKSP_CODE(
4747     on init
4748     exit(0 or 0)
4749     end on
4750     )NKSP_CODE",
4751     .expectExitResultFinal = false
4752     });
4753    
4754 schoenebeck 3551 #if !SILENT_TEST
4755     std::cout << std::endl;
4756     #endif
4757     }
4758    
4759     static void testLogicalNotOperator() {
4760     #if !SILENT_TEST
4761     std::cout << "UNIT TEST: logical not (not) operator\n";
4762     #endif
4763    
4764 schoenebeck 3575 // integer tests ...
4765    
4766 schoenebeck 3551 runScript({
4767     .code = R"NKSP_CODE(
4768     on init
4769     exit(not 1)
4770     end on
4771     )NKSP_CODE",
4772     .expectBoolExitResult = false
4773     });
4774    
4775     runScript({
4776     .code = R"NKSP_CODE(
4777     on init
4778     exit(not 2)
4779     end on
4780     )NKSP_CODE",
4781     .expectBoolExitResult = false
4782     });
4783    
4784     runScript({
4785     .code = R"NKSP_CODE(
4786     on init
4787     exit(not 0)
4788     end on
4789     )NKSP_CODE",
4790     .expectBoolExitResult = true
4791     });
4792    
4793 schoenebeck 3575 // real number tests ...
4794     // (not allowed for this operator)
4795    
4796     runScript({
4797     .code = R"NKSP_CODE(
4798     on init
4799     exit(not 1.0)
4800     end on
4801     )NKSP_CODE",
4802     .expectParseError = true // real numbers not allowed for this operator
4803     });
4804    
4805 schoenebeck 3581 // std unit tests ...
4806     // (not allowed for this operator)
4807    
4808     runScript({
4809     .code = R"NKSP_CODE(
4810     on init
4811     exit(not 1s)
4812     end on
4813     )NKSP_CODE",
4814     .expectParseError = true // std units not allowed for this operator
4815     });
4816    
4817     // 'final' ('!') operator tests ...
4818    
4819     runScript({
4820     .code = R"NKSP_CODE(
4821     on init
4822     exit(not !1)
4823     end on
4824     )NKSP_CODE",
4825     .expectExitResultFinal = true
4826     });
4827    
4828     runScript({
4829     .code = R"NKSP_CODE(
4830     on init
4831     exit(not 1)
4832     end on
4833     )NKSP_CODE",
4834     .expectExitResultFinal = false
4835     });
4836    
4837 schoenebeck 3551 #if !SILENT_TEST
4838     std::cout << std::endl;
4839     #endif
4840     }
4841    
4842     static void testBitwiseAndOperator() {
4843     #if !SILENT_TEST
4844     std::cout << "UNIT TEST: bitwise and (.and.) operator\n";
4845     #endif
4846    
4847 schoenebeck 3575 // integer tests ...
4848    
4849 schoenebeck 3551 runScript({
4850     .code = R"NKSP_CODE(
4851     on init
4852     exit(1 .and. 1)
4853     end on
4854     )NKSP_CODE",
4855     .expectIntExitResult = 1
4856     });
4857    
4858     runScript({
4859     .code = R"NKSP_CODE(
4860     on init
4861     exit(43 .and. 142)
4862     end on
4863     )NKSP_CODE",
4864     .expectIntExitResult = 10
4865     });
4866    
4867 schoenebeck 3575 // real number tests ...
4868     // (not allowed for this operator)
4869    
4870     runScript({
4871     .code = R"NKSP_CODE(
4872     on init
4873     exit(1.0 .and. 1.0)
4874     end on
4875     )NKSP_CODE",
4876     .expectParseError = true // real numbers not allowed for this operator
4877     });
4878    
4879     // mixed type tests ...
4880     // (not allowed for this operator)
4881    
4882     runScript({
4883     .code = R"NKSP_CODE(
4884     on init
4885     exit(1.0 .and. 1)
4886     end on
4887     )NKSP_CODE",
4888     .expectParseError = true // real numbers not allowed for this operator
4889     });
4890    
4891     runScript({
4892     .code = R"NKSP_CODE(
4893     on init
4894     exit(1 .and. 1.0)
4895     end on
4896     )NKSP_CODE",
4897     .expectParseError = true // real numbers not allowed for this operator
4898     });
4899    
4900 schoenebeck 3581 // std unit tests ...
4901     // (not allowed for this operator)
4902    
4903     runScript({
4904     .code = R"NKSP_CODE(
4905     on init
4906     exit(1s .and. 1)
4907     end on
4908     )NKSP_CODE",
4909     .expectParseError = true // std units not allowed for this operator
4910     });
4911    
4912     runScript({
4913     .code = R"NKSP_CODE(
4914     on init
4915     exit(1 .and. 1s)
4916     end on
4917     )NKSP_CODE",
4918     .expectParseError = true // std units not allowed for this operator
4919     });
4920    
4921     // 'final' ('!') operator tests ...
4922    
4923     runScript({
4924     .code = R"NKSP_CODE(
4925     on init
4926     exit(!43 .and. !142)
4927     end on
4928     )NKSP_CODE",
4929     .expectIntExitResult = 10,
4930     .expectExitResultFinal = true
4931     });
4932    
4933     runScript({
4934     .code = R"NKSP_CODE(
4935     on init
4936     exit(43 .and. 142)
4937     end on
4938     )NKSP_CODE",
4939     .expectIntExitResult = 10,
4940     .expectExitResultFinal = false
4941     });
4942    
4943 schoenebeck 3551 #if !SILENT_TEST
4944     std::cout << std::endl;
4945     #endif
4946     }
4947    
4948     static void testBitwiseOrOperator() {
4949     #if !SILENT_TEST
4950     std::cout << "UNIT TEST: bitwise or (.or.) operator\n";
4951     #endif
4952    
4953 schoenebeck 3575 // integer tests ...
4954    
4955 schoenebeck 3551 runScript({
4956     .code = R"NKSP_CODE(
4957     on init
4958     exit(1 .or. 1)
4959     end on
4960     )NKSP_CODE",
4961     .expectIntExitResult = 1
4962     });
4963    
4964     runScript({
4965     .code = R"NKSP_CODE(
4966     on init
4967     exit(0 .or. 0)
4968     end on
4969     )NKSP_CODE",
4970     .expectIntExitResult = 0
4971     });
4972    
4973     runScript({
4974     .code = R"NKSP_CODE(
4975     on init
4976     exit(43 .or. 142)
4977     end on
4978     )NKSP_CODE",
4979     .expectIntExitResult = 175
4980     });
4981    
4982 schoenebeck 3575 // real number tests ...
4983     // (not allowed for this operator)
4984    
4985     runScript({
4986     .code = R"NKSP_CODE(
4987     on init
4988     exit(1.0 .or. 1.0)
4989     end on
4990     )NKSP_CODE",
4991     .expectParseError = true // real numbers not allowed for this operator
4992     });
4993    
4994     // mixed type tests ...
4995     // (not allowed for this operator)
4996    
4997     runScript({
4998     .code = R"NKSP_CODE(
4999     on init
5000     exit(1.0 .or. 1)
5001     end on
5002     )NKSP_CODE",
5003     .expectParseError = true // real numbers not allowed for this operator
5004     });
5005    
5006     runScript({
5007     .code = R"NKSP_CODE(
5008     on init
5009     exit(1 .or. 1.0)
5010     end on
5011     )NKSP_CODE",
5012     .expectParseError = true // real numbers not allowed for this operator
5013     });
5014    
5015 schoenebeck 3581 // std unit tests ...
5016     // (not allowed for this operator)
5017    
5018     runScript({
5019     .code = R"NKSP_CODE(
5020     on init
5021     exit(1s .or. 1)
5022     end on
5023     )NKSP_CODE",
5024     .expectParseError = true // std units not allowed for this operator
5025     });
5026    
5027     runScript({
5028     .code = R"NKSP_CODE(
5029     on init
5030     exit(1 .or. 1s)
5031     end on
5032     )NKSP_CODE",
5033     .expectParseError = true // std units not allowed for this operator
5034     });
5035    
5036     // 'final' ('!') operator tests ...
5037    
5038     runScript({
5039     .code = R"NKSP_CODE(
5040     on init
5041     exit(!43 .or. !142)
5042     end on
5043     )NKSP_CODE",
5044     .expectIntExitResult = 175,
5045     .expectExitResultFinal = true
5046     });
5047    
5048     runScript({
5049     .code = R"NKSP_CODE(
5050     on init
5051     exit(43 .or. 142)
5052     end on
5053     )NKSP_CODE",
5054     .expectIntExitResult = 175,
5055     .expectExitResultFinal = false
5056     });
5057    
5058 schoenebeck 3551 #if !SILENT_TEST
5059     std::cout << std::endl;
5060     #endif
5061     }
5062    
5063     static void testBitwiseNotOperator() {
5064     #if !SILENT_TEST
5065     std::cout << "UNIT TEST: bitwise not (.not.) operator\n";
5066     #endif
5067    
5068 schoenebeck 3575 // integer tests ...
5069    
5070 schoenebeck 3551 runScript({
5071     .code = R"NKSP_CODE(
5072     on init
5073     exit(.not. -1)
5074     end on
5075     )NKSP_CODE",
5076     .expectIntExitResult = 0
5077     });
5078    
5079     runScript({
5080     .code = R"NKSP_CODE(
5081     on init
5082     exit(.not. 0)
5083     end on
5084     )NKSP_CODE",
5085     .expectIntExitResult = -1
5086     });
5087    
5088     runScript({
5089     .code = R"NKSP_CODE(
5090     on init
5091     exit(.not. 3)
5092     end on
5093     )NKSP_CODE",
5094     .expectIntExitResult = ssize_t(size_t(-1) << 2)
5095     });
5096    
5097 schoenebeck 3575 // real number tests ...
5098     // (not allowed for this operator)
5099    
5100     runScript({
5101     .code = R"NKSP_CODE(
5102     on init
5103     exit(.not. 1.0)
5104     end on
5105     )NKSP_CODE",
5106     .expectParseError = true // real numbers not allowed for this operator
5107     });
5108    
5109     runScript({
5110     .code = R"NKSP_CODE(
5111     on init
5112     exit(.not. -1.0)
5113     end on
5114     )NKSP_CODE",
5115     .expectParseError = true // real numbers not allowed for this operator
5116     });
5117    
5118 schoenebeck 3581 // std unit tests ...
5119     // (not allowed for this operator)
5120    
5121     runScript({
5122     .code = R"NKSP_CODE(
5123     on init
5124     exit(.not. 1s)
5125     end on
5126     )NKSP_CODE",
5127     .expectParseError = true // std units not allowed for this operator
5128     });
5129    
5130     // 'final' ('!') operator tests ...
5131    
5132     runScript({
5133     .code = R"NKSP_CODE(
5134     on init
5135     exit(.not. !0)
5136     end on
5137     )NKSP_CODE",
5138     .expectIntExitResult = -1,
5139     .expectExitResultFinal = true
5140     });
5141    
5142     runScript({
5143     .code = R"NKSP_CODE(
5144     on init
5145     exit(.not. 0)
5146     end on
5147     )NKSP_CODE",
5148     .expectIntExitResult = -1,
5149     .expectExitResultFinal = false
5150     });
5151    
5152 schoenebeck 3551 #if !SILENT_TEST
5153     std::cout << std::endl;
5154     #endif
5155     }
5156    
5157     static void testPrecedenceOfOperators() {
5158     #if !SILENT_TEST
5159     std::cout << "UNIT TEST: precedence of operators\n";
5160     #endif
5161    
5162 schoenebeck 3575 // integer tests ...
5163    
5164 schoenebeck 3551 runScript({
5165     .code = R"NKSP_CODE(
5166     on init
5167     exit(3 + 4 * 2)
5168     end on
5169     )NKSP_CODE",
5170     .expectIntExitResult = 11
5171     });
5172    
5173     runScript({
5174     .code = R"NKSP_CODE(
5175     on init
5176     exit(4 * 2 + 3)
5177     end on
5178     )NKSP_CODE",
5179     .expectIntExitResult = 11
5180     });
5181    
5182     runScript({
5183     .code = R"NKSP_CODE(
5184     on init
5185     exit((3 + 4) * 2)
5186     end on
5187     )NKSP_CODE",
5188     .expectIntExitResult = 14
5189     });
5190    
5191     runScript({
5192     .code = R"NKSP_CODE(
5193     on init
5194     exit(4 * (2 + 3))
5195     end on
5196     )NKSP_CODE",
5197     .expectIntExitResult = 20
5198     });
5199    
5200 schoenebeck 3575 // real number tests ...
5201    
5202     runScript({
5203     .code = R"NKSP_CODE(
5204     on init
5205     exit(3.2 + 4.0 * 2.0)
5206     end on
5207     )NKSP_CODE",
5208     .expectRealExitResult = 11.2
5209     });
5210    
5211     runScript({
5212     .code = R"NKSP_CODE(
5213     on init
5214     exit(4.0 * 2.0 + 3.2)
5215     end on
5216     )NKSP_CODE",
5217     .expectRealExitResult = 11.2
5218     });
5219    
5220     runScript({
5221     .code = R"NKSP_CODE(
5222     on init
5223     exit((3.2 + 4.0) * 2.0)
5224     end on
5225     )NKSP_CODE",
5226     .expectRealExitResult = 14.4
5227     });
5228    
5229     runScript({
5230     .code = R"NKSP_CODE(
5231     on init
5232     exit(4.0 * (2.0 + 3.2))
5233     end on
5234     )NKSP_CODE",
5235     .expectRealExitResult = 20.8
5236     });
5237    
5238 schoenebeck 3581 // std unit tests ...
5239    
5240     runScript({
5241     .code = R"NKSP_CODE(
5242     on init
5243     exit(4 * (2us + 3us) + 7ms)
5244     end on
5245     )NKSP_CODE",
5246     .expectIntExitResult = 7020,
5247     .expectExitResultUnitPrefix = { VM_MICRO },
5248     .expectExitResultUnit = VM_SECOND
5249     });
5250    
5251     runScript({
5252     .code = R"NKSP_CODE(
5253     on init
5254     declare $a := 4
5255     declare $c := 3us
5256     exit($a * (2us + $c) + 7ms)
5257     end on
5258     )NKSP_CODE",
5259     .expectIntExitResult = 7020,
5260     .expectExitResultUnitPrefix = { VM_MICRO },
5261     .expectExitResultUnit = VM_SECOND
5262     });
5263    
5264     runScript({
5265     .code = R"NKSP_CODE(
5266     on init
5267     declare $a := 4
5268     declare $b := 2us
5269     declare $c := 3us
5270     exit($a * ($b + $c) + 7ms)
5271     end on
5272     )NKSP_CODE",
5273     .expectIntExitResult = 7020,
5274     .expectExitResultUnitPrefix = { VM_MICRO },
5275     .expectExitResultUnit = VM_SECOND
5276     });
5277    
5278     runScript({
5279     .code = R"NKSP_CODE(
5280     on init
5281     declare $a := 4
5282     declare $b := 2us
5283     declare $c := 3us
5284     declare $d := 7ms
5285     exit($a * ($b + $c) + 7ms)
5286     end on
5287     )NKSP_CODE",
5288     .expectIntExitResult = 7020,
5289     .expectExitResultUnitPrefix = { VM_MICRO },
5290     .expectExitResultUnit = VM_SECOND
5291     });
5292    
5293     runScript({
5294     .code = R"NKSP_CODE(
5295     on init
5296     declare $c := 3us
5297     declare $a := 4
5298     declare $d := 7ms
5299     declare $b := 2us
5300     exit($a * ($b + $c) + 7ms)
5301     end on
5302     )NKSP_CODE",
5303     .expectIntExitResult = 7020,
5304     .expectExitResultUnitPrefix = { VM_MICRO },
5305     .expectExitResultUnit = VM_SECOND
5306     });
5307    
5308     runScript({
5309     .code = R"NKSP_CODE(
5310     on init
5311     exit(4.0 * (2.0mdB + 3.2mdB) / 2.0)
5312     end on
5313     )NKSP_CODE",
5314     .expectRealExitResult = 10.4,
5315     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5316     .expectExitResultUnit = VM_BEL
5317     });
5318    
5319     runScript({
5320     .code = R"NKSP_CODE(
5321     on init
5322     declare ~a := 2.0mdB
5323     declare ~b := 3.2mdB
5324     exit(4.0 * (~a + ~b) / 2.0)
5325     end on
5326     )NKSP_CODE",
5327     .expectRealExitResult = 10.4,
5328     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5329     .expectExitResultUnit = VM_BEL
5330     });
5331    
5332     runScript({
5333     .code = R"NKSP_CODE(
5334     on init
5335     declare ~b := 3.2mdB
5336     declare ~a := 2.0mdB
5337     exit(4.0 * (~a + ~b) / 2.0)
5338     end on
5339     )NKSP_CODE",
5340     .expectRealExitResult = 10.4,
5341     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5342     .expectExitResultUnit = VM_BEL
5343     });
5344    
5345     runScript({
5346     .code = R"NKSP_CODE(
5347     on init
5348     declare ~a := 4.0
5349     declare ~b := 2.0mdB
5350     declare ~c := 3.2mdB
5351     declare ~d := 2.0
5352     exit((~a * (~b + ~c) / ~d) + 1.1mdB)
5353     end on
5354     )NKSP_CODE",
5355     .expectRealExitResult = 11.5,
5356     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5357     .expectExitResultUnit = VM_BEL
5358     });
5359    
5360     runScript({
5361     .code = R"NKSP_CODE(
5362     on init
5363     declare ~c := 3.2mdB
5364     declare ~a := 4.0
5365     declare ~d := 2.0
5366     declare ~b := 2.0mdB
5367     exit(~a * (~b + ~c) / ~d + 1.1mdB)
5368     end on
5369     )NKSP_CODE",
5370     .expectRealExitResult = 11.5,
5371     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5372     .expectExitResultUnit = VM_BEL
5373     });
5374    
5375     // 'final' ('!') operator tests ...
5376    
5377     runScript({
5378     .code = R"NKSP_CODE(
5379     on init
5380     declare $a := 4
5381     declare $b := !2us
5382     declare $c := 3us
5383     declare $d := 7ms
5384     exit($a * ($b + $c) + 7ms)
5385     end on
5386     )NKSP_CODE",
5387     .expectIntExitResult = 7020,
5388     .expectExitResultUnitPrefix = { VM_MICRO },
5389     .expectExitResultUnit = VM_SECOND,
5390     .expectExitResultFinal = true,
5391     .expectParseWarning = true // only one operand is defined as 'final', result will be final though
5392     });
5393    
5394     runScript({
5395     .code = R"NKSP_CODE(
5396     on init
5397     declare $a := 4
5398     declare $b := 2us
5399     declare $c := !3us
5400     declare $d := 7ms
5401     exit($a * ($b + $c) + 7ms)
5402     end on
5403     )NKSP_CODE",
5404     .expectIntExitResult = 7020,
5405     .expectExitResultUnitPrefix = { VM_MICRO },
5406     .expectExitResultUnit = VM_SECOND,
5407     .expectExitResultFinal = true,
5408     .expectParseWarning = true // only one operand is defined as 'final', result will be final though
5409     });
5410    
5411 schoenebeck 3551 #if !SILENT_TEST
5412     std::cout << std::endl;
5413     #endif
5414     }
5415    
5416 schoenebeck 3727 static void testIntVarDeclaration() {
5417     #if !SILENT_TEST
5418     std::cout << "UNIT TEST: int var declaration\n";
5419     #endif
5420    
5421     runScript({
5422     .code = R"NKSP_CODE(
5423     on init
5424     declare $a
5425     exit($a)
5426     end on
5427     )NKSP_CODE",
5428     .expectIntExitResult = 0
5429     });
5430    
5431     runScript({
5432     .code = R"NKSP_CODE(
5433     on init
5434     declare $a := 24
5435     exit($a)
5436     end on
5437     )NKSP_CODE",
5438     .expectIntExitResult = 24
5439     });
5440    
5441     runScript({
5442     .code = R"NKSP_CODE(
5443     on init
5444     declare $a := 24
5445     $a := 8
5446     exit($a)
5447     end on
5448     )NKSP_CODE",
5449     .expectIntExitResult = 8
5450     });
5451    
5452     runScript({
5453     .code = R"NKSP_CODE(
5454     on init
5455     declare $a
5456     declare $a
5457     end on
5458     )NKSP_CODE",
5459     .expectParseError = true // variable re-declaration
5460     });
5461    
5462     runScript({
5463     .code = R"NKSP_CODE(
5464     on init
5465     declare const $a
5466     end on
5467     )NKSP_CODE",
5468     .expectParseError = true // const variable declaration without assignment
5469     });
5470    
5471     runScript({
5472     .code = R"NKSP_CODE(
5473     on init
5474     declare const $a := 24
5475     exit($a)
5476     end on
5477     )NKSP_CODE",
5478     .expectIntExitResult = 24
5479     });
5480    
5481     runScript({
5482     .code = R"NKSP_CODE(
5483     on init
5484     declare const $a := 24
5485     $a := 8
5486     end on
5487     )NKSP_CODE",
5488     .expectParseError = true // attempt to modify const variable
5489     });
5490    
5491     runScript({
5492     .code = R"NKSP_CODE(
5493     on init
5494     declare const $a := 24
5495     declare const $b := $a
5496     exit($b)
5497     end on
5498     )NKSP_CODE",
5499     .expectIntExitResult = 24
5500     });
5501    
5502     runScript({
5503     .code = R"NKSP_CODE(
5504     on init
5505     declare $a := 24
5506     declare const $b := $a
5507     end on
5508     )NKSP_CODE",
5509     .expectParseError = true // const variable defined with non-const assignment
5510     });
5511    
5512     runScript({
5513     .code = R"NKSP_CODE(
5514     on init
5515     declare polyphonic $a
5516     exit($a)
5517     end on
5518     )NKSP_CODE",
5519     .expectIntExitResult = 0
5520     });
5521    
5522     runScript({
5523     .code = R"NKSP_CODE(
5524     on init
5525     declare const polyphonic $a
5526     end on
5527     )NKSP_CODE",
5528     .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
5529     });
5530    
5531     runScript({
5532     .code = R"NKSP_CODE(
5533     on init
5534     declare polyphonic const $a
5535     end on
5536     )NKSP_CODE",
5537     .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
5538     });
5539    
5540     runScript({
5541     .code = R"NKSP_CODE(
5542     on init
5543     declare const polyphonic $a := 3
5544     end on
5545     )NKSP_CODE",
5546     .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
5547     });
5548    
5549     runScript({
5550     .code = R"NKSP_CODE(
5551     on init
5552     declare polyphonic const $a := 3
5553     end on
5554     )NKSP_CODE",
5555     .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
5556     });
5557    
5558     runScript({
5559     .code = R"NKSP_CODE(
5560     on init
5561     declare ~a := 24
5562     exit(~a)
5563     end on
5564     )NKSP_CODE",
5565     .expectParseWarning = true, // real type declaration vs. int value assignment
5566     .expectIntExitResult = 24
5567     });
5568    
5569     runScript({
5570     .code = R"NKSP_CODE(
5571     on init
5572     declare %a := 24
5573     exit(%a)
5574     end on
5575     )NKSP_CODE",
5576     .expectParseWarning = true, // int array type declaration vs. int scalar value assignment
5577     .expectIntExitResult = 24
5578     });
5579    
5580     runScript({
5581     .code = R"NKSP_CODE(
5582     on init
5583     declare const %a := 24
5584     exit(%a)
5585     end on
5586     )NKSP_CODE",
5587     .expectParseWarning = true, // int array type declaration vs. int scalar value assignment
5588     .expectIntExitResult = 24
5589     });
5590    
5591     runScript({
5592     .code = R"NKSP_CODE(
5593     on init
5594     declare ?a := 24
5595     exit(?a)
5596     end on
5597     )NKSP_CODE",
5598     .expectParseWarning = true, // real array type declaration vs. int scalar value assignment
5599     .expectIntExitResult = 24
5600     });
5601    
5602     runScript({
5603     .code = R"NKSP_CODE(
5604     on init
5605     declare const ?a := 24
5606     exit(?a)
5607     end on
5608     )NKSP_CODE",
5609     .expectParseWarning = true, // real array type declaration vs. int scalar value assignment
5610     .expectIntExitResult = 24
5611     });
5612    
5613     runScript({
5614     .code = R"NKSP_CODE(
5615     on init
5616     declare @a := 24
5617     exit(@a)
5618     end on
5619     )NKSP_CODE",
5620     .expectParseWarning = true, // string type declaration vs. int scalar value assignment
5621     .expectIntExitResult = 24
5622     });
5623    
5624     runScript({
5625     .code = R"NKSP_CODE(
5626     on init
5627     declare const @a := 24
5628     exit(@a)
5629     end on
5630     )NKSP_CODE",
5631     .expectParseWarning = true, // string type declaration vs. int scalar value assignment
5632     .expectIntExitResult = 24
5633     });
5634    
5635     runScript({
5636     .code = R"NKSP_CODE(
5637     on init
5638     declare $a := ( 0, 1, 2 )
5639     end on
5640     )NKSP_CODE",
5641     .expectParseError = true // int scalar type declaration vs. int array value assignment
5642     });
5643    
5644     runScript({
5645     .code = R"NKSP_CODE(
5646     on init
5647     declare const $a := ( 0, 1, 2 )
5648     end on
5649     )NKSP_CODE",
5650     .expectParseError = true // int scalar type declaration vs. int array value assignment
5651     });
5652    
5653     runScript({
5654     .code = R"NKSP_CODE(
5655     on init
5656     declare a
5657     end on
5658     )NKSP_CODE",
5659     .expectParseError = true // missing type prefix character in variable name
5660     });
5661    
5662     runScript({
5663     .code = R"NKSP_CODE(
5664     on init
5665     declare a := 24
5666     end on
5667     )NKSP_CODE",
5668     .expectParseError = true // missing type prefix character in variable name
5669     });
5670    
5671     runScript({
5672     .code = R"NKSP_CODE(
5673     on init
5674     declare const a := 24
5675     end on
5676     )NKSP_CODE",
5677     .expectParseError = true // missing type prefix character in variable name
5678     });
5679    
5680     runScript({
5681     .code = R"NKSP_CODE(
5682     on init
5683     declare polyphonic a
5684     end on
5685     )NKSP_CODE",
5686     .expectParseError = true // missing type prefix character in variable name
5687     });
5688    
5689     runScript({
5690     .code = R"NKSP_CODE(
5691     on init
5692     declare $a := max(8,24)
5693     exit($a)
5694     end on
5695     )NKSP_CODE",
5696     .expectIntExitResult = 24
5697     });
5698    
5699     runScript({
5700     .code = R"NKSP_CODE(
5701     on init
5702     declare $a := abort($NI_CALLBACK_ID)
5703     end on
5704     )NKSP_CODE",
5705     .expectParseError = true // assigned expression does not result in a value
5706     });
5707    
5708     runScript({
5709     .code = R"NKSP_CODE(
5710     on init
5711     declare const $a := abort($NI_CALLBACK_ID)
5712     end on
5713     )NKSP_CODE",
5714     .expectParseError = true // assigned expression does not result in a value
5715     });
5716    
5717     #if !SILENT_TEST
5718     std::cout << std::endl;
5719     #endif
5720     }
5721    
5722     static void testIntArrayVarDeclaration() {
5723     #if !SILENT_TEST
5724     std::cout << "UNIT TEST: int array var declaration\n";
5725     #endif
5726    
5727     runScript({
5728     .code = R"NKSP_CODE(
5729     on init
5730     declare %a[3]
5731     exit( %a[0] + %a[1] + %a[2] )
5732     end on
5733     )NKSP_CODE",
5734     .expectIntExitResult = 0
5735     });
5736    
5737     runScript({
5738     .code = R"NKSP_CODE(
5739     on init
5740     declare %a[0]
5741     end on
5742     )NKSP_CODE",
5743     .expectParseError = true // illegal array size
5744     });
5745    
5746     runScript({
5747     .code = R"NKSP_CODE(
5748     on init
5749     declare %a[-1]
5750     end on
5751     )NKSP_CODE",
5752     .expectParseError = true // illegal array size
5753     });
5754    
5755     runScript({
5756     .code = R"NKSP_CODE(
5757     on init
5758     declare %a[3] := ( 1, 2, 3 )
5759     exit( %a[0] + %a[1] + %a[2] )
5760     end on
5761     )NKSP_CODE",
5762     .expectIntExitResult = (1 + 2 + 3)
5763     });
5764    
5765     runScript({
5766     .code = R"NKSP_CODE(
5767     on init
5768     declare const $sz := 3
5769     declare %a[$sz] := ( 1, 2, 3 )
5770     exit( %a[0] + %a[1] + %a[2] )
5771     end on
5772     )NKSP_CODE",
5773     .expectIntExitResult = (1 + 2 + 3)
5774     });
5775    
5776     runScript({
5777     .code = R"NKSP_CODE(
5778     on init
5779     declare const $sz := 3
5780     declare const %a[$sz] := ( 1, 2, 3 )
5781     exit( %a[0] + %a[1] + %a[2] )
5782     end on
5783     )NKSP_CODE",
5784     .expectIntExitResult = (1 + 2 + 3)
5785     });
5786    
5787     runScript({
5788     .code = R"NKSP_CODE(
5789     on init
5790     declare $sz := 3
5791     declare %a[$sz] := ( 1, 2, 3 )
5792     end on
5793     )NKSP_CODE",
5794     .expectParseError = true // array size must be constant expression
5795     });
5796    
5797     runScript({
5798     .code = R"NKSP_CODE(
5799     on init
5800     declare $sz := 3
5801     declare const %a[$sz] := ( 1, 2, 3 )
5802     end on
5803     )NKSP_CODE",
5804     .expectParseError = true // array size must be constant expression
5805     });
5806    
5807     runScript({
5808     .code = R"NKSP_CODE(
5809     on init
5810     declare const ~sz := 3.0
5811     declare const %a[~sz] := ( 1, 2, 3 )
5812     end on
5813     )NKSP_CODE",
5814     .expectParseError = true // array size must be integer type
5815     });
5816    
5817     runScript({
5818     .code = R"NKSP_CODE(
5819     on init
5820     declare %a[3s] := ( 1, 2, 3 )
5821     end on
5822     )NKSP_CODE",
5823     .expectParseError = true // units not allowed for array size
5824     });
5825    
5826     runScript({
5827     .code = R"NKSP_CODE(
5828     on init
5829     declare %a[3m] := ( 1, 2, 3 )
5830     end on
5831     )NKSP_CODE",
5832     .expectParseError = true // units not allowed for array size
5833     });
5834    
5835     runScript({
5836     .code = R"NKSP_CODE(
5837     on init
5838     declare const %a[!3] := ( 1, 2, 3 )
5839     exit( %a[0] + %a[1] + %a[2] )
5840     end on
5841     )NKSP_CODE",
5842     .expectIntExitResult = (1 + 2 + 3),
5843     .expectParseWarning = true // 'final' operator is meaningless for array size
5844     });
5845    
5846     runScript({
5847     .code = R"NKSP_CODE(
5848     on init
5849     declare %a[3] := ( 1, 2, 3 )
5850     %a[0] := 4
5851     %a[1] := 5
5852     %a[2] := 6
5853     exit( %a[0] + %a[1] + %a[2] )
5854     end on
5855     )NKSP_CODE",
5856     .expectIntExitResult = (4 + 5 + 6)
5857     });
5858    
5859     runScript({
5860     .code = R"NKSP_CODE(
5861     on init
5862     declare %a[3]
5863     declare %a[3]
5864     end on
5865     )NKSP_CODE",
5866     .expectParseError = true // variable re-declaration
5867     });
5868    
5869     runScript({
5870     .code = R"NKSP_CODE(
5871     on init
5872     declare const %a[3]
5873     end on
5874     )NKSP_CODE",
5875     .expectParseError = true // const variable declaration without assignment
5876     });
5877    
5878     runScript({
5879     .code = R"NKSP_CODE(
5880     on init
5881     declare const %a[3] := ( 1, 2, 3 )
5882     exit( %a[0] + %a[1] + %a[2] )
5883     end on
5884     )NKSP_CODE",
5885     .expectIntExitResult = (1 + 2 + 3)
5886     });
5887    
5888     runScript({
5889     .code = R"NKSP_CODE(
5890     on init
5891     declare const %a[3] := ( 1, 2, 3, 4 )
5892     end on
5893     )NKSP_CODE",
5894     .expectParseError = true // incompatible array sizes
5895     });
5896    
5897     runScript({
5898     .code = R"NKSP_CODE(
5899     on init
5900     declare const %a[3] := ( 1, 2, 3 )
5901     %a[0] := 8
5902     end on
5903     )NKSP_CODE",
5904     .expectParseError = true // attempt to modify const variable
5905     });
5906    
5907     runScript({
5908     .code = R"NKSP_CODE(
5909     on init
5910     declare const %a[3] := ( 1, 2, 3 )
5911     declare const %b[3] := ( %a[0], %a[1], %a[2] )
5912     exit( %b[0] + %b[1] + %b[2] )
5913     end on
5914     )NKSP_CODE",
5915     .expectIntExitResult = (1 + 2 + 3)
5916     });
5917    
5918     runScript({
5919     .code = R"NKSP_CODE(
5920     on init
5921     declare %a[3] := ( 1, 2, 3 )
5922     declare const %b[3] := ( %a[0], %a[1], %a[2] )
5923     end on
5924     )NKSP_CODE",
5925     .expectParseError = true // const array defined with non-const assignment
5926     });
5927    
5928     runScript({
5929     .code = R"NKSP_CODE(
5930     on init
5931     declare polyphonic %a[3]
5932     end on
5933     )NKSP_CODE",
5934     .expectParseError = true // polyphonic not allowed for array types
5935     });
5936    
5937     runScript({
5938     .code = R"NKSP_CODE(
5939     on init
5940     declare polyphonic %a[3] := ( 1, 2, 3 )
5941     end on
5942     )NKSP_CODE",
5943     .expectParseError = true // polyphonic not allowed for array types
5944     });
5945    
5946     runScript({
5947     .code = R"NKSP_CODE(
5948     on init
5949     declare const polyphonic %a[3]
5950     end on
5951     )NKSP_CODE",
5952     .expectParseError = true // polyphonic not allowed for array types
5953     });
5954    
5955     runScript({
5956     .code = R"NKSP_CODE(
5957     on init
5958     declare const polyphonic %a[3] := ( 1, 2, 3 )
5959     end on
5960     )NKSP_CODE",
5961     .expectParseError = true // polyphonic not allowed for array types
5962     });
5963    
5964     runScript({
5965     .code = R"NKSP_CODE(
5966     on init
5967     declare polyphonic const %a[3]
5968     end on
5969     )NKSP_CODE",
5970     .expectParseError = true // polyphonic not allowed for array types
5971     });
5972    
5973     runScript({
5974     .code = R"NKSP_CODE(
5975     on init
5976     declare polyphonic const %a[3] := ( 1, 2, 3 )
5977     end on
5978     )NKSP_CODE",
5979     .expectParseError = true // polyphonic not allowed for array types
5980     });
5981    
5982     runScript({
5983     .code = R"NKSP_CODE(
5984     on init
5985     declare %a[3] := ( 1, max(8,24), 3 )
5986     exit( %a[0] + %a[1] + %a[2] )
5987     end on
5988     )NKSP_CODE",
5989     .expectIntExitResult = ( 1 + 24 + 3 )
5990     });
5991    
5992     runScript({
5993     .code = R"NKSP_CODE(
5994     on init
5995     declare %a[3] := ( 1, abort($NI_CALLBACK_ID), 3 )
5996     end on
5997     )NKSP_CODE",
5998     .expectParseError = true // assigned expression does not result in a value
5999     });
6000    
6001     runScript({
6002     .code = R"NKSP_CODE(
6003     on init
6004     declare const %a[3] := ( 1, abort($NI_CALLBACK_ID), 3 )
6005     end on
6006     )NKSP_CODE",
6007     .expectParseError = true // assigned expression does not result in a value
6008     });
6009    
6010     runScript({
6011     .code = R"NKSP_CODE(
6012     on init
6013     declare %a[3] := ( 1.0, 2.0, 3.0 )
6014     end on
6015     )NKSP_CODE",
6016     .expectParseError = true // int array declaration vs. real array assignment
6017     });
6018    
6019     runScript({
6020     .code = R"NKSP_CODE(
6021     on init
6022     declare %a[3] := ( 1, 2, 3.0 )
6023     end on
6024     )NKSP_CODE",
6025     .expectParseError = true // 3rd element not an integer
6026     });
6027    
6028     runScript({
6029     .code = R"NKSP_CODE(
6030     on init
6031     declare %a[3] := ( "x", "y", "z" )
6032     end on
6033     )NKSP_CODE",
6034     .expectParseError = true // int array declaration vs. string array assignment
6035     });
6036    
6037     runScript({
6038     .code = R"NKSP_CODE(
6039     on init
6040     declare a[3] := ( 1, 2, 3 )
6041     end on
6042     )NKSP_CODE",
6043     .expectParseError = true // missing type prefix character in variable name
6044     });
6045    
6046     runScript({
6047     .code = R"NKSP_CODE(
6048     on init
6049     declare a[3]
6050     end on
6051     )NKSP_CODE",
6052     .expectParseError = true // missing type prefix character in variable name
6053     });
6054    
6055     runScript({
6056     .code = R"NKSP_CODE(
6057     on init
6058     declare const %a[3] := ( 1, 2s, 3 )
6059     end on
6060     )NKSP_CODE",
6061     .expectParseError = true // unit types not allowed for arrays
6062     });
6063    
6064     runScript({
6065     .code = R"NKSP_CODE(
6066     on init
6067     declare const %a[3] := ( 1, !2, 3 )
6068     end on
6069     )NKSP_CODE",
6070     .expectParseError = true // 'final' not allowed for arrays
6071     });
6072    
6073     #if !SILENT_TEST
6074     std::cout << std::endl;
6075     #endif
6076     }
6077    
6078     static void testRealVarDeclaration() {
6079     #if !SILENT_TEST
6080     std::cout << "UNIT TEST: real var declaration\n";
6081     #endif
6082    
6083     runScript({
6084     .code = R"NKSP_CODE(
6085     on init
6086     declare ~a
6087     exit(~a)
6088     end on
6089     )NKSP_CODE",
6090     .expectRealExitResult = 0.0
6091     });
6092    
6093     runScript({
6094     .code = R"NKSP_CODE(
6095     on init
6096     declare ~a := 24.8
6097     exit(~a)
6098     end on
6099     )NKSP_CODE",
6100     .expectRealExitResult = 24.8
6101     });
6102    
6103     runScript({
6104     .code = R"NKSP_CODE(
6105     on init
6106     declare ~a := 8.24
6107     ~a := 24.8
6108     exit(~a)
6109     end on
6110     )NKSP_CODE",
6111     .expectRealExitResult = 24.8
6112     });
6113    
6114     runScript({
6115     .code = R"NKSP_CODE(
6116     on init
6117     declare ~a
6118     declare ~a
6119     end on
6120     )NKSP_CODE",
6121     .expectParseError = true // variable re-declaration
6122     });
6123    
6124     runScript({
6125     .code = R"NKSP_CODE(
6126     on init
6127     declare const ~a
6128     end on
6129     )NKSP_CODE",
6130     .expectParseError = true // const variable declaration without assignment
6131     });
6132    
6133     runScript({
6134     .code = R"NKSP_CODE(
6135     on init
6136     declare const ~a := 8.24
6137     exit(~a)
6138     end on
6139     )NKSP_CODE",
6140     .expectRealExitResult = 8.24
6141     });
6142    
6143     runScript({
6144     .code = R"NKSP_CODE(
6145     on init
6146     declare const ~a := 28.0
6147     ~a := 8.0
6148     end on
6149     )NKSP_CODE",
6150     .expectParseError = true // attempt to modify const variable
6151     });
6152    
6153     runScript({
6154     .code = R"NKSP_CODE(
6155     on init
6156     declare const ~a := 24.8
6157     declare const ~b := ~a
6158     exit(~b)
6159     end on
6160     )NKSP_CODE",
6161     .expectRealExitResult = 24.8
6162     });
6163    
6164     runScript({
6165     .code = R"NKSP_CODE(
6166     on init
6167     declare ~a := 24.0
6168     declare const ~b := ~a
6169     end on
6170     )NKSP_CODE",
6171     .expectParseError = true // const variable defined with non-const assignment
6172     });
6173    
6174     runScript({
6175     .code = R"NKSP_CODE(
6176     on init
6177     declare polyphonic ~a
6178     exit(~a)
6179     end on
6180     )NKSP_CODE",
6181     .expectRealExitResult = 0.0
6182     });
6183    
6184     runScript({
6185     .code = R"NKSP_CODE(
6186     on init
6187     declare const polyphonic ~a
6188     end on
6189     )NKSP_CODE",
6190     .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
6191     });
6192    
6193     runScript({
6194     .code = R"NKSP_CODE(
6195     on init
6196     declare polyphonic const ~a
6197     end on
6198     )NKSP_CODE",
6199     .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
6200     });
6201    
6202     runScript({
6203     .code = R"NKSP_CODE(
6204     on init
6205     declare const polyphonic ~a := 3.0
6206     end on
6207     )NKSP_CODE",
6208     .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
6209     });
6210    
6211     runScript({
6212     .code = R"NKSP_CODE(
6213     on init
6214     declare polyphonic const ~a := 3.0
6215     end on
6216     )NKSP_CODE",
6217     .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
6218     });
6219    
6220     runScript({
6221     .code = R"NKSP_CODE(
6222     on init
6223     declare $a := 24.8
6224     exit($a)
6225     end on
6226     )NKSP_CODE",
6227     .expectParseWarning = true, // int type declaration vs. real value assignment
6228     .expectRealExitResult = 24.8
6229     });
6230    
6231     runScript({
6232     .code = R"NKSP_CODE(
6233     on init
6234     declare %a := 24.8
6235     exit(%a)
6236     end on
6237     )NKSP_CODE",
6238     .expectParseWarning = true, // int array type declaration vs. real scalar value assignment
6239     .expectRealExitResult = 24.8
6240     });
6241    
6242     runScript({
6243     .code = R"NKSP_CODE(
6244     on init
6245     declare const %a := 24.8
6246     exit(%a)
6247     end on
6248     )NKSP_CODE",
6249     .expectParseWarning = true, // int array type declaration vs. real scalar value assignment
6250     .expectRealExitResult = 24.8
6251     });
6252    
6253     runScript({
6254     .code = R"NKSP_CODE(
6255     on init
6256     declare ?a := 24.8
6257     exit(?a)
6258     end on
6259     )NKSP_CODE",
6260     .expectParseWarning = true, // real array type declaration vs. real scalar value assignment
6261     .expectRealExitResult = 24.8
6262     });
6263    
6264     runScript({
6265     .code = R"NKSP_CODE(
6266     on init
6267     declare const ?a := 24.8
6268     exit(?a)
6269     end on
6270     )NKSP_CODE",
6271     .expectParseWarning = true, // real array type declaration vs. real scalar value assignment
6272     .expectRealExitResult = 24.8
6273     });
6274    
6275     runScript({
6276     .code = R"NKSP_CODE(
6277     on init
6278     declare @a := 24.8
6279     exit(@a)
6280     end on
6281     )NKSP_CODE",
6282     .expectParseWarning = true, // string type declaration vs. real scalar value assignment
6283     .expectRealExitResult = 24.8
6284     });
6285    
6286     runScript({
6287     .code = R"NKSP_CODE(
6288     on init
6289     declare const @a := 24.8
6290     exit(@a)
6291     end on
6292     )NKSP_CODE",
6293     .expectParseWarning = true, // string type declaration vs. real scalar value assignment
6294     .expectRealExitResult = 24.8
6295     });
6296    
6297     runScript({
6298     .code = R"NKSP_CODE(
6299     on init
6300     declare ~a := ( 0, 1, 2 )
6301     end on
6302     )NKSP_CODE",
6303     .expectParseError = true // real scalar type declaration vs. int array value assignment
6304     });
6305    
6306     runScript({
6307     .code = R"NKSP_CODE(
6308     on init
6309     declare const ~a := ( 0, 1, 2 )
6310     end on
6311     )NKSP_CODE",
6312     .expectParseError = true // real scalar type declaration vs. int array value assignment
6313     });
6314    
6315     runScript({
6316     .code = R"NKSP_CODE(
6317     on init
6318     declare a := 24.8
6319     end on
6320     )NKSP_CODE",
6321     .expectParseError = true // missing type prefix character in variable name
6322     });
6323    
6324     runScript({
6325     .code = R"NKSP_CODE(
6326     on init
6327     declare const a := 24.8
6328     end on
6329     )NKSP_CODE",
6330     .expectParseError = true // missing type prefix character in variable name
6331     });
6332    
6333     runScript({
6334     .code = R"NKSP_CODE(
6335     on init
6336     declare ~a := max(8.1,24.2)
6337     exit(~a)
6338     end on
6339     )NKSP_CODE",
6340     .expectRealExitResult = 24.2
6341     });
6342    
6343     runScript({
6344     .code = R"NKSP_CODE(
6345     on init
6346     declare ~a := abort($NI_CALLBACK_ID)
6347     end on
6348     )NKSP_CODE",
6349     .expectParseError = true // assigned expression does not result in a value
6350     });
6351    
6352     runScript({
6353     .code = R"NKSP_CODE(
6354     on init
6355     declare const ~a := abort($NI_CALLBACK_ID)
6356     end on
6357     )NKSP_CODE",
6358     .expectParseError = true // assigned expression does not result in a value
6359     });
6360    
6361     #if !SILENT_TEST
6362     std::cout << std::endl;
6363     #endif
6364     }
6365    
6366     static void testRealArrayVarDeclaration() {
6367     #if !SILENT_TEST
6368     std::cout << "UNIT TEST: real array var declaration\n";
6369     #endif
6370    
6371     runScript({
6372     .code = R"NKSP_CODE(
6373     on init
6374     declare ?a[3]
6375     exit( ?a[0] + ?a[1] + ?a[2] )
6376     end on
6377     )NKSP_CODE",
6378     .expectRealExitResult = 0.0
6379     });
6380    
6381     runScript({
6382     .code = R"NKSP_CODE(
6383     on init
6384     declare ?a[0]
6385     end on
6386     )NKSP_CODE",
6387     .expectParseError = true // illegal array size
6388     });
6389    
6390     runScript({
6391     .code = R"NKSP_CODE(
6392     on init
6393     declare ?a[-1]
6394     end on
6395     )NKSP_CODE",
6396     .expectParseError = true // illegal array size
6397     });
6398    
6399     runScript({
6400     .code = R"NKSP_CODE(
6401     on init
6402     declare ?a[3] := ( 1.1, 2.2, 3.3 )
6403     exit( ?a[0] + ?a[1] + ?a[2] )
6404     end on
6405     )NKSP_CODE",
6406     .expectRealExitResult = (1.1 + 2.2 + 3.3)
6407     });
6408    
6409     runScript({
6410     .code = R"NKSP_CODE(
6411     on init
6412     declare const $sz := 3
6413     declare ?a[$sz] := ( 1.1, 2.2, 3.3 )
6414     exit( ?a[0] + ?a[1] + ?a[2] )
6415     end on
6416     )NKSP_CODE",
6417     .expectRealExitResult = (1.1 + 2.2 + 3.3)
6418     });
6419    
6420     runScript({
6421     .code = R"NKSP_CODE(
6422     on init
6423     declare const $sz := 3
6424     declare const ?a[$sz] := ( 1.1, 2.2, 3.3 )
6425     exit( ?a[0] + ?a[1] + ?a[2] )
6426     end on
6427     )NKSP_CODE",
6428     .expectRealExitResult = (1.1 + 2.2 + 3.3)
6429     });
6430    
6431     runScript({
6432     .code = R"NKSP_CODE(
6433     on init
6434     declare $sz := 3
6435     declare ?a[$sz] := ( 1.1, 2.2, 3.3 )
6436     end on
6437     )NKSP_CODE",
6438     .expectParseError = true // array size must be constant expression
6439     });
6440    
6441     runScript({
6442     .code = R"NKSP_CODE(
6443     on init
6444     declare $sz := 3
6445     declare const ?a[$sz] := ( 1.1, 2.2, 3.3 )
6446     end on
6447     )NKSP_CODE",
6448     .expectParseError = true // array size must be constant expression
6449     });
6450    
6451     runScript({
6452     .code = R"NKSP_CODE(
6453     on init
6454     declare const ~sz := 3.0
6455     declare const ?a[~sz] := ( 1.1, 2.2, 3.3 )
6456     end on
6457     )NKSP_CODE",
6458     .expectParseError = true // array size must be integer type
6459     });
6460    
6461     runScript({
6462     .code = R"NKSP_CODE(
6463     on init
6464     declare ?a[3s] := ( 1.1, 2.2, 3.3 )
6465     end on
6466     )NKSP_CODE",
6467     .expectParseError = true // units not allowed for array size
6468     });
6469    
6470     runScript({
6471     .code = R"NKSP_CODE(
6472     on init
6473     declare ?a[3m] := ( 1.1, 2.2, 3.3 )
6474     end on
6475     )NKSP_CODE",
6476     .expectParseError = true // units not allowed for array size
6477     });
6478    
6479     runScript({
6480     .code = R"NKSP_CODE(
6481     on init
6482     declare const ?a[!3] := ( 1.1, 2.2, 3.3 )
6483     exit( ?a[0] + ?a[1] + ?a[2] )
6484     end on
6485     )NKSP_CODE",
6486     .expectRealExitResult = (1.1 + 2.2 + 3.3),
6487     .expectParseWarning = true // 'final' operator is meaningless for array size
6488     });
6489    
6490     runScript({
6491     .code = R"NKSP_CODE(
6492     on init
6493     declare ?a[3] := ( 1.0, 2.0, 3.0 )
6494     ?a[0] := 4.5
6495     ?a[1] := 5.5
6496     ?a[2] := 6.5
6497     exit( ?a[0] + ?a[1] + ?a[2] )
6498     end on
6499     )NKSP_CODE",
6500     .expectRealExitResult = (4.5 + 5.5 + 6.5)
6501     });
6502    
6503     runScript({
6504     .code = R"NKSP_CODE(
6505     on init
6506     declare ?a[3]
6507     declare ?a[3]
6508     end on
6509     )NKSP_CODE",
6510     .expectParseError = true // variable re-declaration
6511     });
6512    
6513     runScript({
6514     .code = R"NKSP_CODE(
6515     on init
6516     declare const ?a[3]
6517     end on
6518     )NKSP_CODE",
6519     .expectParseError = true // const variable declaration without assignment
6520     });
6521    
6522     runScript({
6523     .code = R"NKSP_CODE(
6524     on init
6525     declare const ?a[3] := ( 1.1, 2.2, 3.3 )
6526     exit( ?a[0] + ?a[1] + ?a[2] )
6527     end on
6528     )NKSP_CODE",
6529     .expectRealExitResult = (1.1 + 2.2 + 3.3)
6530     });
6531    
6532     runScript({
6533     .code = R"NKSP_CODE(
6534     on init
6535     declare const ?a[3] := ( 1.1, 2.2, 3.3, 4.4 )
6536     end on
6537     )NKSP_CODE",
6538     .expectParseError = true // incompatible array sizes
6539     });
6540    
6541     runScript({
6542     .code = R"NKSP_CODE(
6543     on init
6544     declare const ?a[3] := ( 1.0, 2.0, 3.0 )
6545     ?a[0] := 8.0
6546     end on
6547     )NKSP_CODE",
6548     .expectParseError = true // attempt to modify const variable
6549     });
6550    
6551     runScript({
6552     .code = R"NKSP_CODE(
6553     on init
6554     declare const ?a[3] := ( 1.1, 2.2, 3.3 )
6555     declare const ?b[3] := ( ?a[0], ?a[1], ?a[2] )
6556     exit( ?b[0] + ?b[1] + ?b[2] )
6557     end on
6558     )NKSP_CODE",
6559     .expectRealExitResult = (1.1 + 2.2 + 3.3)
6560     });
6561    
6562     runScript({
6563     .code = R"NKSP_CODE(
6564     on init
6565     declare ?a[3] := ( 1.1, 2.2, 3.3 )
6566     declare const ?b[3] := ( ?a[0], ?a[1], ?a[2] )
6567     end on
6568     )NKSP_CODE",
6569     .expectParseError = true // const array defined with non-const assignment
6570     });
6571    
6572     runScript({
6573     .code = R"NKSP_CODE(
6574     on init
6575     declare polyphonic ?a[3]
6576     end on
6577     )NKSP_CODE",
6578     .expectParseError = true // polyphonic not allowed for array types
6579     });
6580    
6581     runScript({
6582     .code = R"NKSP_CODE(
6583     on init
6584     declare polyphonic ?a[3] := ( 1.0, 2.0, 3.0 )
6585     end on
6586     )NKSP_CODE",
6587     .expectParseError = true // polyphonic not allowed for array types
6588     });
6589    
6590     runScript({
6591     .code = R"NKSP_CODE(
6592     on init
6593     declare const polyphonic ?a[3]
6594     end on
6595     )NKSP_CODE",
6596     .expectParseError = true // polyphonic not allowed for array types
6597     });
6598    
6599     runScript({
6600     .code = R"NKSP_CODE(
6601     on init
6602     declare const polyphonic ?a[3] := ( 1.0, 2.0, 3.0 )
6603     end on
6604     )NKSP_CODE",
6605     .expectParseError = true // polyphonic not allowed for array types
6606     });
6607    
6608     runScript({
6609     .code = R"NKSP_CODE(
6610     on init
6611     declare polyphonic const ?a[3]
6612     end on
6613     )NKSP_CODE",
6614     .expectParseError = true // polyphonic not allowed for array types
6615     });
6616    
6617     runScript({
6618     .code = R"NKSP_CODE(
6619     on init
6620     declare polyphonic const ?a[3] := ( 1.0, 2.0, 3.0 )
6621     end on
6622     )NKSP_CODE",
6623     .expectParseError = true // polyphonic not allowed for array types
6624     });
6625    
6626     runScript({
6627     .code = R"NKSP_CODE(
6628     on init
6629     declare ?a[3] := ( 1.0, max(8.3,24.6), 3.0 )
6630     exit( ?a[0] + ?a[1] + ?a[2] )
6631     end on
6632     )NKSP_CODE",
6633     .expectRealExitResult = ( 1.0 + 24.6 + 3.0 )
6634     });
6635    
6636     runScript({
6637     .code = R"NKSP_CODE(
6638     on init
6639     declare ?a[3] := ( 1.0, abort($NI_CALLBACK_ID), 3.0 )
6640     end on
6641     )NKSP_CODE",
6642     .expectParseError = true // assigned expression does not result in a value
6643     });
6644    
6645     runScript({
6646     .code = R"NKSP_CODE(
6647     on init
6648     declare const ?a[3] := ( 1.0, abort($NI_CALLBACK_ID), 3.0 )
6649     end on
6650     )NKSP_CODE",
6651     .expectParseError = true // assigned expression does not result in a value
6652     });
6653    
6654     runScript({
6655     .code = R"NKSP_CODE(
6656     on init
6657     declare ?a[3] := ( 1, 2, 3 )
6658     end on
6659     )NKSP_CODE",
6660     .expectParseError = true // real array declaration vs. int array assignment
6661     });
6662    
6663     runScript({
6664     .code = R"NKSP_CODE(
6665     on init
6666     declare ?a[3] := ( 1.0, 2.0, 3 )
6667     end on
6668     )NKSP_CODE",
6669     .expectParseError = true // 3rd element not a real value
6670     });
6671    
6672     runScript({
6673     .code = R"NKSP_CODE(
6674     on init
6675     declare ?a[3] := ( "x", "y", "z" )
6676     end on
6677     )NKSP_CODE",
6678     .expectParseError = true // real array declaration vs. string array assignment
6679     });
6680    
6681     runScript({
6682     .code = R"NKSP_CODE(
6683     on init
6684     declare a[3] := ( 1.0, 2.0, 3.0 )
6685     end on
6686     )NKSP_CODE",
6687     .expectParseError = true // missing type prefix character in variable name
6688     });
6689    
6690     runScript({
6691     .code = R"NKSP_CODE(
6692     on init
6693     declare const ?a[3] := ( 1.0, 2.0s, 3.0 )
6694     end on
6695     )NKSP_CODE",
6696     .expectParseError = true // unit types not allowed for arrays
6697     });
6698    
6699     runScript({
6700     .code = R"NKSP_CODE(
6701     on init
6702     declare const ?a[3] := ( 1.0, !2.0, 3.0 )
6703     end on
6704     )NKSP_CODE",
6705     .expectParseError = true // 'final' not allowed for arrays
6706     });
6707    
6708     #if !SILENT_TEST
6709     std::cout << std::endl;
6710     #endif
6711     }
6712    
6713     static void testStringVarDeclaration() {
6714     #if !SILENT_TEST
6715     std::cout << "UNIT TEST: string var declaration\n";
6716     #endif
6717    
6718     runScript({
6719     .code = R"NKSP_CODE(
6720     on init
6721     declare @a
6722     exit(@a)
6723     end on
6724     )NKSP_CODE",
6725     .expectStringExitResult = ""
6726     });
6727    
6728     runScript({
6729     .code = R"NKSP_CODE(
6730     on init
6731     declare @a := "foo"
6732     exit(@a)
6733     end on
6734     )NKSP_CODE",
6735     .expectStringExitResult = "foo"
6736     });
6737    
6738     runScript({
6739     .code = R"NKSP_CODE(
6740     on init
6741     declare @a := "foo"
6742     @a := "bar"
6743     exit(@a)
6744     end on
6745     )NKSP_CODE",
6746     .expectStringExitResult = "bar"
6747     });
6748    
6749     runScript({
6750     .code = R"NKSP_CODE(
6751     on init
6752     declare @a
6753     declare @a
6754     end on
6755     )NKSP_CODE",
6756     .expectParseError = true // variable re-declaration
6757     });
6758    
6759     runScript({
6760     .code = R"NKSP_CODE(
6761     on init
6762     declare const @a
6763     end on
6764     )NKSP_CODE",
6765     .expectParseError = true // const variable declaration without assignment
6766     });
6767    
6768     runScript({
6769     .code = R"NKSP_CODE(
6770     on init
6771     declare const @a := "foo"
6772     exit(@a)
6773     end on
6774     )NKSP_CODE",
6775     .expectStringExitResult = "foo"
6776     });
6777    
6778     runScript({
6779     .code = R"NKSP_CODE(
6780     on init
6781     declare const @a := "foo"
6782     @a := "bar"
6783     end on
6784     )NKSP_CODE",
6785     .expectParseError = true // attempt to modify const variable
6786     });
6787    
6788     runScript({
6789     .code = R"NKSP_CODE(
6790     on init
6791     declare const @a := "foo"
6792     declare const @b := @a
6793     exit(@b)
6794     end on
6795     )NKSP_CODE",
6796     .expectStringExitResult = "foo"
6797     });
6798    
6799     runScript({
6800     .code = R"NKSP_CODE(
6801     on init
6802     declare @a := "foo"
6803     declare const @b := @a
6804     end on
6805     )NKSP_CODE",
6806     .expectParseError = true // const variable defined with non-const assignment
6807     });
6808    
6809     runScript({
6810     .code = R"NKSP_CODE(
6811     on init
6812     declare polyphonic @a
6813     end on
6814     )NKSP_CODE",
6815     .expectParseError = true // 'polyphonic' not allowed for string type
6816     });
6817    
6818     runScript({
6819     .code = R"NKSP_CODE(
6820     on init
6821     declare const polyphonic @a
6822     end on
6823     )NKSP_CODE",
6824     .expectParseError = true // 'polyphonic' not allowed for string type
6825     });
6826    
6827     runScript({
6828     .code = R"NKSP_CODE(
6829     on init
6830     declare polyphonic const @a
6831     end on
6832     )NKSP_CODE",
6833     .expectParseError = true // 'polyphonic' not allowed for string type
6834     });
6835    
6836     runScript({
6837     .code = R"NKSP_CODE(
6838     on init
6839     declare polyphonic @a = "foo"
6840     end on
6841     )NKSP_CODE",
6842     .expectParseError = true // 'polyphonic' not allowed for string type
6843     });
6844    
6845     runScript({
6846     .code = R"NKSP_CODE(
6847     on init
6848     declare polyphonic const @a = "foo"
6849     end on
6850     )NKSP_CODE",
6851     .expectParseError = true // 'polyphonic' not allowed for string type
6852     });
6853    
6854     runScript({
6855     .code = R"NKSP_CODE(
6856     on init
6857     declare const polyphonic @a = "foo"
6858     end on
6859     )NKSP_CODE",
6860     .expectParseError = true // 'polyphonic' not allowed for string type
6861     });
6862    
6863     runScript({
6864     .code = R"NKSP_CODE(
6865     on init
6866     declare $a := "foo"
6867     exit($a)
6868     end on
6869     )NKSP_CODE",
6870     .expectParseWarning = true, // int type declaration vs. string assignment
6871     .expectStringExitResult = "foo"
6872     });
6873    
6874     runScript({
6875     .code = R"NKSP_CODE(
6876     on init
6877     declare ~a := "foo"
6878     exit(~a)
6879     end on
6880     )NKSP_CODE",
6881     .expectParseWarning = true, // real type declaration vs. string assignment
6882     .expectStringExitResult = "foo"
6883     });
6884    
6885     runScript({
6886     .code = R"NKSP_CODE(
6887     on init
6888     declare %a := "foo"
6889     exit(%a)
6890     end on
6891     )NKSP_CODE",
6892     .expectParseWarning = true, // int array type declaration vs. string assignment
6893     .expectStringExitResult = "foo"
6894     });
6895    
6896     runScript({
6897     .code = R"NKSP_CODE(
6898     on init
6899     declare const $a := "foo"
6900     exit($a)
6901     end on
6902     )NKSP_CODE",
6903     .expectParseWarning = true, // int type declaration vs. string assignment
6904     .expectStringExitResult = "foo"
6905     });
6906    
6907     runScript({
6908     .code = R"NKSP_CODE(
6909     on init
6910     declare const ~a := "foo"
6911     exit(~a)
6912     end on
6913     )NKSP_CODE",
6914     .expectParseWarning = true, // real type declaration vs. string assignment
6915     .expectStringExitResult = "foo"
6916     });
6917    
6918     runScript({
6919     .code = R"NKSP_CODE(
6920     on init
6921     declare const %a := "foo"
6922     exit(%a)
6923     end on
6924     )NKSP_CODE",
6925     .expectParseWarning = true, // int array type declaration vs. string assignment
6926     .expectStringExitResult = "foo"
6927     });
6928    
6929     runScript({
6930     .code = R"NKSP_CODE(
6931     on init
6932     declare a := "foo"
6933     end on
6934     )NKSP_CODE",
6935     .expectParseError = true // missing type prefix character in variable name
6936     });
6937    
6938     runScript({
6939     .code = R"NKSP_CODE(
6940     on init
6941     declare const a := "foo"
6942     end on
6943     )NKSP_CODE",
6944     .expectParseError = true // missing type prefix character in variable name
6945     });
6946    
6947     runScript({
6948     .code = R"NKSP_CODE(
6949     on init
6950     declare @a := abort($NI_CALLBACK_ID)
6951     end on
6952     )NKSP_CODE",
6953     .expectParseError = true // assigned expression does not result in a value
6954     });
6955    
6956     runScript({
6957     .code = R"NKSP_CODE(
6958     on init
6959     declare const @a := abort($NI_CALLBACK_ID)
6960     end on
6961     )NKSP_CODE",
6962     .expectParseError = true // assigned expression does not result in a value
6963     });
6964    
6965     #if !SILENT_TEST
6966     std::cout << std::endl;
6967     #endif
6968     }
6969    
6970 schoenebeck 3551 static void testBuiltInMinFunction() {
6971     #if !SILENT_TEST
6972     std::cout << "UNIT TEST: built-in min() function\n";
6973     #endif
6974    
6975     runScript({
6976     .code = R"NKSP_CODE(
6977     on init
6978     declare $foo := min
6979     end on
6980     )NKSP_CODE",
6981     .expectParseError = true // because min() function requires 2 arguments
6982     });
6983    
6984     runScript({
6985     .code = R"NKSP_CODE(
6986     on init
6987     declare $foo := min()
6988     end on
6989     )NKSP_CODE",
6990     .expectParseError = true // because min() function requires 2 arguments
6991     });
6992    
6993     runScript({
6994     .code = R"NKSP_CODE(
6995     on init
6996     declare $foo := min(1)
6997     end on
6998     )NKSP_CODE",
6999     .expectParseError = true // because min() function requires 2 arguments
7000     });
7001    
7002 schoenebeck 3577 // integer tests ...
7003    
7004 schoenebeck 3551 runScript({
7005     .code = R"NKSP_CODE(
7006     on init
7007     declare $foo := min(1,2)
7008     exit($foo)
7009     end on
7010     )NKSP_CODE",
7011     .expectIntExitResult = 1
7012     });
7013    
7014     runScript({
7015     .code = R"NKSP_CODE(
7016     on init
7017     declare $foo := min(-30,4)
7018     exit($foo)
7019     end on
7020     )NKSP_CODE",
7021     .expectIntExitResult = -30
7022     });
7023    
7024 schoenebeck 3577 // real number tests ...
7025    
7026     runScript({
7027     .code = R"NKSP_CODE(
7028     on init
7029 schoenebeck 3581 declare ~foo := min(1.0, 2.0)
7030     exit(~foo)
7031 schoenebeck 3577 end on
7032     )NKSP_CODE",
7033     .expectRealExitResult = 1.0
7034     });
7035    
7036     runScript({
7037     .code = R"NKSP_CODE(
7038     on init
7039 schoenebeck 3581 declare ~foo := min(-30.0, 4.0)
7040     exit(~foo)
7041 schoenebeck 3577 end on
7042     )NKSP_CODE",
7043     .expectRealExitResult = -30.0
7044     });
7045    
7046     runScript({
7047     .code = R"NKSP_CODE(
7048     on init
7049 schoenebeck 3581 declare ~foo := min(1.1, 1.13)
7050     exit(~foo)
7051 schoenebeck 3577 end on
7052     )NKSP_CODE",
7053     .expectRealExitResult = 1.1
7054     });
7055    
7056     runScript({
7057     .code = R"NKSP_CODE(
7058     on init
7059 schoenebeck 3581 declare ~foo := min(1.13, 1.1)
7060     exit(~foo)
7061 schoenebeck 3577 end on
7062     )NKSP_CODE",
7063     .expectRealExitResult = 1.1
7064     });
7065    
7066     // mixed type tests ...
7067    
7068     runScript({
7069     .code = R"NKSP_CODE(
7070     on init
7071 schoenebeck 3581 declare ~foo := min(1, 1.16)
7072     exit(~foo)
7073     end on
7074     )NKSP_CODE",
7075     .expectRealExitResult = 1.0,
7076     .expectParseWarning = true // min() warns if data types of arguments not matching
7077     });
7078    
7079     runScript({
7080     .code = R"NKSP_CODE(
7081     on init
7082     declare ~foo := min(-3.92, 9)
7083     exit(~foo)
7084     end on
7085     )NKSP_CODE",
7086     .expectRealExitResult = -3.92,
7087     .expectParseWarning = true // min() warns if data types of arguments not matching
7088     });
7089    
7090     // std unit tests ...
7091    
7092     runScript({
7093     .code = R"NKSP_CODE(
7094     on init
7095     declare $foo := min(30ms,4s)
7096 schoenebeck 3577 exit($foo)
7097     end on
7098     )NKSP_CODE",
7099 schoenebeck 3581 .expectIntExitResult = 30,
7100     .expectExitResultUnitPrefix = { VM_MILLI },
7101     .expectExitResultUnit = VM_SECOND,
7102 schoenebeck 3577 });
7103    
7104     runScript({
7105     .code = R"NKSP_CODE(
7106     on init
7107 schoenebeck 3581 declare $foo := min(4s,30ms)
7108 schoenebeck 3577 exit($foo)
7109     end on
7110     )NKSP_CODE",
7111 schoenebeck 3581 .expectIntExitResult = 30,
7112     .expectExitResultUnitPrefix = { VM_MILLI },
7113     .expectExitResultUnit = VM_SECOND,
7114 schoenebeck 3577 });
7115    
7116 schoenebeck 3581 runScript({
7117     .code = R"NKSP_CODE(
7118     on init
7119     declare $foo := min(-30mdB,-4dB)
7120     exit($foo)
7121     end on
7122     )NKSP_CODE",
7123     .expectIntExitResult = -4,
7124     .expectExitResultUnitPrefix = { VM_DECI },
7125     .expectExitResultUnit = VM_BEL,
7126     });
7127    
7128     runScript({
7129     .code = R"NKSP_CODE(
7130     on init
7131     declare $foo := min(-4dB,-30mdB)
7132     exit($foo)
7133     end on
7134     )NKSP_CODE",
7135     .expectIntExitResult = -4,
7136     .expectExitResultUnitPrefix = { VM_DECI },
7137     .expectExitResultUnit = VM_BEL,
7138     });
7139    
7140     runScript({
7141     .code = R"NKSP_CODE(
7142     on init
7143     declare $foo := min(-4s,-30Hz)
7144     exit($foo)
7145     end on
7146     )NKSP_CODE",
7147     .expectParseError = true // min() requires arguments to have same unit type
7148     });
7149    
7150     runScript({
7151     .code = R"NKSP_CODE(
7152     on init
7153     declare $foo := min(-4s,-30)
7154     exit($foo)
7155     end on
7156     )NKSP_CODE",
7157     .expectParseError = true // min() requires arguments to have same unit type
7158     });
7159    
7160     runScript({
7161     .code = R"NKSP_CODE(
7162     on init
7163     declare $foo := min(-4,-30s)
7164     exit($foo)
7165     end on
7166     )NKSP_CODE",
7167     .expectParseError = true // min() requires arguments to have same unit type
7168     });
7169    
7170     runScript({
7171     .code = R"NKSP_CODE(
7172     on init
7173     declare ~foo := min(0.9s,1.0s)
7174     exit(~foo)
7175     end on
7176     )NKSP_CODE",
7177     .expectRealExitResult = 0.9,
7178     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
7179     .expectExitResultUnit = VM_SECOND,
7180     });
7181    
7182     // 'final' ('!') operator tests ...
7183    
7184     runScript({
7185     .code = R"NKSP_CODE(
7186     on init
7187     declare $foo := min(!30,!4)
7188     exit($foo)
7189     end on
7190     )NKSP_CODE",
7191     .expectIntExitResult = 4,
7192     .expectExitResultFinal = true
7193     });
7194    
7195     runScript({
7196     .code = R"NKSP_CODE(
7197     on init
7198     declare $foo := min(30,4)
7199     exit($foo)
7200     end on
7201     )NKSP_CODE",
7202     .expectIntExitResult = 4,
7203     .expectExitResultFinal = false
7204     });
7205    
7206     runScript({
7207     .code = R"NKSP_CODE(
7208     on init
7209     declare $foo := min(30,!4)
7210     exit($foo)
7211     end on
7212     )NKSP_CODE",
7213     .expectIntExitResult = 4,
7214     .expectExitResultFinal = true,
7215     .expectParseWarning = true // min() warns if only one argument is 'final'
7216     });
7217    
7218     runScript({
7219     .code = R"NKSP_CODE(
7220     on init
7221     declare $foo := min(!30,4)
7222     exit($foo)
7223     end on
7224     )NKSP_CODE",
7225     .expectIntExitResult = 4,
7226     .expectExitResultFinal = true,
7227     .expectParseWarning = true // min() warns if only one argument is 'final'
7228     });
7229    
7230     runScript({
7231     .code = R"NKSP_CODE(
7232     on init
7233     declare ~foo := min(!12.1,!12.2)
7234     exit(~foo)
7235     end on
7236     )NKSP_CODE",
7237     .expectRealExitResult = 12.1,
7238     .expectExitResultFinal = true
7239     });
7240    
7241     runScript({
7242     .code = R"NKSP_CODE(
7243     on init
7244     declare ~foo := min(12.1,12.2)
7245     exit(~foo)
7246     end on
7247     )NKSP_CODE",
7248     .expectRealExitResult = 12.1,
7249     .expectExitResultFinal = false
7250     });
7251    
7252     runScript({
7253     .code = R"NKSP_CODE(
7254     on init
7255     declare ~foo := min(!12.1,12.2)
7256     exit(~foo)
7257     end on
7258     )NKSP_CODE",
7259     .expectRealExitResult = 12.1,
7260     .expectExitResultFinal = true,
7261     .expectParseWarning = true // min() warns if only one argument is 'final'
7262     });
7263    
7264     runScript({
7265     .code = R"NKSP_CODE(
7266     on init
7267     declare ~foo := min(12.1,!12.2)
7268     exit(~foo)
7269     end on
7270     )NKSP_CODE",
7271     .expectRealExitResult = 12.1,
7272     .expectExitResultFinal = true,
7273     .expectParseWarning = true // min() warns if only one argument is 'final'
7274     });
7275    
7276 schoenebeck 3551 #if !SILENT_TEST
7277     std::cout << std::endl;
7278     #endif
7279     }
7280    
7281     static void testBuiltInMaxFunction() {
7282     #if !SILENT_TEST
7283     std::cout << "UNIT TEST: built-in max() function\n";
7284     #endif
7285    
7286 schoenebeck 3577 // integer tests ...
7287    
7288 schoenebeck 3551 runScript({
7289     .code = R"NKSP_CODE(
7290     on init
7291     declare $foo := max
7292     end on
7293     )NKSP_CODE",
7294     .expectParseError = true // because max() function requires 2 arguments
7295     });
7296    
7297     runScript({
7298     .code = R"NKSP_CODE(
7299     on init
7300     declare $foo := max()
7301     end on
7302     )NKSP_CODE",
7303     .expectParseError = true // because max() function requires 2 arguments
7304     });
7305    
7306     runScript({
7307     .code = R"NKSP_CODE(
7308     on init
7309     declare $foo := max(1)
7310     end on
7311     )NKSP_CODE",
7312     .expectParseError = true // because max() function requires 2 arguments
7313     });
7314    
7315     runScript({
7316     .code = R"NKSP_CODE(
7317     on init
7318     declare $foo := max(1,2)
7319     exit($foo)
7320     end on
7321     )NKSP_CODE",
7322     .expectIntExitResult = 2
7323     });
7324    
7325     runScript({
7326     .code = R"NKSP_CODE(
7327     on init
7328     declare $foo := max(-30,4)
7329     exit($foo)
7330     end on
7331     )NKSP_CODE",
7332     .expectIntExitResult = 4
7333     });
7334    
7335 schoenebeck 3577 // real number tests ...
7336    
7337     runScript({
7338     .code = R"NKSP_CODE(
7339     on init
7340 schoenebeck 3581 declare ~foo := max(1.0, 2.0)
7341     exit(~foo)
7342 schoenebeck 3577 end on
7343     )NKSP_CODE",
7344     .expectRealExitResult = 2.0
7345     });
7346    
7347     runScript({
7348     .code = R"NKSP_CODE(
7349     on init
7350 schoenebeck 3581 declare ~foo := max(-30.0, 4.0)
7351     exit(~foo)
7352 schoenebeck 3577 end on
7353     )NKSP_CODE",
7354     .expectRealExitResult = 4.0
7355     });
7356    
7357     runScript({
7358     .code = R"NKSP_CODE(
7359     on init
7360 schoenebeck 3581 declare ~foo := max(1.1, 1.13)
7361     exit(~foo)
7362 schoenebeck 3577 end on
7363     )NKSP_CODE",
7364     .expectRealExitResult = 1.13
7365     });
7366    
7367     runScript({
7368     .code = R"NKSP_CODE(
7369     on init
7370 schoenebeck 3581 declare ~foo := max(1.13, 1.1)
7371     exit(~foo)
7372 schoenebeck 3577 end on
7373     )NKSP_CODE",
7374     .expectRealExitResult = 1.13
7375     });
7376    
7377     // mixed type tests ...
7378    
7379     runScript({
7380     .code = R"NKSP_CODE(
7381     on init
7382 schoenebeck 3581 declare ~foo := max(1, 1.16)
7383     exit(~foo)
7384     end on
7385     )NKSP_CODE",
7386     .expectRealExitResult = 1.16,
7387     .expectParseWarning = true // max() warns if data types of arguments not matching
7388     });
7389    
7390     runScript({
7391     .code = R"NKSP_CODE(
7392     on init
7393     declare ~foo := max(-3.92, 9)
7394     exit(~foo)
7395     end on
7396     )NKSP_CODE",
7397     .expectRealExitResult = 9.0,
7398     .expectParseWarning = true // max() warns if data types of arguments not matching
7399     });
7400    
7401     // std unit tests ...
7402    
7403     runScript({
7404     .code = R"NKSP_CODE(
7405     on init
7406     declare $foo := max(30ms,4s)
7407 schoenebeck 3577 exit($foo)
7408     end on
7409     )NKSP_CODE",
7410 schoenebeck 3581 .expectIntExitResult = 4,
7411     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
7412     .expectExitResultUnit = VM_SECOND,
7413 schoenebeck 3577 });
7414    
7415     runScript({
7416     .code = R"NKSP_CODE(
7417     on init
7418 schoenebeck 3581 declare $foo := max(4s,30ms)
7419 schoenebeck 3577 exit($foo)
7420     end on
7421     )NKSP_CODE",
7422 schoenebeck 3581 .expectIntExitResult = 4,
7423     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
7424     .expectExitResultUnit = VM_SECOND,
7425 schoenebeck 3577 });
7426    
7427 schoenebeck 3581 runScript({
7428     .code = R"NKSP_CODE(
7429     on init
7430     declare $foo := max(-30mdB,-4dB)
7431     exit($foo)
7432     end on
7433     )NKSP_CODE",
7434     .expectIntExitResult = -30,
7435     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7436     .expectExitResultUnit = VM_BEL,
7437     });
7438    
7439     runScript({
7440     .code = R"NKSP_CODE(
7441     on init
7442     declare $foo := max(-4dB,-30mdB)
7443     exit($foo)
7444     end on
7445     )NKSP_CODE",
7446     .expectIntExitResult = -30,
7447     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7448     .expectExitResultUnit = VM_BEL,
7449     });
7450    
7451     runScript({
7452     .code = R"NKSP_CODE(
7453     on init
7454     declare $foo := max(-4s,-30Hz)
7455     exit($foo)
7456     end on
7457     )NKSP_CODE",
7458     .expectParseError = true // max() requires arguments to have same unit type
7459     });
7460    
7461     runScript({
7462     .code = R"NKSP_CODE(
7463     on init
7464     declare $foo := max(-4s,-30)
7465     exit($foo)
7466     end on
7467     )NKSP_CODE",
7468     .expectParseError = true // max() requires arguments to have same unit type
7469     });
7470    
7471     runScript({
7472     .code = R"NKSP_CODE(
7473     on init
7474     declare $foo := max(-4,-30s)
7475     exit($foo)
7476     end on
7477     )NKSP_CODE",
7478     .expectParseError = true // max() requires arguments to have same unit type
7479     });
7480    
7481     runScript({
7482     .code = R"NKSP_CODE(
7483     on init
7484     declare ~foo := max(0.9s,1.0s)
7485     exit(~foo)
7486     end on
7487     )NKSP_CODE",
7488     .expectRealExitResult = 1.0,
7489     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
7490     .expectExitResultUnit = VM_SECOND,
7491     });
7492    
7493     // 'final' ('!') operator tests ...
7494    
7495     runScript({
7496     .code = R"NKSP_CODE(
7497     on init
7498     declare $foo := max(!30,!4)
7499     exit($foo)
7500     end on
7501     )NKSP_CODE",
7502     .expectIntExitResult = 30,
7503     .expectExitResultFinal = true
7504     });
7505    
7506     runScript({
7507     .code = R"NKSP_CODE(
7508     on init
7509     declare $foo := max(30,4)
7510     exit($foo)
7511     end on
7512     )NKSP_CODE",
7513     .expectIntExitResult = 30,
7514     .expectExitResultFinal = false
7515     });
7516    
7517     runScript({
7518     .code = R"NKSP_CODE(
7519     on init
7520     declare $foo := max(30,!4)
7521     exit($foo)
7522     end on
7523     )NKSP_CODE",
7524     .expectIntExitResult = 30,
7525     .expectExitResultFinal = true,
7526     .expectParseWarning = true // max() warns if only one argument is 'final'
7527     });
7528    
7529     runScript({
7530     .code = R"NKSP_CODE(
7531     on init
7532     declare $foo := max(!30,4)
7533     exit($foo)
7534     end on
7535     )NKSP_CODE",
7536     .expectIntExitResult = 30,
7537     .expectExitResultFinal = true,
7538     .expectParseWarning = true // max() warns if only one argument is 'final'
7539     });
7540    
7541     runScript({
7542     .code = R"NKSP_CODE(
7543     on init
7544     declare ~foo := max(!12.1,!12.2)
7545     exit(~foo)
7546     end on
7547     )NKSP_CODE",
7548     .expectRealExitResult = 12.2,
7549     .expectExitResultFinal = true
7550     });
7551    
7552     runScript({
7553     .code = R"NKSP_CODE(
7554     on init
7555     declare ~foo := max(12.1,12.2)
7556     exit(~foo)
7557     end on
7558     )NKSP_CODE",
7559     .expectRealExitResult = 12.2,
7560     .expectExitResultFinal = false
7561     });
7562    
7563     runScript({
7564     .code = R"NKSP_CODE(
7565     on init
7566     declare ~foo := max(!12.1,12.2)
7567     exit(~foo)
7568     end on
7569     )NKSP_CODE",
7570     .expectRealExitResult = 12.2,
7571     .expectExitResultFinal = true,
7572     .expectParseWarning = true // max() warns if only one argument is 'final'
7573     });
7574    
7575     runScript({
7576     .code = R"NKSP_CODE(
7577     on init
7578     declare ~foo := max(12.1,!12.2)
7579     exit(~foo)
7580     end on
7581     )NKSP_CODE",
7582     .expectRealExitResult = 12.2,
7583     .expectExitResultFinal = true,
7584     .expectParseWarning = true // max() warns if only one argument is 'final'
7585     });
7586    
7587 schoenebeck 3551 #if !SILENT_TEST
7588     std::cout << std::endl;
7589     #endif
7590     }
7591    
7592     static void testBuiltInAbsFunction() {
7593     #if !SILENT_TEST
7594     std::cout << "UNIT TEST: built-in abs() function\n";
7595     #endif
7596    
7597     runScript({
7598     .code = R"NKSP_CODE(
7599     on init
7600     declare $foo := abs
7601     end on
7602     )NKSP_CODE",
7603     .expectParseError = true // because abs() function requires 1 argument
7604     });
7605    
7606     runScript({
7607     .code = R"NKSP_CODE(
7608     on init
7609     declare $foo := abs()
7610     end on
7611     )NKSP_CODE",
7612     .expectParseError = true // because abs() function requires 1 argument
7613     });
7614    
7615 schoenebeck 3577 // integer tests ...
7616    
7617 schoenebeck 3551 runScript({
7618     .code = R"NKSP_CODE(
7619     on init
7620     declare $foo := abs(23)
7621     exit($foo)
7622     end on
7623     )NKSP_CODE",
7624     .expectIntExitResult = 23
7625     });
7626    
7627     runScript({
7628     .code = R"NKSP_CODE(
7629     on init
7630     declare $foo := abs(-23)
7631     exit($foo)
7632     end on
7633     )NKSP_CODE",
7634     .expectIntExitResult = 23
7635     });
7636    
7637 schoenebeck 3577 // real number tests ...
7638    
7639     runScript({
7640     .code = R"NKSP_CODE(
7641     on init
7642     declare ~foo := abs(23.0)
7643     exit(~foo)
7644     end on
7645     )NKSP_CODE",
7646     .expectRealExitResult = 23.0
7647     });
7648    
7649     runScript({
7650     .code = R"NKSP_CODE(
7651     on init
7652     declare ~foo := abs(23.11)
7653     exit(~foo)
7654     end on
7655     )NKSP_CODE",
7656     .expectRealExitResult = 23.11
7657     });
7658    
7659     runScript({
7660     .code = R"NKSP_CODE(
7661     on init
7662     declare ~foo := abs(-23.11)
7663     exit(~foo)
7664     end on
7665     )NKSP_CODE",
7666     .expectRealExitResult = 23.11
7667     });
7668    
7669     runScript({
7670     .code = R"NKSP_CODE(
7671     on init
7672     declare ~bar := -23.11
7673     declare ~foo := abs(~bar)
7674     exit(~foo)
7675     end on
7676     )NKSP_CODE",
7677     .expectRealExitResult = 23.11
7678     });
7679    
7680 schoenebeck 3581 // std unit tests ...
7681    
7682     runScript({
7683     .code = R"NKSP_CODE(
7684     on init
7685     declare $foo := abs(-23kHz)
7686     exit($foo)
7687     end on
7688     )NKSP_CODE",
7689     .expectIntExitResult = 23,
7690     .expectExitResultUnitPrefix = { VM_KILO },
7691     .expectExitResultUnit = VM_HERTZ
7692     });
7693    
7694     runScript({
7695     .code = R"NKSP_CODE(
7696     on init
7697     declare ~foo := abs(-23.4kHz)
7698     exit(~foo)
7699     end on
7700     )NKSP_CODE",
7701     .expectRealExitResult = 23.4,
7702     .expectExitResultUnitPrefix = { VM_KILO },
7703     .expectExitResultUnit = VM_HERTZ
7704     });
7705    
7706     // 'final' ('!') operator tests ...
7707    
7708     runScript({
7709     .code = R"NKSP_CODE(
7710     on init
7711     declare $foo := abs(!-23)
7712     exit($foo)
7713     end on
7714     )NKSP_CODE",
7715     .expectIntExitResult = 23,
7716     .expectExitResultFinal = true
7717     });
7718    
7719     runScript({
7720     .code = R"NKSP_CODE(
7721     on init
7722     declare $foo := abs(-23)
7723     exit($foo)
7724     end on
7725     )NKSP_CODE",
7726     .expectIntExitResult = 23,
7727     .expectExitResultFinal = false
7728     });
7729    
7730     runScript({
7731     .code = R"NKSP_CODE(
7732     on init
7733     declare ~foo := abs(!-23.2)
7734     exit(~foo)
7735     end on
7736     )NKSP_CODE",
7737     .expectRealExitResult = 23.2,
7738     .expectExitResultFinal = true
7739     });
7740    
7741     runScript({
7742     .code = R"NKSP_CODE(
7743     on init
7744     declare ~foo := abs(-23.9)
7745     exit(~foo)
7746     end on
7747     )NKSP_CODE",
7748     .expectRealExitResult = 23.9,
7749     .expectExitResultFinal = false
7750     });
7751    
7752 schoenebeck 3551 #if !SILENT_TEST
7753     std::cout << std::endl;
7754     #endif
7755     }
7756    
7757     static void testBuiltInIncFunction() {
7758     #if !SILENT_TEST
7759     std::cout << "UNIT TEST: built-in inc() function\n";
7760     #endif
7761    
7762 schoenebeck 3581 // integer tests ...
7763    
7764 schoenebeck 3551 runScript({
7765     .code = R"NKSP_CODE(
7766     on init
7767     declare $foo := 5
7768     inc($foo)
7769     exit($foo)
7770     end on
7771     )NKSP_CODE",
7772     .expectIntExitResult = 6
7773     });
7774    
7775     runScript({
7776     .code = R"NKSP_CODE(
7777     on init
7778     declare $foo := 5
7779     inc($foo)
7780     inc($foo)
7781     inc($foo)
7782     exit($foo)
7783     end on
7784     )NKSP_CODE",
7785     .expectIntExitResult = 8
7786     });
7787    
7788     runScript({
7789     .code = R"NKSP_CODE(
7790     on init
7791     declare $foo := 5
7792     inc($foo)
7793     exit( inc($foo) )
7794     end on
7795     )NKSP_CODE",
7796     .expectIntExitResult = 7
7797     });
7798    
7799 schoenebeck 3581 // std unit tests ...
7800    
7801     runScript({
7802     .code = R"NKSP_CODE(
7803     on init
7804     declare $foo := 53mdB
7805     inc($foo)
7806     exit( inc($foo) )
7807     end on
7808     )NKSP_CODE",
7809     .expectIntExitResult = 55,
7810     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7811     .expectExitResultUnit = VM_BEL,
7812     .expectParseWarning = true // inc() warns if argument has a unit
7813     });
7814    
7815     // 'final' ('!') operator tests ...
7816    
7817     runScript({
7818     .code = R"NKSP_CODE(
7819     on init
7820     declare $foo := !53
7821     inc($foo)
7822     exit( inc($foo) )
7823     end on
7824     )NKSP_CODE",
7825     .expectIntExitResult = 55,
7826     .expectExitResultFinal = true
7827     });
7828    
7829     runScript({
7830     .code = R"NKSP_CODE(
7831     on init
7832     declare $foo := 53
7833     inc($foo)
7834     exit( inc($foo) )
7835     end on
7836     )NKSP_CODE",
7837     .expectIntExitResult = 55,
7838     .expectExitResultFinal = false
7839     });
7840    
7841     runScript({
7842     .code = R"NKSP_CODE(
7843     on init
7844     declare $foo := 53
7845     inc($foo)
7846     exit( !inc($foo) )
7847     end on
7848     )NKSP_CODE",
7849     .expectIntExitResult = 55,
7850     .expectExitResultFinal = true
7851     });
7852    
7853 schoenebeck 3551 #if !SILENT_TEST
7854     std::cout << std::endl;
7855     #endif
7856     }
7857    
7858     static void testBuiltInDecFunction() {
7859     #if !SILENT_TEST
7860     std::cout << "UNIT TEST: built-in dec() function\n";
7861     #endif
7862    
7863 schoenebeck 3581 // integer tests ...
7864    
7865 schoenebeck 3551 runScript({
7866     .code = R"NKSP_CODE(
7867     on init
7868     declare $foo := 5
7869     dec($foo)
7870     exit($foo)
7871     end on
7872     )NKSP_CODE",
7873     .expectIntExitResult = 4
7874     });
7875    
7876     runScript({
7877     .code = R"NKSP_CODE(
7878     on init
7879     declare $foo := 5
7880     dec($foo)
7881     dec($foo)
7882     dec($foo)
7883     exit($foo)
7884     end on
7885     )NKSP_CODE",
7886     .expectIntExitResult = 2
7887     });
7888    
7889     runScript({
7890     .code = R"NKSP_CODE(
7891     on init
7892     declare $foo := 5
7893     dec($foo)
7894     exit( dec($foo) )
7895     end on
7896     )NKSP_CODE",
7897     .expectIntExitResult = 3
7898     });
7899    
7900 schoenebeck 3581 // std unit tests ...
7901    
7902     runScript({
7903     .code = R"NKSP_CODE(
7904     on init
7905     declare $foo := 53mdB
7906     dec($foo)
7907     exit( dec($foo) )
7908     end on
7909     )NKSP_CODE",
7910     .expectIntExitResult = 51,
7911     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7912     .expectExitResultUnit = VM_BEL,
7913     .expectParseWarning = true // dec() warns if argument has a unit
7914     });
7915    
7916     // 'final' ('!') operator tests ...
7917    
7918     runScript({
7919     .code = R"NKSP_CODE(
7920     on init
7921     declare $foo := !53
7922     dec($foo)
7923     exit( dec($foo) )
7924     end on
7925     )NKSP_CODE",
7926     .expectIntExitResult = 51,
7927     .expectExitResultFinal = true
7928     });
7929    
7930     runScript({
7931     .code = R"NKSP_CODE(
7932     on init
7933     declare $foo := 53
7934     dec($foo)
7935     exit( dec($foo) )
7936     end on
7937     )NKSP_CODE",
7938     .expectIntExitResult = 51,
7939     .expectExitResultFinal = false
7940     });
7941    
7942     runScript({
7943     .code = R"NKSP_CODE(
7944     on init
7945     declare $foo := 53
7946     dec($foo)
7947     exit( !dec($foo) )
7948     end on
7949     )NKSP_CODE",
7950     .expectIntExitResult = 51,
7951     .expectExitResultFinal = true
7952     });
7953    
7954 schoenebeck 3551 #if !SILENT_TEST
7955     std::cout << std::endl;
7956     #endif
7957     }
7958    
7959     static void testBuiltInInRangeFunction() {
7960     #if !SILENT_TEST
7961     std::cout << "UNIT TEST: built-in in_range() function\n";
7962     #endif
7963    
7964 schoenebeck 3581 // integer tests ...
7965    
7966 schoenebeck 3551 runScript({
7967     .code = R"NKSP_CODE(
7968     on init
7969     exit( in_range(1,4,9) )
7970     end on
7971     )NKSP_CODE",
7972     .expectBoolExitResult = false
7973     });
7974    
7975     runScript({
7976     .code = R"NKSP_CODE(
7977     on init
7978     exit( in_range(5,4,9) )
7979     end on
7980     )NKSP_CODE",
7981     .expectBoolExitResult = true
7982     });
7983    
7984     runScript({
7985     .code = R"NKSP_CODE(
7986     on init
7987     exit( in_range(9,4,9) )
7988     end on
7989     )NKSP_CODE",
7990     .expectBoolExitResult = true
7991     });
7992    
7993     runScript({
7994     .code = R"NKSP_CODE(
7995     on init
7996     exit( in_range(10,4,9) )
7997     end on
7998     )NKSP_CODE",
7999     .expectBoolExitResult = false
8000     });
8001    
8002     runScript({
8003     .code = R"NKSP_CODE(
8004     on init
8005     exit( in_range(-6,-5,5) )
8006     end on
8007     )NKSP_CODE",
8008     .expectBoolExitResult = false
8009     });
8010    
8011     runScript({
8012     .code = R"NKSP_CODE(
8013     on init
8014     exit( in_range(-5,-5,5) )
8015     end on
8016     )NKSP_CODE",
8017     .expectBoolExitResult = true
8018     });
8019    
8020     runScript({
8021     .code = R"NKSP_CODE(
8022     on init
8023     exit( in_range(0,-5,5) )
8024     end on
8025     )NKSP_CODE",
8026     .expectBoolExitResult = true
8027     });
8028    
8029     runScript({
8030     .code = R"NKSP_CODE(
8031     on init
8032     exit( in_range(5,-5,5) )
8033     end on
8034     )NKSP_CODE",
8035     .expectBoolExitResult = true
8036     });
8037    
8038     runScript({
8039     .code = R"NKSP_CODE(
8040     on init
8041     exit( in_range(6,-5,5) )
8042     end on
8043     )NKSP_CODE",
8044     .expectBoolExitResult = false
8045     });
8046    
8047 schoenebeck 3581 // real number tests ...
8048    
8049     runScript({
8050     .code = R"NKSP_CODE(
8051     on init
8052     exit( in_range(12.2,12.1,12.9) )
8053     end on
8054     )NKSP_CODE",
8055     .expectBoolExitResult = true
8056     });
8057    
8058     runScript({
8059     .code = R"NKSP_CODE(
8060     on init
8061     exit( in_range(12.2,12.9,12.1) )
8062     end on
8063     )NKSP_CODE",
8064     .expectBoolExitResult = true
8065     });
8066    
8067     runScript({
8068     .code = R"NKSP_CODE(
8069     on init
8070     exit( in_range(12.0,12.1,12.9) )
8071     end on
8072     )NKSP_CODE",
8073     .expectBoolExitResult = false
8074     });
8075    
8076     runScript({
8077     .code = R"NKSP_CODE(
8078     on init
8079     exit( in_range(12.0,12.9,12.1) )
8080     end on
8081     )NKSP_CODE",
8082     .expectBoolExitResult = false
8083     });
8084    
8085     runScript({
8086     .code = R"NKSP_CODE(
8087     on init
8088     exit( in_range(0.0,-0.3,0.3) )
8089     end on
8090     )NKSP_CODE",
8091     .expectBoolExitResult = true
8092     });
8093    
8094     runScript({
8095     .code = R"NKSP_CODE(
8096     on init
8097     exit( in_range(-0.34,-0.3,0.3) )
8098     end on
8099     )NKSP_CODE",
8100     .expectBoolExitResult = false
8101     });
8102    
8103     runScript({
8104     .code = R"NKSP_CODE(
8105     on init
8106     exit( in_range(0.34,-0.3,0.3) )
8107     end on
8108     )NKSP_CODE",
8109     .expectBoolExitResult = false
8110     });
8111    
8112     runScript({
8113     .code = R"NKSP_CODE(
8114     on init
8115     exit( in_range(-0.3,-0.3,0.3) )
8116     end on
8117     )NKSP_CODE",
8118     .expectBoolExitResult = true
8119     });
8120    
8121     runScript({
8122     .code = R"NKSP_CODE(
8123     on init
8124     exit( in_range(0.3,-0.3,0.3) )
8125     end on
8126     )NKSP_CODE",
8127     .expectBoolExitResult = true
8128     });
8129    
8130     // mixed type tests ...
8131    
8132     runScript({
8133     .code = R"NKSP_CODE(
8134     on init
8135     exit( in_range(4.0,-5,5) )
8136     end on
8137     )NKSP_CODE",
8138     .expectBoolExitResult = true,
8139     .expectParseWarning = true // in_range() warns if not all arguments are of same type
8140     });
8141    
8142     runScript({
8143     .code = R"NKSP_CODE(
8144     on init
8145     exit( in_range(5,-5,5.0) )
8146     end on
8147     )NKSP_CODE",
8148     .expectBoolExitResult = true,
8149     .expectParseWarning = true // in_range() warns if not all arguments are of same type
8150     });
8151    
8152     runScript({
8153     .code = R"NKSP_CODE(
8154     on init
8155     exit( in_range(-5,-5.0,5) )
8156     end on
8157     )NKSP_CODE",
8158     .expectBoolExitResult = true,
8159     .expectParseWarning = true // in_range() warns if not all arguments are of same type
8160     });
8161    
8162     // std unit tests ...
8163    
8164     runScript({
8165     .code = R"NKSP_CODE(
8166     on init
8167     exit( in_range(4000Hz,3kHz,5kHz) )
8168     end on
8169     )NKSP_CODE",
8170     .expectBoolExitResult = true,
8171     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8172     .expectExitResultUnit = VM_NO_UNIT
8173     });
8174    
8175     runScript({
8176     .code = R"NKSP_CODE(
8177     on init
8178     exit( in_range(5000Hz,3kHz,5kHz) )
8179     end on
8180     )NKSP_CODE",
8181     .expectBoolExitResult = true,
8182     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8183     .expectExitResultUnit = VM_NO_UNIT
8184     });
8185    
8186     runScript({
8187     .code = R"NKSP_CODE(
8188     on init
8189     exit( in_range(5001Hz,3kHz,5kHz) )
8190     end on
8191     )NKSP_CODE",
8192     .expectBoolExitResult = false,
8193     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8194     .expectExitResultUnit = VM_NO_UNIT
8195     });
8196    
8197     runScript({
8198     .code = R"NKSP_CODE(
8199     on init
8200     exit( in_range(3000Hz,3kHz,5kHz) )
8201     end on
8202     )NKSP_CODE",
8203     .expectBoolExitResult = true,
8204     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8205     .expectExitResultUnit = VM_NO_UNIT
8206     });
8207    
8208     runScript({
8209     .code = R"NKSP_CODE(
8210     on init
8211     exit( in_range(2999Hz,3kHz,5kHz) )
8212     end on
8213     )NKSP_CODE",
8214     .expectBoolExitResult = false,
8215     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8216     .expectExitResultUnit = VM_NO_UNIT
8217     });
8218    
8219     runScript({
8220     .code = R"NKSP_CODE(
8221     on init
8222     exit( in_range(0.003s,3000.0us,5ms) )
8223     end on
8224     )NKSP_CODE",
8225     .expectBoolExitResult = true,
8226     .expectParseWarning = true, // in_range() warns if not all arguments are of same type
8227     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8228     .expectExitResultUnit = VM_NO_UNIT
8229     });
8230    
8231     runScript({
8232     .code = R"NKSP_CODE(
8233     on init
8234     exit( in_range(0.005s,3000.0us,5ms) )
8235     end on
8236     )NKSP_CODE",
8237     .expectBoolExitResult = true,
8238     .expectParseWarning = true, // in_range() warns if not all arguments are of same type,
8239     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8240     .expectExitResultUnit = VM_NO_UNIT
8241     });
8242    
8243     runScript({
8244     .code = R"NKSP_CODE(
8245     on init
8246     exit( in_range(0.0051s,3000.0us,5ms) )
8247     end on
8248     )NKSP_CODE",
8249     .expectBoolExitResult = false,
8250     .expectParseWarning = true, // in_range() warns if not all arguments are of same type
8251     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8252     .expectExitResultUnit = VM_NO_UNIT
8253     });
8254    
8255     runScript({
8256     .code = R"NKSP_CODE(
8257     on init
8258     exit( in_range(3s,2Hz,5Hz) )
8259     end on
8260     )NKSP_CODE",
8261     .expectParseError = true // in_range() throws error if not all arguments' unit types equal,
8262     });
8263    
8264     runScript({
8265     .code = R"NKSP_CODE(
8266     on init
8267     exit( in_range(3Hz,2s,5Hz) )
8268     end on
8269     )NKSP_CODE",
8270     .expectParseError = true // in_range() throws error if not all arguments' unit types equal
8271     });
8272    
8273     runScript({
8274     .code = R"NKSP_CODE(
8275     on init
8276     exit( in_range(3Hz,2Hz,5s) )
8277     end on
8278     )NKSP_CODE",
8279     .expectParseError = true // in_range() throws error if not all arguments' unit types equal
8280     });
8281    
8282     // 'final' ('!') operator tests ...
8283     // (result should always be NOT final)
8284    
8285     runScript({
8286     .code = R"NKSP_CODE(
8287     on init
8288     exit( in_range(!9,!4,!9) )
8289     end on
8290     )NKSP_CODE",
8291     .expectBoolExitResult = true,
8292     .expectExitResultFinal = false
8293     });
8294    
8295 schoenebeck 3551 #if !SILENT_TEST
8296     std::cout << std::endl;
8297     #endif
8298     }
8299    
8300     static void testBuiltInRandomFunction() {
8301     #if !SILENT_TEST
8302     std::cout << "UNIT TEST: built-in random() function\n";
8303     #endif
8304    
8305 schoenebeck 3581 // integer tests ...
8306    
8307     runScript({
8308     .code = R"NKSP_CODE(
8309     on init
8310     exit( random(-5,5) )
8311     end on
8312     )NKSP_CODE",
8313     .expectExitResultIsInt = true // only check type, exact value is irrelevant here
8314     });
8315    
8316 schoenebeck 3551 for (int run = 0; run < 20; ++run) {
8317     runScript({
8318     .code = R"NKSP_CODE(
8319     on init
8320     declare $foo := random(-5,5)
8321     exit( in_range($foo,-5,5) )
8322     end on
8323     )NKSP_CODE",
8324     .expectBoolExitResult = true
8325     });
8326     }
8327    
8328 schoenebeck 3581 // real number tests ...
8329    
8330     runScript({
8331     .code = R"NKSP_CODE(
8332     on init
8333     exit( random(-0.5,0.5) )
8334     end on
8335     )NKSP_CODE",
8336     .expectExitResultIsReal = true // only check type, exact value is irrelevant here
8337     });
8338    
8339     runScript({
8340     .code = R"NKSP_CODE(
8341     on init
8342     declare ~foo := random(-5.0,5.0)
8343     exit(~foo)
8344     end on
8345     )NKSP_CODE",
8346     .expectExitResultIsReal = true // only check type, exact value is irrelevant here
8347     });
8348    
8349     for (int run = 0; run < 20; ++run) {
8350     runScript({
8351     .code = R"NKSP_CODE(
8352     on init
8353     declare ~foo := random(-0.5,0.5)
8354     exit( in_range(~foo,-0.5,0.5) )
8355     end on
8356     )NKSP_CODE",
8357     .expectBoolExitResult = true
8358     });
8359     }
8360    
8361     for (int run = 0; run < 20; ++run) {
8362     runScript({
8363     .code = R"NKSP_CODE(
8364     on init
8365     declare ~foo := random(-5.0,12.0)
8366     exit( in_range(~foo,-5.0,12.0) )
8367     end on
8368     )NKSP_CODE",
8369     .expectBoolExitResult = true
8370     });
8371     }
8372    
8373     for (int run = 0; run < 20; ++run) {
8374     runScript({
8375     .code = R"NKSP_CODE(
8376     on init
8377     declare ~foo := random(23.3,98.4)
8378     exit( in_range(~foo,23.3,98.4) )
8379     end on
8380     )NKSP_CODE",
8381     .expectBoolExitResult = true
8382     });
8383     }
8384    
8385     // std unit tests ...
8386    
8387     runScript({
8388     .code = R"NKSP_CODE(
8389     on init
8390     exit( random(-5Hz,5Hz) )
8391     end on
8392     )NKSP_CODE",
8393     .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
8394     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
8395     .expectExitResultUnit = VM_HERTZ
8396     });
8397    
8398     for (int run = 0; run < 20; ++run) {
8399     runScript({
8400     .code = R"NKSP_CODE(
8401     on init
8402     declare $foo := random(-5Hz,5Hz)
8403     exit( in_range($foo,-5Hz,5Hz) )
8404     end on
8405     )NKSP_CODE",
8406     .expectBoolExitResult = true
8407     });
8408     }
8409    
8410     runScript({
8411     .code = R"NKSP_CODE(
8412     on init
8413     exit( random(5us,1ms) )
8414     end on
8415     )NKSP_CODE",
8416     .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
8417     .expectExitResultUnitPrefix = { VM_MICRO },
8418     .expectExitResultUnit = VM_SECOND
8419     });
8420    
8421     for (int run = 0; run < 20; ++run) {
8422     runScript({
8423     .code = R"NKSP_CODE(
8424     on init
8425     declare $foo := random(5us,1ms)
8426     exit( in_range($foo,5us,1ms) )
8427     end on
8428     )NKSP_CODE",
8429     .expectBoolExitResult = true
8430     });
8431     }
8432    
8433     runScript({
8434     .code = R"NKSP_CODE(
8435     on init
8436     exit( random(1ms,5000us) )
8437     end on
8438     )NKSP_CODE",
8439     .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
8440     .expectExitResultUnitPrefix = { VM_MICRO },
8441     .expectExitResultUnit = VM_SECOND
8442     });
8443    
8444     for (int run = 0; run < 20; ++run) {
8445     runScript({
8446     .code = R"NKSP_CODE(
8447     on init
8448     declare $foo := random(1ms,5000us)
8449     exit( in_range($foo,1ms,5000us) )
8450     end on
8451     )NKSP_CODE",
8452     .expectBoolExitResult = true
8453     });
8454     }
8455    
8456     runScript({
8457     .code = R"NKSP_CODE(
8458     on init
8459     exit( random(1kHz,20kHz) )
8460     end on
8461     )NKSP_CODE",
8462     .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
8463     .expectExitResultUnitPrefix = { VM_KILO },
8464     .expectExitResultUnit = VM_HERTZ
8465     });
8466    
8467     for (int run = 0; run < 20; ++run) {
8468     runScript({
8469     .code = R"NKSP_CODE(
8470     on init
8471     declare $foo := random(1kHz,20kHz)
8472     exit( in_range($foo,1kHz,20kHz) )
8473     end on
8474     )NKSP_CODE",
8475     .expectBoolExitResult = true
8476     });
8477     }
8478    
8479     runScript({
8480     .code = R"NKSP_CODE(
8481     on init
8482     exit( random(1.2us,3.5us) )
8483     end on
8484     )NKSP_CODE",
8485     .expectExitResultIsReal = true, // only check type, exact value is irrelevant here
8486     .expectExitResultUnitPrefix = { VM_MICRO },
8487     .expectExitResultUnit = VM_SECOND
8488     });
8489    
8490     for (int run = 0; run < 20; ++run) {
8491     runScript({
8492     .code = R"NKSP_CODE(
8493     on init
8494     declare ~foo := random(1.2us,3.5us)
8495     exit( in_range(~foo,1.2us,3.5us) )
8496     end on
8497     )NKSP_CODE",
8498     .expectBoolExitResult = true
8499     });
8500     }
8501    
8502     runScript({
8503     .code = R"NKSP_CODE(
8504     on init
8505     exit( random(5.2us,1.1ms) )
8506     end on
8507     )NKSP_CODE",
8508     .expectExitResultIsReal = true, // only check type, exact value is irrelevant here
8509     .expectExitResultUnitPrefix = { VM_MICRO },
8510     .expectExitResultUnit = VM_SECOND
8511     });
8512    
8513     for (int run = 0; run < 20; ++run) {
8514     runScript({
8515     .code = R"NKSP_CODE(
8516     on init
8517     declare ~foo := random(5.2us,1.1ms)
8518     exit( in_range(~foo,5.2us,1.1ms) )
8519     end on
8520     )NKSP_CODE",
8521     .expectBoolExitResult = true
8522     });
8523     }
8524    
8525     runScript({
8526     .code = R"NKSP_CODE(
8527     on init
8528     exit( random(1Hz,12s) )
8529     end on
8530     )NKSP_CODE",
8531     .expectParseError = true // random() throws error if arguments' unit types don't match
8532     });
8533    
8534     runScript({
8535     .code = R"NKSP_CODE(
8536     on init
8537     exit( random(1,12s) )
8538     end on
8539     )NKSP_CODE",
8540     .expectParseError = true // random() throws error if arguments' unit types don't match
8541     });
8542    
8543     runScript({
8544     .code = R"NKSP_CODE(
8545     on init
8546     exit( random(1s,12) )
8547     end on
8548     )NKSP_CODE",
8549     .expectParseError = true // random() throws error if arguments' unit types don't match
8550     });
8551    
8552     // 'final' ('!') operator tests ...
8553    
8554     runScript({
8555     .code = R"NKSP_CODE(
8556     on init
8557     exit( random(!1,!12) )
8558     end on
8559     )NKSP_CODE",
8560     .expectExitResultFinal = true
8561     });
8562    
8563     runScript({
8564     .code = R"NKSP_CODE(
8565     on init
8566     exit( random(1,12) )
8567     end on
8568     )NKSP_CODE",
8569     .expectExitResultFinal = false
8570     });
8571    
8572     runScript({
8573     .code = R"NKSP_CODE(
8574     on init
8575     exit( random(!1,12) )
8576     end on
8577     )NKSP_CODE",
8578     .expectExitResultFinal = true,
8579     .expectParseWarning = true // random() warns if only one argument is 'final'
8580     });
8581    
8582     runScript({
8583     .code = R"NKSP_CODE(
8584     on init
8585     exit( random(1,!12) )
8586     end on
8587     )NKSP_CODE",
8588     .expectExitResultFinal = true,
8589     .expectParseWarning = true // random() warns if only one argument is 'final'
8590     });
8591    
8592 schoenebeck 3551 #if !SILENT_TEST
8593     std::cout << std::endl;
8594     #endif
8595     }
8596    
8597     static void testBuiltInShiftLeftFunction() {
8598     #if !SILENT_TEST
8599     std::cout << "UNIT TEST: built-in sh_left() function\n";
8600     #endif
8601    
8602     runScript({
8603     .code = R"NKSP_CODE(
8604     on init
8605     exit( sh_left(1,0) )
8606     end on
8607     )NKSP_CODE",
8608     .expectIntExitResult = 1
8609     });
8610    
8611     runScript({
8612     .code = R"NKSP_CODE(
8613     on init
8614     exit( sh_left(1,1) )
8615     end on
8616     )NKSP_CODE",
8617     .expectIntExitResult = 2
8618     });
8619    
8620     runScript({
8621     .code = R"NKSP_CODE(
8622     on init
8623     exit( sh_left(1,2) )
8624     end on
8625     )NKSP_CODE",
8626     .expectIntExitResult = 4
8627     });
8628    
8629     runScript({
8630     .code = R"NKSP_CODE(
8631     on init
8632     exit( sh_left(1,3) )
8633     end on
8634     )NKSP_CODE",
8635     .expectIntExitResult = 8
8636     });
8637    
8638     #if !SILENT_TEST
8639     std::cout << std::endl;
8640     #endif
8641     }
8642    
8643     static void testBuiltInShiftRightFunction() {
8644     #if !SILENT_TEST
8645     std::cout << "UNIT TEST: built-in sh_right() function\n";
8646     #endif
8647    
8648     runScript({
8649     .code = R"NKSP_CODE(
8650     on init
8651     exit( sh_right(8,0) )
8652     end on
8653     )NKSP_CODE",
8654     .expectIntExitResult = 8
8655     });
8656    
8657     runScript({
8658     .code = R"NKSP_CODE(
8659     on init
8660     exit( sh_right(8,1) )
8661     end on
8662     )NKSP_CODE",
8663     .expectIntExitResult = 4
8664     });
8665    
8666     runScript({
8667     .code = R"NKSP_CODE(
8668     on init
8669     exit( sh_right(8,2) )
8670     end on
8671     )NKSP_CODE",
8672     .expectIntExitResult = 2
8673     });
8674    
8675     runScript({
8676     .code = R"NKSP_CODE(
8677     on init
8678     exit( sh_right(8,3) )
8679     end on
8680     )NKSP_CODE",
8681     .expectIntExitResult = 1
8682     });
8683    
8684     runScript({
8685     .code = R"NKSP_CODE(
8686     on init
8687     exit( sh_right(8,4) )
8688     end on
8689     )NKSP_CODE",
8690     .expectIntExitResult = 0
8691     });
8692    
8693     #if !SILENT_TEST
8694     std::cout << std::endl;
8695     #endif
8696     }
8697    
8698 schoenebeck 3678 static void testBuiltInMsbFunction() {
8699     #if !SILENT_TEST
8700     std::cout << "UNIT TEST: built-in msb() function\n";
8701     #endif
8702    
8703     runScript({
8704     .code = R"NKSP_CODE(
8705     on init
8706     exit( msb(0) )
8707     end on
8708     )NKSP_CODE",
8709     .expectIntExitResult = 0
8710     });
8711    
8712     runScript({
8713     .code = R"NKSP_CODE(
8714     on init
8715     exit( msb(127) )
8716     end on
8717     )NKSP_CODE",
8718     .expectIntExitResult = 0
8719     });
8720    
8721     runScript({
8722     .code = R"NKSP_CODE(
8723     on init
8724     exit( msb(128) )
8725     end on
8726     )NKSP_CODE",
8727     .expectIntExitResult = 1
8728     });
8729    
8730     runScript({
8731     .code = R"NKSP_CODE(
8732     on init
8733     exit( msb(16255) )
8734     end on
8735     )NKSP_CODE",
8736     .expectIntExitResult = 126
8737     });
8738    
8739     runScript({
8740     .code = R"NKSP_CODE(
8741     on init
8742     exit( msb(16256) )
8743     end on
8744     )NKSP_CODE",
8745     .expectIntExitResult = 127
8746     });
8747    
8748     runScript({
8749     .code = R"NKSP_CODE(
8750     on init
8751     exit( msb(16383) )
8752     end on
8753     )NKSP_CODE",
8754     .expectIntExitResult = 127
8755     });
8756    
8757     #if !SILENT_TEST
8758     std::cout << std::endl;
8759     #endif
8760     }
8761    
8762     static void testBuiltInLsbFunction() {
8763     #if !SILENT_TEST
8764     std::cout << "UNIT TEST: built-in lsb() function\n";
8765     #endif
8766    
8767     runScript({
8768     .code = R"NKSP_CODE(
8769     on init
8770     exit( lsb(0) )
8771     end on
8772     )NKSP_CODE",
8773     .expectIntExitResult = 0
8774     });
8775    
8776     runScript({
8777     .code = R"NKSP_CODE(
8778     on init
8779     exit( lsb(1) )
8780     end on
8781     )NKSP_CODE",
8782     .expectIntExitResult = 1
8783     });
8784    
8785     runScript({
8786     .code = R"NKSP_CODE(
8787     on init
8788     exit( lsb(126) )
8789     end on
8790     )NKSP_CODE",
8791     .expectIntExitResult = 126
8792     });
8793    
8794     runScript({
8795     .code = R"NKSP_CODE(
8796     on init
8797     exit( lsb(127) )
8798     end on
8799     )NKSP_CODE",
8800     .expectIntExitResult = 127
8801     });
8802    
8803     runScript({
8804     .code = R"NKSP_CODE(
8805     on init
8806     exit( lsb(128) )
8807     end on
8808     )NKSP_CODE",
8809     .expectIntExitResult = 0
8810     });
8811    
8812     runScript({
8813     .code = R"NKSP_CODE(
8814     on init
8815     exit( lsb(16255) )
8816     end on
8817     )NKSP_CODE",
8818     .expectIntExitResult = 127
8819     });
8820    
8821     runScript({
8822     .code = R"NKSP_CODE(
8823     on init
8824     exit( lsb(16256) )
8825     end on
8826     )NKSP_CODE",
8827     .expectIntExitResult = 0
8828     });
8829    
8830     #if !SILENT_TEST
8831     std::cout << std::endl;
8832     #endif
8833     }
8834    
8835 schoenebeck 3575 static void testBuiltInIntToRealFunction() {
8836     #if !SILENT_TEST
8837     std::cout << "UNIT TEST: built-in int_to_real() function\n";
8838     #endif
8839    
8840     runScript({
8841     .code = R"NKSP_CODE(
8842     on init
8843     exit( int_to_real(8) )
8844     end on
8845     )NKSP_CODE",
8846     .expectRealExitResult = 8.0
8847     });
8848    
8849     runScript({
8850     .code = R"NKSP_CODE(
8851     on init
8852     declare $foo := 23
8853     exit( int_to_real($foo) )
8854     end on
8855     )NKSP_CODE",
8856     .expectRealExitResult = 23.0
8857     });
8858    
8859 schoenebeck 3581 // std unit tests ...
8860    
8861     runScript({
8862     .code = R"NKSP_CODE(
8863     on init
8864     exit( int_to_real(-58mdB) )
8865     end on
8866     )NKSP_CODE",
8867     .expectRealExitResult = -58.0,
8868     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
8869     .expectExitResultUnit = VM_BEL
8870     });
8871    
8872     runScript({
8873     .code = R"NKSP_CODE(
8874     on init
8875     declare $foo := -58mdB
8876     exit( int_to_real($foo) )
8877     end on
8878     )NKSP_CODE",
8879     .expectRealExitResult = -58.0,
8880     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
8881     .expectExitResultUnit = VM_BEL
8882     });
8883    
8884     // 'final' ('!') operator tests ...
8885    
8886     runScript({
8887     .code = R"NKSP_CODE(
8888     on init
8889     declare $foo := !-58
8890     exit( int_to_real($foo) )
8891     end on
8892     )NKSP_CODE",
8893     .expectRealExitResult = -58.0,
8894     .expectExitResultFinal = true
8895     });
8896    
8897     runScript({
8898     .code = R"NKSP_CODE(
8899     on init
8900     declare $foo := -58
8901     exit( int_to_real($foo) )
8902     end on
8903     )NKSP_CODE",
8904     .expectRealExitResult = -58.0,
8905     .expectExitResultFinal = false
8906     });
8907    
8908 schoenebeck 3575 #if !SILENT_TEST
8909     std::cout << std::endl;
8910     #endif
8911     }
8912    
8913     static void testBuiltInRealFunction() {
8914     #if !SILENT_TEST
8915     std::cout << "UNIT TEST: built-in real() function\n";
8916     #endif
8917    
8918     runScript({
8919     .code = R"NKSP_CODE(
8920     on init
8921     exit( real(8) )
8922     end on
8923     )NKSP_CODE",
8924     .expectRealExitResult = 8.0
8925     });
8926    
8927     runScript({
8928     .code = R"NKSP_CODE(
8929     on init
8930     declare $foo := 23
8931     exit( real($foo) )
8932     end on
8933     )NKSP_CODE",
8934     .expectRealExitResult = 23.0
8935     });
8936    
8937 schoenebeck 3581 // std unit tests ...
8938    
8939     runScript({
8940     .code = R"NKSP_CODE(
8941     on init
8942     exit( real(-58mdB) )
8943     end on
8944     )NKSP_CODE",
8945     .expectRealExitResult = -58.0,
8946     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
8947     .expectExitResultUnit = VM_BEL
8948     });
8949    
8950     runScript({
8951     .code = R"NKSP_CODE(
8952     on init
8953     declare $foo := -58mdB
8954     exit( real($foo) )
8955     end on
8956     )NKSP_CODE",
8957     .expectRealExitResult = -58.0,
8958     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
8959     .expectExitResultUnit = VM_BEL
8960     });
8961    
8962     // 'final' ('!') operator tests ...
8963    
8964     runScript({
8965     .code = R"NKSP_CODE(
8966     on init
8967     declare $foo := !-58
8968     exit( real($foo) )
8969     end on
8970     )NKSP_CODE",
8971     .expectRealExitResult = -58.0,
8972     .expectExitResultFinal = true
8973     });
8974    
8975     runScript({
8976     .code = R"NKSP_CODE(
8977     on init
8978     declare $foo := -58
8979     exit( real($foo) )
8980     end on
8981     )NKSP_CODE",
8982     .expectRealExitResult = -58.0,
8983     .expectExitResultFinal = false
8984     });
8985    
8986 schoenebeck 3575 #if !SILENT_TEST
8987     std::cout << std::endl;
8988     #endif
8989     }
8990    
8991     static void testBuiltInRealToIntFunction() {
8992     #if !SILENT_TEST
8993     std::cout << "UNIT TEST: built-in real_to_int() function\n";
8994     #endif
8995    
8996     runScript({
8997     .code = R"NKSP_CODE(
8998     on init
8999     exit( real_to_int(8.9) )
9000     end on
9001     )NKSP_CODE",
9002     .expectIntExitResult = 8
9003     });
9004    
9005     runScript({
9006     .code = R"NKSP_CODE(
9007     on init
9008     declare ~foo := 8.9
9009     exit( real_to_int(~foo) )
9010     end on
9011     )NKSP_CODE",
9012     .expectIntExitResult = 8
9013     });
9014    
9015 schoenebeck 3581 // std unit tests ...
9016    
9017     runScript({
9018     .code = R"NKSP_CODE(
9019     on init
9020     declare ~foo := 8.9mdB
9021     exit( real_to_int(~foo) )
9022     end on
9023     )NKSP_CODE",
9024     .expectIntExitResult = 8,
9025     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
9026     .expectExitResultUnit = VM_BEL
9027     });
9028    
9029     // 'final' ('!') operator tests ...
9030    
9031     runScript({
9032     .code = R"NKSP_CODE(
9033     on init
9034     declare ~foo := !8.9
9035     exit( real_to_int(~foo) )
9036     end on
9037     )NKSP_CODE",
9038     .expectIntExitResult = 8,
9039     .expectExitResultFinal = true
9040     });
9041    
9042     runScript({
9043     .code = R"NKSP_CODE(
9044     on init
9045     declare ~foo := 8.9
9046     exit( real_to_int(~foo) )
9047     end on
9048     )NKSP_CODE",
9049     .expectIntExitResult = 8,
9050     .expectExitResultFinal = false
9051     });
9052    
9053 schoenebeck 3575 #if !SILENT_TEST
9054     std::cout << std::endl;
9055     #endif
9056     }
9057    
9058     static void testBuiltInIntFunction() {
9059     #if !SILENT_TEST
9060     std::cout << "UNIT TEST: built-in int() function\n";
9061     #endif
9062    
9063     runScript({
9064     .code = R"NKSP_CODE(
9065     on init
9066     exit( int(8.9) )
9067     end on
9068     )NKSP_CODE",
9069     .expectIntExitResult = 8
9070     });
9071    
9072     runScript({
9073     .code = R"NKSP_CODE(
9074     on init
9075     declare ~foo := 8.9
9076     exit( int(~foo) )
9077     end on
9078     )NKSP_CODE",
9079     .expectIntExitResult = 8
9080     });
9081    
9082 schoenebeck 3581 // std unit tests ...
9083    
9084     runScript({
9085     .code = R"NKSP_CODE(
9086     on init
9087     declare ~foo := 8.9mdB
9088     exit( int(~foo) )
9089     end on
9090     )NKSP_CODE",
9091     .expectIntExitResult = 8,
9092     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
9093     .expectExitResultUnit = VM_BEL
9094     });
9095    
9096     // 'final' ('!') operator tests ...
9097    
9098     runScript({
9099     .code = R"NKSP_CODE(
9100     on init
9101     declare ~foo := !8.9
9102     exit( int(~foo) )
9103     end on
9104     )NKSP_CODE",
9105     .expectIntExitResult = 8,
9106     .expectExitResultFinal = true
9107     });
9108    
9109     runScript({
9110     .code = R"NKSP_CODE(
9111     on init
9112     declare ~foo := 8.9
9113     exit( int(~foo) )
9114     end on
9115     )NKSP_CODE",
9116     .expectIntExitResult = 8,
9117     .expectExitResultFinal = false
9118     });
9119    
9120 schoenebeck 3575 #if !SILENT_TEST
9121     std::cout << std::endl;
9122     #endif
9123     }
9124    
9125 schoenebeck 3551 static void testBuiltInArrayEqualFunction() {
9126     #if !SILENT_TEST
9127     std::cout << "UNIT TEST: built-in array_equal() function\n";
9128     #endif
9129    
9130 schoenebeck 3581 // integer array tests ...
9131    
9132 schoenebeck 3551 runScript({
9133     .code = R"NKSP_CODE(
9134     on init
9135     declare %foo[3] := ( 1, 2, 3 )
9136     declare %bar[3] := ( 1, 2, 3 )
9137     exit( array_equal(%foo, %bar) )
9138     end on
9139     )NKSP_CODE",
9140     .expectBoolExitResult = true
9141     });
9142    
9143     runScript({
9144     .code = R"NKSP_CODE(
9145     on init
9146     declare %foo[1] := ( 1 )
9147     declare %bar[1] := ( 1 )
9148     exit( array_equal(%foo, %bar) )
9149     end on
9150     )NKSP_CODE",
9151     .expectBoolExitResult = true
9152     });
9153    
9154     runScript({
9155     .code = R"NKSP_CODE(
9156     on init
9157     declare %foo[3] := ( 1, 2, 3 )
9158     declare %bar[3] := ( 0, 2, 3 )
9159     exit( array_equal(%foo, %bar) )
9160     end on
9161     )NKSP_CODE",
9162     .expectBoolExitResult = false
9163     });
9164    
9165     runScript({
9166     .code = R"NKSP_CODE(
9167     on init
9168     declare %foo[3] := ( 1, 2, 3 )
9169     declare %bar[3] := ( 3, 2, 1 )
9170     exit( array_equal(%foo, %bar) )
9171     end on
9172     )NKSP_CODE",
9173     .expectBoolExitResult = false
9174     });
9175    
9176     runScript({
9177     .code = R"NKSP_CODE(
9178     on init
9179     declare %foo[3] := ( 1, 2, 3 )
9180     declare %bar[2] := ( 1, 2 )
9181     exit( array_equal(%foo, %bar) )
9182     end on
9183     )NKSP_CODE",
9184 schoenebeck 3581 .expectBoolExitResult = false,
9185     .expectParseWarning = true // array_equal() warns if array sizes do not match
9186     });
9187    
9188     // real number array tests ...
9189    
9190     runScript({
9191     .code = R"NKSP_CODE(
9192     on init
9193     declare ?foo[3] := ( 1.0, 2.0, 3.0 )
9194     declare ?bar[3] := ( 1.0, 2.0, 3.0 )
9195     exit( array_equal(?foo, ?bar) )
9196     end on
9197     )NKSP_CODE",
9198     .expectBoolExitResult = true
9199     });
9200    
9201     runScript({
9202     .code = R"NKSP_CODE(
9203     on init
9204     declare ?foo[3] := ( 1.0, 1.1, 3.4 )
9205     declare ?bar[3] := ( 1.0, 1.1, 3.4 )
9206     exit( array_equal(?foo, ?bar) )
9207     end on
9208     )NKSP_CODE",
9209     .expectBoolExitResult = true
9210     });
9211    
9212     runScript({
9213     .code = R"NKSP_CODE(
9214     on init
9215     declare ?foo[3] := ( 1.0, 1.1, 3.4 )
9216     declare ?bar[3] := ( 1.0, 1.2, 3.4 )
9217     exit( array_equal(?foo, ?bar) )
9218     end on
9219     )NKSP_CODE",
9220 schoenebeck 3551 .expectBoolExitResult = false
9221     });
9222    
9223 schoenebeck 3581 runScript({
9224     .code = R"NKSP_CODE(
9225     on init
9226     declare ?foo[3] := ( 1.0, 1.1, 3.4 )
9227     declare ?bar[2] := ( 1.0, 1.1 )
9228     exit( array_equal(?foo, ?bar) )
9229     end on
9230     )NKSP_CODE",
9231     .expectBoolExitResult = false,
9232     .expectParseWarning = true // array_equal() warns if array sizes do not match
9233     });
9234    
9235     // std unit tests ...
9236     // (only metric prefixes allowed, unit types are prohibited for arrays ATM)
9237    
9238     runScript({
9239     .code = R"NKSP_CODE(
9240     on init
9241     declare %foo[3] := ( 1, 1s, 1 )
9242     declare %bar[3] := ( 1, 1, 1 )
9243     exit( array_equal(%foo, %bar) )
9244     end on
9245     )NKSP_CODE",
9246     .expectParseError = true // see comment above
9247     });
9248    
9249     runScript({
9250     .code = R"NKSP_CODE(
9251     on init
9252     declare %foo[3] := ( 1k, 1, 1m )
9253     declare %bar[3] := ( 1k, 1, 1m )
9254     exit( array_equal(%foo, %bar) )
9255     end on
9256     )NKSP_CODE",
9257     .expectBoolExitResult = true
9258     });
9259    
9260     runScript({
9261     .code = R"NKSP_CODE(
9262     on init
9263     declare %foo[3] := ( 1m, 1, 1k )
9264     declare %bar[3] := ( 1k, 1, 1m )
9265     exit( array_equal(%foo, %bar) )
9266     end on
9267     )NKSP_CODE",
9268     .expectBoolExitResult = false
9269     });
9270    
9271     runScript({
9272     .code = R"NKSP_CODE(
9273     on init
9274     declare %foo[3] := ( 1, 1k, 1 )
9275     declare %bar[3] := ( 1, 1, 1 )
9276     exit( array_equal(%foo, %bar) )
9277     end on
9278     )NKSP_CODE",
9279     .expectBoolExitResult = false
9280     });
9281    
9282     runScript({
9283     .code = R"NKSP_CODE(
9284     on init
9285     declare %foo[3] := ( 1, 1k, 1 )
9286     declare %bar[3] := ( 1, 1000, 1 )
9287     exit( array_equal(%foo, %bar) )
9288     end on
9289     )NKSP_CODE",
9290     .expectBoolExitResult = true
9291     });
9292    
9293     runScript({
9294     .code = R"NKSP_CODE(
9295     on init
9296     declare %foo[3] := ( 1, 2, 3000 )
9297     declare %bar[3] := ( 1, 2, 3k )
9298     exit( array_equal(%foo, %bar) )
9299     end on
9300     )NKSP_CODE",
9301     .expectBoolExitResult = true
9302     });
9303    
9304     runScript({
9305     .code = R"NKSP_CODE(
9306     on init
9307     declare %foo[3] := ( 1, 2, 3m )
9308     declare %bar[3] := ( 1, 2, 3k )
9309     exit( array_equal(%foo, %bar) )
9310     end on
9311     )NKSP_CODE",
9312     .expectBoolExitResult = false
9313     });
9314    
9315     runScript({
9316     .code = R"NKSP_CODE(
9317     on init
9318     declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
9319     declare ?bar[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
9320     exit( array_equal(?foo, ?bar) )
9321     end on
9322     )NKSP_CODE",
9323     .expectBoolExitResult = true
9324     });
9325    
9326     runScript({
9327     .code = R"NKSP_CODE(
9328     on init
9329     declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
9330     declare ?bar[4] := ( 1.0, 1.0 , 1.1m, 3.4k )
9331     exit( array_equal(?foo, ?bar) )
9332     end on
9333     )NKSP_CODE",
9334     .expectBoolExitResult = false
9335     });
9336    
9337     runScript({
9338     .code = R"NKSP_CODE(
9339     on init
9340     declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
9341     declare ?bar[4] := ( 1.0, 1.0m, 1.1k, 3.4k )
9342     exit( array_equal(?foo, ?bar) )
9343     end on
9344     )NKSP_CODE",
9345     .expectBoolExitResult = false
9346     });
9347    
9348     runScript({
9349     .code = R"NKSP_CODE(
9350     on init
9351     declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
9352     declare ?bar[4] := ( 1.0, 1.0m, 1.1m, 3.4u )
9353     exit( array_equal(?foo, ?bar) )
9354     end on
9355     )NKSP_CODE",
9356     .expectBoolExitResult = false
9357     });
9358    
9359     runScript({
9360     .code = R"NKSP_CODE(
9361     on init
9362     declare ?foo[3] := ( 1.0, 1.0k, 1.1m )
9363     declare ?bar[3] := ( 1.0, 1000.0, 1.1m )
9364     exit( array_equal(?foo, ?bar) )
9365     end on
9366     )NKSP_CODE",
9367     .expectBoolExitResult = true
9368     });
9369    
9370     runScript({
9371     .code = R"NKSP_CODE(
9372     on init
9373     declare ?foo[3] := ( 1.0, 1.0k, 1.1u )
9374     declare ?bar[3] := ( 1.0, 1000.0, 0.0011m )
9375     exit( array_equal(?foo, ?bar) )
9376     end on
9377     )NKSP_CODE",
9378     .expectBoolExitResult = true
9379     });
9380    
9381     runScript({
9382     .code = R"NKSP_CODE(
9383     on init
9384     declare ?foo[3] := ( 1.0, 1.0k, 1.1u )
9385     declare ?bar[3] := ( 1.0, 1000.0, 0.0016m )
9386     exit( array_equal(?foo, ?bar) )
9387     end on
9388     )NKSP_CODE",
9389     .expectBoolExitResult = false
9390     });
9391    
9392     // 'final' ('!') operator tests ...
9393     // (currently prohibited for arrays)
9394    
9395     runScript({
9396     .code = R"NKSP_CODE(
9397     on init
9398     declare %foo[3] := ( !1, !1, !1 )
9399     declare %bar[3] := ( !1, !1, !1 )
9400     exit( array_equal(%foo, %bar) )
9401     end on
9402     )NKSP_CODE",
9403     .expectParseError = true // see comment above
9404     });
9405    
9406     runScript({
9407     .code = R"NKSP_CODE(
9408     on init
9409     declare ?foo[3] := ( !1.0, !1.0, !1.0 )
9410     declare ?bar[3] := ( !1.0, !1.0, !1.0 )
9411     exit( array_equal(?foo, ?bar) )
9412     end on
9413     )NKSP_CODE",
9414     .expectParseError = true // see comment above
9415     });
9416    
9417 schoenebeck 3551 #if !SILENT_TEST
9418     std::cout << std::endl;
9419     #endif
9420     }
9421    
9422     static void testBuiltInSortFunction() {
9423     #if !SILENT_TEST
9424     std::cout << "UNIT TEST: built-in sort() function\n";
9425     #endif
9426    
9427 schoenebeck 3581 // integer array tests ...
9428    
9429 schoenebeck 3551 runScript({
9430     .code = R"NKSP_CODE(
9431     on init
9432     declare %input[3] := ( 19, 3, 6 )
9433     declare %expected[3] := ( 3, 6, 19 )
9434     sort(%input, 0)
9435     exit( array_equal(%input, %expected) )
9436     end on
9437     )NKSP_CODE",
9438     .expectBoolExitResult = true
9439     });
9440    
9441     runScript({
9442     .code = R"NKSP_CODE(
9443     on init
9444     declare %input[3] := ( 19, 3, 6 )
9445     declare %expected[3] := ( 19, 6, 3 )
9446     sort(%input, 1)
9447     exit( array_equal(%input, %expected) )
9448     end on
9449     )NKSP_CODE",
9450     .expectBoolExitResult = true
9451     });
9452    
9453 schoenebeck 3581 runScript({
9454     .code = R"NKSP_CODE(
9455     on init
9456     declare %input[6] := ( 1, 80, 120, 40, 3000, 20 )
9457     declare %expected[6] := ( 1, 20, 40, 80, 120, 3000 )
9458     sort(%input, 0)
9459     exit( array_equal(%input, %expected) )
9460     end on
9461     )NKSP_CODE",
9462     .expectBoolExitResult = true
9463     });
9464    
9465     // real number array tests ...
9466    
9467     runScript({
9468     .code = R"NKSP_CODE(
9469     on init
9470     declare ?input[4] := ( 1.4, 1.0, 13.4, 2.7 )
9471     declare ?expected[4] := ( 1.0, 1.4, 2.7, 13.4 )
9472     sort(?input, 0)
9473     exit( array_equal(?input, ?expected) )
9474     end on
9475     )NKSP_CODE",
9476     .expectBoolExitResult = true
9477     });
9478    
9479     runScript({
9480     .code = R"NKSP_CODE(
9481     on init
9482     declare ?input[4] := ( 1.4, 1.0, 13.4, 2.7 )
9483     declare ?expected[4] := ( 13.4, 2.7, 1.4, 1.0 )
9484     sort(?input, 1)
9485     exit( array_equal(?input, ?expected) )
9486     end on
9487     )NKSP_CODE",
9488     .expectBoolExitResult = true
9489     });
9490    
9491     // std unit tests ...
9492     // (only metric prefixes are allowed for arrays ATM)
9493    
9494     runScript({
9495     .code = R"NKSP_CODE(
9496     on init
9497     declare %input[3] := ( 1k, 6, 900 )
9498     declare %expected[3] := ( 6, 900, 1k )
9499     sort(%input, 0)
9500     exit( array_equal(%input, %expected) )
9501     end on
9502     )NKSP_CODE",
9503     .expectBoolExitResult = true
9504     });
9505    
9506     runScript({
9507     .code = R"NKSP_CODE(
9508     on init
9509     declare %input[3] := ( 900, 1k, 6 )
9510     declare %expected[3] := ( 1k, 900, 6 )
9511     sort(%input, 1)
9512     exit( array_equal(%input, %expected) )
9513     end on
9514     )NKSP_CODE",
9515     .expectBoolExitResult = true
9516     });
9517    
9518     runScript({
9519     .code = R"NKSP_CODE(
9520     on init
9521     declare %input[6] := ( 1k, 8m, 4k, 12000u, 3000u, 1000u )
9522     declare %expected[6] := ( 1000u, 3000u, 8m, 12000u, 1k, 4k )
9523     sort(%input, 0)
9524     exit( array_equal(%input, %expected) )
9525     end on
9526     )NKSP_CODE",
9527     .expectBoolExitResult = true
9528     });
9529    
9530     runScript({
9531     .code = R"NKSP_CODE(
9532     on init
9533     declare ?input[3] := ( 1.0k, 6.0, 900.0 )
9534     declare ?expected[3] := ( 6.0, 900.0, 1.0k )
9535     sort(?input, 0)
9536     exit( array_equal(?input, ?expected) )
9537     end on
9538     )NKSP_CODE",
9539     .expectBoolExitResult = true
9540     });
9541    
9542     runScript({
9543     .code = R"NKSP_CODE(
9544     on init
9545     declare ?input[3] := ( 900.0, 1.0k, 6.0 )
9546     declare ?expected[3] := ( 1.0k, 900.0, 6.0 )
9547     sort(?input, 1)
9548     exit( array_equal(?input, ?expected) )
9549     end on
9550     )NKSP_CODE",
9551     .expectBoolExitResult = true
9552     });
9553    
9554     runScript({
9555     .code = R"NKSP_CODE(
9556     on init
9557     declare ?input[3] := ( 1.0k, 0.9k, 1.1k )
9558     declare ?expected[3] := ( 0.9k, 1.0k, 1.1k )
9559     sort(?input, 0)
9560     exit( array_equal(?input, ?expected) )
9561     end on
9562     )NKSP_CODE",
9563     .expectBoolExitResult = true
9564     });
9565    
9566     runScript({
9567     .code = R"NKSP_CODE(
9568     on init
9569     declare ?input[3] := ( 2.0m, 1000.1u, 1.0 )
9570     declare ?expected[3] := ( 1000.1u, 2.0m, 1.0 )
9571     sort(?input, 0)
9572     exit( array_equal(?input, ?expected) )
9573     end on
9574     )NKSP_CODE",
9575     .expectBoolExitResult = true
9576     });
9577    
9578     runScript({
9579     .code = R"NKSP_CODE(
9580     on init
9581     declare ?input[4] := ( 2.0m, 1000.1u, 1.0, 1400.0u )
9582     declare ?expected[4] := ( 1000.1u, 1400.0u, 2.0m, 1.0 )
9583     sort(?input, 0)
9584     exit( array_equal(?input, ?expected) )
9585     end on
9586     )NKSP_CODE",
9587     .expectBoolExitResult = true
9588     });
9589    
9590     runScript({
9591     .code = R"NKSP_CODE(
9592     on init
9593     declare ?input[4] := ( 2.0m, 1000.1u, 1.0, 1400.0u )
9594     declare ?expected[4] := ( 1.0, 2.0m, 1400.0u, 1000.1u )
9595     sort(?input, 1)
9596     exit( array_equal(?input, ?expected) )
9597     end on
9598     )NKSP_CODE",
9599     .expectBoolExitResult = true
9600     });
9601    
9602     runScript({
9603     .code = R"NKSP_CODE(
9604     on init
9605     declare ?input[6] := ( 0.9k, 8.0m, 1.1k, 12000.0u, 3000.0u, 1000.0u )
9606     declare ?expected[6] := ( 1000.0u, 3000.0u, 8.0m, 12000.0u, 0.9k, 1.1k )
9607     sort(?input, 0)
9608     exit( array_equal(?input, ?expected) )
9609     end on
9610     )NKSP_CODE",
9611     .expectBoolExitResult = true
9612     });
9613    
9614     runScript({
9615     .code = R"NKSP_CODE(
9616     on init
9617     declare ?input[6] := ( 0.9k, 8.0m, 1.1k, 12000.0u, 3000.0u, 1000.0u )
9618     declare ?expected[6] := ( 1.1k, 0.9k, 12000.0u, 8.0m, 3000.0u, 1000.0u )
9619     sort(?input, 1)
9620     exit( array_equal(?input, ?expected) )
9621     end on
9622     )NKSP_CODE",
9623     .expectBoolExitResult = true
9624     });
9625    
9626 schoenebeck 3551 #if !SILENT_TEST
9627     std::cout << std::endl;
9628     #endif
9629     }
9630    
9631 schoenebeck 3590 static void testBuiltInRoundFunction() {
9632     #if !SILENT_TEST
9633     std::cout << "UNIT TEST: built-in round() function\n";
9634     #endif
9635    
9636     // integer tests ...
9637     // (ATM not allowed for this function)
9638    
9639     runScript({
9640     .code = R"NKSP_CODE(
9641     on init
9642     declare $foo := 1
9643     exit( round($foo) )
9644     end on
9645     )NKSP_CODE",
9646     .expectParseError = true // integer not allowed for this function ATM
9647     });
9648    
9649     // real number tests ...
9650    
9651     runScript({
9652     .code = R"NKSP_CODE(
9653     on init
9654     exit( round(99.4) )
9655     end on
9656     )NKSP_CODE",
9657     .expectRealExitResult = 99.0
9658     });
9659    
9660     runScript({
9661     .code = R"NKSP_CODE(
9662     on init
9663     exit( round(99.5) )
9664     end on
9665     )NKSP_CODE",
9666     .expectRealExitResult = 100.0
9667     });
9668    
9669     // std unit tests ...
9670    
9671     runScript({
9672     .code = R"NKSP_CODE(
9673     on init
9674     exit( round(2.4ms) )
9675     end on
9676     )NKSP_CODE",
9677     .expectRealExitResult = 2.0,
9678     .expectExitResultUnitPrefix = { VM_MILLI },
9679     .expectExitResultUnit = VM_SECOND
9680     });
9681    
9682     runScript({
9683     .code = R"NKSP_CODE(
9684     on init
9685     exit( round(2.6kHz) )
9686     end on
9687     )NKSP_CODE",
9688     .expectRealExitResult = 3.0,
9689     .expectExitResultUnitPrefix = { VM_KILO },
9690     .expectExitResultUnit = VM_HERTZ
9691     });
9692    
9693     // 'final' ('!') operator tests ...
9694    
9695     runScript({
9696     .code = R"NKSP_CODE(
9697     on init
9698     exit( round(123.8) )
9699     end on
9700     )NKSP_CODE",
9701     .expectRealExitResult = 124.0,
9702     .expectExitResultFinal = false
9703     });
9704    
9705     runScript({
9706     .code = R"NKSP_CODE(
9707     on init
9708     exit( round(!123.8) )
9709     end on
9710     )NKSP_CODE",
9711     .expectRealExitResult = 124.0,
9712     .expectExitResultFinal = true
9713     });
9714    
9715     #if !SILENT_TEST
9716     std::cout << std::endl;
9717     #endif
9718     }
9719    
9720     static void testBuiltInCeilFunction() {
9721     #if !SILENT_TEST
9722     std::cout << "UNIT TEST: built-in ceil() function\n";
9723     #endif
9724    
9725     // integer tests ...
9726     // (ATM not allowed for this function)
9727    
9728     runScript({
9729     .code = R"NKSP_CODE(
9730     on init
9731     declare $foo := 1
9732     exit( ceil($foo) )
9733     end on
9734     )NKSP_CODE",
9735     .expectParseError = true // integer not allowed for this function ATM
9736     });
9737    
9738     // real number tests ...
9739    
9740     runScript({
9741     .code = R"NKSP_CODE(
9742     on init
9743     exit( ceil(99.0) )
9744     end on
9745     )NKSP_CODE",
9746     .expectRealExitResult = 99.0
9747     });
9748    
9749     runScript({
9750     .code = R"NKSP_CODE(
9751     on init
9752     exit( ceil(99.1) )
9753     end on
9754     )NKSP_CODE",
9755     .expectRealExitResult = 100.0
9756     });
9757    
9758     runScript({
9759     .code = R"NKSP_CODE(
9760     on init
9761     exit( ceil(99.9) )
9762     end on
9763     )NKSP_CODE",
9764     .expectRealExitResult = 100.0
9765     });
9766    
9767     // std unit tests ...
9768    
9769     runScript({
9770     .code = R"NKSP_CODE(
9771     on init
9772     exit( ceil(2.4ms) )
9773     end on
9774     )NKSP_CODE",
9775     .expectRealExitResult = 3.0,
9776     .expectExitResultUnitPrefix = { VM_MILLI },
9777     .expectExitResultUnit = VM_SECOND
9778     });
9779    
9780     runScript({
9781     .code = R"NKSP_CODE(
9782     on init
9783     exit( ceil(2.6kHz) )
9784     end on
9785     )NKSP_CODE",
9786     .expectRealExitResult = 3.0,
9787     .expectExitResultUnitPrefix = { VM_KILO },
9788     .expectExitResultUnit = VM_HERTZ
9789     });
9790    
9791     // 'final' ('!') operator tests ...
9792    
9793     runScript({
9794     .code = R"NKSP_CODE(
9795     on init
9796     exit( ceil(123.1) )
9797     end on
9798     )NKSP_CODE",
9799     .expectRealExitResult = 124.0,
9800     .expectExitResultFinal = false
9801     });
9802    
9803     runScript({
9804     .code = R"NKSP_CODE(
9805     on init
9806     exit( ceil(!123.8) )
9807     end on
9808     )NKSP_CODE",
9809     .expectRealExitResult = 124.0,
9810     .expectExitResultFinal = true
9811     });
9812    
9813     #if !SILENT_TEST
9814     std::cout << std::endl;
9815     #endif
9816     }
9817    
9818     static void testBuiltInFloorFunction() {
9819     #if !SILENT_TEST
9820     std::cout << "UNIT TEST: built-in floor() function\n";
9821     #endif
9822    
9823     // integer tests ...
9824     // (ATM not allowed for this function)
9825    
9826     runScript({
9827     .code = R"NKSP_CODE(
9828     on init
9829     declare $foo := 1
9830     exit( floor($foo) )
9831     end on
9832     )NKSP_CODE",
9833     .expectParseError = true // integer not allowed for this function ATM
9834     });
9835    
9836     // real number tests ...
9837    
9838     runScript({
9839     .code = R"NKSP_CODE(
9840     on init
9841     exit( floor(99.0) )
9842     end on
9843     )NKSP_CODE",
9844     .expectRealExitResult = 99.0
9845     });
9846    
9847     runScript({
9848     .code = R"NKSP_CODE(
9849     on init
9850     exit( floor(99.1) )
9851     end on
9852     )NKSP_CODE",
9853     .expectRealExitResult = 99.0
9854     });
9855    
9856     runScript({
9857     .code = R"NKSP_CODE(
9858     on init
9859     exit( floor(99.9) )
9860     end on
9861     )NKSP_CODE",
9862     .expectRealExitResult = 99.0
9863     });
9864    
9865     // std unit tests ...
9866    
9867     runScript({
9868     .code = R"NKSP_CODE(
9869     on init
9870     exit( floor(2.4ms) )
9871     end on
9872     )NKSP_CODE",
9873     .expectRealExitResult = 2.0,
9874     .expectExitResultUnitPrefix = { VM_MILLI },
9875     .expectExitResultUnit = VM_SECOND
9876     });
9877    
9878     runScript({
9879     .code = R"NKSP_CODE(
9880     on init
9881     exit( floor(2.6kHz) )
9882     end on
9883     )NKSP_CODE",
9884     .expectRealExitResult = 2.0,
9885     .expectExitResultUnitPrefix = { VM_KILO },
9886     .expectExitResultUnit = VM_HERTZ
9887     });
9888    
9889     // 'final' ('!') operator tests ...
9890    
9891     runScript({
9892     .code = R"NKSP_CODE(
9893     on init
9894     exit( floor(123.1) )
9895     end on
9896     )NKSP_CODE",
9897     .expectRealExitResult = 123.0,
9898     .expectExitResultFinal = false
9899     });
9900    
9901     runScript({
9902     .code = R"NKSP_CODE(
9903     on init
9904     exit( floor(!123.8) )
9905     end on
9906     )NKSP_CODE",
9907     .expectRealExitResult = 123.0,
9908     .expectExitResultFinal = true
9909     });
9910    
9911     #if !SILENT_TEST
9912     std::cout << std::endl;
9913     #endif
9914     }
9915    
9916     static void testBuiltInSqrtFunction() {
9917     #if !SILENT_TEST
9918     std::cout << "UNIT TEST: built-in sqrt() function\n";
9919     #endif
9920    
9921     // integer tests ...
9922     // (ATM not allowed for this function)
9923    
9924     runScript({
9925     .code = R"NKSP_CODE(
9926     on init
9927     declare $foo := 1
9928     exit( sqrt($foo) )
9929     end on
9930     )NKSP_CODE",
9931     .expectParseError = true // integer not allowed for this function ATM
9932     });
9933    
9934     // real number tests ...
9935    
9936     runScript({
9937     .code = R"NKSP_CODE(
9938     on init
9939     exit( sqrt(36.0) )
9940     end on
9941     )NKSP_CODE",
9942     .expectRealExitResult = 6.0
9943     });
9944    
9945     // std unit tests ...
9946    
9947     runScript({
9948     .code = R"NKSP_CODE(
9949     on init
9950     exit( sqrt(100.0ms) )
9951     end on
9952     )NKSP_CODE",
9953     .expectRealExitResult = 10.0,
9954     .expectExitResultUnitPrefix = { VM_MILLI },
9955     .expectExitResultUnit = VM_SECOND
9956     });
9957    
9958     runScript({
9959     .code = R"NKSP_CODE(
9960     on init
9961     exit( sqrt(5.76kHz) )
9962     end on
9963     )NKSP_CODE",
9964     .expectRealExitResult = 2.4,
9965     .expectExitResultUnitPrefix = { VM_KILO },
9966     .expectExitResultUnit = VM_HERTZ
9967     });
9968    
9969     // 'final' ('!') operator tests ...
9970    
9971     runScript({
9972     .code = R"NKSP_CODE(
9973     on init
9974     exit( sqrt(25.0) )
9975     end on
9976     )NKSP_CODE",
9977     .expectRealExitResult = 5.0,
9978     .expectExitResultFinal = false
9979     });
9980    
9981     runScript({
9982     .code = R"NKSP_CODE(
9983     on init
9984     exit( sqrt(!25.0) )
9985     end on
9986     )NKSP_CODE",
9987     .expectRealExitResult = 5.0,
9988     .expectExitResultFinal = true
9989     });
9990    
9991     #if !SILENT_TEST
9992     std::cout << std::endl;
9993     #endif
9994     }
9995    
9996     static void testBuiltInLogFunction() {
9997     #if !SILENT_TEST
9998     std::cout << "UNIT TEST: built-in log() function\n";
9999     #endif
10000    
10001     // integer tests ...
10002     // (ATM not allowed for this function)
10003    
10004     runScript({
10005     .code = R"NKSP_CODE(
10006     on init
10007     declare $foo := 1
10008     exit( log($foo) )
10009     end on
10010     )NKSP_CODE",
10011     .expectParseError = true // integer not allowed for this function ATM
10012     });
10013    
10014     // real number tests ...
10015    
10016     runScript({
10017     .code = R"NKSP_CODE(
10018     on init
10019     exit( log(1.0) )
10020     end on
10021     )NKSP_CODE",
10022     .expectRealExitResult = 0.0
10023     });
10024    
10025     runScript({
10026     .code = R"NKSP_CODE(
10027     on init
10028     exit( log(~NI_MATH_E) )
10029     end on
10030     )NKSP_CODE",
10031     .expectRealExitResult = 1.0
10032     });
10033    
10034     // std unit tests ...
10035    
10036     runScript({
10037     .code = R"NKSP_CODE(
10038     on init
10039     exit( log(~NI_MATH_E * 1.0ms) )
10040     end on
10041     )NKSP_CODE",
10042     .expectRealExitResult = 1.0,
10043     .expectExitResultUnitPrefix = { VM_MILLI },
10044     .expectExitResultUnit = VM_SECOND
10045     });
10046    
10047     runScript({
10048     .code = R"NKSP_CODE(
10049     on init
10050     exit( log(~NI_MATH_E * 1.0kHz) )
10051     end on
10052     )NKSP_CODE",
10053     .expectRealExitResult = 1.0,
10054     .expectExitResultUnitPrefix = { VM_KILO },
10055     .expectExitResultUnit = VM_HERTZ
10056     });
10057    
10058     // 'final' ('!') operator tests ...
10059    
10060     runScript({
10061     .code = R"NKSP_CODE(
10062     on init
10063     exit( log(~NI_MATH_E * 1.0) )
10064     end on
10065     )NKSP_CODE",
10066     .expectRealExitResult = 1.0,
10067     .expectExitResultFinal = false
10068     });
10069    
10070     runScript({
10071     .code = R"NKSP_CODE(
10072     on init
10073     exit( log(!(~NI_MATH_E * 1.0)) )
10074     end on
10075     )NKSP_CODE",
10076     .expectRealExitResult = 1.0,
10077     .expectExitResultFinal = true
10078     });
10079    
10080     #if !SILENT_TEST
10081     std::cout << std::endl;
10082     #endif
10083     }
10084    
10085     static void testBuiltInLog2Function() {
10086     #if !SILENT_TEST
10087     std::cout << "UNIT TEST: built-in log2() function\n";
10088     #endif
10089    
10090     // integer tests ...
10091     // (ATM not allowed for this function)
10092    
10093     runScript({
10094     .code = R"NKSP_CODE(
10095     on init
10096     declare $foo := 1
10097     exit( log2($foo) )
10098     end on
10099     )NKSP_CODE",
10100     .expectParseError = true // integer not allowed for this function ATM
10101     });
10102    
10103     // real number tests ...
10104    
10105     runScript({
10106     .code = R"NKSP_CODE(
10107     on init
10108     exit( log2(1.0) )
10109     end on
10110     )NKSP_CODE",
10111     .expectRealExitResult = 0.0
10112     });
10113    
10114     runScript({
10115     .code = R"NKSP_CODE(
10116     on init
10117     exit( log2(32.0) )
10118     end on
10119     )NKSP_CODE",
10120     .expectRealExitResult = 5.0
10121     });
10122    
10123     // std unit tests ...
10124    
10125     runScript({
10126     .code = R"NKSP_CODE(
10127     on init
10128     exit( log2(32.0ms) )
10129     end on
10130     )NKSP_CODE",
10131     .expectRealExitResult = 5.0,
10132     .expectExitResultUnitPrefix = { VM_MILLI },
10133     .expectExitResultUnit = VM_SECOND
10134     });
10135    
10136     runScript({
10137     .code = R"NKSP_CODE(
10138     on init
10139     exit( log2(32.0kHz) )
10140     end on
10141     )NKSP_CODE",
10142     .expectRealExitResult = 5.0,
10143     .expectExitResultUnitPrefix = { VM_KILO },
10144     .expectExitResultUnit = VM_HERTZ
10145     });
10146    
10147     // 'final' ('!') operator tests ...
10148    
10149     runScript({
10150     .code = R"NKSP_CODE(
10151     on init
10152     exit( log2(32.0) )
10153     end on
10154     )NKSP_CODE",
10155     .expectRealExitResult = 5.0,
10156     .expectExitResultFinal = false
10157     });
10158    
10159     runScript({
10160     .code = R"NKSP_CODE(
10161     on init
10162     exit( log2(!32.0) )
10163     end on
10164     )NKSP_CODE",
10165     .expectRealExitResult = 5.0,
10166     .expectExitResultFinal = true
10167     });
10168    
10169     #if !SILENT_TEST
10170     std::cout << std::endl;
10171     #endif
10172     }
10173    
10174     static void testBuiltInLog10Function() {
10175     #if !SILENT_TEST
10176     std::cout << "UNIT TEST: built-in log10() function\n";
10177     #endif
10178    
10179     // integer tests ...
10180     // (ATM not allowed for this function)
10181    
10182     runScript({
10183     .code = R"NKSP_CODE(
10184     on init
10185     declare $foo := 1
10186     exit( log10($foo) )
10187     end on
10188     )NKSP_CODE",
10189     .expectParseError = true // integer not allowed for this function ATM
10190     });
10191    
10192     // real number tests ...
10193    
10194     runScript({
10195     .code = R"NKSP_CODE(
10196     on init
10197     exit( log10(1000.0) )
10198     end on
10199     )NKSP_CODE",
10200     .expectRealExitResult = 3.0
10201     });
10202    
10203     runScript({
10204     .code = R"NKSP_CODE(
10205     on init
10206     exit( log10(1000.0) )
10207     end on
10208     )NKSP_CODE",
10209     .expectRealExitResult = 3.0
10210     });
10211    
10212     // std unit tests ...
10213    
10214     runScript({
10215     .code = R"NKSP_CODE(
10216     on init
10217     exit( log10(1000.0ms) )
10218     end on
10219     )NKSP_CODE",
10220     .expectRealExitResult = 3.0,
10221     .expectExitResultUnitPrefix = { VM_MILLI },
10222     .expectExitResultUnit = VM_SECOND
10223     });
10224    
10225     runScript({
10226     .code = R"NKSP_CODE(
10227     on init
10228     exit( log10(1000.0kHz) )
10229     end on
10230     )NKSP_CODE",
10231     .expectRealExitResult = 3.0,
10232     .expectExitResultUnitPrefix = { VM_KILO },
10233     .expectExitResultUnit = VM_HERTZ
10234     });
10235    
10236     // 'final' ('!') operator tests ...
10237    
10238     runScript({
10239     .code = R"NKSP_CODE(
10240     on init
10241     exit( log10(1000.0) )
10242     end on
10243     )NKSP_CODE",
10244     .expectRealExitResult = 3.0,
10245     .expectExitResultFinal = false
10246     });
10247    
10248     runScript({
10249     .code = R"NKSP_CODE(
10250     on init
10251     exit( log10(!1000.0) )
10252     end on
10253     )NKSP_CODE",
10254     .expectRealExitResult = 3.0,
10255     .expectExitResultFinal = true
10256     });
10257    
10258     #if !SILENT_TEST
10259     std::cout << std::endl;
10260     #endif
10261     }
10262    
10263     static void testBuiltInExpFunction() {
10264     #if !SILENT_TEST
10265     std::cout << "UNIT TEST: built-in exp() function\n";
10266     #endif
10267    
10268     // integer tests ...
10269     // (ATM not allowed for this function)
10270    
10271     runScript({
10272     .code = R"NKSP_CODE(
10273     on init
10274     declare $foo := 1
10275     exit( exp($foo) )
10276     end on
10277     )NKSP_CODE",
10278     .expectParseError = true // integer not allowed for this function ATM
10279     });
10280    
10281     // real number tests ...
10282    
10283     runScript({
10284     .code = R"NKSP_CODE(
10285     on init
10286     exit( exp(0.0) )
10287     end on
10288     )NKSP_CODE",
10289     .expectRealExitResult = 1.0
10290     });
10291    
10292     runScript({
10293     .code = R"NKSP_CODE(
10294     on init
10295     exit( exp(1.0) )
10296     end on
10297     )NKSP_CODE",
10298     .expectRealExitResult = M_E
10299     });
10300    
10301     // std unit tests ...
10302    
10303     runScript({
10304     .code = R"NKSP_CODE(
10305     on init
10306     exit( exp(0.0ms) )
10307     end on
10308     )NKSP_CODE",
10309     .expectRealExitResult = 1.0,
10310     .expectExitResultUnitPrefix = { VM_MILLI },
10311     .expectExitResultUnit = VM_SECOND
10312     });
10313    
10314     runScript({
10315     .code = R"NKSP_CODE(
10316     on init
10317     exit( exp(0.0kHz) )
10318     end on
10319     )NKSP_CODE",
10320     .expectRealExitResult = 1.0,
10321     .expectExitResultUnitPrefix = { VM_KILO },
10322     .expectExitResultUnit = VM_HERTZ
10323     });
10324    
10325     // 'final' ('!') operator tests ...
10326    
10327     runScript({
10328     .code = R"NKSP_CODE(
10329     on init
10330     exit( exp(0.0) )
10331     end on
10332     )NKSP_CODE",
10333     .expectRealExitResult = 1.0,
10334     .expectExitResultFinal = false
10335     });
10336    
10337     runScript({
10338     .code = R"NKSP_CODE(
10339     on init
10340     exit( exp(!0.0) )
10341     end on
10342     )NKSP_CODE",
10343     .expectRealExitResult = 1.0,
10344     .expectExitResultFinal = true
10345     });
10346    
10347     #if !SILENT_TEST
10348     std::cout << std::endl;
10349     #endif
10350     }
10351    
10352     static void testBuiltInPowFunction() {
10353     #if !SILENT_TEST
10354     std::cout << "UNIT TEST: built-in pow() function\n";
10355     #endif
10356    
10357     // integer tests ...
10358     // (ATM not allowed for this function)
10359    
10360     runScript({
10361     .code = R"NKSP_CODE(
10362     on init
10363     declare $foo := 1
10364     exit( pow($foo,$foo) )
10365     end on
10366     )NKSP_CODE",
10367     .expectParseError = true // integer not allowed for this function ATM
10368     });
10369    
10370     // real number tests ...
10371    
10372     runScript({
10373     .code = R"NKSP_CODE(
10374     on init
10375     exit( pow(1.0) )
10376     end on
10377     )NKSP_CODE",
10378     .expectParseError = true // because pow() requires exactly 2 arguments
10379     });
10380    
10381     runScript({
10382     .code = R"NKSP_CODE(
10383     on init
10384     exit( pow(3.0,4.0) )
10385     end on
10386     )NKSP_CODE",
10387     .expectRealExitResult = 81.0
10388     });
10389    
10390     // std unit tests ...
10391    
10392     runScript({
10393     .code = R"NKSP_CODE(
10394     on init
10395     exit( pow(3.0ms,4.0ms) )
10396     end on
10397     )NKSP_CODE",
10398     .expectParseError = true // because units are prohibited for 2nd argument
10399     });
10400    
10401     runScript({
10402     .code = R"NKSP_CODE(
10403     on init
10404     exit( pow(3.0,4.0ms) )
10405     end on
10406     )NKSP_CODE",
10407     .expectParseError = true // because units are prohibited for 2nd argument
10408     });
10409    
10410     runScript({
10411     .code = R"NKSP_CODE(
10412     on init
10413     exit( pow(3.0ms,4.0) )
10414     end on
10415     )NKSP_CODE",
10416     .expectRealExitResult = 81.0,
10417     .expectExitResultUnitPrefix = { VM_MILLI },
10418     .expectExitResultUnit = VM_SECOND
10419     });
10420    
10421     runScript({
10422     .code = R"NKSP_CODE(
10423     on init
10424     exit( pow(3.0kHz,4.0) )
10425     end on
10426     )NKSP_CODE",
10427     .expectRealExitResult = 81.0,
10428     .expectExitResultUnitPrefix = { VM_KILO },
10429     .expectExitResultUnit = VM_HERTZ
10430     });
10431    
10432     // 'final' ('!') operator tests ...
10433    
10434     runScript({
10435     .code = R"NKSP_CODE(
10436     on init
10437     exit( pow(3.0,4.0) )
10438     end on
10439     )NKSP_CODE",
10440     .expectRealExitResult = 81.0,
10441     .expectExitResultFinal = false
10442     });
10443    
10444     runScript({
10445     .code = R"NKSP_CODE(
10446     on init
10447     exit( pow(!3.0,4.0) )
10448     end on
10449     )NKSP_CODE",
10450     .expectRealExitResult = 81.0,
10451     .expectExitResultFinal = true
10452     });
10453    
10454     runScript({
10455     .code = R"NKSP_CODE(
10456     on init
10457     exit( pow(3.0,!4.0) )
10458     end on
10459     )NKSP_CODE",
10460     .expectParseError = true // because 'final' is meaningless for 2nd argument
10461     });
10462    
10463     #if !SILENT_TEST
10464     std::cout << std::endl;
10465     #endif
10466     }
10467    
10468     static void testBuiltInSinFunction() {
10469     #if !SILENT_TEST
10470     std::cout << "UNIT TEST: built-in sin() function\n";
10471     #endif
10472    
10473     // integer tests ...
10474     // (ATM not allowed for this function)
10475    
10476     runScript({
10477     .code = R"NKSP_CODE(
10478     on init
10479     declare $foo := 1
10480     exit( sin($foo) )
10481     end on
10482     )NKSP_CODE",
10483     .expectParseError = true // integer not allowed for this function ATM
10484     });
10485    
10486     // real number tests ...
10487    
10488     runScript({
10489     .code = R"NKSP_CODE(
10490     on init
10491     exit( sin(0.0) )
10492     end on
10493     )NKSP_CODE",
10494     .expectRealExitResult = 0.0
10495     });
10496    
10497     runScript({
10498     .code = R"NKSP_CODE(
10499     on init
10500     exit( sin(0.5 * ~NI_MATH_PI) )
10501     end on
10502     )NKSP_CODE",
10503     .expectRealExitResult = 1.0
10504     });
10505    
10506     runScript({
10507     .code = R"NKSP_CODE(
10508     on init
10509     exit( sin(~NI_MATH_PI) )
10510     end on
10511     )NKSP_CODE",
10512     .expectRealExitResult = 0.0
10513     });
10514    
10515     runScript({
10516     .code = R"NKSP_CODE(
10517     on init
10518     exit( sin(1.5 * ~NI_MATH_PI) )
10519     end on
10520     )NKSP_CODE",
10521     .expectRealExitResult = -1.0
10522     });
10523    
10524     // std unit tests ...
10525    
10526     runScript({
10527     .code = R"NKSP_CODE(
10528     on init
10529     exit( sin(0.0ms) )
10530     end on
10531     )NKSP_CODE",
10532     .expectRealExitResult = 0.0,
10533     .expectExitResultUnitPrefix = { VM_MILLI },
10534     .expectExitResultUnit = VM_SECOND
10535     });
10536    
10537     runScript({
10538     .code = R"NKSP_CODE(
10539     on init
10540     exit( sin(0.0kHz) )
10541     end on
10542     )NKSP_CODE",
10543     .expectRealExitResult = 0.0,
10544     .expectExitResultUnitPrefix = { VM_KILO },
10545     .expectExitResultUnit = VM_HERTZ
10546     });
10547    
10548     // 'final' ('!') operator tests ...
10549    
10550     runScript({
10551     .code = R"NKSP_CODE(
10552     on init
10553     exit( sin(0.0) )
10554     end on
10555     )NKSP_CODE",
10556     .expectRealExitResult = 0.0,
10557     .expectExitResultFinal = false
10558     });
10559    
10560     runScript({
10561     .code = R"NKSP_CODE(
10562     on init
10563     exit( sin(!0.0) )
10564     end on
10565     )NKSP_CODE",
10566     .expectRealExitResult = 0.0,
10567     .expectExitResultFinal = true
10568     });
10569    
10570     #if !SILENT_TEST
10571     std::cout << std::endl;
10572     #endif
10573     }
10574    
10575     static void testBuiltInCosFunction() {
10576     #if !SILENT_TEST
10577     std::cout << "UNIT TEST: built-in cos() function\n";
10578     #endif
10579    
10580     // integer tests ...
10581     // (ATM not allowed for this function)
10582    
10583     runScript({
10584     .code = R"NKSP_CODE(
10585     on init
10586     declare $foo := 1
10587     exit( cos($foo) )
10588     end on
10589     )NKSP_CODE",
10590     .expectParseError = true // integer not allowed for this function ATM
10591     });
10592    
10593     // real number tests ...
10594    
10595     runScript({
10596     .code = R"NKSP_CODE(
10597     on init
10598     exit( cos(0.0) )
10599     end on
10600     )NKSP_CODE",
10601     .expectRealExitResult = 1.0
10602     });
10603    
10604     runScript({
10605     .code = R"NKSP_CODE(
10606     on init
10607     exit( cos(0.5 * ~NI_MATH_PI) )
10608     end on
10609     )NKSP_CODE",
10610     .expectRealExitResult = 0.0
10611     });
10612    
10613     runScript({
10614     .code = R"NKSP_CODE(
10615     on init
10616     exit( cos(~NI_MATH_PI) )
10617     end on
10618     )NKSP_CODE",
10619     .expectRealExitResult = -1.0
10620     });
10621    
10622     runScript({
10623     .code = R"NKSP_CODE(
10624     on init
10625     exit( cos(1.5 * ~NI_MATH_PI) )
10626     end on
10627     )NKSP_CODE",
10628     .expectRealExitResult = 0.0
10629     });
10630    
10631     // std unit tests ...
10632    
10633     runScript({
10634     .code = R"NKSP_CODE(
10635     on init
10636     exit( cos(0.0ms) )
10637     end on
10638     )NKSP_CODE",
10639     .expectRealExitResult = 1.0,
10640     .expectExitResultUnitPrefix = { VM_MILLI },
10641     .expectExitResultUnit = VM_SECOND
10642     });
10643    
10644     runScript({
10645     .code = R"NKSP_CODE(
10646     on init
10647     exit( cos(0.0kHz) )
10648     end on
10649     )NKSP_CODE",
10650     .expectRealExitResult = 1.0,
10651     .expectExitResultUnitPrefix = { VM_KILO },
10652     .expectExitResultUnit = VM_HERTZ
10653     });
10654    
10655     // 'final' ('!') operator tests ...
10656    
10657     runScript({
10658     .code = R"NKSP_CODE(
10659     on init
10660     exit( cos(0.0) )
10661     end on
10662     )NKSP_CODE",
10663     .expectRealExitResult = 1.0,
10664     .expectExitResultFinal = false
10665     });
10666    
10667     runScript({
10668     .code = R"NKSP_CODE(
10669     on init
10670     exit( cos(!0.0) )
10671     end on
10672     )NKSP_CODE",
10673     .expectRealExitResult = 1.0,
10674     .expectExitResultFinal = true
10675     });
10676    
10677     #if !SILENT_TEST
10678     std::cout << std::endl;
10679     #endif
10680     }
10681    
10682     static void testBuiltInTanFunction() {
10683     #if !SILENT_TEST
10684     std::cout << "UNIT TEST: built-in tan() function\n";
10685     #endif
10686    
10687     // integer tests ...
10688     // (ATM not allowed for this function)
10689    
10690     runScript({
10691     .code = R"NKSP_CODE(
10692     on init
10693     declare $foo := 1
10694     exit( tan($foo) )
10695     end on
10696     )NKSP_CODE",
10697     .expectParseError = true // integer not allowed for this function ATM
10698     });
10699    
10700     // real number tests ...
10701    
10702     runScript({
10703     .code = R"NKSP_CODE(
10704     on init
10705     exit( tan(0.0) )
10706     end on
10707     )NKSP_CODE",
10708     .expectRealExitResult = 0.0
10709     });
10710    
10711     runScript({
10712     .code = R"NKSP_CODE(
10713     on init
10714     exit( tan(0.25 * ~NI_MATH_PI) )
10715     end on
10716     )NKSP_CODE",
10717     .expectRealExitResult = 1.0
10718     });
10719    
10720     // std unit tests ...
10721    
10722     runScript({
10723     .code = R"NKSP_CODE(
10724     on init
10725     exit( tan(0.0ms) )
10726     end on
10727     )NKSP_CODE",
10728     .expectRealExitResult = 0.0,
10729     .expectExitResultUnitPrefix = { VM_MILLI },
10730     .expectExitResultUnit = VM_SECOND
10731     });
10732    
10733     runScript({
10734     .code = R"NKSP_CODE(
10735     on init
10736     exit( tan(0.0kHz) )
10737     end on
10738     )NKSP_CODE",
10739     .expectRealExitResult = 0.0,
10740     .expectExitResultUnitPrefix = { VM_KILO },
10741     .expectExitResultUnit = VM_HERTZ
10742     });
10743    
10744     // 'final' ('!') operator tests ...
10745    
10746     runScript({
10747     .code = R"NKSP_CODE(
10748     on init
10749     exit( tan(0.0) )
10750     end on
10751     )NKSP_CODE",
10752     .expectRealExitResult = 0.0,
10753     .expectExitResultFinal = false
10754     });
10755    
10756     runScript({
10757     .code = R"NKSP_CODE(
10758     on init
10759     exit( tan(!0.0) )
10760     end on
10761     )NKSP_CODE",
10762     .expectRealExitResult = 0.0,
10763     .expectExitResultFinal = true
10764     });
10765    
10766     #if !SILENT_TEST
10767     std::cout << std::endl;
10768     #endif
10769     }
10770    
10771     static void testBuiltInAsinFunction() {
10772     #if !SILENT_TEST
10773     std::cout << "UNIT TEST: built-in asin() function\n";
10774     #endif
10775    
10776     // integer tests ...
10777     // (ATM not allowed for this function)
10778    
10779     runScript({
10780     .code = R"NKSP_CODE(
10781     on init
10782     declare $foo := 1
10783     exit( asin($foo) )
10784     end on
10785     )NKSP_CODE",
10786     .expectParseError = true // integer not allowed for this function ATM
10787     });
10788    
10789     // real number tests ...
10790    
10791     runScript({
10792     .code = R"NKSP_CODE(
10793     on init
10794     exit( asin(0.0) )
10795     end on
10796     )NKSP_CODE",
10797     .expectRealExitResult = 0.0
10798     });
10799    
10800     runScript({
10801     .code = R"NKSP_CODE(
10802     on init
10803     exit( asin(1.0) )
10804     end on
10805     )NKSP_CODE",
10806     .expectRealExitResult = 0.5 * M_PI
10807     });
10808    
10809     runScript({
10810     .code = R"NKSP_CODE(
10811     on init
10812     exit( asin(-1.0) )
10813     end on
10814     )NKSP_CODE",
10815     .expectRealExitResult = -0.5 * M_PI
10816     });
10817    
10818     // std unit tests ...
10819    
10820     runScript({
10821     .code = R"NKSP_CODE(
10822     on init
10823     exit( asin(0.0ms) )
10824     end on
10825     )NKSP_CODE",
10826     .expectRealExitResult = 0.0,
10827     .expectExitResultUnitPrefix = { VM_MILLI },
10828     .expectExitResultUnit = VM_SECOND
10829     });
10830    
10831     runScript({
10832     .code = R"NKSP_CODE(
10833     on init
10834     exit( asin(0.0kHz) )
10835     end on
10836     )NKSP_CODE",
10837     .expectRealExitResult = 0.0,
10838     .expectExitResultUnitPrefix = { VM_KILO },
10839     .expectExitResultUnit = VM_HERTZ
10840     });
10841    
10842     // 'final' ('!') operator tests ...
10843    
10844     runScript({
10845     .code = R"NKSP_CODE(
10846     on init
10847     exit( asin(0.0) )
10848     end on
10849     )NKSP_CODE",
10850     .expectRealExitResult = 0.0,
10851     .expectExitResultFinal = false
10852     });
10853    
10854     runScript({
10855     .code = R"NKSP_CODE(
10856     on init
10857     exit( asin(!0.0) )
10858     end on
10859     )NKSP_CODE",
10860     .expectRealExitResult = 0.0,
10861     .expectExitResultFinal = true
10862     });
10863    
10864     #if !SILENT_TEST
10865     std::cout << std::endl;
10866     #endif
10867     }
10868    
10869     static void testBuiltInAcosFunction() {
10870     #if !SILENT_TEST
10871     std::cout << "UNIT TEST: built-in acos() function\n";
10872     #endif
10873    
10874     // integer tests ...
10875     // (ATM not allowed for this function)
10876    
10877     runScript({
10878     .code = R"NKSP_CODE(
10879     on init
10880     declare $foo := 1
10881     exit( acos($foo) )
10882     end on
10883     )NKSP_CODE",
10884     .expectParseError = true // integer not allowed for this function ATM
10885     });
10886    
10887     // real number tests ...
10888    
10889     runScript({
10890     .code = R"NKSP_CODE(
10891     on init
10892     exit( acos(1.0) )
10893     end on
10894     )NKSP_CODE",
10895     .expectRealExitResult = 0.0
10896     });
10897    
10898     runScript({
10899     .code = R"NKSP_CODE(
10900     on init
10901     exit( acos(0.0) )
10902     end on
10903     )NKSP_CODE",
10904     .expectRealExitResult = 0.5 * M_PI
10905     });
10906    
10907     runScript({
10908     .code = R"NKSP_CODE(
10909     on init
10910     exit( acos(-1.0) )
10911     end on
10912     )NKSP_CODE",
10913     .expectRealExitResult = M_PI
10914     });
10915    
10916     // std unit tests ...
10917    
10918     runScript({
10919     .code = R"NKSP_CODE(
10920     on init
10921     exit( acos(1.0ms) )
10922     end on
10923     )NKSP_CODE",
10924     .expectRealExitResult = 0.0,
10925     .expectExitResultUnitPrefix = { VM_MILLI },
10926     .expectExitResultUnit = VM_SECOND
10927     });
10928    
10929     runScript({
10930     .code = R"NKSP_CODE(
10931     on init
10932     exit( acos(1.0kHz) )
10933     end on
10934     )NKSP_CODE",
10935     .expectRealExitResult = 0.0,
10936     .expectExitResultUnitPrefix = { VM_KILO },
10937     .expectExitResultUnit = VM_HERTZ
10938     });
10939    
10940     // 'final' ('!') operator tests ...
10941    
10942     runScript({
10943     .code = R"NKSP_CODE(
10944     on init
10945     exit( acos(1.0) )
10946     end on
10947     )NKSP_CODE",
10948     .expectRealExitResult = 0.0,
10949     .expectExitResultFinal = false
10950     });
10951    
10952     runScript({
10953     .code = R"NKSP_CODE(
10954     on init
10955     exit( acos(!1.0) )
10956     end on
10957     )NKSP_CODE",
10958     .expectRealExitResult = 0.0,
10959     .expectExitResultFinal = true
10960     });
10961    
10962     #if !SILENT_TEST
10963     std::cout << std::endl;
10964     #endif
10965     }
10966    
10967     static void testBuiltInAtanFunction() {
10968     #if !SILENT_TEST
10969     std::cout << "UNIT TEST: built-in atan() function\n";
10970     #endif
10971    
10972     // integer tests ...
10973     // (ATM not allowed for this function)
10974    
10975     runScript({
10976     .code = R"NKSP_CODE(
10977     on init
10978     declare $foo := 1
10979     exit( atan($foo) )
10980     end on
10981     )NKSP_CODE",
10982     .expectParseError = true // integer not allowed for this function ATM
10983     });
10984    
10985     // real number tests ...
10986    
10987     runScript({
10988     .code = R"NKSP_CODE(
10989     on init
10990     exit( atan(0.0) )
10991     end on
10992     )NKSP_CODE",
10993     .expectRealExitResult = 0.0
10994     });
10995    
10996     runScript({
10997     .code = R"NKSP_CODE(
10998     on init
10999     exit( atan(1.0) )
11000     end on
11001     )NKSP_CODE",
11002     .expectRealExitResult = 0.25 * M_PI
11003     });
11004    
11005     // std unit tests ...
11006    
11007     runScript({
11008     .code = R"NKSP_CODE(
11009     on init
11010     exit( atan(0.0ms) )
11011     end on
11012     )NKSP_CODE",
11013     .expectRealExitResult = 0.0,
11014     .expectExitResultUnitPrefix = { VM_MILLI },
11015     .expectExitResultUnit = VM_SECOND
11016     });
11017    
11018     runScript({
11019     .code = R"NKSP_CODE(
11020     on init
11021     exit( atan(0.0kHz) )
11022     end on
11023     )NKSP_CODE",
11024     .expectRealExitResult = 0.0,
11025     .expectExitResultUnitPrefix = { VM_KILO },
11026     .expectExitResultUnit = VM_HERTZ
11027     });
11028    
11029     // 'final' ('!') operator tests ...
11030    
11031     runScript({
11032     .code = R"NKSP_CODE(
11033     on init
11034     exit( atan(0.0) )
11035     end on
11036     )NKSP_CODE",
11037     .expectRealExitResult = 0.0,
11038     .expectExitResultFinal = false
11039     });
11040    
11041     runScript({
11042     .code = R"NKSP_CODE(
11043     on init
11044     exit( atan(!0.0) )
11045     end on
11046     )NKSP_CODE",
11047     .expectRealExitResult = 0.0,
11048     .expectExitResultFinal = true
11049     });
11050    
11051     #if !SILENT_TEST
11052     std::cout << std::endl;
11053     #endif
11054     }
11055    
11056 schoenebeck 3551 static void testBuiltInNumElementsFunction() {
11057     #if !SILENT_TEST
11058     std::cout << "UNIT TEST: built-in num_elements() function\n";
11059     #endif
11060    
11061 schoenebeck 3581 // integer array tests ...
11062    
11063 schoenebeck 3551 runScript({
11064     .code = R"NKSP_CODE(
11065     on init
11066     declare %foo[3] := ( 19, 3, 6 )
11067     exit( num_elements(%foo) )
11068     end on
11069     )NKSP_CODE",
11070     .expectIntExitResult = 3
11071     });
11072    
11073     runScript({
11074     .code = R"NKSP_CODE(
11075     on init
11076     declare %foo[1] := ( 19 )
11077     exit( num_elements(%foo) )
11078     end on
11079     )NKSP_CODE",
11080     .expectIntExitResult = 1
11081     });
11082    
11083     runScript({
11084     .code = R"NKSP_CODE(
11085     on init
11086     declare %foo[5] := ( 1, 2, 3, 4, 5 )
11087     exit( num_elements(%foo) )
11088     end on
11089     )NKSP_CODE",
11090     .expectIntExitResult = 5
11091     });
11092    
11093 schoenebeck 3581 // real array tests ...
11094    
11095     runScript({
11096     .code = R"NKSP_CODE(
11097     on init
11098     declare ?foo[3] := ( 19.0, 3.2, 6.5 )
11099     exit( num_elements(?foo) )
11100     end on
11101     )NKSP_CODE",
11102     .expectIntExitResult = 3
11103     });
11104    
11105     runScript({
11106     .code = R"NKSP_CODE(
11107     on init
11108     declare ?foo[1] := ( 19.0 )
11109     exit( num_elements(?foo) )
11110     end on
11111     )NKSP_CODE",
11112     .expectIntExitResult = 1
11113     });
11114    
11115     runScript({
11116     .code = R"NKSP_CODE(
11117     on init
11118     declare ?foo[5] := ( 1.1, 2.2, 3.3, 4.4, 5.5 )
11119     exit( num_elements(?foo) )
11120     end on
11121     )NKSP_CODE",
11122     .expectIntExitResult = 5
11123     });
11124    
11125 schoenebeck 3551 #if !SILENT_TEST
11126     std::cout << std::endl;
11127     #endif
11128     }
11129    
11130     static void testBuiltInSearchFunction() {
11131     #if !SILENT_TEST
11132     std::cout << "UNIT TEST: built-in search() function\n";
11133     #endif
11134    
11135 schoenebeck 3581 // integer array tests ...
11136    
11137 schoenebeck 3551 runScript({
11138     .code = R"NKSP_CODE(
11139     on init
11140     declare %foo[3] := ( 19, 3, 6 )
11141     exit( search(%foo, 19) )
11142     end on
11143     )NKSP_CODE",
11144     .expectIntExitResult = 0
11145     });
11146    
11147     runScript({
11148     .code = R"NKSP_CODE(
11149     on init
11150     declare %foo[3] := ( 19, 3, 6 )
11151     exit( search(%foo, 3) )
11152     end on
11153     )NKSP_CODE",
11154     .expectIntExitResult = 1
11155     });
11156    
11157     runScript({
11158     .code = R"NKSP_CODE(
11159     on init
11160     declare %foo[3] := ( 19, 3, 6 )
11161     exit( search(%foo, 6) )
11162     end on
11163     )NKSP_CODE",
11164     .expectIntExitResult = 2
11165     });
11166    
11167     runScript({
11168     .code = R"NKSP_CODE(
11169     on init
11170     declare %foo[3] := ( 19, 3, 6 )
11171     exit( search(%foo, 2) )
11172     end on
11173     )NKSP_CODE",
11174     .expectIntExitResult = -1
11175     });
11176    
11177 schoenebeck 3581 // real array tests ...
11178    
11179     runScript({
11180     .code = R"NKSP_CODE(
11181     on init
11182     declare ?foo[3] := ( 19.12, 3.45, 6.89 )
11183     exit( search(?foo, 19.12) )
11184     end on
11185     )NKSP_CODE",
11186     .expectIntExitResult = 0
11187     });
11188    
11189     runScript({
11190     .code = R"NKSP_CODE(
11191     on init
11192     declare ?foo[3] := ( 19.12, 3.45, 6.89 )
11193     exit( search(?foo, 3.45) )
11194     end on
11195     )NKSP_CODE",
11196     .expectIntExitResult = 1
11197     });
11198    
11199     runScript({
11200     .code = R"NKSP_CODE(
11201     on init
11202     declare ?foo[3] := ( 19.12, 3.45, 6.89 )
11203     exit( search(?foo, 6.89) )
11204     end on
11205     )NKSP_CODE",
11206     .expectIntExitResult = 2
11207     });
11208    
11209     runScript({
11210     .code = R"NKSP_CODE(
11211     on init
11212     declare ?foo[3] := ( 19.12, 3.45, 6.89 )
11213     exit( search(?foo, 6.99) )
11214     end on
11215     )NKSP_CODE",
11216     .expectIntExitResult = -1
11217     });
11218    
11219 schoenebeck 3551 #if !SILENT_TEST
11220     std::cout << std::endl;
11221     #endif
11222     }
11223    
11224     static void testIfStatement() {
11225     #if !SILENT_TEST
11226     std::cout << "UNIT TEST: if statement\n";
11227     #endif
11228    
11229     runScript({
11230     .code = R"NKSP_CODE(
11231     on init
11232     declare $foo := 1
11233     if ($foo)
11234     exit(42)
11235     end if
11236     end on
11237     )NKSP_CODE",
11238     .expectIntExitResult = 42
11239     });
11240    
11241     runScript({
11242     .code = R"NKSP_CODE(
11243     on init
11244     declare $foo := 0
11245     if ($foo)
11246     exit(42)
11247     end if
11248     exit(3)
11249     end on
11250     )NKSP_CODE",
11251     .expectIntExitResult = 3
11252     });
11253    
11254     runScript({
11255     .code = R"NKSP_CODE(
11256     on init
11257     declare $foo := 1
11258     if ($foo)
11259     exit(42)
11260     else
11261     exit(3)
11262     end if
11263     end on
11264     )NKSP_CODE",
11265     .expectIntExitResult = 42
11266     });
11267    
11268     runScript({
11269     .code = R"NKSP_CODE(
11270     on init
11271     declare $foo := 0
11272     if ($foo)
11273     exit(42)
11274     else
11275     exit(3)
11276     end if
11277     end on
11278     )NKSP_CODE",
11279     .expectIntExitResult = 3
11280     });
11281    
11282     #if !SILENT_TEST
11283     std::cout << std::endl;
11284     #endif
11285     }
11286    
11287     static void testWhileStatement() {
11288     #if !SILENT_TEST
11289     std::cout << "UNIT TEST: while statement\n";
11290     #endif
11291    
11292     runScript({
11293     .code = R"NKSP_CODE(
11294     on init
11295     declare $foo := 100
11296     declare $i := 50
11297     while ($i)
11298     $foo := $foo + 1
11299     $i := $i - 1
11300     end while
11301     exit($foo)
11302     end on
11303     )NKSP_CODE",
11304     .expectIntExitResult = 150
11305     });
11306    
11307     #if !SILENT_TEST
11308     std::cout << std::endl;
11309     #endif
11310     }
11311    
11312 schoenebeck 3693 static void testBuiltInVars() {
11313     #if !SILENT_TEST
11314     std::cout << "UNIT TEST: built-in variables\n";
11315     #endif
11316    
11317     runScript({
11318     .code = R"NKSP_CODE(
11319     on init
11320     exit($NKSP_PERF_TIMER)
11321     end on
11322     )NKSP_CODE",
11323     .expectExitResultIsInt = true,
11324     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11325     .expectExitResultUnit = VM_NO_UNIT
11326     });
11327    
11328     runScript({
11329     .code = R"NKSP_CODE(
11330     on init
11331     exit($NKSP_REAL_TIMER)
11332     end on
11333     )NKSP_CODE",
11334     .expectExitResultIsInt = true,
11335     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11336     .expectExitResultUnit = VM_NO_UNIT
11337     });
11338    
11339     runScript({
11340     .code = R"NKSP_CODE(
11341     on init
11342     exit($KSP_TIMER)
11343     end on
11344     )NKSP_CODE",
11345     .expectExitResultIsInt = true,
11346     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11347     .expectExitResultUnit = VM_NO_UNIT
11348     });
11349    
11350     runScript({
11351     .code = R"NKSP_CODE(
11352     on init
11353     exit(~NI_MATH_PI)
11354     end on
11355     )NKSP_CODE",
11356     .expectExitResultIsReal = true,
11357     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11358     .expectExitResultUnit = VM_NO_UNIT
11359     });
11360    
11361     runScript({
11362     .code = R"NKSP_CODE(
11363     on init
11364     exit(~NI_MATH_E)
11365     end on
11366     )NKSP_CODE",
11367     .expectExitResultIsReal = true,
11368     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11369     .expectExitResultUnit = VM_NO_UNIT
11370     });
11371    
11372     runScript({
11373     .code = R"NKSP_CODE(
11374     on init
11375     exit($NI_CB_TYPE_INIT)
11376     end on
11377     )NKSP_CODE",
11378     .expectIntExitResult = VM_EVENT_HANDLER_INIT,
11379     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11380     .expectExitResultUnit = VM_NO_UNIT
11381     });
11382    
11383     runScript({
11384     .code = R"NKSP_CODE(
11385     on init
11386     exit($NI_CB_TYPE_NOTE)
11387     end on
11388     )NKSP_CODE",
11389     .expectIntExitResult = VM_EVENT_HANDLER_NOTE,
11390     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11391     .expectExitResultUnit = VM_NO_UNIT
11392     });
11393    
11394     runScript({
11395     .code = R"NKSP_CODE(
11396     on init
11397     exit($NI_CB_TYPE_RELEASE)
11398     end on
11399     )NKSP_CODE",
11400     .expectIntExitResult = VM_EVENT_HANDLER_RELEASE,
11401     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11402     .expectExitResultUnit = VM_NO_UNIT
11403     });
11404    
11405     runScript({
11406     .code = R"NKSP_CODE(
11407     on init
11408     exit($NI_CB_TYPE_CONTROLLER)
11409     end on
11410     )NKSP_CODE",
11411     .expectIntExitResult = VM_EVENT_HANDLER_CONTROLLER,
11412     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11413     .expectExitResultUnit = VM_NO_UNIT
11414     });
11415    
11416     runScript({
11417     .code = R"NKSP_CODE(
11418     on init
11419     exit($NI_CB_TYPE_RPN)
11420     end on
11421     )NKSP_CODE",
11422     .expectIntExitResult = VM_EVENT_HANDLER_RPN,
11423     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11424     .expectExitResultUnit = VM_NO_UNIT
11425     });
11426    
11427     runScript({
11428     .code = R"NKSP_CODE(
11429     on init
11430     exit($NI_CB_TYPE_NRPN)
11431     end on
11432     )NKSP_CODE",
11433     .expectIntExitResult = VM_EVENT_HANDLER_NRPN,
11434     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11435     .expectExitResultUnit = VM_NO_UNIT
11436     });
11437    
11438     #if !SILENT_TEST
11439     std::cout << std::endl;
11440     #endif
11441     }
11442    
11443 schoenebeck 3551 #if !NO_MAIN
11444    
11445     int main() {
11446     testBuiltInExitFunction();
11447     testStringConcatOperator();
11448 schoenebeck 3575 testNegOperator();
11449 schoenebeck 3551 testPlusOperator();
11450     testMinusOperator();
11451     testModuloOperator();
11452     testMultiplyOperator();
11453     testDivideOperator();
11454     testSmallerThanOperator();
11455     testGreaterThanOperator();
11456     testSmallerOrEqualOperator();
11457     testGreaterOrEqualOperator();
11458     testEqualOperator();
11459     testUnequalOperator();
11460     testLogicalAndOperator();
11461     testLogicalOrOperator();
11462     testLogicalNotOperator();
11463     testBitwiseAndOperator();
11464     testBitwiseOrOperator();
11465     testBitwiseNotOperator();
11466     testPrecedenceOfOperators();
11467 schoenebeck 3727 testIntVarDeclaration();
11468     testIntArrayVarDeclaration();
11469     testRealVarDeclaration();
11470     testRealArrayVarDeclaration();
11471     testStringVarDeclaration();
11472 schoenebeck 3551 testBuiltInMinFunction();
11473     testBuiltInMaxFunction();
11474     testBuiltInAbsFunction();
11475     testBuiltInIncFunction();
11476     testBuiltInDecFunction();
11477     testBuiltInInRangeFunction();
11478     testBuiltInRandomFunction();
11479     testBuiltInShiftLeftFunction();
11480     testBuiltInShiftRightFunction();
11481 schoenebeck 3678 testBuiltInMsbFunction();
11482     testBuiltInLsbFunction();
11483 schoenebeck 3575 testBuiltInIntToRealFunction();
11484     testBuiltInRealFunction();
11485     testBuiltInRealToIntFunction();
11486     testBuiltInIntFunction();
11487 schoenebeck 3590 testBuiltInRoundFunction();
11488     testBuiltInCeilFunction();
11489     testBuiltInFloorFunction();
11490     testBuiltInSqrtFunction();
11491     testBuiltInLogFunction();
11492     testBuiltInLog2Function();
11493     testBuiltInLog10Function();
11494     testBuiltInExpFunction();
11495     testBuiltInPowFunction();
11496     testBuiltInSinFunction();
11497     testBuiltInCosFunction();
11498     testBuiltInTanFunction();
11499     testBuiltInAsinFunction();
11500     testBuiltInAcosFunction();
11501     testBuiltInAtanFunction();
11502 schoenebeck 3551 testBuiltInArrayEqualFunction();
11503     testBuiltInSortFunction();
11504     testBuiltInNumElementsFunction();
11505     testBuiltInSearchFunction();
11506     testIfStatement();
11507     testWhileStatement();
11508 schoenebeck 3693 testBuiltInVars();
11509 schoenebeck 3551 std::cout << "\nAll tests passed successfully. :-)\n";
11510     return 0;
11511     }
11512    
11513     #endif // !NO_MAIN

  ViewVC Help
Powered by ViewVC