/[svn]/linuxsampler/trunk/src/scriptvm/tests/NKSPCoreLangTest.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/scriptvm/tests/NKSPCoreLangTest.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3693 by schoenebeck, Fri Jan 3 14:53:32 2020 UTC revision 3747 by schoenebeck, Sun Feb 16 11:31:46 2020 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2019 Christian Schoenebeck   * Copyright (c) 2019 - 2020 Christian Schoenebeck
3   *   *
4   * http://www.linuxsampler.org   * http://www.linuxsampler.org
5   *   *
# Line 2095  end on Line 2095  end on
2095          .expectExitResultUnit = VM_SECOND          .expectExitResultUnit = VM_SECOND
2096      });      });
2097    
2098        runScript({
2099            .code = R"NKSP_CODE(
2100    on init
2101      declare ~foo := 1.0  { neutral }
2102      declare $bar := 7000ms
2103      exit(~foo * real($bar))
2104    end on
2105    )NKSP_CODE",
2106            .expectRealExitResult = 7000.0,
2107            .expectExitResultUnitPrefix = { VM_MILLI },
2108            .expectExitResultUnit = VM_SECOND
2109        });
2110    
2111     runScript({
2112            .code = R"NKSP_CODE(
2113    on init
2114      declare $foo := 1  { neutral }
2115      declare $bar := 7000ms
2116      exit(real($foo) * real($bar))
2117    end on
2118    )NKSP_CODE",
2119            .expectRealExitResult = 7000.0,
2120            .expectExitResultUnitPrefix = { VM_MILLI },
2121            .expectExitResultUnit = VM_SECOND
2122        });
2123    
2124      // 'final' ('!') operator tests ...      // 'final' ('!') operator tests ...
2125    
2126      runScript({      runScript({
# Line 2352  end on Line 2378  end on
2378          .expectParseError = true // unit types are not matching          .expectParseError = true // unit types are not matching
2379      });      });
2380    
2381        runScript({
2382            .code = R"NKSP_CODE(
2383    on init
2384      declare $foo := 1000000
2385      declare $bar := 7000ms
2386      exit(real($foo) / 1000000.0 * real($bar))
2387    end on
2388    )NKSP_CODE",
2389            .expectRealExitResult = 7000.0,
2390            .expectExitResultUnitPrefix = { VM_MILLI },
2391            .expectExitResultUnit = VM_SECOND
2392        });
2393    
2394      // 'final' ('!') operator tests ...      // 'final' ('!') operator tests ...
2395    
2396      runScript({      runScript({
# Line 5413  end on Line 5452  end on
5452      #endif      #endif
5453  }  }
5454    
5455    static void testIntVarDeclaration() {
5456        #if !SILENT_TEST
5457        std::cout << "UNIT TEST: int var declaration\n";
5458        #endif
5459    
5460        runScript({
5461            .code = R"NKSP_CODE(
5462    on init
5463      declare $a
5464      exit($a)
5465    end on
5466    )NKSP_CODE",
5467            .expectIntExitResult = 0
5468        });
5469    
5470        runScript({
5471            .code = R"NKSP_CODE(
5472    on init
5473      declare $a := 24
5474      exit($a)
5475    end on
5476    )NKSP_CODE",
5477            .expectIntExitResult = 24
5478        });
5479    
5480        runScript({
5481            .code = R"NKSP_CODE(
5482    on init
5483      declare $a := 24
5484      $a := 8
5485      exit($a)
5486    end on
5487    )NKSP_CODE",
5488            .expectIntExitResult = 8
5489        });
5490    
5491        runScript({
5492            .code = R"NKSP_CODE(
5493    on init
5494      declare $a
5495      declare $a
5496    end on
5497    )NKSP_CODE",
5498            .expectParseError = true // variable re-declaration
5499        });
5500    
5501        runScript({
5502            .code = R"NKSP_CODE(
5503    on init
5504      declare const $a
5505    end on
5506    )NKSP_CODE",
5507            .expectParseError = true // const variable declaration without assignment
5508        });
5509    
5510        runScript({
5511            .code = R"NKSP_CODE(
5512    on init
5513      declare const $a := 24
5514      exit($a)
5515    end on
5516    )NKSP_CODE",
5517            .expectIntExitResult = 24
5518        });
5519    
5520        runScript({
5521            .code = R"NKSP_CODE(
5522    on init
5523      declare const $a := 24
5524      $a := 8
5525    end on
5526    )NKSP_CODE",
5527            .expectParseError = true // attempt to modify const variable
5528        });
5529    
5530        runScript({
5531            .code = R"NKSP_CODE(
5532    on init
5533      declare const $a := 24
5534      declare const $b := $a
5535      exit($b)
5536    end on
5537    )NKSP_CODE",
5538            .expectIntExitResult = 24
5539        });
5540    
5541        runScript({
5542            .code = R"NKSP_CODE(
5543    on init
5544      declare $a := 24
5545      declare const $b := $a
5546    end on
5547    )NKSP_CODE",
5548            .expectParseError = true // const variable defined with non-const assignment
5549        });
5550    
5551        runScript({
5552            .code = R"NKSP_CODE(
5553    on init
5554      declare polyphonic $a
5555      exit($a)
5556    end on
5557    )NKSP_CODE",
5558            .expectIntExitResult = 0
5559        });
5560    
5561        runScript({
5562            .code = R"NKSP_CODE(
5563    on init
5564      declare const polyphonic $a
5565    end on
5566    )NKSP_CODE",
5567            .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
5568        });
5569    
5570        runScript({
5571            .code = R"NKSP_CODE(
5572    on init
5573      declare polyphonic const $a
5574    end on
5575    )NKSP_CODE",
5576            .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
5577        });
5578    
5579        runScript({
5580            .code = R"NKSP_CODE(
5581    on init
5582      declare const polyphonic $a := 3
5583    end on
5584    )NKSP_CODE",
5585            .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
5586        });
5587    
5588        runScript({
5589            .code = R"NKSP_CODE(
5590    on init
5591      declare polyphonic const $a := 3
5592    end on
5593    )NKSP_CODE",
5594            .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
5595        });
5596    
5597        runScript({
5598            .code = R"NKSP_CODE(
5599    on init
5600      declare ~a := 24
5601      exit(~a)
5602    end on
5603    )NKSP_CODE",
5604            .expectParseWarning = true, // real type declaration vs. int value assignment
5605            .expectIntExitResult = 24
5606        });
5607    
5608        runScript({
5609            .code = R"NKSP_CODE(
5610    on init
5611      declare %a := 24
5612      exit(%a)
5613    end on
5614    )NKSP_CODE",
5615            .expectParseWarning = true, // int array type declaration vs. int scalar value assignment
5616            .expectIntExitResult = 24
5617        });
5618    
5619        runScript({
5620            .code = R"NKSP_CODE(
5621    on init
5622      declare const %a := 24
5623      exit(%a)
5624    end on
5625    )NKSP_CODE",
5626            .expectParseWarning = true, // int array type declaration vs. int scalar value assignment
5627            .expectIntExitResult = 24
5628        });
5629    
5630        runScript({
5631            .code = R"NKSP_CODE(
5632    on init
5633      declare ?a := 24
5634      exit(?a)
5635    end on
5636    )NKSP_CODE",
5637            .expectParseWarning = true, // real array type declaration vs. int scalar value assignment
5638            .expectIntExitResult = 24
5639        });
5640    
5641        runScript({
5642            .code = R"NKSP_CODE(
5643    on init
5644      declare const ?a := 24
5645      exit(?a)
5646    end on
5647    )NKSP_CODE",
5648            .expectParseWarning = true, // real array type declaration vs. int scalar value assignment
5649            .expectIntExitResult = 24
5650        });
5651    
5652        runScript({
5653            .code = R"NKSP_CODE(
5654    on init
5655      declare @a := 24
5656      exit(@a)
5657    end on
5658    )NKSP_CODE",
5659            .expectParseWarning = true, // string type declaration vs. int scalar value assignment
5660            .expectIntExitResult = 24
5661        });
5662    
5663        runScript({
5664            .code = R"NKSP_CODE(
5665    on init
5666      declare const @a := 24
5667      exit(@a)
5668    end on
5669    )NKSP_CODE",
5670            .expectParseWarning = true, // string type declaration vs. int scalar value assignment
5671            .expectIntExitResult = 24
5672        });
5673    
5674        runScript({
5675            .code = R"NKSP_CODE(
5676    on init
5677      declare $a := ( 0, 1, 2 )
5678    end on
5679    )NKSP_CODE",
5680            .expectParseError = true // int scalar type declaration vs. int array value assignment
5681        });
5682    
5683        runScript({
5684            .code = R"NKSP_CODE(
5685    on init
5686      declare const $a := ( 0, 1, 2 )
5687    end on
5688    )NKSP_CODE",
5689            .expectParseError = true // int scalar type declaration vs. int array value assignment
5690        });
5691    
5692        runScript({
5693            .code = R"NKSP_CODE(
5694    on init
5695      declare a
5696    end on
5697    )NKSP_CODE",
5698            .expectParseError = true // missing type prefix character in variable name
5699        });
5700    
5701        runScript({
5702            .code = R"NKSP_CODE(
5703    on init
5704      declare a := 24
5705    end on
5706    )NKSP_CODE",
5707            .expectParseError = true // missing type prefix character in variable name
5708        });
5709    
5710        runScript({
5711            .code = R"NKSP_CODE(
5712    on init
5713      declare const a := 24
5714    end on
5715    )NKSP_CODE",
5716            .expectParseError = true // missing type prefix character in variable name
5717        });
5718    
5719        runScript({
5720            .code = R"NKSP_CODE(
5721    on init
5722      declare polyphonic a
5723    end on
5724    )NKSP_CODE",
5725            .expectParseError = true // missing type prefix character in variable name
5726        });
5727    
5728        runScript({
5729            .code = R"NKSP_CODE(
5730    on init
5731      declare $a := max(8,24)
5732      exit($a)
5733    end on
5734    )NKSP_CODE",
5735            .expectIntExitResult = 24
5736        });
5737    
5738        runScript({
5739            .code = R"NKSP_CODE(
5740    on init
5741      declare $a := abort($NI_CALLBACK_ID)
5742    end on
5743    )NKSP_CODE",
5744            .expectParseError = true // assigned expression does not result in a value
5745        });
5746    
5747        runScript({
5748            .code = R"NKSP_CODE(
5749    on init
5750      declare const $a := abort($NI_CALLBACK_ID)
5751    end on
5752    )NKSP_CODE",
5753            .expectParseError = true // assigned expression does not result in a value
5754        });
5755    
5756        #if !SILENT_TEST
5757        std::cout << std::endl;
5758        #endif
5759    }
5760    
5761    static void testIntArrayVarDeclaration() {
5762        #if !SILENT_TEST
5763        std::cout << "UNIT TEST: int array var declaration\n";
5764        #endif
5765    
5766        runScript({
5767            .code = R"NKSP_CODE(
5768    on init
5769      declare %a[3]
5770      exit( %a[0] + %a[1] + %a[2] )
5771    end on
5772    )NKSP_CODE",
5773            .expectIntExitResult = 0
5774        });
5775    
5776        runScript({
5777            .code = R"NKSP_CODE(
5778    on init
5779      declare %a[0]
5780    end on
5781    )NKSP_CODE",
5782            .expectParseError = true // illegal array size
5783        });
5784    
5785        runScript({
5786            .code = R"NKSP_CODE(
5787    on init
5788      declare %a[-1]
5789    end on
5790    )NKSP_CODE",
5791            .expectParseError = true // illegal array size
5792        });
5793    
5794        runScript({
5795            .code = R"NKSP_CODE(
5796    on init
5797      declare %a[3] := ( 1, 2, 3 )
5798      exit( %a[0] + %a[1] + %a[2] )
5799    end on
5800    )NKSP_CODE",
5801            .expectIntExitResult = (1 + 2 + 3)
5802        });
5803    
5804        runScript({
5805            .code = R"NKSP_CODE(
5806    on init
5807      declare const $sz := 3
5808      declare %a[$sz] := ( 1, 2, 3 )
5809      exit( %a[0] + %a[1] + %a[2] )
5810    end on
5811    )NKSP_CODE",
5812            .expectIntExitResult = (1 + 2 + 3)
5813        });
5814    
5815        runScript({
5816            .code = R"NKSP_CODE(
5817    on init
5818      declare const $sz := 3
5819      declare const %a[$sz] := ( 1, 2, 3 )
5820      exit( %a[0] + %a[1] + %a[2] )
5821    end on
5822    )NKSP_CODE",
5823            .expectIntExitResult = (1 + 2 + 3)
5824        });
5825    
5826        runScript({
5827            .code = R"NKSP_CODE(
5828    on init
5829      declare $sz := 3
5830      declare %a[$sz] := ( 1, 2, 3 )
5831    end on
5832    )NKSP_CODE",
5833            .expectParseError = true // array size must be constant expression
5834        });
5835    
5836        runScript({
5837            .code = R"NKSP_CODE(
5838    on init
5839      declare $sz := 3
5840      declare const %a[$sz] := ( 1, 2, 3 )
5841    end on
5842    )NKSP_CODE",
5843            .expectParseError = true // array size must be constant expression
5844        });
5845    
5846        runScript({
5847            .code = R"NKSP_CODE(
5848    on init
5849      declare const ~sz := 3.0
5850      declare const %a[~sz] := ( 1, 2, 3 )
5851    end on
5852    )NKSP_CODE",
5853            .expectParseError = true // array size must be integer type
5854        });
5855    
5856        runScript({
5857            .code = R"NKSP_CODE(
5858    on init
5859      declare %a[3s] := ( 1, 2, 3 )
5860    end on
5861    )NKSP_CODE",
5862            .expectParseError = true // units not allowed for array size
5863        });
5864    
5865        runScript({
5866            .code = R"NKSP_CODE(
5867    on init
5868      declare %a[3m] := ( 1, 2, 3 )
5869    end on
5870    )NKSP_CODE",
5871            .expectParseError = true // units not allowed for array size
5872        });
5873    
5874        runScript({
5875            .code = R"NKSP_CODE(
5876    on init
5877      declare const %a[!3] := ( 1, 2, 3 )
5878      exit( %a[0] + %a[1] + %a[2] )
5879    end on
5880    )NKSP_CODE",
5881            .expectIntExitResult = (1 + 2 + 3),
5882            .expectParseWarning = true // 'final' operator is meaningless for array size
5883        });
5884    
5885        runScript({
5886            .code = R"NKSP_CODE(
5887    on init
5888      declare %a[3] := ( 1, 2, 3 )
5889      %a[0] := 4
5890      %a[1] := 5
5891      %a[2] := 6
5892      exit( %a[0] + %a[1] + %a[2] )
5893    end on
5894    )NKSP_CODE",
5895            .expectIntExitResult = (4 + 5 + 6)
5896        });
5897    
5898        runScript({
5899            .code = R"NKSP_CODE(
5900    on init
5901      declare %a[3]
5902      declare %a[3]
5903    end on
5904    )NKSP_CODE",
5905            .expectParseError = true // variable re-declaration
5906        });
5907    
5908        runScript({
5909            .code = R"NKSP_CODE(
5910    on init
5911      declare const %a[3]
5912    end on
5913    )NKSP_CODE",
5914            .expectParseError = true // const variable declaration without assignment
5915        });
5916    
5917        runScript({
5918            .code = R"NKSP_CODE(
5919    on init
5920      declare const %a[3] := ( 1, 2, 3 )
5921      exit( %a[0] + %a[1] + %a[2] )
5922    end on
5923    )NKSP_CODE",
5924            .expectIntExitResult = (1 + 2 + 3)
5925        });
5926    
5927        runScript({
5928            .code = R"NKSP_CODE(
5929    on init
5930      declare const %a[3] := ( 1, 2, 3, 4 )
5931    end on
5932    )NKSP_CODE",
5933            .expectParseError = true // incompatible array sizes
5934        });
5935    
5936        runScript({
5937            .code = R"NKSP_CODE(
5938    on init
5939      declare const %a[3] := ( 1, 2, 3 )
5940      %a[0] := 8
5941    end on
5942    )NKSP_CODE",
5943            .expectParseError = true // attempt to modify const variable
5944        });
5945    
5946        runScript({
5947            .code = R"NKSP_CODE(
5948    on init
5949      declare const %a[3] := ( 1, 2, 3 )
5950      declare const %b[3] := ( %a[0], %a[1], %a[2] )
5951      exit( %b[0] + %b[1] + %b[2] )
5952    end on
5953    )NKSP_CODE",
5954            .expectIntExitResult = (1 + 2 + 3)
5955        });
5956    
5957        runScript({
5958            .code = R"NKSP_CODE(
5959    on init
5960      declare %a[3] := ( 1, 2, 3 )
5961      declare const %b[3] := ( %a[0], %a[1], %a[2] )
5962    end on
5963    )NKSP_CODE",
5964            .expectParseError = true // const array defined with non-const assignment
5965        });
5966    
5967        runScript({
5968            .code = R"NKSP_CODE(
5969    on init
5970      declare polyphonic %a[3]
5971    end on
5972    )NKSP_CODE",
5973            .expectParseError = true // polyphonic not allowed for array types
5974        });
5975    
5976        runScript({
5977            .code = R"NKSP_CODE(
5978    on init
5979      declare polyphonic %a[3] := ( 1, 2, 3 )
5980    end on
5981    )NKSP_CODE",
5982            .expectParseError = true // polyphonic not allowed for array types
5983        });
5984    
5985        runScript({
5986            .code = R"NKSP_CODE(
5987    on init
5988      declare const polyphonic %a[3]
5989    end on
5990    )NKSP_CODE",
5991            .expectParseError = true // polyphonic not allowed for array types
5992        });
5993    
5994        runScript({
5995            .code = R"NKSP_CODE(
5996    on init
5997      declare const polyphonic %a[3] := ( 1, 2, 3 )
5998    end on
5999    )NKSP_CODE",
6000            .expectParseError = true // polyphonic not allowed for array types
6001        });
6002    
6003        runScript({
6004            .code = R"NKSP_CODE(
6005    on init
6006      declare polyphonic const %a[3]
6007    end on
6008    )NKSP_CODE",
6009            .expectParseError = true // polyphonic not allowed for array types
6010        });
6011    
6012        runScript({
6013            .code = R"NKSP_CODE(
6014    on init
6015      declare polyphonic const %a[3] := ( 1, 2, 3 )
6016    end on
6017    )NKSP_CODE",
6018            .expectParseError = true // polyphonic not allowed for array types
6019        });
6020    
6021        runScript({
6022            .code = R"NKSP_CODE(
6023    on init
6024      declare %a[3] := ( 1, max(8,24), 3 )
6025      exit( %a[0] + %a[1] + %a[2] )
6026    end on
6027    )NKSP_CODE",
6028            .expectIntExitResult = ( 1 + 24 + 3 )
6029        });
6030    
6031        runScript({
6032            .code = R"NKSP_CODE(
6033    on init
6034      declare %a[3] := ( 1, abort($NI_CALLBACK_ID), 3 )
6035    end on
6036    )NKSP_CODE",
6037            .expectParseError = true // assigned expression does not result in a value
6038        });
6039    
6040        runScript({
6041            .code = R"NKSP_CODE(
6042    on init
6043      declare const %a[3] := ( 1, abort($NI_CALLBACK_ID), 3 )
6044    end on
6045    )NKSP_CODE",
6046            .expectParseError = true // assigned expression does not result in a value
6047        });
6048    
6049        runScript({
6050            .code = R"NKSP_CODE(
6051    on init
6052      declare %a[3] := ( 1.0, 2.0, 3.0 )
6053    end on
6054    )NKSP_CODE",
6055            .expectParseError = true // int array declaration vs. real array assignment
6056        });
6057    
6058        runScript({
6059            .code = R"NKSP_CODE(
6060    on init
6061      declare %a[3] := ( 1, 2, 3.0 )
6062    end on
6063    )NKSP_CODE",
6064            .expectParseError = true // 3rd element not an integer
6065        });
6066    
6067        runScript({
6068            .code = R"NKSP_CODE(
6069    on init
6070      declare %a[3] := ( "x", "y", "z" )
6071    end on
6072    )NKSP_CODE",
6073            .expectParseError = true // int array declaration vs. string array assignment
6074        });
6075    
6076        runScript({
6077            .code = R"NKSP_CODE(
6078    on init
6079      declare a[3] := ( 1, 2, 3 )
6080    end on
6081    )NKSP_CODE",
6082            .expectParseError = true // missing type prefix character in variable name
6083        });
6084    
6085        runScript({
6086            .code = R"NKSP_CODE(
6087    on init
6088      declare a[3]
6089    end on
6090    )NKSP_CODE",
6091            .expectParseError = true // missing type prefix character in variable name
6092        });
6093    
6094        runScript({
6095            .code = R"NKSP_CODE(
6096    on init
6097      declare const %a[3] := ( 1, 2s, 3 )
6098    end on
6099    )NKSP_CODE",
6100            .expectParseError = true // unit types not allowed for arrays
6101        });
6102    
6103        runScript({
6104            .code = R"NKSP_CODE(
6105    on init
6106      declare const %a[3] := ( 1, !2, 3 )
6107    end on
6108    )NKSP_CODE",
6109            .expectParseError = true // 'final' not allowed for arrays
6110        });
6111    
6112        #if !SILENT_TEST
6113        std::cout << std::endl;
6114        #endif
6115    }
6116    
6117    static void testRealVarDeclaration() {
6118        #if !SILENT_TEST
6119        std::cout << "UNIT TEST: real var declaration\n";
6120        #endif
6121    
6122        runScript({
6123            .code = R"NKSP_CODE(
6124    on init
6125      declare ~a
6126      exit(~a)
6127    end on
6128    )NKSP_CODE",
6129            .expectRealExitResult = 0.0
6130        });
6131    
6132        runScript({
6133            .code = R"NKSP_CODE(
6134    on init
6135      declare ~a := 24.8
6136      exit(~a)
6137    end on
6138    )NKSP_CODE",
6139            .expectRealExitResult = 24.8
6140        });
6141    
6142        runScript({
6143            .code = R"NKSP_CODE(
6144    on init
6145      declare ~a := 8.24
6146      ~a := 24.8
6147      exit(~a)
6148    end on
6149    )NKSP_CODE",
6150            .expectRealExitResult = 24.8
6151        });
6152    
6153        runScript({
6154            .code = R"NKSP_CODE(
6155    on init
6156      declare ~a
6157      declare ~a
6158    end on
6159    )NKSP_CODE",
6160            .expectParseError = true // variable re-declaration
6161        });
6162    
6163        runScript({
6164            .code = R"NKSP_CODE(
6165    on init
6166      declare const ~a
6167    end on
6168    )NKSP_CODE",
6169            .expectParseError = true // const variable declaration without assignment
6170        });
6171    
6172        runScript({
6173            .code = R"NKSP_CODE(
6174    on init
6175      declare const ~a := 8.24
6176      exit(~a)
6177    end on
6178    )NKSP_CODE",
6179            .expectRealExitResult = 8.24
6180        });
6181    
6182        runScript({
6183            .code = R"NKSP_CODE(
6184    on init
6185      declare const ~a := 28.0
6186      ~a := 8.0
6187    end on
6188    )NKSP_CODE",
6189            .expectParseError = true // attempt to modify const variable
6190        });
6191    
6192        runScript({
6193            .code = R"NKSP_CODE(
6194    on init
6195      declare const ~a := 24.8
6196      declare const ~b := ~a
6197      exit(~b)
6198    end on
6199    )NKSP_CODE",
6200            .expectRealExitResult = 24.8
6201        });
6202    
6203        runScript({
6204            .code = R"NKSP_CODE(
6205    on init
6206      declare ~a := 24.0
6207      declare const ~b := ~a
6208    end on
6209    )NKSP_CODE",
6210            .expectParseError = true // const variable defined with non-const assignment
6211        });
6212    
6213        runScript({
6214            .code = R"NKSP_CODE(
6215    on init
6216      declare polyphonic ~a
6217      exit(~a)
6218    end on
6219    )NKSP_CODE",
6220            .expectRealExitResult = 0.0
6221        });
6222    
6223        runScript({
6224            .code = R"NKSP_CODE(
6225    on init
6226      declare const polyphonic ~a
6227    end on
6228    )NKSP_CODE",
6229            .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
6230        });
6231    
6232        runScript({
6233            .code = R"NKSP_CODE(
6234    on init
6235      declare polyphonic const ~a
6236    end on
6237    )NKSP_CODE",
6238            .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
6239        });
6240    
6241        runScript({
6242            .code = R"NKSP_CODE(
6243    on init
6244      declare const polyphonic ~a := 3.0
6245    end on
6246    )NKSP_CODE",
6247            .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
6248        });
6249    
6250        runScript({
6251            .code = R"NKSP_CODE(
6252    on init
6253      declare polyphonic const ~a := 3.0
6254    end on
6255    )NKSP_CODE",
6256            .expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless
6257        });
6258    
6259        runScript({
6260            .code = R"NKSP_CODE(
6261    on init
6262      declare $a := 24.8
6263      exit($a)
6264    end on
6265    )NKSP_CODE",
6266            .expectParseWarning = true, // int type declaration vs. real value assignment
6267            .expectRealExitResult = 24.8
6268        });
6269    
6270        runScript({
6271            .code = R"NKSP_CODE(
6272    on init
6273      declare %a := 24.8
6274      exit(%a)
6275    end on
6276    )NKSP_CODE",
6277            .expectParseWarning = true, // int array type declaration vs. real scalar value assignment
6278            .expectRealExitResult = 24.8
6279        });
6280    
6281        runScript({
6282            .code = R"NKSP_CODE(
6283    on init
6284      declare const %a := 24.8
6285      exit(%a)
6286    end on
6287    )NKSP_CODE",
6288            .expectParseWarning = true, // int array type declaration vs. real scalar value assignment
6289            .expectRealExitResult = 24.8
6290        });
6291    
6292        runScript({
6293            .code = R"NKSP_CODE(
6294    on init
6295      declare ?a := 24.8
6296      exit(?a)
6297    end on
6298    )NKSP_CODE",
6299            .expectParseWarning = true, // real array type declaration vs. real scalar value assignment
6300            .expectRealExitResult = 24.8
6301        });
6302    
6303        runScript({
6304            .code = R"NKSP_CODE(
6305    on init
6306      declare const ?a := 24.8
6307      exit(?a)
6308    end on
6309    )NKSP_CODE",
6310            .expectParseWarning = true, // real array type declaration vs. real scalar value assignment
6311            .expectRealExitResult = 24.8
6312        });
6313    
6314        runScript({
6315            .code = R"NKSP_CODE(
6316    on init
6317      declare @a := 24.8
6318      exit(@a)
6319    end on
6320    )NKSP_CODE",
6321            .expectParseWarning = true, // string type declaration vs. real scalar value assignment
6322            .expectRealExitResult = 24.8
6323        });
6324    
6325        runScript({
6326            .code = R"NKSP_CODE(
6327    on init
6328      declare const @a := 24.8
6329      exit(@a)
6330    end on
6331    )NKSP_CODE",
6332            .expectParseWarning = true, // string type declaration vs. real scalar value assignment
6333            .expectRealExitResult = 24.8
6334        });
6335    
6336        runScript({
6337            .code = R"NKSP_CODE(
6338    on init
6339      declare ~a := ( 0, 1, 2 )
6340    end on
6341    )NKSP_CODE",
6342            .expectParseError = true // real scalar type declaration vs. int array value assignment
6343        });
6344    
6345        runScript({
6346            .code = R"NKSP_CODE(
6347    on init
6348      declare const ~a := ( 0, 1, 2 )
6349    end on
6350    )NKSP_CODE",
6351            .expectParseError = true // real scalar type declaration vs. int array value assignment
6352        });
6353    
6354        runScript({
6355            .code = R"NKSP_CODE(
6356    on init
6357      declare a := 24.8
6358    end on
6359    )NKSP_CODE",
6360            .expectParseError = true // missing type prefix character in variable name
6361        });
6362    
6363        runScript({
6364            .code = R"NKSP_CODE(
6365    on init
6366      declare const a := 24.8
6367    end on
6368    )NKSP_CODE",
6369            .expectParseError = true // missing type prefix character in variable name
6370        });
6371    
6372        runScript({
6373            .code = R"NKSP_CODE(
6374    on init
6375      declare ~a := max(8.1,24.2)
6376      exit(~a)
6377    end on
6378    )NKSP_CODE",
6379            .expectRealExitResult = 24.2
6380        });
6381    
6382        runScript({
6383            .code = R"NKSP_CODE(
6384    on init
6385      declare ~a := abort($NI_CALLBACK_ID)
6386    end on
6387    )NKSP_CODE",
6388            .expectParseError = true // assigned expression does not result in a value
6389        });
6390    
6391        runScript({
6392            .code = R"NKSP_CODE(
6393    on init
6394      declare const ~a := abort($NI_CALLBACK_ID)
6395    end on
6396    )NKSP_CODE",
6397            .expectParseError = true // assigned expression does not result in a value
6398        });
6399    
6400        #if !SILENT_TEST
6401        std::cout << std::endl;
6402        #endif
6403    }
6404    
6405    static void testRealArrayVarDeclaration() {
6406        #if !SILENT_TEST
6407        std::cout << "UNIT TEST: real array var declaration\n";
6408        #endif
6409    
6410        runScript({
6411            .code = R"NKSP_CODE(
6412    on init
6413      declare ?a[3]
6414      exit( ?a[0] + ?a[1] + ?a[2] )
6415    end on
6416    )NKSP_CODE",
6417            .expectRealExitResult = 0.0
6418        });
6419    
6420        runScript({
6421            .code = R"NKSP_CODE(
6422    on init
6423      declare ?a[0]
6424    end on
6425    )NKSP_CODE",
6426            .expectParseError = true // illegal array size
6427        });
6428    
6429        runScript({
6430            .code = R"NKSP_CODE(
6431    on init
6432      declare ?a[-1]
6433    end on
6434    )NKSP_CODE",
6435            .expectParseError = true // illegal array size
6436        });
6437    
6438        runScript({
6439            .code = R"NKSP_CODE(
6440    on init
6441      declare ?a[3] := ( 1.1, 2.2, 3.3 )
6442      exit( ?a[0] + ?a[1] + ?a[2] )
6443    end on
6444    )NKSP_CODE",
6445            .expectRealExitResult = (1.1 + 2.2 + 3.3)
6446        });
6447    
6448        runScript({
6449            .code = R"NKSP_CODE(
6450    on init
6451      declare const $sz := 3
6452      declare ?a[$sz] := ( 1.1, 2.2, 3.3 )
6453      exit( ?a[0] + ?a[1] + ?a[2] )
6454    end on
6455    )NKSP_CODE",
6456            .expectRealExitResult = (1.1 + 2.2 + 3.3)
6457        });
6458    
6459        runScript({
6460            .code = R"NKSP_CODE(
6461    on init
6462      declare const $sz := 3
6463      declare const ?a[$sz] := ( 1.1, 2.2, 3.3 )
6464      exit( ?a[0] + ?a[1] + ?a[2] )
6465    end on
6466    )NKSP_CODE",
6467            .expectRealExitResult = (1.1 + 2.2 + 3.3)
6468        });
6469    
6470        runScript({
6471            .code = R"NKSP_CODE(
6472    on init
6473      declare $sz := 3
6474      declare ?a[$sz] := ( 1.1, 2.2, 3.3 )
6475    end on
6476    )NKSP_CODE",
6477            .expectParseError = true // array size must be constant expression
6478        });
6479    
6480        runScript({
6481            .code = R"NKSP_CODE(
6482    on init
6483      declare $sz := 3
6484      declare const ?a[$sz] := ( 1.1, 2.2, 3.3 )
6485    end on
6486    )NKSP_CODE",
6487            .expectParseError = true // array size must be constant expression
6488        });
6489    
6490        runScript({
6491            .code = R"NKSP_CODE(
6492    on init
6493      declare const ~sz := 3.0
6494      declare const ?a[~sz] := ( 1.1, 2.2, 3.3 )
6495    end on
6496    )NKSP_CODE",
6497            .expectParseError = true // array size must be integer type
6498        });
6499    
6500        runScript({
6501            .code = R"NKSP_CODE(
6502    on init
6503      declare ?a[3s] := ( 1.1, 2.2, 3.3 )
6504    end on
6505    )NKSP_CODE",
6506            .expectParseError = true // units not allowed for array size
6507        });
6508    
6509        runScript({
6510            .code = R"NKSP_CODE(
6511    on init
6512      declare ?a[3m] := ( 1.1, 2.2, 3.3 )
6513    end on
6514    )NKSP_CODE",
6515            .expectParseError = true // units not allowed for array size
6516        });
6517    
6518        runScript({
6519            .code = R"NKSP_CODE(
6520    on init
6521      declare const ?a[!3] := ( 1.1, 2.2, 3.3 )
6522      exit( ?a[0] + ?a[1] + ?a[2] )
6523    end on
6524    )NKSP_CODE",
6525            .expectRealExitResult = (1.1 + 2.2 + 3.3),
6526            .expectParseWarning = true // 'final' operator is meaningless for array size
6527        });
6528    
6529        runScript({
6530            .code = R"NKSP_CODE(
6531    on init
6532      declare ?a[3] := ( 1.0, 2.0, 3.0 )
6533      ?a[0] := 4.5
6534      ?a[1] := 5.5
6535      ?a[2] := 6.5
6536      exit( ?a[0] + ?a[1] + ?a[2] )
6537    end on
6538    )NKSP_CODE",
6539            .expectRealExitResult = (4.5 + 5.5 + 6.5)
6540        });
6541    
6542        runScript({
6543            .code = R"NKSP_CODE(
6544    on init
6545      declare ?a[3]
6546      declare ?a[3]
6547    end on
6548    )NKSP_CODE",
6549            .expectParseError = true // variable re-declaration
6550        });
6551    
6552        runScript({
6553            .code = R"NKSP_CODE(
6554    on init
6555      declare const ?a[3]
6556    end on
6557    )NKSP_CODE",
6558            .expectParseError = true // const variable declaration without assignment
6559        });
6560    
6561        runScript({
6562            .code = R"NKSP_CODE(
6563    on init
6564      declare const ?a[3] := ( 1.1, 2.2, 3.3 )
6565      exit( ?a[0] + ?a[1] + ?a[2] )
6566    end on
6567    )NKSP_CODE",
6568            .expectRealExitResult = (1.1 + 2.2 + 3.3)
6569        });
6570    
6571        runScript({
6572            .code = R"NKSP_CODE(
6573    on init
6574      declare const ?a[3] := ( 1.1, 2.2, 3.3, 4.4 )
6575    end on
6576    )NKSP_CODE",
6577            .expectParseError = true // incompatible array sizes
6578        });
6579    
6580        runScript({
6581            .code = R"NKSP_CODE(
6582    on init
6583      declare const ?a[3] := ( 1.0, 2.0, 3.0 )
6584      ?a[0] := 8.0
6585    end on
6586    )NKSP_CODE",
6587            .expectParseError = true // attempt to modify const variable
6588        });
6589    
6590        runScript({
6591            .code = R"NKSP_CODE(
6592    on init
6593      declare const ?a[3] := ( 1.1, 2.2, 3.3 )
6594      declare const ?b[3] := ( ?a[0], ?a[1], ?a[2] )
6595      exit( ?b[0] + ?b[1] + ?b[2] )
6596    end on
6597    )NKSP_CODE",
6598            .expectRealExitResult = (1.1 + 2.2 + 3.3)
6599        });
6600    
6601        runScript({
6602            .code = R"NKSP_CODE(
6603    on init
6604      declare ?a[3] := ( 1.1, 2.2, 3.3 )
6605      declare const ?b[3] := ( ?a[0], ?a[1], ?a[2] )
6606    end on
6607    )NKSP_CODE",
6608            .expectParseError = true // const array defined with non-const assignment
6609        });
6610    
6611        runScript({
6612            .code = R"NKSP_CODE(
6613    on init
6614      declare polyphonic ?a[3]
6615    end on
6616    )NKSP_CODE",
6617            .expectParseError = true // polyphonic not allowed for array types
6618        });
6619    
6620        runScript({
6621            .code = R"NKSP_CODE(
6622    on init
6623      declare polyphonic ?a[3] := ( 1.0, 2.0, 3.0 )
6624    end on
6625    )NKSP_CODE",
6626            .expectParseError = true // polyphonic not allowed for array types
6627        });
6628    
6629        runScript({
6630            .code = R"NKSP_CODE(
6631    on init
6632      declare const polyphonic ?a[3]
6633    end on
6634    )NKSP_CODE",
6635            .expectParseError = true // polyphonic not allowed for array types
6636        });
6637    
6638        runScript({
6639            .code = R"NKSP_CODE(
6640    on init
6641      declare const polyphonic ?a[3] := ( 1.0, 2.0, 3.0 )
6642    end on
6643    )NKSP_CODE",
6644            .expectParseError = true // polyphonic not allowed for array types
6645        });
6646    
6647        runScript({
6648            .code = R"NKSP_CODE(
6649    on init
6650      declare polyphonic const ?a[3]
6651    end on
6652    )NKSP_CODE",
6653            .expectParseError = true // polyphonic not allowed for array types
6654        });
6655    
6656        runScript({
6657            .code = R"NKSP_CODE(
6658    on init
6659      declare polyphonic const ?a[3] := ( 1.0, 2.0, 3.0 )
6660    end on
6661    )NKSP_CODE",
6662            .expectParseError = true // polyphonic not allowed for array types
6663        });
6664    
6665        runScript({
6666            .code = R"NKSP_CODE(
6667    on init
6668      declare ?a[3] := ( 1.0, max(8.3,24.6), 3.0 )
6669      exit( ?a[0] + ?a[1] + ?a[2] )
6670    end on
6671    )NKSP_CODE",
6672            .expectRealExitResult = ( 1.0 + 24.6 + 3.0 )
6673        });
6674    
6675        runScript({
6676            .code = R"NKSP_CODE(
6677    on init
6678      declare ?a[3] := ( 1.0, abort($NI_CALLBACK_ID), 3.0 )
6679    end on
6680    )NKSP_CODE",
6681            .expectParseError = true // assigned expression does not result in a value
6682        });
6683    
6684        runScript({
6685            .code = R"NKSP_CODE(
6686    on init
6687      declare const ?a[3] := ( 1.0, abort($NI_CALLBACK_ID), 3.0 )
6688    end on
6689    )NKSP_CODE",
6690            .expectParseError = true // assigned expression does not result in a value
6691        });
6692    
6693        runScript({
6694            .code = R"NKSP_CODE(
6695    on init
6696      declare ?a[3] := ( 1, 2, 3 )
6697    end on
6698    )NKSP_CODE",
6699            .expectParseError = true // real array declaration vs. int array assignment
6700        });
6701    
6702        runScript({
6703            .code = R"NKSP_CODE(
6704    on init
6705      declare ?a[3] := ( 1.0, 2.0, 3 )
6706    end on
6707    )NKSP_CODE",
6708            .expectParseError = true // 3rd element not a real value
6709        });
6710    
6711        runScript({
6712            .code = R"NKSP_CODE(
6713    on init
6714      declare ?a[3] := ( "x", "y", "z" )
6715    end on
6716    )NKSP_CODE",
6717            .expectParseError = true // real array declaration vs. string array assignment
6718        });
6719    
6720        runScript({
6721            .code = R"NKSP_CODE(
6722    on init
6723      declare a[3] := ( 1.0, 2.0, 3.0 )
6724    end on
6725    )NKSP_CODE",
6726            .expectParseError = true // missing type prefix character in variable name
6727        });
6728    
6729        runScript({
6730            .code = R"NKSP_CODE(
6731    on init
6732      declare const ?a[3] := ( 1.0, 2.0s, 3.0 )
6733    end on
6734    )NKSP_CODE",
6735            .expectParseError = true // unit types not allowed for arrays
6736        });
6737    
6738        runScript({
6739            .code = R"NKSP_CODE(
6740    on init
6741      declare const ?a[3] := ( 1.0, !2.0, 3.0 )
6742    end on
6743    )NKSP_CODE",
6744            .expectParseError = true // 'final' not allowed for arrays
6745        });
6746    
6747        #if !SILENT_TEST
6748        std::cout << std::endl;
6749        #endif
6750    }
6751    
6752    static void testStringVarDeclaration() {
6753        #if !SILENT_TEST
6754        std::cout << "UNIT TEST: string var declaration\n";
6755        #endif
6756    
6757    runScript({
6758            .code = R"NKSP_CODE(
6759    on init
6760      declare @a
6761      exit(@a)
6762    end on
6763    )NKSP_CODE",
6764            .expectStringExitResult = ""
6765        });
6766    
6767        runScript({
6768            .code = R"NKSP_CODE(
6769    on init
6770      declare @a := "foo"
6771      exit(@a)
6772    end on
6773    )NKSP_CODE",
6774            .expectStringExitResult = "foo"
6775        });
6776    
6777        runScript({
6778            .code = R"NKSP_CODE(
6779    on init
6780      declare @a := "foo"
6781      @a := "bar"
6782      exit(@a)
6783    end on
6784    )NKSP_CODE",
6785            .expectStringExitResult = "bar"
6786        });
6787    
6788        runScript({
6789            .code = R"NKSP_CODE(
6790    on init
6791      declare @a
6792      declare @a
6793    end on
6794    )NKSP_CODE",
6795            .expectParseError = true // variable re-declaration
6796        });
6797    
6798        runScript({
6799            .code = R"NKSP_CODE(
6800    on init
6801      declare const @a
6802    end on
6803    )NKSP_CODE",
6804            .expectParseError = true // const variable declaration without assignment
6805        });
6806    
6807        runScript({
6808            .code = R"NKSP_CODE(
6809    on init
6810      declare const @a := "foo"
6811      exit(@a)
6812    end on
6813    )NKSP_CODE",
6814            .expectStringExitResult = "foo"
6815        });
6816    
6817        runScript({
6818            .code = R"NKSP_CODE(
6819    on init
6820      declare const @a := "foo"
6821      @a := "bar"
6822    end on
6823    )NKSP_CODE",
6824            .expectParseError = true // attempt to modify const variable
6825        });
6826    
6827        runScript({
6828            .code = R"NKSP_CODE(
6829    on init
6830      declare const @a := "foo"
6831      declare const @b := @a
6832      exit(@b)
6833    end on
6834    )NKSP_CODE",
6835            .expectStringExitResult = "foo"
6836        });
6837    
6838        runScript({
6839            .code = R"NKSP_CODE(
6840    on init
6841      declare @a := "foo"
6842      declare const @b := @a
6843    end on
6844    )NKSP_CODE",
6845            .expectParseError = true // const variable defined with non-const assignment
6846        });
6847    
6848        runScript({
6849            .code = R"NKSP_CODE(
6850    on init
6851      declare polyphonic @a
6852    end on
6853    )NKSP_CODE",
6854            .expectParseError = true // 'polyphonic' not allowed for string type
6855        });
6856    
6857        runScript({
6858            .code = R"NKSP_CODE(
6859    on init
6860      declare const polyphonic @a
6861    end on
6862    )NKSP_CODE",
6863            .expectParseError = true // 'polyphonic' not allowed for string type
6864        });
6865    
6866        runScript({
6867            .code = R"NKSP_CODE(
6868    on init
6869      declare polyphonic const @a
6870    end on
6871    )NKSP_CODE",
6872            .expectParseError = true // 'polyphonic' not allowed for string type
6873        });
6874    
6875        runScript({
6876            .code = R"NKSP_CODE(
6877    on init
6878      declare polyphonic @a = "foo"
6879    end on
6880    )NKSP_CODE",
6881            .expectParseError = true // 'polyphonic' not allowed for string type
6882        });
6883    
6884        runScript({
6885            .code = R"NKSP_CODE(
6886    on init
6887      declare polyphonic const @a = "foo"
6888    end on
6889    )NKSP_CODE",
6890            .expectParseError = true // 'polyphonic' not allowed for string type
6891        });
6892    
6893        runScript({
6894            .code = R"NKSP_CODE(
6895    on init
6896      declare const polyphonic @a = "foo"
6897    end on
6898    )NKSP_CODE",
6899            .expectParseError = true // 'polyphonic' not allowed for string type
6900        });
6901    
6902        runScript({
6903            .code = R"NKSP_CODE(
6904    on init
6905      declare $a := "foo"
6906      exit($a)
6907    end on
6908    )NKSP_CODE",
6909            .expectParseWarning = true, // int type declaration vs. string assignment
6910            .expectStringExitResult = "foo"
6911        });
6912    
6913        runScript({
6914            .code = R"NKSP_CODE(
6915    on init
6916      declare ~a := "foo"
6917      exit(~a)
6918    end on
6919    )NKSP_CODE",
6920            .expectParseWarning = true, // real type declaration vs. string assignment
6921            .expectStringExitResult = "foo"
6922        });
6923    
6924        runScript({
6925            .code = R"NKSP_CODE(
6926    on init
6927      declare %a := "foo"
6928      exit(%a)
6929    end on
6930    )NKSP_CODE",
6931            .expectParseWarning = true, // int array type declaration vs. string assignment
6932            .expectStringExitResult = "foo"
6933        });
6934    
6935        runScript({
6936            .code = R"NKSP_CODE(
6937    on init
6938      declare const $a := "foo"
6939      exit($a)
6940    end on
6941    )NKSP_CODE",
6942            .expectParseWarning = true, // int type declaration vs. string assignment
6943            .expectStringExitResult = "foo"
6944        });
6945    
6946        runScript({
6947            .code = R"NKSP_CODE(
6948    on init
6949      declare const ~a := "foo"
6950      exit(~a)
6951    end on
6952    )NKSP_CODE",
6953            .expectParseWarning = true, // real type declaration vs. string assignment
6954            .expectStringExitResult = "foo"
6955        });
6956    
6957        runScript({
6958            .code = R"NKSP_CODE(
6959    on init
6960      declare const %a := "foo"
6961      exit(%a)
6962    end on
6963    )NKSP_CODE",
6964            .expectParseWarning = true, // int array type declaration vs. string assignment
6965            .expectStringExitResult = "foo"
6966        });
6967    
6968        runScript({
6969            .code = R"NKSP_CODE(
6970    on init
6971      declare a := "foo"
6972    end on
6973    )NKSP_CODE",
6974            .expectParseError = true // missing type prefix character in variable name
6975        });
6976    
6977        runScript({
6978            .code = R"NKSP_CODE(
6979    on init
6980      declare const a := "foo"
6981    end on
6982    )NKSP_CODE",
6983            .expectParseError = true // missing type prefix character in variable name
6984        });
6985    
6986        runScript({
6987            .code = R"NKSP_CODE(
6988    on init
6989      declare @a := abort($NI_CALLBACK_ID)
6990    end on
6991    )NKSP_CODE",
6992            .expectParseError = true // assigned expression does not result in a value
6993        });
6994    
6995        runScript({
6996            .code = R"NKSP_CODE(
6997    on init
6998      declare const @a := abort($NI_CALLBACK_ID)
6999    end on
7000    )NKSP_CODE",
7001            .expectParseError = true // assigned expression does not result in a value
7002        });
7003    
7004        #if !SILENT_TEST
7005        std::cout << std::endl;
7006        #endif
7007    }
7008    
7009  static void testBuiltInMinFunction() {  static void testBuiltInMinFunction() {
7010      #if !SILENT_TEST      #if !SILENT_TEST
7011      std::cout << "UNIT TEST: built-in min() function\n";      std::cout << "UNIT TEST: built-in min() function\n";
# Line 7327  end on Line 8920  end on
8920          .expectExitResultUnit = VM_BEL          .expectExitResultUnit = VM_BEL
8921      });      });
8922    
8923        runScript({
8924            .code = R"NKSP_CODE(
8925    on init
8926      declare $foo := 7000ms
8927      exit( int_to_real($foo) )
8928    end on
8929    )NKSP_CODE",
8930            .expectRealExitResult = 7000.0,
8931            .expectExitResultUnitPrefix = { VM_MILLI },
8932            .expectExitResultUnit = VM_SECOND
8933        });
8934    
8935        runScript({
8936            .code = R"NKSP_CODE(
8937    on init
8938      declare $foo := 7000ms
8939      declare @s := "" & int_to_real($foo)
8940      exit( @s )
8941    end on
8942    )NKSP_CODE",
8943            .expectStringExitResult = "7000ms",
8944        });
8945    
8946        runScript({
8947            .code = R"NKSP_CODE(
8948    on init
8949      declare $foo := 700ms
8950      exit( int_to_real($foo) / 7.0 )
8951    end on
8952    )NKSP_CODE",
8953            .expectRealExitResult = 100.0,
8954            .expectExitResultUnitPrefix = { VM_MILLI },
8955            .expectExitResultUnit = VM_SECOND
8956        });
8957    
8958        runScript({
8959            .code = R"NKSP_CODE(
8960    on init
8961      declare $foo := 700ms
8962      exit( int_to_real($foo) / 7.0 & "" )
8963    end on
8964    )NKSP_CODE",
8965            .expectStringExitResult = "100ms"
8966        });
8967    
8968      // 'final' ('!') operator tests ...      // 'final' ('!') operator tests ...
8969    
8970      runScript({      runScript({
# Line 7405  end on Line 9043  end on
9043          .expectExitResultUnit = VM_BEL          .expectExitResultUnit = VM_BEL
9044      });      });
9045    
9046        runScript({
9047            .code = R"NKSP_CODE(
9048    on init
9049      declare $foo := 7000ms
9050      exit( real($foo) )
9051    end on
9052    )NKSP_CODE",
9053            .expectRealExitResult = 7000.0,
9054            .expectExitResultUnitPrefix = { VM_MILLI },
9055            .expectExitResultUnit = VM_SECOND
9056        });
9057    
9058        runScript({
9059            .code = R"NKSP_CODE(
9060    on init
9061      declare $foo := 7000ms
9062      declare @s := "" & real($foo)
9063      exit( @s )
9064    end on
9065    )NKSP_CODE",
9066            .expectStringExitResult = "7000ms",
9067        });
9068    
9069        runScript({
9070            .code = R"NKSP_CODE(
9071    on init
9072      declare $foo := 700ms
9073      exit( real($foo) / 7.0 )
9074    end on
9075    )NKSP_CODE",
9076            .expectRealExitResult = 100.0,
9077            .expectExitResultUnitPrefix = { VM_MILLI },
9078            .expectExitResultUnit = VM_SECOND
9079        });
9080    
9081        runScript({
9082            .code = R"NKSP_CODE(
9083    on init
9084      declare $foo := 700ms
9085      exit( real($foo) / 7.0 & "" )
9086    end on
9087    )NKSP_CODE",
9088            .expectStringExitResult = "100ms"
9089        });
9090    
9091      // 'final' ('!') operator tests ...      // 'final' ('!') operator tests ...
9092    
9093      runScript({      runScript({
# Line 7472  end on Line 9155  end on
9155          .expectExitResultUnit = VM_BEL          .expectExitResultUnit = VM_BEL
9156      });      });
9157    
9158        runScript({
9159            .code = R"NKSP_CODE(
9160    on init
9161      declare ~foo := 9000.0us
9162      exit( real_to_int(~foo) )
9163    end on
9164    )NKSP_CODE",
9165            .expectIntExitResult = 9000.0,
9166            .expectExitResultUnitPrefix = { VM_MICRO },
9167            .expectExitResultUnit = VM_SECOND
9168        });
9169    
9170        runScript({
9171            .code = R"NKSP_CODE(
9172    on init
9173      declare ~foo := 9000.0us
9174      declare @s := "" & real_to_int(~foo)
9175      exit( @s )
9176    end on
9177    )NKSP_CODE",
9178            .expectStringExitResult = "9000us",
9179        });
9180    
9181        runScript({
9182            .code = R"NKSP_CODE(
9183    on init
9184      declare ~foo := 700.0ms
9185      exit( real_to_int(~foo) / 7 )
9186    end on
9187    )NKSP_CODE",
9188            .expectIntExitResult = 100,
9189            .expectExitResultUnitPrefix = { VM_MILLI },
9190            .expectExitResultUnit = VM_SECOND
9191        });
9192    
9193        runScript({
9194            .code = R"NKSP_CODE(
9195    on init
9196      declare ~foo := 700.0ms
9197      exit( real_to_int(~foo) / 7 & "" )
9198    end on
9199    )NKSP_CODE",
9200            .expectStringExitResult = "100ms"
9201        });
9202    
9203      // 'final' ('!') operator tests ...      // 'final' ('!') operator tests ...
9204    
9205      runScript({      runScript({
# Line 7539  end on Line 9267  end on
9267          .expectExitResultUnit = VM_BEL          .expectExitResultUnit = VM_BEL
9268      });      });
9269    
9270        runScript({
9271            .code = R"NKSP_CODE(
9272    on init
9273      declare ~foo := 9000.0us
9274      exit( int(~foo) )
9275    end on
9276    )NKSP_CODE",
9277            .expectIntExitResult = 9000.0,
9278            .expectExitResultUnitPrefix = { VM_MICRO },
9279            .expectExitResultUnit = VM_SECOND
9280        });
9281    
9282        runScript({
9283            .code = R"NKSP_CODE(
9284    on init
9285      declare ~foo := 9000.0us
9286      declare @s := "" & int(~foo)
9287      exit( @s )
9288    end on
9289    )NKSP_CODE",
9290            .expectStringExitResult = "9000us",
9291        });
9292    
9293        runScript({
9294            .code = R"NKSP_CODE(
9295    on init
9296      declare ~foo := 700.0ms
9297      exit( int(~foo) / 7 )
9298    end on
9299    )NKSP_CODE",
9300            .expectIntExitResult = 100,
9301            .expectExitResultUnitPrefix = { VM_MILLI },
9302            .expectExitResultUnit = VM_SECOND
9303        });
9304    
9305        runScript({
9306            .code = R"NKSP_CODE(
9307    on init
9308      declare ~foo := 700.0ms
9309      exit( int(~foo) / 7 & "" )
9310    end on
9311    )NKSP_CODE",
9312            .expectStringExitResult = "100ms"
9313        });
9314    
9315      // 'final' ('!') operator tests ...      // 'final' ('!') operator tests ...
9316    
9317      runScript({      runScript({
# Line 8234  end on Line 10007  end on
10007          .expectExitResultUnit = VM_HERTZ          .expectExitResultUnit = VM_HERTZ
10008      });      });
10009    
10010        runScript({
10011            .code = R"NKSP_CODE(
10012    on init
10013      exit( ceil(9.4ms / 2.0) )
10014    end on
10015    )NKSP_CODE",
10016            .expectRealExitResult = 5.0,
10017            .expectExitResultUnitPrefix = { VM_MILLI },
10018            .expectExitResultUnit = VM_SECOND
10019        });
10020    
10021        runScript({
10022            .code = R"NKSP_CODE(
10023    on init
10024      exit( ceil( ceil(8.4us) / 2.0) )
10025    end on
10026    )NKSP_CODE",
10027            .expectRealExitResult = 5.0,
10028            .expectExitResultUnitPrefix = { VM_MICRO },
10029            .expectExitResultUnit = VM_SECOND
10030        });
10031    
10032      // 'final' ('!') operator tests ...      // 'final' ('!') operator tests ...
10033    
10034      runScript({      runScript({
# Line 8332  end on Line 10127  end on
10127          .expectExitResultUnit = VM_HERTZ          .expectExitResultUnit = VM_HERTZ
10128      });      });
10129    
10130        runScript({
10131            .code = R"NKSP_CODE(
10132    on init
10133      exit( floor(4.4ms / 2.0) )
10134    end on
10135    )NKSP_CODE",
10136            .expectRealExitResult = 2.0,
10137            .expectExitResultUnitPrefix = { VM_MILLI },
10138            .expectExitResultUnit = VM_SECOND
10139        });
10140    
10141        runScript({
10142            .code = R"NKSP_CODE(
10143    on init
10144      exit( floor( floor(8.4us) / 4.0) )
10145    end on
10146    )NKSP_CODE",
10147            .expectRealExitResult = 2.0,
10148            .expectExitResultUnitPrefix = { VM_MICRO },
10149            .expectExitResultUnit = VM_SECOND
10150        });
10151    
10152      // 'final' ('!') operator tests ...      // 'final' ('!') operator tests ...
10153    
10154      runScript({      runScript({
# Line 9910  int main() { Line 11727  int main() {
11727      testBitwiseOrOperator();      testBitwiseOrOperator();
11728      testBitwiseNotOperator();      testBitwiseNotOperator();
11729      testPrecedenceOfOperators();      testPrecedenceOfOperators();
11730        testIntVarDeclaration();
11731        testIntArrayVarDeclaration();
11732        testRealVarDeclaration();
11733        testRealArrayVarDeclaration();
11734        testStringVarDeclaration();
11735      testBuiltInMinFunction();      testBuiltInMinFunction();
11736      testBuiltInMaxFunction();      testBuiltInMaxFunction();
11737      testBuiltInAbsFunction();      testBuiltInAbsFunction();

Legend:
Removed from v.3693  
changed lines
  Added in v.3747

  ViewVC Help
Powered by ViewVC