/[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 3575 - (hide annotations) (download)
Wed Aug 28 11:12:04 2019 UTC (4 years, 7 months ago) by schoenebeck
Original Path: linuxsampler/trunk/src/scriptvm/tests/NKSPTest.cpp
File size: 56067 byte(s)
NKSP: Added some initial floating point test cases.

* RTMath: Implemented floating point comparison methods
  fEqual32(float,float) and fEqual64(double,double)
  which take the expected floating point tolerances
  into account.

* NKSP: Allow built-in exit() function to potentially
  accept real type argument as well.

* NKSP: Added real number test cases for built-in
  functions exit(), int_to_real(), real(), real_to_int()
  and int(), as well as for the plus, minus and negate
  language operators.

1 schoenebeck 3551 /*
2     * Copyright (c) 2019 Christian Schoenebeck
3     *
4     * http://www.linuxsampler.org
5     *
6     * This file is part of LinuxSampler and released under the same terms.
7     * See README file for details.
8     */
9    
10     // This file contains automated test cases against the NKSP real-time
11     // instrument script engine.
12    
13     #include "../../common/global.h"
14     #include "../../common/optional.h"
15 schoenebeck 3575 #include "../../common/RTMath.h"
16 schoenebeck 3551 #include "../ScriptVM.h"
17     #include "../common.h"
18     #include <sstream>
19     #include <stdlib.h>
20     #include <time.h>
21     #include <assert.h>
22     #include <functional>
23    
24     #ifndef TEST_ASSERT
25     # define TEST_ASSERT assert
26     #endif
27    
28     using namespace LinuxSampler;
29     using namespace std;
30    
31     struct RunScriptOpt {
32     String code;
33     bool expectParseError;
34     bool expectRuntimeError;
35     bool expectNoExitResult;
36     bool prohibitExitFunctionArguments;
37 schoenebeck 3575 optional<vmint> expectIntExitResult;
38 schoenebeck 3551 optional<bool> expectBoolExitResult;
39 schoenebeck 3575 optional<vmfloat> expectRealExitResult;
40 schoenebeck 3551 optional<String> expectStringExitResult;
41     };
42    
43     static void runScript(const RunScriptOpt& opt) {
44     ScriptVM vm;
45     vm.setAutoSuspendEnabled(false);
46     if (!opt.prohibitExitFunctionArguments)
47     vm.setExitResultEnabled(true);
48     unique_ptr<VMParserContext> parserCtx(
49     vm.loadScript(opt.code)
50     );
51     vector<ParserIssue> errors = parserCtx->errors();
52     if (opt.expectParseError) {
53     TEST_ASSERT(!errors.empty());
54     return;
55     } else {
56     for (ParserIssue& err : errors) {
57     err.dump();
58     }
59     TEST_ASSERT(errors.empty());
60     }
61     TEST_ASSERT(parserCtx->eventHandler(0));
62     unique_ptr<VMExecContext> execCtx(
63     vm.createExecContext(&*parserCtx)
64     );
65     for (int i = 0; parserCtx->eventHandler(i); ++i) {
66     VMEventHandler* handler = parserCtx->eventHandler(i);
67     VMExecStatus_t result = vm.exec(&*parserCtx, &*execCtx, handler);
68     if (opt.expectRuntimeError) {
69     TEST_ASSERT(result & VM_EXEC_ERROR);
70     } else {
71     TEST_ASSERT(!(result & VM_EXEC_ERROR));
72     }
73     if (opt.expectNoExitResult) {
74     VMExpr* resExpr = execCtx->exitResult();
75     TEST_ASSERT(!resExpr);
76     }
77     if (opt.expectIntExitResult) {
78     VMExpr* resExpr = execCtx->exitResult();
79     TEST_ASSERT(resExpr);
80     TEST_ASSERT(resExpr->exprType() == INT_EXPR);
81     TEST_ASSERT(resExpr->asInt()->evalInt() == *opt.expectIntExitResult);
82     }
83 schoenebeck 3575 if (opt.expectRealExitResult) {
84     VMExpr* resExpr = execCtx->exitResult();
85     TEST_ASSERT(resExpr);
86     TEST_ASSERT(resExpr->exprType() == REAL_EXPR);
87     if (sizeof(vmfloat) == sizeof(float)) {
88     TEST_ASSERT(RTMath::fEqual32(resExpr->asReal()->evalReal(), *opt.expectRealExitResult));
89     } else {
90     TEST_ASSERT(RTMath::fEqual64(resExpr->asReal()->evalReal(), *opt.expectRealExitResult));
91     }
92     }
93 schoenebeck 3551 if (opt.expectBoolExitResult) {
94     VMExpr* resExpr = execCtx->exitResult();
95     TEST_ASSERT(resExpr);
96     TEST_ASSERT(resExpr->exprType() == INT_EXPR);
97     TEST_ASSERT(bool(resExpr->asInt()->evalInt()) == *opt.expectBoolExitResult);
98     }
99     if (opt.expectStringExitResult) {
100     VMExpr* resExpr = execCtx->exitResult();
101     TEST_ASSERT(resExpr);
102     TEST_ASSERT(resExpr->exprType() == STRING_EXPR);
103     TEST_ASSERT(resExpr->asString()->evalStr() == *opt.expectStringExitResult);
104     }
105     }
106     }
107    
108     static void testBuiltInExitFunction() {
109     #if !SILENT_TEST
110     std::cout << "UNIT TEST: built-in exit() function\n";
111     #endif
112    
113     runScript({
114     .code = R"NKSP_CODE(
115     on init
116     end on
117     )NKSP_CODE",
118     .expectNoExitResult = true
119     });
120    
121     runScript({
122     .code = R"NKSP_CODE(
123     on init
124     exit
125     end on
126     )NKSP_CODE",
127     .expectNoExitResult = true
128     });
129    
130     runScript({
131     .code = R"NKSP_CODE(
132     on init
133     exit()
134     end on
135     )NKSP_CODE",
136     .expectNoExitResult = true
137     });
138    
139 schoenebeck 3575 // integer tests ...
140    
141 schoenebeck 3551 runScript({
142     .code = R"NKSP_CODE(
143     on init
144     exit(42)
145     end on
146     )NKSP_CODE",
147     .expectIntExitResult = 42
148     });
149    
150     runScript({
151     .code = R"NKSP_CODE(
152     on init
153     declare $foo := 1
154     if ($foo)
155     exit(21)
156     end if
157     end on
158     )NKSP_CODE",
159     .expectIntExitResult = 21
160     });
161    
162     runScript({
163     .code = R"NKSP_CODE(
164     on init
165     declare $foo := 0
166     if ($foo)
167     exit(21)
168     end if
169     exit(99)
170     end on
171     )NKSP_CODE",
172     .expectIntExitResult = 99
173     });
174    
175 schoenebeck 3575 // string tests ...
176    
177 schoenebeck 3551 runScript({
178     .code = R"NKSP_CODE(
179     on init
180     exit("fourtytwo!")
181     end on
182     )NKSP_CODE",
183     .expectStringExitResult = "fourtytwo!"
184     });
185    
186     // in production environment we prohibit the built-in exit() function to
187     // accept any arguments
188     runScript({
189     .code = R"NKSP_CODE(
190     on init
191     exit(42)
192     end on
193     )NKSP_CODE",
194     .expectParseError = true, // see comment above why
195     .prohibitExitFunctionArguments = true // simulate production environment
196     });
197    
198 schoenebeck 3575 // real number tests ...
199    
200     runScript({
201     .code = R"NKSP_CODE(
202     on init
203     exit(3.14)
204     end on
205     )NKSP_CODE",
206     .expectRealExitResult = 3.14
207     });
208    
209     runScript({
210     .code = R"NKSP_CODE(
211     on init
212     declare $foo := 1
213     if ($foo)
214     exit(3.14)
215     end if
216     end on
217     )NKSP_CODE",
218     .expectRealExitResult = 3.14
219     });
220    
221     runScript({
222     .code = R"NKSP_CODE(
223     on init
224     declare $foo := 0
225     if ($foo)
226     exit(3.14)
227     end if
228     exit(6.9)
229     end on
230     )NKSP_CODE",
231     .expectRealExitResult = 6.9
232     });
233    
234 schoenebeck 3551 #if !SILENT_TEST
235     std::cout << std::endl;
236     #endif
237     }
238    
239     static void testStringConcatOperator() {
240     #if !SILENT_TEST
241     std::cout << "UNIT TEST: string concatenation (&) operator\n";
242     #endif
243    
244     runScript({
245     .code = R"NKSP_CODE(
246     on init
247     declare @s := "foo" & " bar"
248     exit(@s)
249     end on
250     )NKSP_CODE",
251     .expectStringExitResult = "foo bar"
252     });
253    
254     runScript({
255     .code = R"NKSP_CODE(
256     on init
257     declare @s := "foo" & " bar" & " " & 123
258     exit(@s)
259     end on
260     )NKSP_CODE",
261     .expectStringExitResult = "foo bar 123"
262     });
263    
264     runScript({
265     .code = R"NKSP_CODE(
266     on init
267     declare $i := 123
268     declare @s := "foo" & " bar" & " " & $i
269     exit(@s)
270     end on
271     )NKSP_CODE",
272     .expectStringExitResult = "foo bar 123"
273     });
274    
275     #if !SILENT_TEST
276     std::cout << std::endl;
277     #endif
278     }
279    
280 schoenebeck 3575 static void testNegOperator() {
281     #if !SILENT_TEST
282     std::cout << "UNIT TEST: negate (-) operator\n";
283     #endif
284    
285     // integer tests ...
286    
287     runScript({
288     .code = R"NKSP_CODE(
289     on init
290     exit(-87)
291     end on
292     )NKSP_CODE",
293     .expectIntExitResult = -87
294     });
295    
296     runScript({
297     .code = R"NKSP_CODE(
298     on init
299     declare $foo := -87
300     exit(-$foo)
301     end on
302     )NKSP_CODE",
303     .expectIntExitResult = 87
304     });
305    
306     // real number tests ...
307    
308     runScript({
309     .code = R"NKSP_CODE(
310     on init
311     exit(-99.3)
312     end on
313     )NKSP_CODE",
314     .expectRealExitResult = -99.3
315     });
316    
317     runScript({
318     .code = R"NKSP_CODE(
319     on init
320     declare ~foo := -99.3
321     exit(-~foo)
322     end on
323     )NKSP_CODE",
324     .expectRealExitResult = 99.3
325     });
326    
327     #if !SILENT_TEST
328     std::cout << std::endl;
329     #endif
330     }
331    
332 schoenebeck 3551 static void testPlusOperator() {
333     #if !SILENT_TEST
334     std::cout << "UNIT TEST: plus (+) operator\n";
335     #endif
336    
337 schoenebeck 3575 // integer tests ...
338    
339 schoenebeck 3551 runScript({
340     .code = R"NKSP_CODE(
341     on init
342     exit(4 + 3)
343     end on
344     )NKSP_CODE",
345     .expectIntExitResult = 7
346     });
347    
348     runScript({
349     .code = R"NKSP_CODE(
350     on init
351     exit(42 + 145)
352     end on
353     )NKSP_CODE",
354     .expectIntExitResult = 187
355     });
356    
357     runScript({
358     .code = R"NKSP_CODE(
359     on init
360     exit(-4 + 2)
361     end on
362     )NKSP_CODE",
363     .expectIntExitResult = -2
364     });
365    
366 schoenebeck 3575 // real number tests ...
367    
368     runScript({
369     .code = R"NKSP_CODE(
370     on init
371     exit(4.0 + 3.0)
372     end on
373     )NKSP_CODE",
374     .expectRealExitResult = 7.0
375     });
376    
377     runScript({
378     .code = R"NKSP_CODE(
379     on init
380     exit(42.3 + 145.2)
381     end on
382     )NKSP_CODE",
383     .expectRealExitResult = 187.5
384     });
385    
386     runScript({
387     .code = R"NKSP_CODE(
388     on init
389     exit(-4.0 + 2.2)
390     end on
391     )NKSP_CODE",
392     .expectRealExitResult = -1.8
393     });
394    
395 schoenebeck 3551 #if !SILENT_TEST
396     std::cout << std::endl;
397     #endif
398     }
399    
400     static void testMinusOperator() {
401     #if !SILENT_TEST
402     std::cout << "UNIT TEST: minus (-) operator\n";
403     #endif
404    
405 schoenebeck 3575 // integer tests ...
406    
407 schoenebeck 3551 runScript({
408     .code = R"NKSP_CODE(
409     on init
410     exit(4 - 3)
411     end on
412     )NKSP_CODE",
413     .expectIntExitResult = 1
414     });
415    
416     runScript({
417     .code = R"NKSP_CODE(
418     on init
419     exit(139 - 74)
420     end on
421     )NKSP_CODE",
422     .expectIntExitResult = 65
423     });
424    
425     runScript({
426     .code = R"NKSP_CODE(
427     on init
428     exit(3 - 9)
429     end on
430     )NKSP_CODE",
431     .expectIntExitResult = -6
432     });
433    
434     runScript({
435     .code = R"NKSP_CODE(
436     on init
437     exit(-3 - 18)
438     end on
439     )NKSP_CODE",
440     .expectIntExitResult = -21
441     });
442    
443 schoenebeck 3575 // real number tests ...
444    
445     runScript({
446     .code = R"NKSP_CODE(
447     on init
448     exit(4.0 - 0.2)
449     end on
450     )NKSP_CODE",
451     .expectRealExitResult = 3.8
452     });
453    
454     runScript({
455     .code = R"NKSP_CODE(
456     on init
457     exit(3.1 - 9.65)
458     end on
459     )NKSP_CODE",
460     .expectRealExitResult = -6.55
461     });
462    
463     runScript({
464     .code = R"NKSP_CODE(
465     on init
466     exit(-3.0 - 18.1)
467     end on
468     )NKSP_CODE",
469     .expectRealExitResult = -21.1
470     });
471    
472 schoenebeck 3551 #if !SILENT_TEST
473     std::cout << std::endl;
474     #endif
475     }
476    
477     static void testModuloOperator() {
478     #if !SILENT_TEST
479     std::cout << "UNIT TEST: modulo (mod) operator\n";
480     #endif
481    
482 schoenebeck 3575 // integer tests ...
483    
484 schoenebeck 3551 runScript({
485     .code = R"NKSP_CODE(
486     on init
487     exit(10 mod 8)
488     end on
489     )NKSP_CODE",
490     .expectIntExitResult = 2
491     });
492    
493 schoenebeck 3575 runScript({
494     .code = R"NKSP_CODE(
495     on init
496     declare $a := 10
497     declare $b := 8
498     exit($a mod $b)
499     end on
500     )NKSP_CODE",
501     .expectIntExitResult = 2
502     });
503    
504     // real number tests ...
505     // (mod operator prohibits real numbers ATM)
506    
507     runScript({
508     .code = R"NKSP_CODE(
509     on init
510     exit(10.0 mod 8.0)
511     end on
512     )NKSP_CODE",
513     .expectParseError = true // mod operator prohibits real numbers ATM
514     });
515    
516     runScript({
517     .code = R"NKSP_CODE(
518     on init
519     exit(10 mod 8.0)
520     end on
521     )NKSP_CODE",
522     .expectParseError = true // mod operator prohibits real numbers ATM
523     });
524    
525     runScript({
526     .code = R"NKSP_CODE(
527     on init
528     exit(10.0 mod 8)
529     end on
530     )NKSP_CODE",
531     .expectParseError = true // mod operator prohibits real numbers ATM
532     });
533    
534     runScript({
535     .code = R"NKSP_CODE(
536     on init
537     declare ~a := 10.0
538     declare ~b := 8.0
539     exit(~a mod ~b)
540     end on
541     )NKSP_CODE",
542     .expectParseError = true // mod operator prohibits real numbers ATM
543     });
544    
545 schoenebeck 3551 #if !SILENT_TEST
546     std::cout << std::endl;
547     #endif
548     }
549    
550     static void testMultiplyOperator() {
551     #if !SILENT_TEST
552     std::cout << "UNIT TEST: multiply (*) operator\n";
553     #endif
554    
555 schoenebeck 3575 // integer tests ...
556    
557 schoenebeck 3551 runScript({
558     .code = R"NKSP_CODE(
559     on init
560     exit(10 * 8)
561     end on
562     )NKSP_CODE",
563     .expectIntExitResult = 80
564     });
565    
566     runScript({
567     .code = R"NKSP_CODE(
568     on init
569     exit(-3 * -4)
570     end on
571     )NKSP_CODE",
572     .expectIntExitResult = 12
573     });
574    
575     runScript({
576     .code = R"NKSP_CODE(
577     on init
578     exit(-52 * 63)
579     end on
580     )NKSP_CODE",
581     .expectIntExitResult = -3276
582     });
583    
584     runScript({
585     .code = R"NKSP_CODE(
586     on init
587     exit(123 * -59)
588     end on
589     )NKSP_CODE",
590     .expectIntExitResult = -7257
591     });
592    
593 schoenebeck 3575 // real number tests ...
594    
595     runScript({
596     .code = R"NKSP_CODE(
597     on init
598     exit(10.2 * 8.4)
599     end on
600     )NKSP_CODE",
601     .expectRealExitResult = 85.68
602     });
603    
604     runScript({
605     .code = R"NKSP_CODE(
606     on init
607     exit(10.0 * -3.33)
608     end on
609     )NKSP_CODE",
610     .expectRealExitResult = -33.3
611     });
612    
613     runScript({
614     .code = R"NKSP_CODE(
615     on init
616     exit(-3.33 * 10.0)
617     end on
618     )NKSP_CODE",
619     .expectRealExitResult = -33.3
620     });
621    
622     runScript({
623     .code = R"NKSP_CODE(
624     on init
625     exit(-3.33 * -10.0)
626     end on
627     )NKSP_CODE",
628     .expectRealExitResult = 33.3
629     });
630    
631     // mixed type tests ...
632     // (mixed int * real forbidden ATM)
633    
634     runScript({
635     .code = R"NKSP_CODE(
636     on init
637     exit(2 * 3.0)
638     end on
639     )NKSP_CODE",
640     .expectParseError = true // mixed int * real forbidden ATM
641     });
642    
643     runScript({
644     .code = R"NKSP_CODE(
645     on init
646     exit(2.0 * 3)
647     end on
648     )NKSP_CODE",
649     .expectParseError = true // mixed int * real forbidden ATM
650     });
651    
652 schoenebeck 3551 #if !SILENT_TEST
653     std::cout << std::endl;
654     #endif
655     }
656    
657     static void testDivideOperator() {
658     #if !SILENT_TEST
659     std::cout << "UNIT TEST: divide (/) operator\n";
660     #endif
661    
662 schoenebeck 3575 // integer tests ...
663    
664 schoenebeck 3551 runScript({
665     .code = R"NKSP_CODE(
666     on init
667     exit(9 / 3)
668     end on
669     )NKSP_CODE",
670     .expectIntExitResult = 3
671     });
672    
673     runScript({
674     .code = R"NKSP_CODE(
675     on init
676     exit(-27 / 3)
677     end on
678     )NKSP_CODE",
679     .expectIntExitResult = -9
680     });
681    
682     runScript({
683     .code = R"NKSP_CODE(
684     on init
685     exit(35 / -5)
686     end on
687     )NKSP_CODE",
688     .expectIntExitResult = -7
689     });
690    
691     runScript({
692     .code = R"NKSP_CODE(
693     on init
694     exit(39 / -5)
695     end on
696     )NKSP_CODE",
697     .expectIntExitResult = -7
698     });
699    
700 schoenebeck 3575 // real number tests ...
701    
702     runScript({
703     .code = R"NKSP_CODE(
704     on init
705     exit(9.0 / 10.0)
706     end on
707     )NKSP_CODE",
708     .expectRealExitResult = 0.9
709     });
710    
711     runScript({
712     .code = R"NKSP_CODE(
713     on init
714     exit(-9.0 / 10.0)
715     end on
716     )NKSP_CODE",
717     .expectRealExitResult = -0.9
718     });
719    
720     runScript({
721     .code = R"NKSP_CODE(
722     on init
723     exit(9.0 / -10.0)
724     end on
725     )NKSP_CODE",
726     .expectRealExitResult = -0.9
727     });
728    
729     runScript({
730     .code = R"NKSP_CODE(
731     on init
732     exit(-9.0 / -10.0)
733     end on
734     )NKSP_CODE",
735     .expectRealExitResult = 0.9
736     });
737    
738     // mixed type tests ...
739     // (mixed int / real forbidden ATM)
740    
741     runScript({
742     .code = R"NKSP_CODE(
743     on init
744     exit(9 / 10.0)
745     end on
746     )NKSP_CODE",
747     .expectParseError = true // mixed int / real forbidden ATM
748     });
749    
750     runScript({
751     .code = R"NKSP_CODE(
752     on init
753     exit(9.0 / 10)
754     end on
755     )NKSP_CODE",
756     .expectParseError = true // mixed int / real forbidden ATM
757     });
758    
759 schoenebeck 3551 #if !SILENT_TEST
760     std::cout << std::endl;
761     #endif
762     }
763    
764     static void testSmallerThanOperator() {
765     #if !SILENT_TEST
766     std::cout << "UNIT TEST: smaller than (<) operator\n";
767     #endif
768    
769 schoenebeck 3575 // integer tests ...
770    
771 schoenebeck 3551 runScript({
772     .code = R"NKSP_CODE(
773     on init
774     exit(3 < 4)
775     end on
776     )NKSP_CODE",
777     .expectBoolExitResult = true
778     });
779    
780     runScript({
781     .code = R"NKSP_CODE(
782     on init
783     exit(4 < 3)
784     end on
785     )NKSP_CODE",
786     .expectBoolExitResult = false
787     });
788    
789     runScript({
790     .code = R"NKSP_CODE(
791     on init
792     exit(-4 < 3)
793     end on
794     )NKSP_CODE",
795     .expectBoolExitResult = true
796     });
797    
798     runScript({
799     .code = R"NKSP_CODE(
800     on init
801     exit(3 < -4)
802     end on
803     )NKSP_CODE",
804     .expectBoolExitResult = false
805     });
806    
807     runScript({
808     .code = R"NKSP_CODE(
809     on init
810     exit(123 < -45)
811     end on
812     )NKSP_CODE",
813     .expectBoolExitResult = false
814     });
815    
816     runScript({
817     .code = R"NKSP_CODE(
818     on init
819     exit(-45 < 123)
820     end on
821     )NKSP_CODE",
822     .expectBoolExitResult = true
823     });
824    
825 schoenebeck 3575 // real number tests ...
826    
827     runScript({
828     .code = R"NKSP_CODE(
829     on init
830     exit(3.0 < 4.0)
831     end on
832     )NKSP_CODE",
833     .expectBoolExitResult = true
834     });
835    
836     runScript({
837     .code = R"NKSP_CODE(
838     on init
839     exit(4.0 < 3.0)
840     end on
841     )NKSP_CODE",
842     .expectBoolExitResult = false
843     });
844    
845     runScript({
846     .code = R"NKSP_CODE(
847     on init
848     exit(1.2 < 1.23)
849     end on
850     )NKSP_CODE",
851     .expectBoolExitResult = true
852     });
853    
854     runScript({
855     .code = R"NKSP_CODE(
856     on init
857     exit(1.23 < 1.2)
858     end on
859     )NKSP_CODE",
860     .expectBoolExitResult = false
861     });
862    
863     runScript({
864     .code = R"NKSP_CODE(
865     on init
866     exit(-4.0 < 3.0)
867     end on
868     )NKSP_CODE",
869     .expectBoolExitResult = true
870     });
871    
872     runScript({
873     .code = R"NKSP_CODE(
874     on init
875     exit(3.0 < -4.0)
876     end on
877     )NKSP_CODE",
878     .expectBoolExitResult = false
879     });
880    
881     runScript({
882     .code = R"NKSP_CODE(
883     on init
884     exit(123.0 < -45.0)
885     end on
886     )NKSP_CODE",
887     .expectBoolExitResult = false
888     });
889    
890     runScript({
891     .code = R"NKSP_CODE(
892     on init
893     exit(-45.0 < 123.0)
894     end on
895     )NKSP_CODE",
896     .expectBoolExitResult = true
897     });
898    
899     // mixed type tests ...
900    
901     runScript({
902     .code = R"NKSP_CODE(
903     on init
904     exit(9 < 9.1)
905     end on
906     )NKSP_CODE",
907     .expectBoolExitResult = true
908     });
909    
910     runScript({
911     .code = R"NKSP_CODE(
912     on init
913     exit(9.1 < 9)
914     end on
915     )NKSP_CODE",
916     .expectBoolExitResult = false
917     });
918    
919 schoenebeck 3551 #if !SILENT_TEST
920     std::cout << std::endl;
921     #endif
922     }
923    
924     static void testGreaterThanOperator() {
925     #if !SILENT_TEST
926     std::cout << "UNIT TEST: greater than (>) operator\n";
927     #endif
928    
929 schoenebeck 3575 // integer tests ...
930    
931 schoenebeck 3551 runScript({
932     .code = R"NKSP_CODE(
933     on init
934     exit(3 > 4)
935     end on
936     )NKSP_CODE",
937     .expectBoolExitResult = false
938     });
939    
940     runScript({
941     .code = R"NKSP_CODE(
942     on init
943     exit(4 > 3)
944     end on
945     )NKSP_CODE",
946     .expectBoolExitResult = true
947     });
948    
949     runScript({
950     .code = R"NKSP_CODE(
951     on init
952     exit(-4 > 3)
953     end on
954     )NKSP_CODE",
955     .expectBoolExitResult = false
956     });
957    
958     runScript({
959     .code = R"NKSP_CODE(
960     on init
961     exit(3 > -4)
962     end on
963     )NKSP_CODE",
964     .expectBoolExitResult = true
965     });
966    
967     runScript({
968     .code = R"NKSP_CODE(
969     on init
970     exit(123 > -45)
971     end on
972     )NKSP_CODE",
973     .expectBoolExitResult = true
974     });
975    
976     runScript({
977     .code = R"NKSP_CODE(
978     on init
979     exit(-45 > 123)
980     end on
981     )NKSP_CODE",
982     .expectBoolExitResult = false
983     });
984    
985 schoenebeck 3575 // real number tests ...
986    
987     runScript({
988     .code = R"NKSP_CODE(
989     on init
990     exit(3.0 > 4.0)
991     end on
992     )NKSP_CODE",
993     .expectBoolExitResult = false
994     });
995    
996     runScript({
997     .code = R"NKSP_CODE(
998     on init
999     exit(4.0 > 3.0)
1000     end on
1001     )NKSP_CODE",
1002     .expectBoolExitResult = true
1003     });
1004    
1005     runScript({
1006     .code = R"NKSP_CODE(
1007     on init
1008     exit(1.2 > 1.23)
1009     end on
1010     )NKSP_CODE",
1011     .expectBoolExitResult = false
1012     });
1013    
1014     runScript({
1015     .code = R"NKSP_CODE(
1016     on init
1017     exit(1.23 > 1.2)
1018     end on
1019     )NKSP_CODE",
1020     .expectBoolExitResult = true
1021     });
1022    
1023     runScript({
1024     .code = R"NKSP_CODE(
1025     on init
1026     exit(-4.0 > 3.0)
1027     end on
1028     )NKSP_CODE",
1029     .expectBoolExitResult = false
1030     });
1031    
1032     runScript({
1033     .code = R"NKSP_CODE(
1034     on init
1035     exit(3.0 > -4.0)
1036     end on
1037     )NKSP_CODE",
1038     .expectBoolExitResult = true
1039     });
1040    
1041     runScript({
1042     .code = R"NKSP_CODE(
1043     on init
1044     exit(123.0 > -45.0)
1045     end on
1046     )NKSP_CODE",
1047     .expectBoolExitResult = true
1048     });
1049    
1050     runScript({
1051     .code = R"NKSP_CODE(
1052     on init
1053     exit(-45.0 > 123.0)
1054     end on
1055     )NKSP_CODE",
1056     .expectBoolExitResult = false
1057     });
1058    
1059     // mixed type tests ...
1060    
1061     runScript({
1062     .code = R"NKSP_CODE(
1063     on init
1064     exit(9 > 9.1)
1065     end on
1066     )NKSP_CODE",
1067     .expectBoolExitResult = false
1068     });
1069    
1070     runScript({
1071     .code = R"NKSP_CODE(
1072     on init
1073     exit(9.1 > 9)
1074     end on
1075     )NKSP_CODE",
1076     .expectBoolExitResult = true
1077     });
1078    
1079 schoenebeck 3551 #if !SILENT_TEST
1080     std::cout << std::endl;
1081     #endif
1082     }
1083    
1084     static void testSmallerOrEqualOperator() {
1085     #if !SILENT_TEST
1086     std::cout << "UNIT TEST: smaller-or-equal (<=) operator\n";
1087     #endif
1088    
1089 schoenebeck 3575 // integer tests ...
1090    
1091 schoenebeck 3551 runScript({
1092     .code = R"NKSP_CODE(
1093     on init
1094     exit(3 <= 3)
1095     end on
1096     )NKSP_CODE",
1097     .expectBoolExitResult = true
1098     });
1099    
1100     runScript({
1101     .code = R"NKSP_CODE(
1102     on init
1103     exit(4 <= 4)
1104     end on
1105     )NKSP_CODE",
1106     .expectBoolExitResult = true
1107     });
1108    
1109     runScript({
1110     .code = R"NKSP_CODE(
1111     on init
1112     exit(-23 <= -23)
1113     end on
1114     )NKSP_CODE",
1115     .expectBoolExitResult = true
1116     });
1117    
1118     runScript({
1119     .code = R"NKSP_CODE(
1120     on init
1121     exit(23 <= -23)
1122     end on
1123     )NKSP_CODE",
1124     .expectBoolExitResult = false
1125     });
1126    
1127     runScript({
1128     .code = R"NKSP_CODE(
1129     on init
1130     exit(3 <= 4)
1131     end on
1132     )NKSP_CODE",
1133     .expectBoolExitResult = true
1134     });
1135    
1136     runScript({
1137     .code = R"NKSP_CODE(
1138     on init
1139     exit(4 <= 3)
1140     end on
1141     )NKSP_CODE",
1142     .expectBoolExitResult = false
1143     });
1144    
1145     runScript({
1146     .code = R"NKSP_CODE(
1147     on init
1148     exit(-4 <= 3)
1149     end on
1150     )NKSP_CODE",
1151     .expectBoolExitResult = true
1152     });
1153    
1154     runScript({
1155     .code = R"NKSP_CODE(
1156     on init
1157     exit(3 <= -4)
1158     end on
1159     )NKSP_CODE",
1160     .expectBoolExitResult = false
1161     });
1162    
1163     runScript({
1164     .code = R"NKSP_CODE(
1165     on init
1166     exit(123 <= -45)
1167     end on
1168     )NKSP_CODE",
1169     .expectBoolExitResult = false
1170     });
1171    
1172     runScript({
1173     .code = R"NKSP_CODE(
1174     on init
1175     exit(-45 <= 123)
1176     end on
1177     )NKSP_CODE",
1178     .expectBoolExitResult = true
1179     });
1180    
1181 schoenebeck 3575 // real number tests ...
1182    
1183     runScript({
1184     .code = R"NKSP_CODE(
1185     on init
1186     exit(3.0 <= 3.0)
1187     end on
1188     )NKSP_CODE",
1189     .expectBoolExitResult = true
1190     });
1191    
1192     runScript({
1193     .code = R"NKSP_CODE(
1194     on init
1195     exit(4.33 <= 4.33)
1196     end on
1197     )NKSP_CODE",
1198     .expectBoolExitResult = true
1199     });
1200    
1201     runScript({
1202     .code = R"NKSP_CODE(
1203     on init
1204     exit(-23.1 <= -23.1)
1205     end on
1206     )NKSP_CODE",
1207     .expectBoolExitResult = true
1208     });
1209    
1210     runScript({
1211     .code = R"NKSP_CODE(
1212     on init
1213     exit(23.3 <= -23.3)
1214     end on
1215     )NKSP_CODE",
1216     .expectBoolExitResult = false
1217     });
1218    
1219     runScript({
1220     .code = R"NKSP_CODE(
1221     on init
1222     exit(3.0 <= 4.0)
1223     end on
1224     )NKSP_CODE",
1225     .expectBoolExitResult = true
1226     });
1227    
1228     runScript({
1229     .code = R"NKSP_CODE(
1230     on init
1231     exit(4.0 <= 3.0)
1232     end on
1233     )NKSP_CODE",
1234     .expectBoolExitResult = false
1235     });
1236    
1237     runScript({
1238     .code = R"NKSP_CODE(
1239     on init
1240     exit(-4.0 <= 3.0)
1241     end on
1242     )NKSP_CODE",
1243     .expectBoolExitResult = true
1244     });
1245    
1246     runScript({
1247     .code = R"NKSP_CODE(
1248     on init
1249     exit(3.0 <= -4.0)
1250     end on
1251     )NKSP_CODE",
1252     .expectBoolExitResult = false
1253     });
1254    
1255     runScript({
1256     .code = R"NKSP_CODE(
1257     on init
1258     exit(123.0 <= -45.0)
1259     end on
1260     )NKSP_CODE",
1261     .expectBoolExitResult = false
1262     });
1263    
1264     runScript({
1265     .code = R"NKSP_CODE(
1266     on init
1267     exit(-45.0 <= 123.0)
1268     end on
1269     )NKSP_CODE",
1270     .expectBoolExitResult = true
1271     });
1272    
1273     // mixed type tests ...
1274    
1275     runScript({
1276     .code = R"NKSP_CODE(
1277     on init
1278     exit(9 <= 9.1)
1279     end on
1280     )NKSP_CODE",
1281     .expectBoolExitResult = true
1282     });
1283    
1284     runScript({
1285     .code = R"NKSP_CODE(
1286     on init
1287     exit(9.1 <= 9)
1288     end on
1289     )NKSP_CODE",
1290     .expectBoolExitResult = false
1291     });
1292    
1293     runScript({
1294     .code = R"NKSP_CODE(
1295     on init
1296     exit(9 <= 9.0)
1297     end on
1298     )NKSP_CODE",
1299     .expectBoolExitResult = true
1300     });
1301    
1302     runScript({
1303     .code = R"NKSP_CODE(
1304     on init
1305     exit(9.0 <= 9)
1306     end on
1307     )NKSP_CODE",
1308     .expectBoolExitResult = true
1309     });
1310    
1311 schoenebeck 3551 #if !SILENT_TEST
1312     std::cout << std::endl;
1313     #endif
1314     }
1315    
1316     static void testGreaterOrEqualOperator() {
1317     #if !SILENT_TEST
1318     std::cout << "UNIT TEST: greater-or-equal (>=) operator\n";
1319     #endif
1320    
1321 schoenebeck 3575 // integer tests ...
1322    
1323 schoenebeck 3551 runScript({
1324     .code = R"NKSP_CODE(
1325     on init
1326     exit(3 >= 3)
1327     end on
1328     )NKSP_CODE",
1329     .expectBoolExitResult = true
1330     });
1331    
1332     runScript({
1333     .code = R"NKSP_CODE(
1334     on init
1335     exit(4 >= 4)
1336     end on
1337     )NKSP_CODE",
1338     .expectBoolExitResult = true
1339     });
1340    
1341     runScript({
1342     .code = R"NKSP_CODE(
1343     on init
1344     exit(-23 >= -23)
1345     end on
1346     )NKSP_CODE",
1347     .expectBoolExitResult = true
1348     });
1349    
1350     runScript({
1351     .code = R"NKSP_CODE(
1352     on init
1353     exit(23 >= -23)
1354     end on
1355     )NKSP_CODE",
1356     .expectBoolExitResult = true
1357     });
1358    
1359     runScript({
1360     .code = R"NKSP_CODE(
1361     on init
1362     exit(3 >= 4)
1363     end on
1364     )NKSP_CODE",
1365     .expectBoolExitResult = false
1366     });
1367    
1368     runScript({
1369     .code = R"NKSP_CODE(
1370     on init
1371     exit(4 >= 3)
1372     end on
1373     )NKSP_CODE",
1374     .expectBoolExitResult = true
1375     });
1376    
1377     runScript({
1378     .code = R"NKSP_CODE(
1379     on init
1380     exit(-4 >= 3)
1381     end on
1382     )NKSP_CODE",
1383     .expectBoolExitResult = false
1384     });
1385    
1386     runScript({
1387     .code = R"NKSP_CODE(
1388     on init
1389     exit(3 >= -4)
1390     end on
1391     )NKSP_CODE",
1392     .expectBoolExitResult = true
1393     });
1394    
1395     runScript({
1396     .code = R"NKSP_CODE(
1397     on init
1398     exit(123 >= -45)
1399     end on
1400     )NKSP_CODE",
1401     .expectBoolExitResult = true
1402     });
1403    
1404     runScript({
1405     .code = R"NKSP_CODE(
1406     on init
1407     exit(-45 >= 123)
1408     end on
1409     )NKSP_CODE",
1410     .expectBoolExitResult = false
1411     });
1412    
1413 schoenebeck 3575 // real number tests ...
1414    
1415     runScript({
1416     .code = R"NKSP_CODE(
1417     on init
1418     exit(3.0 >= 3.0)
1419     end on
1420     )NKSP_CODE",
1421     .expectBoolExitResult = true
1422     });
1423    
1424     runScript({
1425     .code = R"NKSP_CODE(
1426     on init
1427     exit(3.1 >= 3.1)
1428     end on
1429     )NKSP_CODE",
1430     .expectBoolExitResult = true
1431     });
1432    
1433     runScript({
1434     .code = R"NKSP_CODE(
1435     on init
1436     exit(3.1 >= 3.0)
1437     end on
1438     )NKSP_CODE",
1439     .expectBoolExitResult = true
1440     });
1441    
1442     runScript({
1443     .code = R"NKSP_CODE(
1444     on init
1445     exit(3.0 >= 3.1)
1446     end on
1447     )NKSP_CODE",
1448     .expectBoolExitResult = false
1449     });
1450    
1451     runScript({
1452     .code = R"NKSP_CODE(
1453     on init
1454     exit(-23.33 >= -23.33)
1455     end on
1456     )NKSP_CODE",
1457     .expectBoolExitResult = true
1458     });
1459    
1460     runScript({
1461     .code = R"NKSP_CODE(
1462     on init
1463     exit(23.0 >= -23.0)
1464     end on
1465     )NKSP_CODE",
1466     .expectBoolExitResult = true
1467     });
1468    
1469     runScript({
1470     .code = R"NKSP_CODE(
1471     on init
1472     exit(3.0 >= 4.0)
1473     end on
1474     )NKSP_CODE",
1475     .expectBoolExitResult = false
1476     });
1477    
1478     runScript({
1479     .code = R"NKSP_CODE(
1480     on init
1481     exit(4.0 >= 3.0)
1482     end on
1483     )NKSP_CODE",
1484     .expectBoolExitResult = true
1485     });
1486    
1487     runScript({
1488     .code = R"NKSP_CODE(
1489     on init
1490     exit(-4.0 >= 3.0)
1491     end on
1492     )NKSP_CODE",
1493     .expectBoolExitResult = false
1494     });
1495    
1496     runScript({
1497     .code = R"NKSP_CODE(
1498     on init
1499     exit(3.0 >= -4.0)
1500     end on
1501     )NKSP_CODE",
1502     .expectBoolExitResult = true
1503     });
1504    
1505     runScript({
1506     .code = R"NKSP_CODE(
1507     on init
1508     exit(123.0 >= -45.0)
1509     end on
1510     )NKSP_CODE",
1511     .expectBoolExitResult = true
1512     });
1513    
1514     runScript({
1515     .code = R"NKSP_CODE(
1516     on init
1517     exit(-45.0 >= 123.0)
1518     end on
1519     )NKSP_CODE",
1520     .expectBoolExitResult = false
1521     });
1522    
1523     // mixed type tests ...
1524    
1525     runScript({
1526     .code = R"NKSP_CODE(
1527     on init
1528     exit(9 >= 9.1)
1529     end on
1530     )NKSP_CODE",
1531     .expectBoolExitResult = false
1532     });
1533    
1534     runScript({
1535     .code = R"NKSP_CODE(
1536     on init
1537     exit(9.1 >= 9)
1538     end on
1539     )NKSP_CODE",
1540     .expectBoolExitResult = true
1541     });
1542    
1543     runScript({
1544     .code = R"NKSP_CODE(
1545     on init
1546     exit(9 >= 9.0)
1547     end on
1548     )NKSP_CODE",
1549     .expectBoolExitResult = true
1550     });
1551    
1552     runScript({
1553     .code = R"NKSP_CODE(
1554     on init
1555     exit(9.0 >= 9)
1556     end on
1557     )NKSP_CODE",
1558     .expectBoolExitResult = true
1559     });
1560    
1561 schoenebeck 3551 #if !SILENT_TEST
1562     std::cout << std::endl;
1563     #endif
1564     }
1565    
1566     static void testEqualOperator() {
1567     #if !SILENT_TEST
1568     std::cout << "UNIT TEST: equal (=) operator\n";
1569     #endif
1570    
1571 schoenebeck 3575 // integer tests ...
1572    
1573 schoenebeck 3551 runScript({
1574     .code = R"NKSP_CODE(
1575     on init
1576     exit(3 = 3)
1577     end on
1578     )NKSP_CODE",
1579     .expectBoolExitResult = true
1580     });
1581    
1582     runScript({
1583     .code = R"NKSP_CODE(
1584     on init
1585     exit(4 = 4)
1586     end on
1587     )NKSP_CODE",
1588     .expectBoolExitResult = true
1589     });
1590    
1591     runScript({
1592     .code = R"NKSP_CODE(
1593     on init
1594     exit(3 = 4)
1595     end on
1596     )NKSP_CODE",
1597     .expectBoolExitResult = false
1598     });
1599    
1600     runScript({
1601     .code = R"NKSP_CODE(
1602     on init
1603     exit(23 = -23)
1604     end on
1605     )NKSP_CODE",
1606     .expectBoolExitResult = false
1607     });
1608    
1609 schoenebeck 3575 // real number tests ...
1610    
1611     runScript({
1612     .code = R"NKSP_CODE(
1613     on init
1614     exit(3.0 = 3.0)
1615     end on
1616     )NKSP_CODE",
1617     .expectBoolExitResult = true
1618     });
1619    
1620     runScript({
1621     .code = R"NKSP_CODE(
1622     on init
1623     exit(4.33 = 4.33)
1624     end on
1625     )NKSP_CODE",
1626     .expectBoolExitResult = true
1627     });
1628    
1629     runScript({
1630     .code = R"NKSP_CODE(
1631     on init
1632     exit(4.31 = 4.35)
1633     end on
1634     )NKSP_CODE",
1635     .expectBoolExitResult = false
1636     });
1637    
1638     runScript({
1639     .code = R"NKSP_CODE(
1640     on init
1641     exit(3.0 = 4.0)
1642     end on
1643     )NKSP_CODE",
1644     .expectBoolExitResult = false
1645     });
1646    
1647     runScript({
1648     .code = R"NKSP_CODE(
1649     on init
1650     exit(23.0 = -23.0)
1651     end on
1652     )NKSP_CODE",
1653     .expectBoolExitResult = false
1654     });
1655    
1656     // mixed type tests ...
1657    
1658     runScript({
1659     .code = R"NKSP_CODE(
1660     on init
1661     exit(23 = 23.0)
1662     end on
1663     )NKSP_CODE",
1664     .expectBoolExitResult = true
1665     });
1666    
1667     runScript({
1668     .code = R"NKSP_CODE(
1669     on init
1670     exit(23.0 = 23)
1671     end on
1672     )NKSP_CODE",
1673     .expectBoolExitResult = true
1674     });
1675    
1676     runScript({
1677     .code = R"NKSP_CODE(
1678     on init
1679     exit(23 = 23.1)
1680     end on
1681     )NKSP_CODE",
1682     .expectBoolExitResult = false
1683     });
1684    
1685     runScript({
1686     .code = R"NKSP_CODE(
1687     on init
1688     exit(23.1 = 23)
1689     end on
1690     )NKSP_CODE",
1691     .expectBoolExitResult = false
1692     });
1693    
1694 schoenebeck 3551 #if !SILENT_TEST
1695     std::cout << std::endl;
1696     #endif
1697     }
1698    
1699     static void testUnequalOperator() {
1700     #if !SILENT_TEST
1701     std::cout << "UNIT TEST: unequal (#) operator\n";
1702     #endif
1703    
1704 schoenebeck 3575 // integer tests ...
1705    
1706 schoenebeck 3551 runScript({
1707     .code = R"NKSP_CODE(
1708     on init
1709     exit(3 # 3)
1710     end on
1711     )NKSP_CODE",
1712     .expectBoolExitResult = false
1713     });
1714    
1715     runScript({
1716     .code = R"NKSP_CODE(
1717     on init
1718     exit(4 # 4)
1719     end on
1720     )NKSP_CODE",
1721     .expectBoolExitResult = false
1722     });
1723    
1724     runScript({
1725     .code = R"NKSP_CODE(
1726     on init
1727     exit(3 # 4)
1728     end on
1729     )NKSP_CODE",
1730     .expectBoolExitResult = true
1731     });
1732    
1733     runScript({
1734     .code = R"NKSP_CODE(
1735     on init
1736     exit(23 # -23)
1737     end on
1738     )NKSP_CODE",
1739     .expectBoolExitResult = true
1740     });
1741    
1742 schoenebeck 3575 // real number tests ...
1743    
1744     runScript({
1745     .code = R"NKSP_CODE(
1746     on init
1747     exit(3.0 # 3.0)
1748     end on
1749     )NKSP_CODE",
1750     .expectBoolExitResult = false
1751     });
1752    
1753     runScript({
1754     .code = R"NKSP_CODE(
1755     on init
1756     exit(3.14 # 3.14)
1757     end on
1758     )NKSP_CODE",
1759     .expectBoolExitResult = false
1760     });
1761    
1762     runScript({
1763     .code = R"NKSP_CODE(
1764     on init
1765     exit(3.19 # 3.12)
1766     end on
1767     )NKSP_CODE",
1768     .expectBoolExitResult = true
1769     });
1770    
1771     runScript({
1772     .code = R"NKSP_CODE(
1773     on init
1774     exit(23.0 # -23.0)
1775     end on
1776     )NKSP_CODE",
1777     .expectBoolExitResult = true
1778     });
1779    
1780     // mixed type tests ...
1781    
1782     runScript({
1783     .code = R"NKSP_CODE(
1784     on init
1785     exit(3 # 3.0)
1786     end on
1787     )NKSP_CODE",
1788     .expectBoolExitResult = false
1789     });
1790    
1791     runScript({
1792     .code = R"NKSP_CODE(
1793     on init
1794     exit(3.0 # 3)
1795     end on
1796     )NKSP_CODE",
1797     .expectBoolExitResult = false
1798     });
1799    
1800     runScript({
1801     .code = R"NKSP_CODE(
1802     on init
1803     exit(3.1 # 3)
1804     end on
1805     )NKSP_CODE",
1806     .expectBoolExitResult = true
1807     });
1808    
1809     runScript({
1810     .code = R"NKSP_CODE(
1811     on init
1812     exit(3 # 3.1)
1813     end on
1814     )NKSP_CODE",
1815     .expectBoolExitResult = true
1816     });
1817    
1818 schoenebeck 3551 #if !SILENT_TEST
1819     std::cout << std::endl;
1820     #endif
1821     }
1822    
1823     static void testLogicalAndOperator() {
1824     #if !SILENT_TEST
1825     std::cout << "UNIT TEST: logical and (and) operator\n";
1826     #endif
1827    
1828 schoenebeck 3575 // integer tests ...
1829    
1830 schoenebeck 3551 runScript({
1831     .code = R"NKSP_CODE(
1832     on init
1833     exit(1 and 1)
1834     end on
1835     )NKSP_CODE",
1836     .expectBoolExitResult = true
1837     });
1838    
1839     runScript({
1840     .code = R"NKSP_CODE(
1841     on init
1842     exit(1 and 2)
1843     end on
1844     )NKSP_CODE",
1845     .expectBoolExitResult = true
1846     });
1847    
1848     runScript({
1849     .code = R"NKSP_CODE(
1850     on init
1851     exit(1 and 3)
1852     end on
1853     )NKSP_CODE",
1854     .expectBoolExitResult = true
1855     });
1856    
1857     runScript({
1858     .code = R"NKSP_CODE(
1859     on init
1860     exit(1 and 0)
1861     end on
1862     )NKSP_CODE",
1863     .expectBoolExitResult = false
1864     });
1865    
1866     runScript({
1867     .code = R"NKSP_CODE(
1868     on init
1869     exit(0 and 1)
1870     end on
1871     )NKSP_CODE",
1872     .expectBoolExitResult = false
1873     });
1874    
1875     runScript({
1876     .code = R"NKSP_CODE(
1877     on init
1878     exit(0 and 0)
1879     end on
1880     )NKSP_CODE",
1881     .expectBoolExitResult = false
1882     });
1883    
1884 schoenebeck 3575 // real number tests ...
1885     // (not allowed for this operator)
1886    
1887     runScript({
1888     .code = R"NKSP_CODE(
1889     on init
1890     exit(1.0 and 1.0)
1891     end on
1892     )NKSP_CODE",
1893     .expectParseError = true // real numbers not allowed for this operator
1894     });
1895    
1896     // mixed type tests ...
1897     // (not allowed for this operator)
1898    
1899     runScript({
1900     .code = R"NKSP_CODE(
1901     on init
1902     exit(1.0 and 1)
1903     end on
1904     )NKSP_CODE",
1905     .expectParseError = true // real numbers not allowed for this operator
1906     });
1907    
1908     runScript({
1909     .code = R"NKSP_CODE(
1910     on init
1911     exit(1 and 1.0)
1912     end on
1913     )NKSP_CODE",
1914     .expectParseError = true // real numbers not allowed for this operator
1915     });
1916    
1917 schoenebeck 3551 #if !SILENT_TEST
1918     std::cout << std::endl;
1919     #endif
1920     }
1921    
1922     static void testLogicalOrOperator() {
1923     #if !SILENT_TEST
1924     std::cout << "UNIT TEST: logical or (or) operator\n";
1925     #endif
1926    
1927 schoenebeck 3575 // integer tests ...
1928    
1929 schoenebeck 3551 runScript({
1930     .code = R"NKSP_CODE(
1931     on init
1932     exit(1 or 1)
1933     end on
1934     )NKSP_CODE",
1935     .expectBoolExitResult = true
1936     });
1937    
1938     runScript({
1939     .code = R"NKSP_CODE(
1940     on init
1941     exit(1 or 2)
1942     end on
1943     )NKSP_CODE",
1944     .expectBoolExitResult = true
1945     });
1946    
1947     runScript({
1948     .code = R"NKSP_CODE(
1949     on init
1950     exit(1 or 3)
1951     end on
1952     )NKSP_CODE",
1953     .expectBoolExitResult = true
1954     });
1955    
1956     runScript({
1957     .code = R"NKSP_CODE(
1958     on init
1959     exit(1 or 0)
1960     end on
1961     )NKSP_CODE",
1962     .expectBoolExitResult = true
1963     });
1964    
1965     runScript({
1966     .code = R"NKSP_CODE(
1967     on init
1968     exit(0 or 1)
1969     end on
1970     )NKSP_CODE",
1971     .expectBoolExitResult = true
1972     });
1973    
1974     runScript({
1975     .code = R"NKSP_CODE(
1976     on init
1977     exit(0 or 0)
1978     end on
1979     )NKSP_CODE",
1980     .expectBoolExitResult = false
1981     });
1982    
1983 schoenebeck 3575 // real number tests ...
1984     // (not allowed for this operator)
1985    
1986     runScript({
1987     .code = R"NKSP_CODE(
1988     on init
1989     exit(1.0 or 1.0)
1990     end on
1991     )NKSP_CODE",
1992     .expectParseError = true // real numbers not allowed for this operator
1993     });
1994    
1995     // mixed type tests ...
1996     // (not allowed for this operator)
1997    
1998     runScript({
1999     .code = R"NKSP_CODE(
2000     on init
2001     exit(1.0 or 1)
2002     end on
2003     )NKSP_CODE",
2004     .expectParseError = true // real numbers not allowed for this operator
2005     });
2006    
2007     runScript({
2008     .code = R"NKSP_CODE(
2009     on init
2010     exit(1 or 1.0)
2011     end on
2012     )NKSP_CODE",
2013     .expectParseError = true // real numbers not allowed for this operator
2014     });
2015    
2016 schoenebeck 3551 #if !SILENT_TEST
2017     std::cout << std::endl;
2018     #endif
2019     }
2020    
2021     static void testLogicalNotOperator() {
2022     #if !SILENT_TEST
2023     std::cout << "UNIT TEST: logical not (not) operator\n";
2024     #endif
2025    
2026 schoenebeck 3575 // integer tests ...
2027    
2028 schoenebeck 3551 runScript({
2029     .code = R"NKSP_CODE(
2030     on init
2031     exit(not 1)
2032     end on
2033     )NKSP_CODE",
2034     .expectBoolExitResult = false
2035     });
2036    
2037     runScript({
2038     .code = R"NKSP_CODE(
2039     on init
2040     exit(not 2)
2041     end on
2042     )NKSP_CODE",
2043     .expectBoolExitResult = false
2044     });
2045    
2046     runScript({
2047     .code = R"NKSP_CODE(
2048     on init
2049     exit(not 0)
2050     end on
2051     )NKSP_CODE",
2052     .expectBoolExitResult = true
2053     });
2054    
2055 schoenebeck 3575 // real number tests ...
2056     // (not allowed for this operator)
2057    
2058     runScript({
2059     .code = R"NKSP_CODE(
2060     on init
2061     exit(not 1.0)
2062     end on
2063     )NKSP_CODE",
2064     .expectParseError = true // real numbers not allowed for this operator
2065     });
2066    
2067 schoenebeck 3551 #if !SILENT_TEST
2068     std::cout << std::endl;
2069     #endif
2070     }
2071    
2072     static void testBitwiseAndOperator() {
2073     #if !SILENT_TEST
2074     std::cout << "UNIT TEST: bitwise and (.and.) operator\n";
2075     #endif
2076    
2077 schoenebeck 3575 // integer tests ...
2078    
2079 schoenebeck 3551 runScript({
2080     .code = R"NKSP_CODE(
2081     on init
2082     exit(1 .and. 1)
2083     end on
2084     )NKSP_CODE",
2085     .expectIntExitResult = 1
2086     });
2087    
2088     runScript({
2089     .code = R"NKSP_CODE(
2090     on init
2091     exit(43 .and. 142)
2092     end on
2093     )NKSP_CODE",
2094     .expectIntExitResult = 10
2095     });
2096    
2097 schoenebeck 3575 // real number tests ...
2098     // (not allowed for this operator)
2099    
2100     runScript({
2101     .code = R"NKSP_CODE(
2102     on init
2103     exit(1.0 .and. 1.0)
2104     end on
2105     )NKSP_CODE",
2106     .expectParseError = true // real numbers not allowed for this operator
2107     });
2108    
2109     // mixed type tests ...
2110     // (not allowed for this operator)
2111    
2112     runScript({
2113     .code = R"NKSP_CODE(
2114     on init
2115     exit(1.0 .and. 1)
2116     end on
2117     )NKSP_CODE",
2118     .expectParseError = true // real numbers not allowed for this operator
2119     });
2120    
2121     runScript({
2122     .code = R"NKSP_CODE(
2123     on init
2124     exit(1 .and. 1.0)
2125     end on
2126     )NKSP_CODE",
2127     .expectParseError = true // real numbers not allowed for this operator
2128     });
2129    
2130 schoenebeck 3551 #if !SILENT_TEST
2131     std::cout << std::endl;
2132     #endif
2133     }
2134    
2135     static void testBitwiseOrOperator() {
2136     #if !SILENT_TEST
2137     std::cout << "UNIT TEST: bitwise or (.or.) operator\n";
2138     #endif
2139    
2140 schoenebeck 3575 // integer tests ...
2141    
2142 schoenebeck 3551 runScript({
2143     .code = R"NKSP_CODE(
2144     on init
2145     exit(1 .or. 1)
2146     end on
2147     )NKSP_CODE",
2148     .expectIntExitResult = 1
2149     });
2150    
2151     runScript({
2152     .code = R"NKSP_CODE(
2153     on init
2154     exit(0 .or. 0)
2155     end on
2156     )NKSP_CODE",
2157     .expectIntExitResult = 0
2158     });
2159    
2160     runScript({
2161     .code = R"NKSP_CODE(
2162     on init
2163     exit(43 .or. 142)
2164     end on
2165     )NKSP_CODE",
2166     .expectIntExitResult = 175
2167     });
2168    
2169 schoenebeck 3575 // real number tests ...
2170     // (not allowed for this operator)
2171    
2172     runScript({
2173     .code = R"NKSP_CODE(
2174     on init
2175     exit(1.0 .or. 1.0)
2176     end on
2177     )NKSP_CODE",
2178     .expectParseError = true // real numbers not allowed for this operator
2179     });
2180    
2181     // mixed type tests ...
2182     // (not allowed for this operator)
2183    
2184     runScript({
2185     .code = R"NKSP_CODE(
2186     on init
2187     exit(1.0 .or. 1)
2188     end on
2189     )NKSP_CODE",
2190     .expectParseError = true // real numbers not allowed for this operator
2191     });
2192    
2193     runScript({
2194     .code = R"NKSP_CODE(
2195     on init
2196     exit(1 .or. 1.0)
2197     end on
2198     )NKSP_CODE",
2199     .expectParseError = true // real numbers not allowed for this operator
2200     });
2201    
2202 schoenebeck 3551 #if !SILENT_TEST
2203     std::cout << std::endl;
2204     #endif
2205     }
2206    
2207     static void testBitwiseNotOperator() {
2208     #if !SILENT_TEST
2209     std::cout << "UNIT TEST: bitwise not (.not.) operator\n";
2210     #endif
2211    
2212 schoenebeck 3575 // integer tests ...
2213    
2214 schoenebeck 3551 runScript({
2215     .code = R"NKSP_CODE(
2216     on init
2217     exit(.not. -1)
2218     end on
2219     )NKSP_CODE",
2220     .expectIntExitResult = 0
2221     });
2222    
2223     runScript({
2224     .code = R"NKSP_CODE(
2225     on init
2226     exit(.not. 0)
2227     end on
2228     )NKSP_CODE",
2229     .expectIntExitResult = -1
2230     });
2231    
2232     runScript({
2233     .code = R"NKSP_CODE(
2234     on init
2235     exit(.not. 3)
2236     end on
2237     )NKSP_CODE",
2238     .expectIntExitResult = ssize_t(size_t(-1) << 2)
2239     });
2240    
2241 schoenebeck 3575 // real number tests ...
2242     // (not allowed for this operator)
2243    
2244     runScript({
2245     .code = R"NKSP_CODE(
2246     on init
2247     exit(.not. 1.0)
2248     end on
2249     )NKSP_CODE",
2250     .expectParseError = true // real numbers not allowed for this operator
2251     });
2252    
2253     runScript({
2254     .code = R"NKSP_CODE(
2255     on init
2256     exit(.not. -1.0)
2257     end on
2258     )NKSP_CODE",
2259     .expectParseError = true // real numbers not allowed for this operator
2260     });
2261    
2262 schoenebeck 3551 #if !SILENT_TEST
2263     std::cout << std::endl;
2264     #endif
2265     }
2266    
2267     static void testPrecedenceOfOperators() {
2268     #if !SILENT_TEST
2269     std::cout << "UNIT TEST: precedence of operators\n";
2270     #endif
2271    
2272 schoenebeck 3575 // integer tests ...
2273    
2274 schoenebeck 3551 runScript({
2275     .code = R"NKSP_CODE(
2276     on init
2277     exit(3 + 4 * 2)
2278     end on
2279     )NKSP_CODE",
2280     .expectIntExitResult = 11
2281     });
2282    
2283     runScript({
2284     .code = R"NKSP_CODE(
2285     on init
2286     exit(4 * 2 + 3)
2287     end on
2288     )NKSP_CODE",
2289     .expectIntExitResult = 11
2290     });
2291    
2292     runScript({
2293     .code = R"NKSP_CODE(
2294     on init
2295     exit((3 + 4) * 2)
2296     end on
2297     )NKSP_CODE",
2298     .expectIntExitResult = 14
2299     });
2300    
2301     runScript({
2302     .code = R"NKSP_CODE(
2303     on init
2304     exit(4 * (2 + 3))
2305     end on
2306     )NKSP_CODE",
2307     .expectIntExitResult = 20
2308     });
2309    
2310 schoenebeck 3575 // real number tests ...
2311    
2312     runScript({
2313     .code = R"NKSP_CODE(
2314     on init
2315     exit(3.2 + 4.0 * 2.0)
2316     end on
2317     )NKSP_CODE",
2318     .expectRealExitResult = 11.2
2319     });
2320    
2321     runScript({
2322     .code = R"NKSP_CODE(
2323     on init
2324     exit(4.0 * 2.0 + 3.2)
2325     end on
2326     )NKSP_CODE",
2327     .expectRealExitResult = 11.2
2328     });
2329    
2330     runScript({
2331     .code = R"NKSP_CODE(
2332     on init
2333     exit((3.2 + 4.0) * 2.0)
2334     end on
2335     )NKSP_CODE",
2336     .expectRealExitResult = 14.4
2337     });
2338    
2339     runScript({
2340     .code = R"NKSP_CODE(
2341     on init
2342     exit(4.0 * (2.0 + 3.2))
2343     end on
2344     )NKSP_CODE",
2345     .expectRealExitResult = 20.8
2346     });
2347    
2348 schoenebeck 3551 #if !SILENT_TEST
2349     std::cout << std::endl;
2350     #endif
2351     }
2352    
2353     static void testBuiltInMinFunction() {
2354     #if !SILENT_TEST
2355     std::cout << "UNIT TEST: built-in min() function\n";
2356     #endif
2357    
2358     runScript({
2359     .code = R"NKSP_CODE(
2360     on init
2361     declare $foo := min
2362     end on
2363     )NKSP_CODE",
2364     .expectParseError = true // because min() function requires 2 arguments
2365     });
2366    
2367     runScript({
2368     .code = R"NKSP_CODE(
2369     on init
2370     declare $foo := min()
2371     end on
2372     )NKSP_CODE",
2373     .expectParseError = true // because min() function requires 2 arguments
2374     });
2375    
2376     runScript({
2377     .code = R"NKSP_CODE(
2378     on init
2379     declare $foo := min(1)
2380     end on
2381     )NKSP_CODE",
2382     .expectParseError = true // because min() function requires 2 arguments
2383     });
2384    
2385     runScript({
2386     .code = R"NKSP_CODE(
2387     on init
2388     declare $foo := min(1,2)
2389     exit($foo)
2390     end on
2391     )NKSP_CODE",
2392     .expectIntExitResult = 1
2393     });
2394    
2395     runScript({
2396     .code = R"NKSP_CODE(
2397     on init
2398     declare $foo := min(-30,4)
2399     exit($foo)
2400     end on
2401     )NKSP_CODE",
2402     .expectIntExitResult = -30
2403     });
2404    
2405     #if !SILENT_TEST
2406     std::cout << std::endl;
2407     #endif
2408     }
2409    
2410     static void testBuiltInMaxFunction() {
2411     #if !SILENT_TEST
2412     std::cout << "UNIT TEST: built-in max() function\n";
2413     #endif
2414    
2415     runScript({
2416     .code = R"NKSP_CODE(
2417     on init
2418     declare $foo := max
2419     end on
2420     )NKSP_CODE",
2421     .expectParseError = true // because max() function requires 2 arguments
2422     });
2423    
2424     runScript({
2425     .code = R"NKSP_CODE(
2426     on init
2427     declare $foo := max()
2428     end on
2429     )NKSP_CODE",
2430     .expectParseError = true // because max() function requires 2 arguments
2431     });
2432    
2433     runScript({
2434     .code = R"NKSP_CODE(
2435     on init
2436     declare $foo := max(1)
2437     end on
2438     )NKSP_CODE",
2439     .expectParseError = true // because max() function requires 2 arguments
2440     });
2441    
2442     runScript({
2443     .code = R"NKSP_CODE(
2444     on init
2445     declare $foo := max(1,2)
2446     exit($foo)
2447     end on
2448     )NKSP_CODE",
2449     .expectIntExitResult = 2
2450     });
2451    
2452     runScript({
2453     .code = R"NKSP_CODE(
2454     on init
2455     declare $foo := max(-30,4)
2456     exit($foo)
2457     end on
2458     )NKSP_CODE",
2459     .expectIntExitResult = 4
2460     });
2461    
2462     #if !SILENT_TEST
2463     std::cout << std::endl;
2464     #endif
2465     }
2466    
2467     static void testBuiltInAbsFunction() {
2468     #if !SILENT_TEST
2469     std::cout << "UNIT TEST: built-in abs() function\n";
2470     #endif
2471    
2472     runScript({
2473     .code = R"NKSP_CODE(
2474     on init
2475     declare $foo := abs
2476     end on
2477     )NKSP_CODE",
2478     .expectParseError = true // because abs() function requires 1 argument
2479     });
2480    
2481     runScript({
2482     .code = R"NKSP_CODE(
2483     on init
2484     declare $foo := abs()
2485     end on
2486     )NKSP_CODE",
2487     .expectParseError = true // because abs() function requires 1 argument
2488     });
2489    
2490     runScript({
2491     .code = R"NKSP_CODE(
2492     on init
2493     declare $foo := abs(23)
2494     exit($foo)
2495     end on
2496     )NKSP_CODE",
2497     .expectIntExitResult = 23
2498     });
2499    
2500     runScript({
2501     .code = R"NKSP_CODE(
2502     on init
2503     declare $foo := abs(-23)
2504     exit($foo)
2505     end on
2506     )NKSP_CODE",
2507     .expectIntExitResult = 23
2508     });
2509    
2510     #if !SILENT_TEST
2511     std::cout << std::endl;
2512     #endif
2513     }
2514    
2515     static void testBuiltInIncFunction() {
2516     #if !SILENT_TEST
2517     std::cout << "UNIT TEST: built-in inc() function\n";
2518     #endif
2519    
2520     runScript({
2521     .code = R"NKSP_CODE(
2522     on init
2523     declare $foo := 5
2524     inc($foo)
2525     exit($foo)
2526     end on
2527     )NKSP_CODE",
2528     .expectIntExitResult = 6
2529     });
2530    
2531     runScript({
2532     .code = R"NKSP_CODE(
2533     on init
2534     declare $foo := 5
2535     inc($foo)
2536     inc($foo)
2537     inc($foo)
2538     exit($foo)
2539     end on
2540     )NKSP_CODE",
2541     .expectIntExitResult = 8
2542     });
2543    
2544     runScript({
2545     .code = R"NKSP_CODE(
2546     on init
2547     declare $foo := 5
2548     inc($foo)
2549     exit( inc($foo) )
2550     end on
2551     )NKSP_CODE",
2552     .expectIntExitResult = 7
2553     });
2554    
2555     #if !SILENT_TEST
2556     std::cout << std::endl;
2557     #endif
2558     }
2559    
2560     static void testBuiltInDecFunction() {
2561     #if !SILENT_TEST
2562     std::cout << "UNIT TEST: built-in dec() function\n";
2563     #endif
2564    
2565     runScript({
2566     .code = R"NKSP_CODE(
2567     on init
2568     declare $foo := 5
2569     dec($foo)
2570     exit($foo)
2571     end on
2572     )NKSP_CODE",
2573     .expectIntExitResult = 4
2574     });
2575    
2576     runScript({
2577     .code = R"NKSP_CODE(
2578     on init
2579     declare $foo := 5
2580     dec($foo)
2581     dec($foo)
2582     dec($foo)
2583     exit($foo)
2584     end on
2585     )NKSP_CODE",
2586     .expectIntExitResult = 2
2587     });
2588    
2589     runScript({
2590     .code = R"NKSP_CODE(
2591     on init
2592     declare $foo := 5
2593     dec($foo)
2594     exit( dec($foo) )
2595     end on
2596     )NKSP_CODE",
2597     .expectIntExitResult = 3
2598     });
2599    
2600     #if !SILENT_TEST
2601     std::cout << std::endl;
2602     #endif
2603     }
2604    
2605     static void testBuiltInInRangeFunction() {
2606     #if !SILENT_TEST
2607     std::cout << "UNIT TEST: built-in in_range() function\n";
2608     #endif
2609    
2610     runScript({
2611     .code = R"NKSP_CODE(
2612     on init
2613     exit( in_range(1,4,9) )
2614     end on
2615     )NKSP_CODE",
2616     .expectBoolExitResult = false
2617     });
2618    
2619     runScript({
2620     .code = R"NKSP_CODE(
2621     on init
2622     exit( in_range(5,4,9) )
2623     end on
2624     )NKSP_CODE",
2625     .expectBoolExitResult = true
2626     });
2627    
2628     runScript({
2629     .code = R"NKSP_CODE(
2630     on init
2631     exit( in_range(9,4,9) )
2632     end on
2633     )NKSP_CODE",
2634     .expectBoolExitResult = true
2635     });
2636    
2637     runScript({
2638     .code = R"NKSP_CODE(
2639     on init
2640     exit( in_range(10,4,9) )
2641     end on
2642     )NKSP_CODE",
2643     .expectBoolExitResult = false
2644     });
2645    
2646     runScript({
2647     .code = R"NKSP_CODE(
2648     on init
2649     exit( in_range(-6,-5,5) )
2650     end on
2651     )NKSP_CODE",
2652     .expectBoolExitResult = false
2653     });
2654    
2655     runScript({
2656     .code = R"NKSP_CODE(
2657     on init
2658     exit( in_range(-5,-5,5) )
2659     end on
2660     )NKSP_CODE",
2661     .expectBoolExitResult = true
2662     });
2663    
2664     runScript({
2665     .code = R"NKSP_CODE(
2666     on init
2667     exit( in_range(0,-5,5) )
2668     end on
2669     )NKSP_CODE",
2670     .expectBoolExitResult = true
2671     });
2672    
2673     runScript({
2674     .code = R"NKSP_CODE(
2675     on init
2676     exit( in_range(5,-5,5) )
2677     end on
2678     )NKSP_CODE",
2679     .expectBoolExitResult = true
2680     });
2681    
2682     runScript({
2683     .code = R"NKSP_CODE(
2684     on init
2685     exit( in_range(6,-5,5) )
2686     end on
2687     )NKSP_CODE",
2688     .expectBoolExitResult = false
2689     });
2690    
2691     #if !SILENT_TEST
2692     std::cout << std::endl;
2693     #endif
2694     }
2695    
2696     static void testBuiltInRandomFunction() {
2697     #if !SILENT_TEST
2698     std::cout << "UNIT TEST: built-in random() function\n";
2699     #endif
2700    
2701     for (int run = 0; run < 20; ++run) {
2702     runScript({
2703     .code = R"NKSP_CODE(
2704     on init
2705     declare $foo := random(-5,5)
2706     exit( in_range($foo,-5,5) )
2707     end on
2708     )NKSP_CODE",
2709     .expectBoolExitResult = true
2710     });
2711     }
2712    
2713     #if !SILENT_TEST
2714     std::cout << std::endl;
2715     #endif
2716     }
2717    
2718     static void testBuiltInShiftLeftFunction() {
2719     #if !SILENT_TEST
2720     std::cout << "UNIT TEST: built-in sh_left() function\n";
2721     #endif
2722    
2723     runScript({
2724     .code = R"NKSP_CODE(
2725     on init
2726     exit( sh_left(1,0) )
2727     end on
2728     )NKSP_CODE",
2729     .expectIntExitResult = 1
2730     });
2731    
2732     runScript({
2733     .code = R"NKSP_CODE(
2734     on init
2735     exit( sh_left(1,1) )
2736     end on
2737     )NKSP_CODE",
2738     .expectIntExitResult = 2
2739     });
2740    
2741     runScript({
2742     .code = R"NKSP_CODE(
2743     on init
2744     exit( sh_left(1,2) )
2745     end on
2746     )NKSP_CODE",
2747     .expectIntExitResult = 4
2748     });
2749    
2750     runScript({
2751     .code = R"NKSP_CODE(
2752     on init
2753     exit( sh_left(1,3) )
2754     end on
2755     )NKSP_CODE",
2756     .expectIntExitResult = 8
2757     });
2758    
2759     #if !SILENT_TEST
2760     std::cout << std::endl;
2761     #endif
2762     }
2763    
2764     static void testBuiltInShiftRightFunction() {
2765     #if !SILENT_TEST
2766     std::cout << "UNIT TEST: built-in sh_right() function\n";
2767     #endif
2768    
2769     runScript({
2770     .code = R"NKSP_CODE(
2771     on init
2772     exit( sh_right(8,0) )
2773     end on
2774     )NKSP_CODE",
2775     .expectIntExitResult = 8
2776     });
2777    
2778     runScript({
2779     .code = R"NKSP_CODE(
2780     on init
2781     exit( sh_right(8,1) )
2782     end on
2783     )NKSP_CODE",
2784     .expectIntExitResult = 4
2785     });
2786    
2787     runScript({
2788     .code = R"NKSP_CODE(
2789     on init
2790     exit( sh_right(8,2) )
2791     end on
2792     )NKSP_CODE",
2793     .expectIntExitResult = 2
2794     });
2795    
2796     runScript({
2797     .code = R"NKSP_CODE(
2798     on init
2799     exit( sh_right(8,3) )
2800     end on
2801     )NKSP_CODE",
2802     .expectIntExitResult = 1
2803     });
2804    
2805     runScript({
2806     .code = R"NKSP_CODE(
2807     on init
2808     exit( sh_right(8,4) )
2809     end on
2810     )NKSP_CODE",
2811     .expectIntExitResult = 0
2812     });
2813    
2814     #if !SILENT_TEST
2815     std::cout << std::endl;
2816     #endif
2817     }
2818    
2819 schoenebeck 3575 static void testBuiltInIntToRealFunction() {
2820     #if !SILENT_TEST
2821     std::cout << "UNIT TEST: built-in int_to_real() function\n";
2822     #endif
2823    
2824     runScript({
2825     .code = R"NKSP_CODE(
2826     on init
2827     exit( int_to_real(8) )
2828     end on
2829     )NKSP_CODE",
2830     .expectRealExitResult = 8.0
2831     });
2832    
2833     runScript({
2834     .code = R"NKSP_CODE(
2835     on init
2836     declare $foo := 23
2837     exit( int_to_real($foo) )
2838     end on
2839     )NKSP_CODE",
2840     .expectRealExitResult = 23.0
2841     });
2842    
2843     #if !SILENT_TEST
2844     std::cout << std::endl;
2845     #endif
2846     }
2847    
2848     static void testBuiltInRealFunction() {
2849     #if !SILENT_TEST
2850     std::cout << "UNIT TEST: built-in real() function\n";
2851     #endif
2852    
2853     runScript({
2854     .code = R"NKSP_CODE(
2855     on init
2856     exit( real(8) )
2857     end on
2858     )NKSP_CODE",
2859     .expectRealExitResult = 8.0
2860     });
2861    
2862     runScript({
2863     .code = R"NKSP_CODE(
2864     on init
2865     declare $foo := 23
2866     exit( real($foo) )
2867     end on
2868     )NKSP_CODE",
2869     .expectRealExitResult = 23.0
2870     });
2871    
2872     #if !SILENT_TEST
2873     std::cout << std::endl;
2874     #endif
2875     }
2876    
2877     static void testBuiltInRealToIntFunction() {
2878     #if !SILENT_TEST
2879     std::cout << "UNIT TEST: built-in real_to_int() function\n";
2880     #endif
2881    
2882     runScript({
2883     .code = R"NKSP_CODE(
2884     on init
2885     exit( real_to_int(8.9) )
2886     end on
2887     )NKSP_CODE",
2888     .expectIntExitResult = 8
2889     });
2890    
2891     runScript({
2892     .code = R"NKSP_CODE(
2893     on init
2894     declare ~foo := 8.9
2895     exit( real_to_int(~foo) )
2896     end on
2897     )NKSP_CODE",
2898     .expectIntExitResult = 8
2899     });
2900    
2901     #if !SILENT_TEST
2902     std::cout << std::endl;
2903     #endif
2904     }
2905    
2906     static void testBuiltInIntFunction() {
2907     #if !SILENT_TEST
2908     std::cout << "UNIT TEST: built-in int() function\n";
2909     #endif
2910    
2911     runScript({
2912     .code = R"NKSP_CODE(
2913     on init
2914     exit( int(8.9) )
2915     end on
2916     )NKSP_CODE",
2917     .expectIntExitResult = 8
2918     });
2919    
2920     runScript({
2921     .code = R"NKSP_CODE(
2922     on init
2923     declare ~foo := 8.9
2924     exit( int(~foo) )
2925     end on
2926     )NKSP_CODE",
2927     .expectIntExitResult = 8
2928     });
2929    
2930     #if !SILENT_TEST
2931     std::cout << std::endl;
2932     #endif
2933     }
2934    
2935 schoenebeck 3551 static void testBuiltInArrayEqualFunction() {
2936     #if !SILENT_TEST
2937     std::cout << "UNIT TEST: built-in array_equal() function\n";
2938     #endif
2939    
2940     runScript({
2941     .code = R"NKSP_CODE(
2942     on init
2943     declare %foo[3] := ( 1, 2, 3 )
2944     declare %bar[3] := ( 1, 2, 3 )
2945     exit( array_equal(%foo, %bar) )
2946     end on
2947     )NKSP_CODE",
2948     .expectBoolExitResult = true
2949     });
2950    
2951     runScript({
2952     .code = R"NKSP_CODE(
2953     on init
2954     declare %foo[1] := ( 1 )
2955     declare %bar[1] := ( 1 )
2956     exit( array_equal(%foo, %bar) )
2957     end on
2958     )NKSP_CODE",
2959     .expectBoolExitResult = true
2960     });
2961    
2962     runScript({
2963     .code = R"NKSP_CODE(
2964     on init
2965     declare %foo[3] := ( 1, 2, 3 )
2966     declare %bar[3] := ( 0, 2, 3 )
2967     exit( array_equal(%foo, %bar) )
2968     end on
2969     )NKSP_CODE",
2970     .expectBoolExitResult = false
2971     });
2972    
2973     runScript({
2974     .code = R"NKSP_CODE(
2975     on init
2976     declare %foo[3] := ( 1, 2, 3 )
2977     declare %bar[3] := ( 3, 2, 1 )
2978     exit( array_equal(%foo, %bar) )
2979     end on
2980     )NKSP_CODE",
2981     .expectBoolExitResult = false
2982     });
2983    
2984     runScript({
2985     .code = R"NKSP_CODE(
2986     on init
2987     declare %foo[3] := ( 1, 2, 3 )
2988     declare %bar[2] := ( 1, 2 )
2989     exit( array_equal(%foo, %bar) )
2990     end on
2991     )NKSP_CODE",
2992     .expectBoolExitResult = false
2993     });
2994    
2995     #if !SILENT_TEST
2996     std::cout << std::endl;
2997     #endif
2998     }
2999    
3000     static void testBuiltInSortFunction() {
3001     #if !SILENT_TEST
3002     std::cout << "UNIT TEST: built-in sort() function\n";
3003     #endif
3004    
3005     runScript({
3006     .code = R"NKSP_CODE(
3007     on init
3008     declare %input[3] := ( 19, 3, 6 )
3009     declare %expected[3] := ( 3, 6, 19 )
3010     sort(%input, 0)
3011     exit( array_equal(%input, %expected) )
3012     end on
3013     )NKSP_CODE",
3014     .expectBoolExitResult = true
3015     });
3016    
3017     runScript({
3018     .code = R"NKSP_CODE(
3019     on init
3020     declare %input[3] := ( 19, 3, 6 )
3021     declare %expected[3] := ( 19, 6, 3 )
3022     sort(%input, 1)
3023     exit( array_equal(%input, %expected) )
3024     end on
3025     )NKSP_CODE",
3026     .expectBoolExitResult = true
3027     });
3028    
3029     #if !SILENT_TEST
3030     std::cout << std::endl;
3031     #endif
3032     }
3033    
3034     static void testBuiltInNumElementsFunction() {
3035     #if !SILENT_TEST
3036     std::cout << "UNIT TEST: built-in num_elements() function\n";
3037     #endif
3038    
3039     runScript({
3040     .code = R"NKSP_CODE(
3041     on init
3042     declare %foo[3] := ( 19, 3, 6 )
3043     exit( num_elements(%foo) )
3044     end on
3045     )NKSP_CODE",
3046     .expectIntExitResult = 3
3047     });
3048    
3049     runScript({
3050     .code = R"NKSP_CODE(
3051     on init
3052     declare %foo[1] := ( 19 )
3053     exit( num_elements(%foo) )
3054     end on
3055     )NKSP_CODE",
3056     .expectIntExitResult = 1
3057     });
3058    
3059     runScript({
3060     .code = R"NKSP_CODE(
3061     on init
3062     declare %foo[5] := ( 1, 2, 3, 4, 5 )
3063     exit( num_elements(%foo) )
3064     end on
3065     )NKSP_CODE",
3066     .expectIntExitResult = 5
3067     });
3068    
3069     #if !SILENT_TEST
3070     std::cout << std::endl;
3071     #endif
3072     }
3073    
3074     static void testBuiltInSearchFunction() {
3075     #if !SILENT_TEST
3076     std::cout << "UNIT TEST: built-in search() function\n";
3077     #endif
3078    
3079     runScript({
3080     .code = R"NKSP_CODE(
3081     on init
3082     declare %foo[3] := ( 19, 3, 6 )
3083     exit( search(%foo, 19) )
3084     end on
3085     )NKSP_CODE",
3086     .expectIntExitResult = 0
3087     });
3088    
3089     runScript({
3090     .code = R"NKSP_CODE(
3091     on init
3092     declare %foo[3] := ( 19, 3, 6 )
3093     exit( search(%foo, 3) )
3094     end on
3095     )NKSP_CODE",
3096     .expectIntExitResult = 1
3097     });
3098    
3099     runScript({
3100     .code = R"NKSP_CODE(
3101     on init
3102     declare %foo[3] := ( 19, 3, 6 )
3103     exit( search(%foo, 6) )
3104     end on
3105     )NKSP_CODE",
3106     .expectIntExitResult = 2
3107     });
3108    
3109     runScript({
3110     .code = R"NKSP_CODE(
3111     on init
3112     declare %foo[3] := ( 19, 3, 6 )
3113     exit( search(%foo, 2) )
3114     end on
3115     )NKSP_CODE",
3116     .expectIntExitResult = -1
3117     });
3118    
3119     #if !SILENT_TEST
3120     std::cout << std::endl;
3121     #endif
3122     }
3123    
3124     static void testIfStatement() {
3125     #if !SILENT_TEST
3126     std::cout << "UNIT TEST: if statement\n";
3127     #endif
3128    
3129     runScript({
3130     .code = R"NKSP_CODE(
3131     on init
3132     declare $foo := 1
3133     if ($foo)
3134     exit(42)
3135     end if
3136     end on
3137     )NKSP_CODE",
3138     .expectIntExitResult = 42
3139     });
3140    
3141     runScript({
3142     .code = R"NKSP_CODE(
3143     on init
3144     declare $foo := 0
3145     if ($foo)
3146     exit(42)
3147     end if
3148     exit(3)
3149     end on
3150     )NKSP_CODE",
3151     .expectIntExitResult = 3
3152     });
3153    
3154     runScript({
3155     .code = R"NKSP_CODE(
3156     on init
3157     declare $foo := 1
3158     if ($foo)
3159     exit(42)
3160     else
3161     exit(3)
3162     end if
3163     end on
3164     )NKSP_CODE",
3165     .expectIntExitResult = 42
3166     });
3167    
3168     runScript({
3169     .code = R"NKSP_CODE(
3170     on init
3171     declare $foo := 0
3172     if ($foo)
3173     exit(42)
3174     else
3175     exit(3)
3176     end if
3177     end on
3178     )NKSP_CODE",
3179     .expectIntExitResult = 3
3180     });
3181    
3182     #if !SILENT_TEST
3183     std::cout << std::endl;
3184     #endif
3185     }
3186    
3187     static void testWhileStatement() {
3188     #if !SILENT_TEST
3189     std::cout << "UNIT TEST: while statement\n";
3190     #endif
3191    
3192     runScript({
3193     .code = R"NKSP_CODE(
3194     on init
3195     declare $foo := 100
3196     declare $i := 50
3197     while ($i)
3198     $foo := $foo + 1
3199     $i := $i - 1
3200     end while
3201     exit($foo)
3202     end on
3203     )NKSP_CODE",
3204     .expectIntExitResult = 150
3205     });
3206    
3207     #if !SILENT_TEST
3208     std::cout << std::endl;
3209     #endif
3210     }
3211    
3212     #if !NO_MAIN
3213    
3214     int main() {
3215     testBuiltInExitFunction();
3216     testStringConcatOperator();
3217 schoenebeck 3575 testNegOperator();
3218 schoenebeck 3551 testPlusOperator();
3219     testMinusOperator();
3220     testModuloOperator();
3221     testMultiplyOperator();
3222     testDivideOperator();
3223     testSmallerThanOperator();
3224     testGreaterThanOperator();
3225     testSmallerOrEqualOperator();
3226     testGreaterOrEqualOperator();
3227     testEqualOperator();
3228     testUnequalOperator();
3229     testLogicalAndOperator();
3230     testLogicalOrOperator();
3231     testLogicalNotOperator();
3232     testBitwiseAndOperator();
3233     testBitwiseOrOperator();
3234     testBitwiseNotOperator();
3235     testPrecedenceOfOperators();
3236     testBuiltInMinFunction();
3237     testBuiltInMaxFunction();
3238     testBuiltInAbsFunction();
3239     testBuiltInIncFunction();
3240     testBuiltInDecFunction();
3241     testBuiltInInRangeFunction();
3242     testBuiltInRandomFunction();
3243     testBuiltInShiftLeftFunction();
3244     testBuiltInShiftRightFunction();
3245 schoenebeck 3575 testBuiltInIntToRealFunction();
3246     testBuiltInRealFunction();
3247     testBuiltInRealToIntFunction();
3248     testBuiltInIntFunction();
3249 schoenebeck 3551 testBuiltInArrayEqualFunction();
3250     testBuiltInSortFunction();
3251     testBuiltInNumElementsFunction();
3252     testBuiltInSearchFunction();
3253     testIfStatement();
3254     testWhileStatement();
3255     std::cout << "\nAll tests passed successfully. :-)\n";
3256     return 0;
3257     }
3258    
3259     #endif // !NO_MAIN

  ViewVC Help
Powered by ViewVC