/[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 3803 - (hide annotations) (download)
Thu Aug 6 11:45:24 2020 UTC (3 years, 8 months ago) by schoenebeck
File size: 230403 byte(s)
NKSP tests: If a test failed, show the test case's NKSP source
code and expectations of that test causing the failure.


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

  ViewVC Help
Powered by ViewVC