/[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 3804 - (hide annotations) (download)
Thu Aug 6 12:15:02 2020 UTC (3 years, 8 months ago) by schoenebeck
File size: 231644 byte(s)
NKSP: Fixed built-in exit() function to behave as return statement.

* VM API: Introduced new signal STMT_RETURN_SIGNALLED.

* NKSP exit() function: signal STMT_RETURN_SIGNALLED instead of
  STMT_ABORT_SIGNALLED.

* NKSP AST: Introduced common base class 'Subroutine' for 'EventHandler'
  and for new 'UserFunction' class.

* NKSP parser: Use 'UserFunction' class instead of 'Statements' class
  for user declared NKSP functions.

* ScriptVM: Handle new STMT_RETURN_SIGNALLED signal by unwinding the
  stack to previous, calling subroutine.

* NKSP tests: Added test cases for exit() acting as return statement.

* Bumped version (2.1.1.svn62).

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

  ViewVC Help
Powered by ViewVC