/[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 3816 - (hide annotations) (download)
Fri Aug 28 17:28:48 2020 UTC (3 years, 7 months ago) by schoenebeck
File size: 232408 byte(s)
* NKSP parser: Fixed crash if unary '-' operator was used on a non-number
  data type.

* NKSP parser: Raise parser error if either unary '-' or '+' operator was
  used with a non-number data type.

* Tests: Added test cases for the fixed issues described above.

* Bumped version (2.1.1.svn63).

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

  ViewVC Help
Powered by ViewVC