/[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 3744 - (hide annotations) (download)
Sat Feb 15 11:50:02 2020 UTC (4 years, 2 months ago) by schoenebeck
File size: 222598 byte(s)
* NKSP: Fixed intermediate function result values never having reflected
  any standard measuring unit type.

* Tests: Guard this fixed NKSP issue by test cases.

* Bumped version (2.1.1.svn49).

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 schoenebeck 3744 runScript({
8885     .code = R"NKSP_CODE(
8886     on init
8887     declare $foo := 7000ms
8888     exit( int_to_real($foo) )
8889     end on
8890     )NKSP_CODE",
8891     .expectRealExitResult = 7000.0,
8892     .expectExitResultUnitPrefix = { VM_MILLI },
8893     .expectExitResultUnit = VM_SECOND
8894     });
8895    
8896     runScript({
8897     .code = R"NKSP_CODE(
8898     on init
8899     declare $foo := 7000ms
8900     declare @s := "" & int_to_real($foo)
8901     exit( @s )
8902     end on
8903     )NKSP_CODE",
8904     .expectStringExitResult = "7000ms",
8905     });
8906    
8907 schoenebeck 3581 // 'final' ('!') operator tests ...
8908    
8909     runScript({
8910     .code = R"NKSP_CODE(
8911     on init
8912     declare $foo := !-58
8913     exit( int_to_real($foo) )
8914     end on
8915     )NKSP_CODE",
8916     .expectRealExitResult = -58.0,
8917     .expectExitResultFinal = true
8918     });
8919    
8920     runScript({
8921     .code = R"NKSP_CODE(
8922     on init
8923     declare $foo := -58
8924     exit( int_to_real($foo) )
8925     end on
8926     )NKSP_CODE",
8927     .expectRealExitResult = -58.0,
8928     .expectExitResultFinal = false
8929     });
8930    
8931 schoenebeck 3575 #if !SILENT_TEST
8932     std::cout << std::endl;
8933     #endif
8934     }
8935    
8936     static void testBuiltInRealFunction() {
8937     #if !SILENT_TEST
8938     std::cout << "UNIT TEST: built-in real() function\n";
8939     #endif
8940    
8941     runScript({
8942     .code = R"NKSP_CODE(
8943     on init
8944     exit( real(8) )
8945     end on
8946     )NKSP_CODE",
8947     .expectRealExitResult = 8.0
8948     });
8949    
8950     runScript({
8951     .code = R"NKSP_CODE(
8952     on init
8953     declare $foo := 23
8954     exit( real($foo) )
8955     end on
8956     )NKSP_CODE",
8957     .expectRealExitResult = 23.0
8958     });
8959    
8960 schoenebeck 3581 // std unit tests ...
8961    
8962     runScript({
8963     .code = R"NKSP_CODE(
8964     on init
8965     exit( real(-58mdB) )
8966     end on
8967     )NKSP_CODE",
8968     .expectRealExitResult = -58.0,
8969     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
8970     .expectExitResultUnit = VM_BEL
8971     });
8972    
8973     runScript({
8974     .code = R"NKSP_CODE(
8975     on init
8976     declare $foo := -58mdB
8977     exit( real($foo) )
8978     end on
8979     )NKSP_CODE",
8980     .expectRealExitResult = -58.0,
8981     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
8982     .expectExitResultUnit = VM_BEL
8983     });
8984    
8985 schoenebeck 3744 runScript({
8986     .code = R"NKSP_CODE(
8987     on init
8988     declare $foo := 7000ms
8989     exit( real($foo) )
8990     end on
8991     )NKSP_CODE",
8992     .expectRealExitResult = 7000.0,
8993     .expectExitResultUnitPrefix = { VM_MILLI },
8994     .expectExitResultUnit = VM_SECOND
8995     });
8996    
8997     runScript({
8998     .code = R"NKSP_CODE(
8999     on init
9000     declare $foo := 7000ms
9001     declare @s := "" & real($foo)
9002     exit( @s )
9003     end on
9004     )NKSP_CODE",
9005     .expectStringExitResult = "7000ms",
9006     });
9007    
9008 schoenebeck 3581 // 'final' ('!') operator tests ...
9009    
9010     runScript({
9011     .code = R"NKSP_CODE(
9012     on init
9013     declare $foo := !-58
9014     exit( real($foo) )
9015     end on
9016     )NKSP_CODE",
9017     .expectRealExitResult = -58.0,
9018     .expectExitResultFinal = true
9019     });
9020    
9021     runScript({
9022     .code = R"NKSP_CODE(
9023     on init
9024     declare $foo := -58
9025     exit( real($foo) )
9026     end on
9027     )NKSP_CODE",
9028     .expectRealExitResult = -58.0,
9029     .expectExitResultFinal = false
9030     });
9031    
9032 schoenebeck 3575 #if !SILENT_TEST
9033     std::cout << std::endl;
9034     #endif
9035     }
9036    
9037     static void testBuiltInRealToIntFunction() {
9038     #if !SILENT_TEST
9039     std::cout << "UNIT TEST: built-in real_to_int() function\n";
9040     #endif
9041    
9042     runScript({
9043     .code = R"NKSP_CODE(
9044     on init
9045     exit( real_to_int(8.9) )
9046     end on
9047     )NKSP_CODE",
9048     .expectIntExitResult = 8
9049     });
9050    
9051     runScript({
9052     .code = R"NKSP_CODE(
9053     on init
9054     declare ~foo := 8.9
9055     exit( real_to_int(~foo) )
9056     end on
9057     )NKSP_CODE",
9058     .expectIntExitResult = 8
9059     });
9060    
9061 schoenebeck 3581 // std unit tests ...
9062    
9063     runScript({
9064     .code = R"NKSP_CODE(
9065     on init
9066     declare ~foo := 8.9mdB
9067     exit( real_to_int(~foo) )
9068     end on
9069     )NKSP_CODE",
9070     .expectIntExitResult = 8,
9071     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
9072     .expectExitResultUnit = VM_BEL
9073     });
9074    
9075 schoenebeck 3744 runScript({
9076     .code = R"NKSP_CODE(
9077     on init
9078     declare ~foo := 9000.0us
9079     exit( real_to_int(~foo) )
9080     end on
9081     )NKSP_CODE",
9082     .expectIntExitResult = 9000.0,
9083     .expectExitResultUnitPrefix = { VM_MICRO },
9084     .expectExitResultUnit = VM_SECOND
9085     });
9086    
9087     runScript({
9088     .code = R"NKSP_CODE(
9089     on init
9090     declare ~foo := 9000.0us
9091     declare @s := "" & real_to_int(~foo)
9092     exit( @s )
9093     end on
9094     )NKSP_CODE",
9095     .expectStringExitResult = "9000us",
9096     });
9097    
9098 schoenebeck 3581 // 'final' ('!') operator tests ...
9099    
9100     runScript({
9101     .code = R"NKSP_CODE(
9102     on init
9103     declare ~foo := !8.9
9104     exit( real_to_int(~foo) )
9105     end on
9106     )NKSP_CODE",
9107     .expectIntExitResult = 8,
9108     .expectExitResultFinal = true
9109     });
9110    
9111     runScript({
9112     .code = R"NKSP_CODE(
9113     on init
9114     declare ~foo := 8.9
9115     exit( real_to_int(~foo) )
9116     end on
9117     )NKSP_CODE",
9118     .expectIntExitResult = 8,
9119     .expectExitResultFinal = false
9120     });
9121    
9122 schoenebeck 3575 #if !SILENT_TEST
9123     std::cout << std::endl;
9124     #endif
9125     }
9126    
9127     static void testBuiltInIntFunction() {
9128     #if !SILENT_TEST
9129     std::cout << "UNIT TEST: built-in int() function\n";
9130     #endif
9131    
9132     runScript({
9133     .code = R"NKSP_CODE(
9134     on init
9135     exit( int(8.9) )
9136     end on
9137     )NKSP_CODE",
9138     .expectIntExitResult = 8
9139     });
9140    
9141     runScript({
9142     .code = R"NKSP_CODE(
9143     on init
9144     declare ~foo := 8.9
9145     exit( int(~foo) )
9146     end on
9147     )NKSP_CODE",
9148     .expectIntExitResult = 8
9149     });
9150    
9151 schoenebeck 3581 // std unit tests ...
9152    
9153     runScript({
9154     .code = R"NKSP_CODE(
9155     on init
9156     declare ~foo := 8.9mdB
9157     exit( int(~foo) )
9158     end on
9159     )NKSP_CODE",
9160     .expectIntExitResult = 8,
9161     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
9162     .expectExitResultUnit = VM_BEL
9163     });
9164    
9165 schoenebeck 3744 runScript({
9166     .code = R"NKSP_CODE(
9167     on init
9168     declare ~foo := 9000.0us
9169     exit( int(~foo) )
9170     end on
9171     )NKSP_CODE",
9172     .expectIntExitResult = 9000.0,
9173     .expectExitResultUnitPrefix = { VM_MICRO },
9174     .expectExitResultUnit = VM_SECOND
9175     });
9176    
9177     runScript({
9178     .code = R"NKSP_CODE(
9179     on init
9180     declare ~foo := 9000.0us
9181     declare @s := "" & int(~foo)
9182     exit( @s )
9183     end on
9184     )NKSP_CODE",
9185     .expectStringExitResult = "9000us",
9186     });
9187    
9188 schoenebeck 3581 // 'final' ('!') operator tests ...
9189    
9190     runScript({
9191     .code = R"NKSP_CODE(
9192     on init
9193     declare ~foo := !8.9
9194     exit( int(~foo) )
9195     end on
9196     )NKSP_CODE",
9197     .expectIntExitResult = 8,
9198     .expectExitResultFinal = true
9199     });
9200    
9201     runScript({
9202     .code = R"NKSP_CODE(
9203     on init
9204     declare ~foo := 8.9
9205     exit( int(~foo) )
9206     end on
9207     )NKSP_CODE",
9208     .expectIntExitResult = 8,
9209     .expectExitResultFinal = false
9210     });
9211    
9212 schoenebeck 3575 #if !SILENT_TEST
9213     std::cout << std::endl;
9214     #endif
9215     }
9216    
9217 schoenebeck 3551 static void testBuiltInArrayEqualFunction() {
9218     #if !SILENT_TEST
9219     std::cout << "UNIT TEST: built-in array_equal() function\n";
9220     #endif
9221    
9222 schoenebeck 3581 // integer array tests ...
9223    
9224 schoenebeck 3551 runScript({
9225     .code = R"NKSP_CODE(
9226     on init
9227     declare %foo[3] := ( 1, 2, 3 )
9228     declare %bar[3] := ( 1, 2, 3 )
9229     exit( array_equal(%foo, %bar) )
9230     end on
9231     )NKSP_CODE",
9232     .expectBoolExitResult = true
9233     });
9234    
9235     runScript({
9236     .code = R"NKSP_CODE(
9237     on init
9238     declare %foo[1] := ( 1 )
9239     declare %bar[1] := ( 1 )
9240     exit( array_equal(%foo, %bar) )
9241     end on
9242     )NKSP_CODE",
9243     .expectBoolExitResult = true
9244     });
9245    
9246     runScript({
9247     .code = R"NKSP_CODE(
9248     on init
9249     declare %foo[3] := ( 1, 2, 3 )
9250     declare %bar[3] := ( 0, 2, 3 )
9251     exit( array_equal(%foo, %bar) )
9252     end on
9253     )NKSP_CODE",
9254     .expectBoolExitResult = false
9255     });
9256    
9257     runScript({
9258     .code = R"NKSP_CODE(
9259     on init
9260     declare %foo[3] := ( 1, 2, 3 )
9261     declare %bar[3] := ( 3, 2, 1 )
9262     exit( array_equal(%foo, %bar) )
9263     end on
9264     )NKSP_CODE",
9265     .expectBoolExitResult = false
9266     });
9267    
9268     runScript({
9269     .code = R"NKSP_CODE(
9270     on init
9271     declare %foo[3] := ( 1, 2, 3 )
9272     declare %bar[2] := ( 1, 2 )
9273     exit( array_equal(%foo, %bar) )
9274     end on
9275     )NKSP_CODE",
9276 schoenebeck 3581 .expectBoolExitResult = false,
9277     .expectParseWarning = true // array_equal() warns if array sizes do not match
9278     });
9279    
9280     // real number array tests ...
9281    
9282     runScript({
9283     .code = R"NKSP_CODE(
9284     on init
9285     declare ?foo[3] := ( 1.0, 2.0, 3.0 )
9286     declare ?bar[3] := ( 1.0, 2.0, 3.0 )
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.0, 1.1, 3.4 )
9297     declare ?bar[3] := ( 1.0, 1.1, 3.4 )
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.0, 1.1, 3.4 )
9308     declare ?bar[3] := ( 1.0, 1.2, 3.4 )
9309     exit( array_equal(?foo, ?bar) )
9310     end on
9311     )NKSP_CODE",
9312 schoenebeck 3551 .expectBoolExitResult = false
9313     });
9314    
9315 schoenebeck 3581 runScript({
9316     .code = R"NKSP_CODE(
9317     on init
9318     declare ?foo[3] := ( 1.0, 1.1, 3.4 )
9319     declare ?bar[2] := ( 1.0, 1.1 )
9320     exit( array_equal(?foo, ?bar) )
9321     end on
9322     )NKSP_CODE",
9323     .expectBoolExitResult = false,
9324     .expectParseWarning = true // array_equal() warns if array sizes do not match
9325     });
9326    
9327     // std unit tests ...
9328     // (only metric prefixes allowed, unit types are prohibited for arrays ATM)
9329    
9330     runScript({
9331     .code = R"NKSP_CODE(
9332     on init
9333     declare %foo[3] := ( 1, 1s, 1 )
9334     declare %bar[3] := ( 1, 1, 1 )
9335     exit( array_equal(%foo, %bar) )
9336     end on
9337     )NKSP_CODE",
9338     .expectParseError = true // see comment above
9339     });
9340    
9341     runScript({
9342     .code = R"NKSP_CODE(
9343     on init
9344     declare %foo[3] := ( 1k, 1, 1m )
9345     declare %bar[3] := ( 1k, 1, 1m )
9346     exit( array_equal(%foo, %bar) )
9347     end on
9348     )NKSP_CODE",
9349     .expectBoolExitResult = true
9350     });
9351    
9352     runScript({
9353     .code = R"NKSP_CODE(
9354     on init
9355     declare %foo[3] := ( 1m, 1, 1k )
9356     declare %bar[3] := ( 1k, 1, 1m )
9357     exit( array_equal(%foo, %bar) )
9358     end on
9359     )NKSP_CODE",
9360     .expectBoolExitResult = false
9361     });
9362    
9363     runScript({
9364     .code = R"NKSP_CODE(
9365     on init
9366     declare %foo[3] := ( 1, 1k, 1 )
9367     declare %bar[3] := ( 1, 1, 1 )
9368     exit( array_equal(%foo, %bar) )
9369     end on
9370     )NKSP_CODE",
9371     .expectBoolExitResult = false
9372     });
9373    
9374     runScript({
9375     .code = R"NKSP_CODE(
9376     on init
9377     declare %foo[3] := ( 1, 1k, 1 )
9378     declare %bar[3] := ( 1, 1000, 1 )
9379     exit( array_equal(%foo, %bar) )
9380     end on
9381     )NKSP_CODE",
9382     .expectBoolExitResult = true
9383     });
9384    
9385     runScript({
9386     .code = R"NKSP_CODE(
9387     on init
9388     declare %foo[3] := ( 1, 2, 3000 )
9389     declare %bar[3] := ( 1, 2, 3k )
9390     exit( array_equal(%foo, %bar) )
9391     end on
9392     )NKSP_CODE",
9393     .expectBoolExitResult = true
9394     });
9395    
9396     runScript({
9397     .code = R"NKSP_CODE(
9398     on init
9399     declare %foo[3] := ( 1, 2, 3m )
9400     declare %bar[3] := ( 1, 2, 3k )
9401     exit( array_equal(%foo, %bar) )
9402     end on
9403     )NKSP_CODE",
9404     .expectBoolExitResult = false
9405     });
9406    
9407     runScript({
9408     .code = R"NKSP_CODE(
9409     on init
9410     declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
9411     declare ?bar[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
9412     exit( array_equal(?foo, ?bar) )
9413     end on
9414     )NKSP_CODE",
9415     .expectBoolExitResult = true
9416     });
9417    
9418     runScript({
9419     .code = R"NKSP_CODE(
9420     on init
9421     declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
9422     declare ?bar[4] := ( 1.0, 1.0 , 1.1m, 3.4k )
9423     exit( array_equal(?foo, ?bar) )
9424     end on
9425     )NKSP_CODE",
9426     .expectBoolExitResult = false
9427     });
9428    
9429     runScript({
9430     .code = R"NKSP_CODE(
9431     on init
9432     declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
9433     declare ?bar[4] := ( 1.0, 1.0m, 1.1k, 3.4k )
9434     exit( array_equal(?foo, ?bar) )
9435     end on
9436     )NKSP_CODE",
9437     .expectBoolExitResult = false
9438     });
9439    
9440     runScript({
9441     .code = R"NKSP_CODE(
9442     on init
9443     declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
9444     declare ?bar[4] := ( 1.0, 1.0m, 1.1m, 3.4u )
9445     exit( array_equal(?foo, ?bar) )
9446     end on
9447     )NKSP_CODE",
9448     .expectBoolExitResult = false
9449     });
9450    
9451     runScript({
9452     .code = R"NKSP_CODE(
9453     on init
9454     declare ?foo[3] := ( 1.0, 1.0k, 1.1m )
9455     declare ?bar[3] := ( 1.0, 1000.0, 1.1m )
9456     exit( array_equal(?foo, ?bar) )
9457     end on
9458     )NKSP_CODE",
9459     .expectBoolExitResult = true
9460     });
9461    
9462     runScript({
9463     .code = R"NKSP_CODE(
9464     on init
9465     declare ?foo[3] := ( 1.0, 1.0k, 1.1u )
9466     declare ?bar[3] := ( 1.0, 1000.0, 0.0011m )
9467     exit( array_equal(?foo, ?bar) )
9468     end on
9469     )NKSP_CODE",
9470     .expectBoolExitResult = true
9471     });
9472    
9473     runScript({
9474     .code = R"NKSP_CODE(
9475     on init
9476     declare ?foo[3] := ( 1.0, 1.0k, 1.1u )
9477     declare ?bar[3] := ( 1.0, 1000.0, 0.0016m )
9478     exit( array_equal(?foo, ?bar) )
9479     end on
9480     )NKSP_CODE",
9481     .expectBoolExitResult = false
9482     });
9483    
9484     // 'final' ('!') operator tests ...
9485     // (currently prohibited for arrays)
9486    
9487     runScript({
9488     .code = R"NKSP_CODE(
9489     on init
9490     declare %foo[3] := ( !1, !1, !1 )
9491     declare %bar[3] := ( !1, !1, !1 )
9492     exit( array_equal(%foo, %bar) )
9493     end on
9494     )NKSP_CODE",
9495     .expectParseError = true // see comment above
9496     });
9497    
9498     runScript({
9499     .code = R"NKSP_CODE(
9500     on init
9501     declare ?foo[3] := ( !1.0, !1.0, !1.0 )
9502     declare ?bar[3] := ( !1.0, !1.0, !1.0 )
9503     exit( array_equal(?foo, ?bar) )
9504     end on
9505     )NKSP_CODE",
9506     .expectParseError = true // see comment above
9507     });
9508    
9509 schoenebeck 3551 #if !SILENT_TEST
9510     std::cout << std::endl;
9511     #endif
9512     }
9513    
9514     static void testBuiltInSortFunction() {
9515     #if !SILENT_TEST
9516     std::cout << "UNIT TEST: built-in sort() function\n";
9517     #endif
9518    
9519 schoenebeck 3581 // integer array tests ...
9520    
9521 schoenebeck 3551 runScript({
9522     .code = R"NKSP_CODE(
9523     on init
9524     declare %input[3] := ( 19, 3, 6 )
9525     declare %expected[3] := ( 3, 6, 19 )
9526     sort(%input, 0)
9527     exit( array_equal(%input, %expected) )
9528     end on
9529     )NKSP_CODE",
9530     .expectBoolExitResult = true
9531     });
9532    
9533     runScript({
9534     .code = R"NKSP_CODE(
9535     on init
9536     declare %input[3] := ( 19, 3, 6 )
9537     declare %expected[3] := ( 19, 6, 3 )
9538     sort(%input, 1)
9539     exit( array_equal(%input, %expected) )
9540     end on
9541     )NKSP_CODE",
9542     .expectBoolExitResult = true
9543     });
9544    
9545 schoenebeck 3581 runScript({
9546     .code = R"NKSP_CODE(
9547     on init
9548     declare %input[6] := ( 1, 80, 120, 40, 3000, 20 )
9549     declare %expected[6] := ( 1, 20, 40, 80, 120, 3000 )
9550     sort(%input, 0)
9551     exit( array_equal(%input, %expected) )
9552     end on
9553     )NKSP_CODE",
9554     .expectBoolExitResult = true
9555     });
9556    
9557     // real number array tests ...
9558    
9559     runScript({
9560     .code = R"NKSP_CODE(
9561     on init
9562     declare ?input[4] := ( 1.4, 1.0, 13.4, 2.7 )
9563     declare ?expected[4] := ( 1.0, 1.4, 2.7, 13.4 )
9564     sort(?input, 0)
9565     exit( array_equal(?input, ?expected) )
9566     end on
9567     )NKSP_CODE",
9568     .expectBoolExitResult = true
9569     });
9570    
9571     runScript({
9572     .code = R"NKSP_CODE(
9573     on init
9574     declare ?input[4] := ( 1.4, 1.0, 13.4, 2.7 )
9575     declare ?expected[4] := ( 13.4, 2.7, 1.4, 1.0 )
9576     sort(?input, 1)
9577     exit( array_equal(?input, ?expected) )
9578     end on
9579     )NKSP_CODE",
9580     .expectBoolExitResult = true
9581     });
9582    
9583     // std unit tests ...
9584     // (only metric prefixes are allowed for arrays ATM)
9585    
9586     runScript({
9587     .code = R"NKSP_CODE(
9588     on init
9589     declare %input[3] := ( 1k, 6, 900 )
9590     declare %expected[3] := ( 6, 900, 1k )
9591     sort(%input, 0)
9592     exit( array_equal(%input, %expected) )
9593     end on
9594     )NKSP_CODE",
9595     .expectBoolExitResult = true
9596     });
9597    
9598     runScript({
9599     .code = R"NKSP_CODE(
9600     on init
9601     declare %input[3] := ( 900, 1k, 6 )
9602     declare %expected[3] := ( 1k, 900, 6 )
9603     sort(%input, 1)
9604     exit( array_equal(%input, %expected) )
9605     end on
9606     )NKSP_CODE",
9607     .expectBoolExitResult = true
9608     });
9609    
9610     runScript({
9611     .code = R"NKSP_CODE(
9612     on init
9613     declare %input[6] := ( 1k, 8m, 4k, 12000u, 3000u, 1000u )
9614     declare %expected[6] := ( 1000u, 3000u, 8m, 12000u, 1k, 4k )
9615     sort(%input, 0)
9616     exit( array_equal(%input, %expected) )
9617     end on
9618     )NKSP_CODE",
9619     .expectBoolExitResult = true
9620     });
9621    
9622     runScript({
9623     .code = R"NKSP_CODE(
9624     on init
9625     declare ?input[3] := ( 1.0k, 6.0, 900.0 )
9626     declare ?expected[3] := ( 6.0, 900.0, 1.0k )
9627     sort(?input, 0)
9628     exit( array_equal(?input, ?expected) )
9629     end on
9630     )NKSP_CODE",
9631     .expectBoolExitResult = true
9632     });
9633    
9634     runScript({
9635     .code = R"NKSP_CODE(
9636     on init
9637     declare ?input[3] := ( 900.0, 1.0k, 6.0 )
9638     declare ?expected[3] := ( 1.0k, 900.0, 6.0 )
9639     sort(?input, 1)
9640     exit( array_equal(?input, ?expected) )
9641     end on
9642     )NKSP_CODE",
9643     .expectBoolExitResult = true
9644     });
9645    
9646     runScript({
9647     .code = R"NKSP_CODE(
9648     on init
9649     declare ?input[3] := ( 1.0k, 0.9k, 1.1k )
9650     declare ?expected[3] := ( 0.9k, 1.0k, 1.1k )
9651     sort(?input, 0)
9652     exit( array_equal(?input, ?expected) )
9653     end on
9654     )NKSP_CODE",
9655     .expectBoolExitResult = true
9656     });
9657    
9658     runScript({
9659     .code = R"NKSP_CODE(
9660     on init
9661     declare ?input[3] := ( 2.0m, 1000.1u, 1.0 )
9662     declare ?expected[3] := ( 1000.1u, 2.0m, 1.0 )
9663     sort(?input, 0)
9664     exit( array_equal(?input, ?expected) )
9665     end on
9666     )NKSP_CODE",
9667     .expectBoolExitResult = true
9668     });
9669    
9670     runScript({
9671     .code = R"NKSP_CODE(
9672     on init
9673     declare ?input[4] := ( 2.0m, 1000.1u, 1.0, 1400.0u )
9674     declare ?expected[4] := ( 1000.1u, 1400.0u, 2.0m, 1.0 )
9675     sort(?input, 0)
9676     exit( array_equal(?input, ?expected) )
9677     end on
9678     )NKSP_CODE",
9679     .expectBoolExitResult = true
9680     });
9681    
9682     runScript({
9683     .code = R"NKSP_CODE(
9684     on init
9685     declare ?input[4] := ( 2.0m, 1000.1u, 1.0, 1400.0u )
9686     declare ?expected[4] := ( 1.0, 2.0m, 1400.0u, 1000.1u )
9687     sort(?input, 1)
9688     exit( array_equal(?input, ?expected) )
9689     end on
9690     )NKSP_CODE",
9691     .expectBoolExitResult = true
9692     });
9693    
9694     runScript({
9695     .code = R"NKSP_CODE(
9696     on init
9697     declare ?input[6] := ( 0.9k, 8.0m, 1.1k, 12000.0u, 3000.0u, 1000.0u )
9698     declare ?expected[6] := ( 1000.0u, 3000.0u, 8.0m, 12000.0u, 0.9k, 1.1k )
9699     sort(?input, 0)
9700     exit( array_equal(?input, ?expected) )
9701     end on
9702     )NKSP_CODE",
9703     .expectBoolExitResult = true
9704     });
9705    
9706     runScript({
9707     .code = R"NKSP_CODE(
9708     on init
9709     declare ?input[6] := ( 0.9k, 8.0m, 1.1k, 12000.0u, 3000.0u, 1000.0u )
9710     declare ?expected[6] := ( 1.1k, 0.9k, 12000.0u, 8.0m, 3000.0u, 1000.0u )
9711     sort(?input, 1)
9712     exit( array_equal(?input, ?expected) )
9713     end on
9714     )NKSP_CODE",
9715     .expectBoolExitResult = true
9716     });
9717    
9718 schoenebeck 3551 #if !SILENT_TEST
9719     std::cout << std::endl;
9720     #endif
9721     }
9722    
9723 schoenebeck 3590 static void testBuiltInRoundFunction() {
9724     #if !SILENT_TEST
9725     std::cout << "UNIT TEST: built-in round() function\n";
9726     #endif
9727    
9728     // integer tests ...
9729     // (ATM not allowed for this function)
9730    
9731     runScript({
9732     .code = R"NKSP_CODE(
9733     on init
9734     declare $foo := 1
9735     exit( round($foo) )
9736     end on
9737     )NKSP_CODE",
9738     .expectParseError = true // integer not allowed for this function ATM
9739     });
9740    
9741     // real number tests ...
9742    
9743     runScript({
9744     .code = R"NKSP_CODE(
9745     on init
9746     exit( round(99.4) )
9747     end on
9748     )NKSP_CODE",
9749     .expectRealExitResult = 99.0
9750     });
9751    
9752     runScript({
9753     .code = R"NKSP_CODE(
9754     on init
9755     exit( round(99.5) )
9756     end on
9757     )NKSP_CODE",
9758     .expectRealExitResult = 100.0
9759     });
9760    
9761     // std unit tests ...
9762    
9763     runScript({
9764     .code = R"NKSP_CODE(
9765     on init
9766     exit( round(2.4ms) )
9767     end on
9768     )NKSP_CODE",
9769     .expectRealExitResult = 2.0,
9770     .expectExitResultUnitPrefix = { VM_MILLI },
9771     .expectExitResultUnit = VM_SECOND
9772     });
9773    
9774     runScript({
9775     .code = R"NKSP_CODE(
9776     on init
9777     exit( round(2.6kHz) )
9778     end on
9779     )NKSP_CODE",
9780     .expectRealExitResult = 3.0,
9781     .expectExitResultUnitPrefix = { VM_KILO },
9782     .expectExitResultUnit = VM_HERTZ
9783     });
9784    
9785     // 'final' ('!') operator tests ...
9786    
9787     runScript({
9788     .code = R"NKSP_CODE(
9789     on init
9790     exit( round(123.8) )
9791     end on
9792     )NKSP_CODE",
9793     .expectRealExitResult = 124.0,
9794     .expectExitResultFinal = false
9795     });
9796    
9797     runScript({
9798     .code = R"NKSP_CODE(
9799     on init
9800     exit( round(!123.8) )
9801     end on
9802     )NKSP_CODE",
9803     .expectRealExitResult = 124.0,
9804     .expectExitResultFinal = true
9805     });
9806    
9807     #if !SILENT_TEST
9808     std::cout << std::endl;
9809     #endif
9810     }
9811    
9812     static void testBuiltInCeilFunction() {
9813     #if !SILENT_TEST
9814     std::cout << "UNIT TEST: built-in ceil() function\n";
9815     #endif
9816    
9817     // integer tests ...
9818     // (ATM not allowed for this function)
9819    
9820     runScript({
9821     .code = R"NKSP_CODE(
9822     on init
9823     declare $foo := 1
9824     exit( ceil($foo) )
9825     end on
9826     )NKSP_CODE",
9827     .expectParseError = true // integer not allowed for this function ATM
9828     });
9829    
9830     // real number tests ...
9831    
9832     runScript({
9833     .code = R"NKSP_CODE(
9834     on init
9835     exit( ceil(99.0) )
9836     end on
9837     )NKSP_CODE",
9838     .expectRealExitResult = 99.0
9839     });
9840    
9841     runScript({
9842     .code = R"NKSP_CODE(
9843     on init
9844     exit( ceil(99.1) )
9845     end on
9846     )NKSP_CODE",
9847     .expectRealExitResult = 100.0
9848     });
9849    
9850     runScript({
9851     .code = R"NKSP_CODE(
9852     on init
9853     exit( ceil(99.9) )
9854     end on
9855     )NKSP_CODE",
9856     .expectRealExitResult = 100.0
9857     });
9858    
9859     // std unit tests ...
9860    
9861     runScript({
9862     .code = R"NKSP_CODE(
9863     on init
9864     exit( ceil(2.4ms) )
9865     end on
9866     )NKSP_CODE",
9867     .expectRealExitResult = 3.0,
9868     .expectExitResultUnitPrefix = { VM_MILLI },
9869     .expectExitResultUnit = VM_SECOND
9870     });
9871    
9872     runScript({
9873     .code = R"NKSP_CODE(
9874     on init
9875     exit( ceil(2.6kHz) )
9876     end on
9877     )NKSP_CODE",
9878     .expectRealExitResult = 3.0,
9879     .expectExitResultUnitPrefix = { VM_KILO },
9880     .expectExitResultUnit = VM_HERTZ
9881     });
9882    
9883     // 'final' ('!') operator tests ...
9884    
9885     runScript({
9886     .code = R"NKSP_CODE(
9887     on init
9888     exit( ceil(123.1) )
9889     end on
9890     )NKSP_CODE",
9891     .expectRealExitResult = 124.0,
9892     .expectExitResultFinal = false
9893     });
9894    
9895     runScript({
9896     .code = R"NKSP_CODE(
9897     on init
9898     exit( ceil(!123.8) )
9899     end on
9900     )NKSP_CODE",
9901     .expectRealExitResult = 124.0,
9902     .expectExitResultFinal = true
9903     });
9904    
9905     #if !SILENT_TEST
9906     std::cout << std::endl;
9907     #endif
9908     }
9909    
9910     static void testBuiltInFloorFunction() {
9911     #if !SILENT_TEST
9912     std::cout << "UNIT TEST: built-in floor() function\n";
9913     #endif
9914    
9915     // integer tests ...
9916     // (ATM not allowed for this function)
9917    
9918     runScript({
9919     .code = R"NKSP_CODE(
9920     on init
9921     declare $foo := 1
9922     exit( floor($foo) )
9923     end on
9924     )NKSP_CODE",
9925     .expectParseError = true // integer not allowed for this function ATM
9926     });
9927    
9928     // real number tests ...
9929    
9930     runScript({
9931     .code = R"NKSP_CODE(
9932     on init
9933     exit( floor(99.0) )
9934     end on
9935     )NKSP_CODE",
9936     .expectRealExitResult = 99.0
9937     });
9938    
9939     runScript({
9940     .code = R"NKSP_CODE(
9941     on init
9942     exit( floor(99.1) )
9943     end on
9944     )NKSP_CODE",
9945     .expectRealExitResult = 99.0
9946     });
9947    
9948     runScript({
9949     .code = R"NKSP_CODE(
9950     on init
9951     exit( floor(99.9) )
9952     end on
9953     )NKSP_CODE",
9954     .expectRealExitResult = 99.0
9955     });
9956    
9957     // std unit tests ...
9958    
9959     runScript({
9960     .code = R"NKSP_CODE(
9961     on init
9962     exit( floor(2.4ms) )
9963     end on
9964     )NKSP_CODE",
9965     .expectRealExitResult = 2.0,
9966     .expectExitResultUnitPrefix = { VM_MILLI },
9967     .expectExitResultUnit = VM_SECOND
9968     });
9969    
9970     runScript({
9971     .code = R"NKSP_CODE(
9972     on init
9973     exit( floor(2.6kHz) )
9974     end on
9975     )NKSP_CODE",
9976     .expectRealExitResult = 2.0,
9977     .expectExitResultUnitPrefix = { VM_KILO },
9978     .expectExitResultUnit = VM_HERTZ
9979     });
9980    
9981     // 'final' ('!') operator tests ...
9982    
9983     runScript({
9984     .code = R"NKSP_CODE(
9985     on init
9986     exit( floor(123.1) )
9987     end on
9988     )NKSP_CODE",
9989     .expectRealExitResult = 123.0,
9990     .expectExitResultFinal = false
9991     });
9992    
9993     runScript({
9994     .code = R"NKSP_CODE(
9995     on init
9996     exit( floor(!123.8) )
9997     end on
9998     )NKSP_CODE",
9999     .expectRealExitResult = 123.0,
10000     .expectExitResultFinal = true
10001     });
10002    
10003     #if !SILENT_TEST
10004     std::cout << std::endl;
10005     #endif
10006     }
10007    
10008     static void testBuiltInSqrtFunction() {
10009     #if !SILENT_TEST
10010     std::cout << "UNIT TEST: built-in sqrt() function\n";
10011     #endif
10012    
10013     // integer tests ...
10014     // (ATM not allowed for this function)
10015    
10016     runScript({
10017     .code = R"NKSP_CODE(
10018     on init
10019     declare $foo := 1
10020     exit( sqrt($foo) )
10021     end on
10022     )NKSP_CODE",
10023     .expectParseError = true // integer not allowed for this function ATM
10024     });
10025    
10026     // real number tests ...
10027    
10028     runScript({
10029     .code = R"NKSP_CODE(
10030     on init
10031     exit( sqrt(36.0) )
10032     end on
10033     )NKSP_CODE",
10034     .expectRealExitResult = 6.0
10035     });
10036    
10037     // std unit tests ...
10038    
10039     runScript({
10040     .code = R"NKSP_CODE(
10041     on init
10042     exit( sqrt(100.0ms) )
10043     end on
10044     )NKSP_CODE",
10045     .expectRealExitResult = 10.0,
10046     .expectExitResultUnitPrefix = { VM_MILLI },
10047     .expectExitResultUnit = VM_SECOND
10048     });
10049    
10050     runScript({
10051     .code = R"NKSP_CODE(
10052     on init
10053     exit( sqrt(5.76kHz) )
10054     end on
10055     )NKSP_CODE",
10056     .expectRealExitResult = 2.4,
10057     .expectExitResultUnitPrefix = { VM_KILO },
10058     .expectExitResultUnit = VM_HERTZ
10059     });
10060    
10061     // 'final' ('!') operator tests ...
10062    
10063     runScript({
10064     .code = R"NKSP_CODE(
10065     on init
10066     exit( sqrt(25.0) )
10067     end on
10068     )NKSP_CODE",
10069     .expectRealExitResult = 5.0,
10070     .expectExitResultFinal = false
10071     });
10072    
10073     runScript({
10074     .code = R"NKSP_CODE(
10075     on init
10076     exit( sqrt(!25.0) )
10077     end on
10078     )NKSP_CODE",
10079     .expectRealExitResult = 5.0,
10080     .expectExitResultFinal = true
10081     });
10082    
10083     #if !SILENT_TEST
10084     std::cout << std::endl;
10085     #endif
10086     }
10087    
10088     static void testBuiltInLogFunction() {
10089     #if !SILENT_TEST
10090     std::cout << "UNIT TEST: built-in log() function\n";
10091     #endif
10092    
10093     // integer tests ...
10094     // (ATM not allowed for this function)
10095    
10096     runScript({
10097     .code = R"NKSP_CODE(
10098     on init
10099     declare $foo := 1
10100     exit( log($foo) )
10101     end on
10102     )NKSP_CODE",
10103     .expectParseError = true // integer not allowed for this function ATM
10104     });
10105    
10106     // real number tests ...
10107    
10108     runScript({
10109     .code = R"NKSP_CODE(
10110     on init
10111     exit( log(1.0) )
10112     end on
10113     )NKSP_CODE",
10114     .expectRealExitResult = 0.0
10115     });
10116    
10117     runScript({
10118     .code = R"NKSP_CODE(
10119     on init
10120     exit( log(~NI_MATH_E) )
10121     end on
10122     )NKSP_CODE",
10123     .expectRealExitResult = 1.0
10124     });
10125    
10126     // std unit tests ...
10127    
10128     runScript({
10129     .code = R"NKSP_CODE(
10130     on init
10131     exit( log(~NI_MATH_E * 1.0ms) )
10132     end on
10133     )NKSP_CODE",
10134     .expectRealExitResult = 1.0,
10135     .expectExitResultUnitPrefix = { VM_MILLI },
10136     .expectExitResultUnit = VM_SECOND
10137     });
10138    
10139     runScript({
10140     .code = R"NKSP_CODE(
10141     on init
10142     exit( log(~NI_MATH_E * 1.0kHz) )
10143     end on
10144     )NKSP_CODE",
10145     .expectRealExitResult = 1.0,
10146     .expectExitResultUnitPrefix = { VM_KILO },
10147     .expectExitResultUnit = VM_HERTZ
10148     });
10149    
10150     // 'final' ('!') operator tests ...
10151    
10152     runScript({
10153     .code = R"NKSP_CODE(
10154     on init
10155     exit( log(~NI_MATH_E * 1.0) )
10156     end on
10157     )NKSP_CODE",
10158     .expectRealExitResult = 1.0,
10159     .expectExitResultFinal = false
10160     });
10161    
10162     runScript({
10163     .code = R"NKSP_CODE(
10164     on init
10165     exit( log(!(~NI_MATH_E * 1.0)) )
10166     end on
10167     )NKSP_CODE",
10168     .expectRealExitResult = 1.0,
10169     .expectExitResultFinal = true
10170     });
10171    
10172     #if !SILENT_TEST
10173     std::cout << std::endl;
10174     #endif
10175     }
10176    
10177     static void testBuiltInLog2Function() {
10178     #if !SILENT_TEST
10179     std::cout << "UNIT TEST: built-in log2() function\n";
10180     #endif
10181    
10182     // integer tests ...
10183     // (ATM not allowed for this function)
10184    
10185     runScript({
10186     .code = R"NKSP_CODE(
10187     on init
10188     declare $foo := 1
10189     exit( log2($foo) )
10190     end on
10191     )NKSP_CODE",
10192     .expectParseError = true // integer not allowed for this function ATM
10193     });
10194    
10195     // real number tests ...
10196    
10197     runScript({
10198     .code = R"NKSP_CODE(
10199     on init
10200     exit( log2(1.0) )
10201     end on
10202     )NKSP_CODE",
10203     .expectRealExitResult = 0.0
10204     });
10205    
10206     runScript({
10207     .code = R"NKSP_CODE(
10208     on init
10209     exit( log2(32.0) )
10210     end on
10211     )NKSP_CODE",
10212     .expectRealExitResult = 5.0
10213     });
10214    
10215     // std unit tests ...
10216    
10217     runScript({
10218     .code = R"NKSP_CODE(
10219     on init
10220     exit( log2(32.0ms) )
10221     end on
10222     )NKSP_CODE",
10223     .expectRealExitResult = 5.0,
10224     .expectExitResultUnitPrefix = { VM_MILLI },
10225     .expectExitResultUnit = VM_SECOND
10226     });
10227    
10228     runScript({
10229     .code = R"NKSP_CODE(
10230     on init
10231     exit( log2(32.0kHz) )
10232     end on
10233     )NKSP_CODE",
10234     .expectRealExitResult = 5.0,
10235     .expectExitResultUnitPrefix = { VM_KILO },
10236     .expectExitResultUnit = VM_HERTZ
10237     });
10238    
10239     // 'final' ('!') operator tests ...
10240    
10241     runScript({
10242     .code = R"NKSP_CODE(
10243     on init
10244     exit( log2(32.0) )
10245     end on
10246     )NKSP_CODE",
10247     .expectRealExitResult = 5.0,
10248     .expectExitResultFinal = false
10249     });
10250    
10251     runScript({
10252     .code = R"NKSP_CODE(
10253     on init
10254     exit( log2(!32.0) )
10255     end on
10256     )NKSP_CODE",
10257     .expectRealExitResult = 5.0,
10258     .expectExitResultFinal = true
10259     });
10260    
10261     #if !SILENT_TEST
10262     std::cout << std::endl;
10263     #endif
10264     }
10265    
10266     static void testBuiltInLog10Function() {
10267     #if !SILENT_TEST
10268     std::cout << "UNIT TEST: built-in log10() function\n";
10269     #endif
10270    
10271     // integer tests ...
10272     // (ATM not allowed for this function)
10273    
10274     runScript({
10275     .code = R"NKSP_CODE(
10276     on init
10277     declare $foo := 1
10278     exit( log10($foo) )
10279     end on
10280     )NKSP_CODE",
10281     .expectParseError = true // integer not allowed for this function ATM
10282     });
10283    
10284     // real number tests ...
10285    
10286     runScript({
10287     .code = R"NKSP_CODE(
10288     on init
10289     exit( log10(1000.0) )
10290     end on
10291     )NKSP_CODE",
10292     .expectRealExitResult = 3.0
10293     });
10294    
10295     runScript({
10296     .code = R"NKSP_CODE(
10297     on init
10298     exit( log10(1000.0) )
10299     end on
10300     )NKSP_CODE",
10301     .expectRealExitResult = 3.0
10302     });
10303    
10304     // std unit tests ...
10305    
10306     runScript({
10307     .code = R"NKSP_CODE(
10308     on init
10309     exit( log10(1000.0ms) )
10310     end on
10311     )NKSP_CODE",
10312     .expectRealExitResult = 3.0,
10313     .expectExitResultUnitPrefix = { VM_MILLI },
10314     .expectExitResultUnit = VM_SECOND
10315     });
10316    
10317     runScript({
10318     .code = R"NKSP_CODE(
10319     on init
10320     exit( log10(1000.0kHz) )
10321     end on
10322     )NKSP_CODE",
10323     .expectRealExitResult = 3.0,
10324     .expectExitResultUnitPrefix = { VM_KILO },
10325     .expectExitResultUnit = VM_HERTZ
10326     });
10327    
10328     // 'final' ('!') operator tests ...
10329    
10330     runScript({
10331     .code = R"NKSP_CODE(
10332     on init
10333     exit( log10(1000.0) )
10334     end on
10335     )NKSP_CODE",
10336     .expectRealExitResult = 3.0,
10337     .expectExitResultFinal = false
10338     });
10339    
10340     runScript({
10341     .code = R"NKSP_CODE(
10342     on init
10343     exit( log10(!1000.0) )
10344     end on
10345     )NKSP_CODE",
10346     .expectRealExitResult = 3.0,
10347     .expectExitResultFinal = true
10348     });
10349    
10350     #if !SILENT_TEST
10351     std::cout << std::endl;
10352     #endif
10353     }
10354    
10355     static void testBuiltInExpFunction() {
10356     #if !SILENT_TEST
10357     std::cout << "UNIT TEST: built-in exp() function\n";
10358     #endif
10359    
10360     // integer tests ...
10361     // (ATM not allowed for this function)
10362    
10363     runScript({
10364     .code = R"NKSP_CODE(
10365     on init
10366     declare $foo := 1
10367     exit( exp($foo) )
10368     end on
10369     )NKSP_CODE",
10370     .expectParseError = true // integer not allowed for this function ATM
10371     });
10372    
10373     // real number tests ...
10374    
10375     runScript({
10376     .code = R"NKSP_CODE(
10377     on init
10378     exit( exp(0.0) )
10379     end on
10380     )NKSP_CODE",
10381     .expectRealExitResult = 1.0
10382     });
10383    
10384     runScript({
10385     .code = R"NKSP_CODE(
10386     on init
10387     exit( exp(1.0) )
10388     end on
10389     )NKSP_CODE",
10390     .expectRealExitResult = M_E
10391     });
10392    
10393     // std unit tests ...
10394    
10395     runScript({
10396     .code = R"NKSP_CODE(
10397     on init
10398     exit( exp(0.0ms) )
10399     end on
10400     )NKSP_CODE",
10401     .expectRealExitResult = 1.0,
10402     .expectExitResultUnitPrefix = { VM_MILLI },
10403     .expectExitResultUnit = VM_SECOND
10404     });
10405    
10406     runScript({
10407     .code = R"NKSP_CODE(
10408     on init
10409     exit( exp(0.0kHz) )
10410     end on
10411     )NKSP_CODE",
10412     .expectRealExitResult = 1.0,
10413     .expectExitResultUnitPrefix = { VM_KILO },
10414     .expectExitResultUnit = VM_HERTZ
10415     });
10416    
10417     // 'final' ('!') operator tests ...
10418    
10419     runScript({
10420     .code = R"NKSP_CODE(
10421     on init
10422     exit( exp(0.0) )
10423     end on
10424     )NKSP_CODE",
10425     .expectRealExitResult = 1.0,
10426     .expectExitResultFinal = false
10427     });
10428    
10429     runScript({
10430     .code = R"NKSP_CODE(
10431     on init
10432     exit( exp(!0.0) )
10433     end on
10434     )NKSP_CODE",
10435     .expectRealExitResult = 1.0,
10436     .expectExitResultFinal = true
10437     });
10438    
10439     #if !SILENT_TEST
10440     std::cout << std::endl;
10441     #endif
10442     }
10443    
10444     static void testBuiltInPowFunction() {
10445     #if !SILENT_TEST
10446     std::cout << "UNIT TEST: built-in pow() function\n";
10447     #endif
10448    
10449     // integer tests ...
10450     // (ATM not allowed for this function)
10451    
10452     runScript({
10453     .code = R"NKSP_CODE(
10454     on init
10455     declare $foo := 1
10456     exit( pow($foo,$foo) )
10457     end on
10458     )NKSP_CODE",
10459     .expectParseError = true // integer not allowed for this function ATM
10460     });
10461    
10462     // real number tests ...
10463    
10464     runScript({
10465     .code = R"NKSP_CODE(
10466     on init
10467     exit( pow(1.0) )
10468     end on
10469     )NKSP_CODE",
10470     .expectParseError = true // because pow() requires exactly 2 arguments
10471     });
10472    
10473     runScript({
10474     .code = R"NKSP_CODE(
10475     on init
10476     exit( pow(3.0,4.0) )
10477     end on
10478     )NKSP_CODE",
10479     .expectRealExitResult = 81.0
10480     });
10481    
10482     // std unit tests ...
10483    
10484     runScript({
10485     .code = R"NKSP_CODE(
10486     on init
10487     exit( pow(3.0ms,4.0ms) )
10488     end on
10489     )NKSP_CODE",
10490     .expectParseError = true // because units are prohibited for 2nd argument
10491     });
10492    
10493     runScript({
10494     .code = R"NKSP_CODE(
10495     on init
10496     exit( pow(3.0,4.0ms) )
10497     end on
10498     )NKSP_CODE",
10499     .expectParseError = true // because units are prohibited for 2nd argument
10500     });
10501    
10502     runScript({
10503     .code = R"NKSP_CODE(
10504     on init
10505     exit( pow(3.0ms,4.0) )
10506     end on
10507     )NKSP_CODE",
10508     .expectRealExitResult = 81.0,
10509     .expectExitResultUnitPrefix = { VM_MILLI },
10510     .expectExitResultUnit = VM_SECOND
10511     });
10512    
10513     runScript({
10514     .code = R"NKSP_CODE(
10515     on init
10516     exit( pow(3.0kHz,4.0) )
10517     end on
10518     )NKSP_CODE",
10519     .expectRealExitResult = 81.0,
10520     .expectExitResultUnitPrefix = { VM_KILO },
10521     .expectExitResultUnit = VM_HERTZ
10522     });
10523    
10524     // 'final' ('!') operator tests ...
10525    
10526     runScript({
10527     .code = R"NKSP_CODE(
10528     on init
10529     exit( pow(3.0,4.0) )
10530     end on
10531     )NKSP_CODE",
10532     .expectRealExitResult = 81.0,
10533     .expectExitResultFinal = false
10534     });
10535    
10536     runScript({
10537     .code = R"NKSP_CODE(
10538     on init
10539     exit( pow(!3.0,4.0) )
10540     end on
10541     )NKSP_CODE",
10542     .expectRealExitResult = 81.0,
10543     .expectExitResultFinal = true
10544     });
10545    
10546     runScript({
10547     .code = R"NKSP_CODE(
10548     on init
10549     exit( pow(3.0,!4.0) )
10550     end on
10551     )NKSP_CODE",
10552     .expectParseError = true // because 'final' is meaningless for 2nd argument
10553     });
10554    
10555     #if !SILENT_TEST
10556     std::cout << std::endl;
10557     #endif
10558     }
10559    
10560     static void testBuiltInSinFunction() {
10561     #if !SILENT_TEST
10562     std::cout << "UNIT TEST: built-in sin() function\n";
10563     #endif
10564    
10565     // integer tests ...
10566     // (ATM not allowed for this function)
10567    
10568     runScript({
10569     .code = R"NKSP_CODE(
10570     on init
10571     declare $foo := 1
10572     exit( sin($foo) )
10573     end on
10574     )NKSP_CODE",
10575     .expectParseError = true // integer not allowed for this function ATM
10576     });
10577    
10578     // real number tests ...
10579    
10580     runScript({
10581     .code = R"NKSP_CODE(
10582     on init
10583     exit( sin(0.0) )
10584     end on
10585     )NKSP_CODE",
10586     .expectRealExitResult = 0.0
10587     });
10588    
10589     runScript({
10590     .code = R"NKSP_CODE(
10591     on init
10592     exit( sin(0.5 * ~NI_MATH_PI) )
10593     end on
10594     )NKSP_CODE",
10595     .expectRealExitResult = 1.0
10596     });
10597    
10598     runScript({
10599     .code = R"NKSP_CODE(
10600     on init
10601     exit( sin(~NI_MATH_PI) )
10602     end on
10603     )NKSP_CODE",
10604     .expectRealExitResult = 0.0
10605     });
10606    
10607     runScript({
10608     .code = R"NKSP_CODE(
10609     on init
10610     exit( sin(1.5 * ~NI_MATH_PI) )
10611     end on
10612     )NKSP_CODE",
10613     .expectRealExitResult = -1.0
10614     });
10615    
10616     // std unit tests ...
10617    
10618     runScript({
10619     .code = R"NKSP_CODE(
10620     on init
10621     exit( sin(0.0ms) )
10622     end on
10623     )NKSP_CODE",
10624     .expectRealExitResult = 0.0,
10625     .expectExitResultUnitPrefix = { VM_MILLI },
10626     .expectExitResultUnit = VM_SECOND
10627     });
10628    
10629     runScript({
10630     .code = R"NKSP_CODE(
10631     on init
10632     exit( sin(0.0kHz) )
10633     end on
10634     )NKSP_CODE",
10635     .expectRealExitResult = 0.0,
10636     .expectExitResultUnitPrefix = { VM_KILO },
10637     .expectExitResultUnit = VM_HERTZ
10638     });
10639    
10640     // 'final' ('!') operator tests ...
10641    
10642     runScript({
10643     .code = R"NKSP_CODE(
10644     on init
10645     exit( sin(0.0) )
10646     end on
10647     )NKSP_CODE",
10648     .expectRealExitResult = 0.0,
10649     .expectExitResultFinal = false
10650     });
10651    
10652     runScript({
10653     .code = R"NKSP_CODE(
10654     on init
10655     exit( sin(!0.0) )
10656     end on
10657     )NKSP_CODE",
10658     .expectRealExitResult = 0.0,
10659     .expectExitResultFinal = true
10660     });
10661    
10662     #if !SILENT_TEST
10663     std::cout << std::endl;
10664     #endif
10665     }
10666    
10667     static void testBuiltInCosFunction() {
10668     #if !SILENT_TEST
10669     std::cout << "UNIT TEST: built-in cos() function\n";
10670     #endif
10671    
10672     // integer tests ...
10673     // (ATM not allowed for this function)
10674    
10675     runScript({
10676     .code = R"NKSP_CODE(
10677     on init
10678     declare $foo := 1
10679     exit( cos($foo) )
10680     end on
10681     )NKSP_CODE",
10682     .expectParseError = true // integer not allowed for this function ATM
10683     });
10684    
10685     // real number tests ...
10686    
10687     runScript({
10688     .code = R"NKSP_CODE(
10689     on init
10690     exit( cos(0.0) )
10691     end on
10692     )NKSP_CODE",
10693     .expectRealExitResult = 1.0
10694     });
10695    
10696     runScript({
10697     .code = R"NKSP_CODE(
10698     on init
10699     exit( cos(0.5 * ~NI_MATH_PI) )
10700     end on
10701     )NKSP_CODE",
10702     .expectRealExitResult = 0.0
10703     });
10704    
10705     runScript({
10706     .code = R"NKSP_CODE(
10707     on init
10708     exit( cos(~NI_MATH_PI) )
10709     end on
10710     )NKSP_CODE",
10711     .expectRealExitResult = -1.0
10712     });
10713    
10714     runScript({
10715     .code = R"NKSP_CODE(
10716     on init
10717     exit( cos(1.5 * ~NI_MATH_PI) )
10718     end on
10719     )NKSP_CODE",
10720     .expectRealExitResult = 0.0
10721     });
10722    
10723     // std unit tests ...
10724    
10725     runScript({
10726     .code = R"NKSP_CODE(
10727     on init
10728     exit( cos(0.0ms) )
10729     end on
10730     )NKSP_CODE",
10731     .expectRealExitResult = 1.0,
10732     .expectExitResultUnitPrefix = { VM_MILLI },
10733     .expectExitResultUnit = VM_SECOND
10734     });
10735    
10736     runScript({
10737     .code = R"NKSP_CODE(
10738     on init
10739     exit( cos(0.0kHz) )
10740     end on
10741     )NKSP_CODE",
10742     .expectRealExitResult = 1.0,
10743     .expectExitResultUnitPrefix = { VM_KILO },
10744     .expectExitResultUnit = VM_HERTZ
10745     });
10746    
10747     // 'final' ('!') operator tests ...
10748    
10749     runScript({
10750     .code = R"NKSP_CODE(
10751     on init
10752     exit( cos(0.0) )
10753     end on
10754     )NKSP_CODE",
10755     .expectRealExitResult = 1.0,
10756     .expectExitResultFinal = false
10757     });
10758    
10759     runScript({
10760     .code = R"NKSP_CODE(
10761     on init
10762     exit( cos(!0.0) )
10763     end on
10764     )NKSP_CODE",
10765     .expectRealExitResult = 1.0,
10766     .expectExitResultFinal = true
10767     });
10768    
10769     #if !SILENT_TEST
10770     std::cout << std::endl;
10771     #endif
10772     }
10773    
10774     static void testBuiltInTanFunction() {
10775     #if !SILENT_TEST
10776     std::cout << "UNIT TEST: built-in tan() function\n";
10777     #endif
10778    
10779     // integer tests ...
10780     // (ATM not allowed for this function)
10781    
10782     runScript({
10783     .code = R"NKSP_CODE(
10784     on init
10785     declare $foo := 1
10786     exit( tan($foo) )
10787     end on
10788     )NKSP_CODE",
10789     .expectParseError = true // integer not allowed for this function ATM
10790     });
10791    
10792     // real number tests ...
10793    
10794     runScript({
10795     .code = R"NKSP_CODE(
10796     on init
10797     exit( tan(0.0) )
10798     end on
10799     )NKSP_CODE",
10800     .expectRealExitResult = 0.0
10801     });
10802    
10803     runScript({
10804     .code = R"NKSP_CODE(
10805     on init
10806     exit( tan(0.25 * ~NI_MATH_PI) )
10807     end on
10808     )NKSP_CODE",
10809     .expectRealExitResult = 1.0
10810     });
10811    
10812     // std unit tests ...
10813    
10814     runScript({
10815     .code = R"NKSP_CODE(
10816     on init
10817     exit( tan(0.0ms) )
10818     end on
10819     )NKSP_CODE",
10820     .expectRealExitResult = 0.0,
10821     .expectExitResultUnitPrefix = { VM_MILLI },
10822     .expectExitResultUnit = VM_SECOND
10823     });
10824    
10825     runScript({
10826     .code = R"NKSP_CODE(
10827     on init
10828     exit( tan(0.0kHz) )
10829     end on
10830     )NKSP_CODE",
10831     .expectRealExitResult = 0.0,
10832     .expectExitResultUnitPrefix = { VM_KILO },
10833     .expectExitResultUnit = VM_HERTZ
10834     });
10835    
10836     // 'final' ('!') operator tests ...
10837    
10838     runScript({
10839     .code = R"NKSP_CODE(
10840     on init
10841     exit( tan(0.0) )
10842     end on
10843     )NKSP_CODE",
10844     .expectRealExitResult = 0.0,
10845     .expectExitResultFinal = false
10846     });
10847    
10848     runScript({
10849     .code = R"NKSP_CODE(
10850     on init
10851     exit( tan(!0.0) )
10852     end on
10853     )NKSP_CODE",
10854     .expectRealExitResult = 0.0,
10855     .expectExitResultFinal = true
10856     });
10857    
10858     #if !SILENT_TEST
10859     std::cout << std::endl;
10860     #endif
10861     }
10862    
10863     static void testBuiltInAsinFunction() {
10864     #if !SILENT_TEST
10865     std::cout << "UNIT TEST: built-in asin() function\n";
10866     #endif
10867    
10868     // integer tests ...
10869     // (ATM not allowed for this function)
10870    
10871     runScript({
10872     .code = R"NKSP_CODE(
10873     on init
10874     declare $foo := 1
10875     exit( asin($foo) )
10876     end on
10877     )NKSP_CODE",
10878     .expectParseError = true // integer not allowed for this function ATM
10879     });
10880    
10881     // real number tests ...
10882    
10883     runScript({
10884     .code = R"NKSP_CODE(
10885     on init
10886     exit( asin(0.0) )
10887     end on
10888     )NKSP_CODE",
10889     .expectRealExitResult = 0.0
10890     });
10891    
10892     runScript({
10893     .code = R"NKSP_CODE(
10894     on init
10895     exit( asin(1.0) )
10896     end on
10897     )NKSP_CODE",
10898     .expectRealExitResult = 0.5 * M_PI
10899     });
10900    
10901     runScript({
10902     .code = R"NKSP_CODE(
10903     on init
10904     exit( asin(-1.0) )
10905     end on
10906     )NKSP_CODE",
10907     .expectRealExitResult = -0.5 * M_PI
10908     });
10909    
10910     // std unit tests ...
10911    
10912     runScript({
10913     .code = R"NKSP_CODE(
10914     on init
10915     exit( asin(0.0ms) )
10916     end on
10917     )NKSP_CODE",
10918     .expectRealExitResult = 0.0,
10919     .expectExitResultUnitPrefix = { VM_MILLI },
10920     .expectExitResultUnit = VM_SECOND
10921     });
10922    
10923     runScript({
10924     .code = R"NKSP_CODE(
10925     on init
10926     exit( asin(0.0kHz) )
10927     end on
10928     )NKSP_CODE",
10929     .expectRealExitResult = 0.0,
10930     .expectExitResultUnitPrefix = { VM_KILO },
10931     .expectExitResultUnit = VM_HERTZ
10932     });
10933    
10934     // 'final' ('!') operator tests ...
10935    
10936     runScript({
10937     .code = R"NKSP_CODE(
10938     on init
10939     exit( asin(0.0) )
10940     end on
10941     )NKSP_CODE",
10942     .expectRealExitResult = 0.0,
10943     .expectExitResultFinal = false
10944     });
10945    
10946     runScript({
10947     .code = R"NKSP_CODE(
10948     on init
10949     exit( asin(!0.0) )
10950     end on
10951     )NKSP_CODE",
10952     .expectRealExitResult = 0.0,
10953     .expectExitResultFinal = true
10954     });
10955    
10956     #if !SILENT_TEST
10957     std::cout << std::endl;
10958     #endif
10959     }
10960    
10961     static void testBuiltInAcosFunction() {
10962     #if !SILENT_TEST
10963     std::cout << "UNIT TEST: built-in acos() function\n";
10964     #endif
10965    
10966     // integer tests ...
10967     // (ATM not allowed for this function)
10968    
10969     runScript({
10970     .code = R"NKSP_CODE(
10971     on init
10972     declare $foo := 1
10973     exit( acos($foo) )
10974     end on
10975     )NKSP_CODE",
10976     .expectParseError = true // integer not allowed for this function ATM
10977     });
10978    
10979     // real number tests ...
10980    
10981     runScript({
10982     .code = R"NKSP_CODE(
10983     on init
10984     exit( acos(1.0) )
10985     end on
10986     )NKSP_CODE",
10987     .expectRealExitResult = 0.0
10988     });
10989    
10990     runScript({
10991     .code = R"NKSP_CODE(
10992     on init
10993     exit( acos(0.0) )
10994     end on
10995     )NKSP_CODE",
10996     .expectRealExitResult = 0.5 * M_PI
10997     });
10998    
10999     runScript({
11000     .code = R"NKSP_CODE(
11001     on init
11002     exit( acos(-1.0) )
11003     end on
11004     )NKSP_CODE",
11005     .expectRealExitResult = M_PI
11006     });
11007    
11008     // std unit tests ...
11009    
11010     runScript({
11011     .code = R"NKSP_CODE(
11012     on init
11013     exit( acos(1.0ms) )
11014     end on
11015     )NKSP_CODE",
11016     .expectRealExitResult = 0.0,
11017     .expectExitResultUnitPrefix = { VM_MILLI },
11018     .expectExitResultUnit = VM_SECOND
11019     });
11020    
11021     runScript({
11022     .code = R"NKSP_CODE(
11023     on init
11024     exit( acos(1.0kHz) )
11025     end on
11026     )NKSP_CODE",
11027     .expectRealExitResult = 0.0,
11028     .expectExitResultUnitPrefix = { VM_KILO },
11029     .expectExitResultUnit = VM_HERTZ
11030     });
11031    
11032     // 'final' ('!') operator tests ...
11033    
11034     runScript({
11035     .code = R"NKSP_CODE(
11036     on init
11037     exit( acos(1.0) )
11038     end on
11039     )NKSP_CODE",
11040     .expectRealExitResult = 0.0,
11041     .expectExitResultFinal = false
11042     });
11043    
11044     runScript({
11045     .code = R"NKSP_CODE(
11046     on init
11047     exit( acos(!1.0) )
11048     end on
11049     )NKSP_CODE",
11050     .expectRealExitResult = 0.0,
11051     .expectExitResultFinal = true
11052     });
11053    
11054     #if !SILENT_TEST
11055     std::cout << std::endl;
11056     #endif
11057     }
11058    
11059     static void testBuiltInAtanFunction() {
11060     #if !SILENT_TEST
11061     std::cout << "UNIT TEST: built-in atan() function\n";
11062     #endif
11063    
11064     // integer tests ...
11065     // (ATM not allowed for this function)
11066    
11067     runScript({
11068     .code = R"NKSP_CODE(
11069     on init
11070     declare $foo := 1
11071     exit( atan($foo) )
11072     end on
11073     )NKSP_CODE",
11074     .expectParseError = true // integer not allowed for this function ATM
11075     });
11076    
11077     // real number tests ...
11078    
11079     runScript({
11080     .code = R"NKSP_CODE(
11081     on init
11082     exit( atan(0.0) )
11083     end on
11084     )NKSP_CODE",
11085     .expectRealExitResult = 0.0
11086     });
11087    
11088     runScript({
11089     .code = R"NKSP_CODE(
11090     on init
11091     exit( atan(1.0) )
11092     end on
11093     )NKSP_CODE",
11094     .expectRealExitResult = 0.25 * M_PI
11095     });
11096    
11097     // std unit tests ...
11098    
11099     runScript({
11100     .code = R"NKSP_CODE(
11101     on init
11102     exit( atan(0.0ms) )
11103     end on
11104     )NKSP_CODE",
11105     .expectRealExitResult = 0.0,
11106     .expectExitResultUnitPrefix = { VM_MILLI },
11107     .expectExitResultUnit = VM_SECOND
11108     });
11109    
11110     runScript({
11111     .code = R"NKSP_CODE(
11112     on init
11113     exit( atan(0.0kHz) )
11114     end on
11115     )NKSP_CODE",
11116     .expectRealExitResult = 0.0,
11117     .expectExitResultUnitPrefix = { VM_KILO },
11118     .expectExitResultUnit = VM_HERTZ
11119     });
11120    
11121     // 'final' ('!') operator tests ...
11122    
11123     runScript({
11124     .code = R"NKSP_CODE(
11125     on init
11126     exit( atan(0.0) )
11127     end on
11128     )NKSP_CODE",
11129     .expectRealExitResult = 0.0,
11130     .expectExitResultFinal = false
11131     });
11132    
11133     runScript({
11134     .code = R"NKSP_CODE(
11135     on init
11136     exit( atan(!0.0) )
11137     end on
11138     )NKSP_CODE",
11139     .expectRealExitResult = 0.0,
11140     .expectExitResultFinal = true
11141     });
11142    
11143     #if !SILENT_TEST
11144     std::cout << std::endl;
11145     #endif
11146     }
11147    
11148 schoenebeck 3551 static void testBuiltInNumElementsFunction() {
11149     #if !SILENT_TEST
11150     std::cout << "UNIT TEST: built-in num_elements() function\n";
11151     #endif
11152    
11153 schoenebeck 3581 // integer array tests ...
11154    
11155 schoenebeck 3551 runScript({
11156     .code = R"NKSP_CODE(
11157     on init
11158     declare %foo[3] := ( 19, 3, 6 )
11159     exit( num_elements(%foo) )
11160     end on
11161     )NKSP_CODE",
11162     .expectIntExitResult = 3
11163     });
11164    
11165     runScript({
11166     .code = R"NKSP_CODE(
11167     on init
11168     declare %foo[1] := ( 19 )
11169     exit( num_elements(%foo) )
11170     end on
11171     )NKSP_CODE",
11172     .expectIntExitResult = 1
11173     });
11174    
11175     runScript({
11176     .code = R"NKSP_CODE(
11177     on init
11178     declare %foo[5] := ( 1, 2, 3, 4, 5 )
11179     exit( num_elements(%foo) )
11180     end on
11181     )NKSP_CODE",
11182     .expectIntExitResult = 5
11183     });
11184    
11185 schoenebeck 3581 // real array tests ...
11186    
11187     runScript({
11188     .code = R"NKSP_CODE(
11189     on init
11190     declare ?foo[3] := ( 19.0, 3.2, 6.5 )
11191     exit( num_elements(?foo) )
11192     end on
11193     )NKSP_CODE",
11194     .expectIntExitResult = 3
11195     });
11196    
11197     runScript({
11198     .code = R"NKSP_CODE(
11199     on init
11200     declare ?foo[1] := ( 19.0 )
11201     exit( num_elements(?foo) )
11202     end on
11203     )NKSP_CODE",
11204     .expectIntExitResult = 1
11205     });
11206    
11207     runScript({
11208     .code = R"NKSP_CODE(
11209     on init
11210     declare ?foo[5] := ( 1.1, 2.2, 3.3, 4.4, 5.5 )
11211     exit( num_elements(?foo) )
11212     end on
11213     )NKSP_CODE",
11214     .expectIntExitResult = 5
11215     });
11216    
11217 schoenebeck 3551 #if !SILENT_TEST
11218     std::cout << std::endl;
11219     #endif
11220     }
11221    
11222     static void testBuiltInSearchFunction() {
11223     #if !SILENT_TEST
11224     std::cout << "UNIT TEST: built-in search() function\n";
11225     #endif
11226    
11227 schoenebeck 3581 // integer array tests ...
11228    
11229 schoenebeck 3551 runScript({
11230     .code = R"NKSP_CODE(
11231     on init
11232     declare %foo[3] := ( 19, 3, 6 )
11233     exit( search(%foo, 19) )
11234     end on
11235     )NKSP_CODE",
11236     .expectIntExitResult = 0
11237     });
11238    
11239     runScript({
11240     .code = R"NKSP_CODE(
11241     on init
11242     declare %foo[3] := ( 19, 3, 6 )
11243     exit( search(%foo, 3) )
11244     end on
11245     )NKSP_CODE",
11246     .expectIntExitResult = 1
11247     });
11248    
11249     runScript({
11250     .code = R"NKSP_CODE(
11251     on init
11252     declare %foo[3] := ( 19, 3, 6 )
11253     exit( search(%foo, 6) )
11254     end on
11255     )NKSP_CODE",
11256     .expectIntExitResult = 2
11257     });
11258    
11259     runScript({
11260     .code = R"NKSP_CODE(
11261     on init
11262     declare %foo[3] := ( 19, 3, 6 )
11263     exit( search(%foo, 2) )
11264     end on
11265     )NKSP_CODE",
11266     .expectIntExitResult = -1
11267     });
11268    
11269 schoenebeck 3581 // real array tests ...
11270    
11271     runScript({
11272     .code = R"NKSP_CODE(
11273     on init
11274     declare ?foo[3] := ( 19.12, 3.45, 6.89 )
11275     exit( search(?foo, 19.12) )
11276     end on
11277     )NKSP_CODE",
11278     .expectIntExitResult = 0
11279     });
11280    
11281     runScript({
11282     .code = R"NKSP_CODE(
11283     on init
11284     declare ?foo[3] := ( 19.12, 3.45, 6.89 )
11285     exit( search(?foo, 3.45) )
11286     end on
11287     )NKSP_CODE",
11288     .expectIntExitResult = 1
11289     });
11290    
11291     runScript({
11292     .code = R"NKSP_CODE(
11293     on init
11294     declare ?foo[3] := ( 19.12, 3.45, 6.89 )
11295     exit( search(?foo, 6.89) )
11296     end on
11297     )NKSP_CODE",
11298     .expectIntExitResult = 2
11299     });
11300    
11301     runScript({
11302     .code = R"NKSP_CODE(
11303     on init
11304     declare ?foo[3] := ( 19.12, 3.45, 6.89 )
11305     exit( search(?foo, 6.99) )
11306     end on
11307     )NKSP_CODE",
11308     .expectIntExitResult = -1
11309     });
11310    
11311 schoenebeck 3551 #if !SILENT_TEST
11312     std::cout << std::endl;
11313     #endif
11314     }
11315    
11316     static void testIfStatement() {
11317     #if !SILENT_TEST
11318     std::cout << "UNIT TEST: if statement\n";
11319     #endif
11320    
11321     runScript({
11322     .code = R"NKSP_CODE(
11323     on init
11324     declare $foo := 1
11325     if ($foo)
11326     exit(42)
11327     end if
11328     end on
11329     )NKSP_CODE",
11330     .expectIntExitResult = 42
11331     });
11332    
11333     runScript({
11334     .code = R"NKSP_CODE(
11335     on init
11336     declare $foo := 0
11337     if ($foo)
11338     exit(42)
11339     end if
11340     exit(3)
11341     end on
11342     )NKSP_CODE",
11343     .expectIntExitResult = 3
11344     });
11345    
11346     runScript({
11347     .code = R"NKSP_CODE(
11348     on init
11349     declare $foo := 1
11350     if ($foo)
11351     exit(42)
11352     else
11353     exit(3)
11354     end if
11355     end on
11356     )NKSP_CODE",
11357     .expectIntExitResult = 42
11358     });
11359    
11360     runScript({
11361     .code = R"NKSP_CODE(
11362     on init
11363     declare $foo := 0
11364     if ($foo)
11365     exit(42)
11366     else
11367     exit(3)
11368     end if
11369     end on
11370     )NKSP_CODE",
11371     .expectIntExitResult = 3
11372     });
11373    
11374     #if !SILENT_TEST
11375     std::cout << std::endl;
11376     #endif
11377     }
11378    
11379     static void testWhileStatement() {
11380     #if !SILENT_TEST
11381     std::cout << "UNIT TEST: while statement\n";
11382     #endif
11383    
11384     runScript({
11385     .code = R"NKSP_CODE(
11386     on init
11387     declare $foo := 100
11388     declare $i := 50
11389     while ($i)
11390     $foo := $foo + 1
11391     $i := $i - 1
11392     end while
11393     exit($foo)
11394     end on
11395     )NKSP_CODE",
11396     .expectIntExitResult = 150
11397     });
11398    
11399     #if !SILENT_TEST
11400     std::cout << std::endl;
11401     #endif
11402     }
11403    
11404 schoenebeck 3693 static void testBuiltInVars() {
11405     #if !SILENT_TEST
11406     std::cout << "UNIT TEST: built-in variables\n";
11407     #endif
11408    
11409     runScript({
11410     .code = R"NKSP_CODE(
11411     on init
11412     exit($NKSP_PERF_TIMER)
11413     end on
11414     )NKSP_CODE",
11415     .expectExitResultIsInt = true,
11416     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11417     .expectExitResultUnit = VM_NO_UNIT
11418     });
11419    
11420     runScript({
11421     .code = R"NKSP_CODE(
11422     on init
11423     exit($NKSP_REAL_TIMER)
11424     end on
11425     )NKSP_CODE",
11426     .expectExitResultIsInt = true,
11427     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11428     .expectExitResultUnit = VM_NO_UNIT
11429     });
11430    
11431     runScript({
11432     .code = R"NKSP_CODE(
11433     on init
11434     exit($KSP_TIMER)
11435     end on
11436     )NKSP_CODE",
11437     .expectExitResultIsInt = true,
11438     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11439     .expectExitResultUnit = VM_NO_UNIT
11440     });
11441    
11442     runScript({
11443     .code = R"NKSP_CODE(
11444     on init
11445     exit(~NI_MATH_PI)
11446     end on
11447     )NKSP_CODE",
11448     .expectExitResultIsReal = true,
11449     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11450     .expectExitResultUnit = VM_NO_UNIT
11451     });
11452    
11453     runScript({
11454     .code = R"NKSP_CODE(
11455     on init
11456     exit(~NI_MATH_E)
11457     end on
11458     )NKSP_CODE",
11459     .expectExitResultIsReal = true,
11460     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11461     .expectExitResultUnit = VM_NO_UNIT
11462     });
11463    
11464     runScript({
11465     .code = R"NKSP_CODE(
11466     on init
11467     exit($NI_CB_TYPE_INIT)
11468     end on
11469     )NKSP_CODE",
11470     .expectIntExitResult = VM_EVENT_HANDLER_INIT,
11471     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11472     .expectExitResultUnit = VM_NO_UNIT
11473     });
11474    
11475     runScript({
11476     .code = R"NKSP_CODE(
11477     on init
11478     exit($NI_CB_TYPE_NOTE)
11479     end on
11480     )NKSP_CODE",
11481     .expectIntExitResult = VM_EVENT_HANDLER_NOTE,
11482     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11483     .expectExitResultUnit = VM_NO_UNIT
11484     });
11485    
11486     runScript({
11487     .code = R"NKSP_CODE(
11488     on init
11489     exit($NI_CB_TYPE_RELEASE)
11490     end on
11491     )NKSP_CODE",
11492     .expectIntExitResult = VM_EVENT_HANDLER_RELEASE,
11493     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11494     .expectExitResultUnit = VM_NO_UNIT
11495     });
11496    
11497     runScript({
11498     .code = R"NKSP_CODE(
11499     on init
11500     exit($NI_CB_TYPE_CONTROLLER)
11501     end on
11502     )NKSP_CODE",
11503     .expectIntExitResult = VM_EVENT_HANDLER_CONTROLLER,
11504     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11505     .expectExitResultUnit = VM_NO_UNIT
11506     });
11507    
11508     runScript({
11509     .code = R"NKSP_CODE(
11510     on init
11511     exit($NI_CB_TYPE_RPN)
11512     end on
11513     )NKSP_CODE",
11514     .expectIntExitResult = VM_EVENT_HANDLER_RPN,
11515     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11516     .expectExitResultUnit = VM_NO_UNIT
11517     });
11518    
11519     runScript({
11520     .code = R"NKSP_CODE(
11521     on init
11522     exit($NI_CB_TYPE_NRPN)
11523     end on
11524     )NKSP_CODE",
11525     .expectIntExitResult = VM_EVENT_HANDLER_NRPN,
11526     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
11527     .expectExitResultUnit = VM_NO_UNIT
11528     });
11529    
11530     #if !SILENT_TEST
11531     std::cout << std::endl;
11532     #endif
11533     }
11534    
11535 schoenebeck 3551 #if !NO_MAIN
11536    
11537     int main() {
11538     testBuiltInExitFunction();
11539     testStringConcatOperator();
11540 schoenebeck 3575 testNegOperator();
11541 schoenebeck 3551 testPlusOperator();
11542     testMinusOperator();
11543     testModuloOperator();
11544     testMultiplyOperator();
11545     testDivideOperator();
11546     testSmallerThanOperator();
11547     testGreaterThanOperator();
11548     testSmallerOrEqualOperator();
11549     testGreaterOrEqualOperator();
11550     testEqualOperator();
11551     testUnequalOperator();
11552     testLogicalAndOperator();
11553     testLogicalOrOperator();
11554     testLogicalNotOperator();
11555     testBitwiseAndOperator();
11556     testBitwiseOrOperator();
11557     testBitwiseNotOperator();
11558     testPrecedenceOfOperators();
11559 schoenebeck 3727 testIntVarDeclaration();
11560     testIntArrayVarDeclaration();
11561     testRealVarDeclaration();
11562     testRealArrayVarDeclaration();
11563     testStringVarDeclaration();
11564 schoenebeck 3551 testBuiltInMinFunction();
11565     testBuiltInMaxFunction();
11566     testBuiltInAbsFunction();
11567     testBuiltInIncFunction();
11568     testBuiltInDecFunction();
11569     testBuiltInInRangeFunction();
11570     testBuiltInRandomFunction();
11571     testBuiltInShiftLeftFunction();
11572     testBuiltInShiftRightFunction();
11573 schoenebeck 3678 testBuiltInMsbFunction();
11574     testBuiltInLsbFunction();
11575 schoenebeck 3575 testBuiltInIntToRealFunction();
11576     testBuiltInRealFunction();
11577     testBuiltInRealToIntFunction();
11578     testBuiltInIntFunction();
11579 schoenebeck 3590 testBuiltInRoundFunction();
11580     testBuiltInCeilFunction();
11581     testBuiltInFloorFunction();
11582     testBuiltInSqrtFunction();
11583     testBuiltInLogFunction();
11584     testBuiltInLog2Function();
11585     testBuiltInLog10Function();
11586     testBuiltInExpFunction();
11587     testBuiltInPowFunction();
11588     testBuiltInSinFunction();
11589     testBuiltInCosFunction();
11590     testBuiltInTanFunction();
11591     testBuiltInAsinFunction();
11592     testBuiltInAcosFunction();
11593     testBuiltInAtanFunction();
11594 schoenebeck 3551 testBuiltInArrayEqualFunction();
11595     testBuiltInSortFunction();
11596     testBuiltInNumElementsFunction();
11597     testBuiltInSearchFunction();
11598     testIfStatement();
11599     testWhileStatement();
11600 schoenebeck 3693 testBuiltInVars();
11601 schoenebeck 3551 std::cout << "\nAll tests passed successfully. :-)\n";
11602     return 0;
11603     }
11604    
11605     #endif // !NO_MAIN

  ViewVC Help
Powered by ViewVC