1 |
/* |
/* |
2 |
* Copyright (c) 2019 Christian Schoenebeck |
* Copyright (c) 2019 - 2020 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
129 |
if (opt.expectExitResultUnit) { |
if (opt.expectExitResultUnit) { |
130 |
VMExpr* resExpr = execCtx->exitResult(); |
VMExpr* resExpr = execCtx->exitResult(); |
131 |
TEST_ASSERT(resExpr); |
TEST_ASSERT(resExpr); |
132 |
VMScalarNumberExpr* numberExpr = resExpr->asScalarNumberExpr(); |
VMNumberExpr* numberExpr = resExpr->asNumber(); |
133 |
TEST_ASSERT(numberExpr); |
TEST_ASSERT(numberExpr); |
134 |
TEST_ASSERT(numberExpr->unitType() == *opt.expectExitResultUnit); |
TEST_ASSERT(numberExpr->unitType() == *opt.expectExitResultUnit); |
135 |
} |
} |
136 |
if (!opt.expectExitResultUnitPrefix.empty()) { |
if (!opt.expectExitResultUnitPrefix.empty()) { |
137 |
VMExpr* resExpr = execCtx->exitResult(); |
VMExpr* resExpr = execCtx->exitResult(); |
138 |
TEST_ASSERT(resExpr); |
TEST_ASSERT(resExpr); |
139 |
VMScalarNumberExpr* numberExpr = resExpr->asScalarNumberExpr(); |
VMNumberExpr* numberExpr = resExpr->asNumber(); |
140 |
TEST_ASSERT(numberExpr); |
TEST_ASSERT(numberExpr); |
141 |
auto prefixes = opt.expectExitResultUnitPrefix; |
auto prefixes = opt.expectExitResultUnitPrefix; |
142 |
if (*prefixes.rbegin() != VM_NO_PREFIX) |
if (*prefixes.rbegin() != VM_NO_PREFIX) |
152 |
if (opt.expectExitResultFinal) { |
if (opt.expectExitResultFinal) { |
153 |
VMExpr* resExpr = execCtx->exitResult(); |
VMExpr* resExpr = execCtx->exitResult(); |
154 |
TEST_ASSERT(resExpr); |
TEST_ASSERT(resExpr); |
155 |
VMScalarNumberExpr* numberExpr = resExpr->asScalarNumberExpr(); |
VMNumberExpr* numberExpr = resExpr->asNumber(); |
156 |
TEST_ASSERT(numberExpr); |
TEST_ASSERT(numberExpr); |
157 |
TEST_ASSERT(numberExpr->isFinal() == *opt.expectExitResultFinal); |
TEST_ASSERT(numberExpr->isFinal() == *opt.expectExitResultFinal); |
158 |
} |
} |
285 |
.expectRealExitResult = 6.9 |
.expectRealExitResult = 6.9 |
286 |
}); |
}); |
287 |
|
|
288 |
|
// int array tests ... |
289 |
|
|
290 |
|
runScript({ |
291 |
|
.code = R"NKSP_CODE( |
292 |
|
on init |
293 |
|
declare %foo[3] |
294 |
|
%foo[0] := 21 |
295 |
|
exit(%foo[0]) |
296 |
|
end on |
297 |
|
)NKSP_CODE", |
298 |
|
.expectIntExitResult = 21 |
299 |
|
}); |
300 |
|
|
301 |
|
runScript({ |
302 |
|
.code = R"NKSP_CODE( |
303 |
|
on init |
304 |
|
declare %foo[3] := ( 12, 23, 34 ) |
305 |
|
exit(%foo[0]) |
306 |
|
end on |
307 |
|
)NKSP_CODE", |
308 |
|
.expectIntExitResult = 12 |
309 |
|
}); |
310 |
|
|
311 |
|
runScript({ |
312 |
|
.code = R"NKSP_CODE( |
313 |
|
on init |
314 |
|
declare %foo[3] := ( 12, 23, 34 ) |
315 |
|
exit(%foo[1]) |
316 |
|
end on |
317 |
|
)NKSP_CODE", |
318 |
|
.expectIntExitResult = 23 |
319 |
|
}); |
320 |
|
|
321 |
|
runScript({ |
322 |
|
.code = R"NKSP_CODE( |
323 |
|
on init |
324 |
|
declare %foo[3] := ( 12, 23, 34 ) |
325 |
|
exit(%foo[2]) |
326 |
|
end on |
327 |
|
)NKSP_CODE", |
328 |
|
.expectIntExitResult = 34 |
329 |
|
}); |
330 |
|
|
331 |
|
runScript({ // make sure array is entirely initialized with zeroes |
332 |
|
.code = R"NKSP_CODE( |
333 |
|
on init |
334 |
|
declare $i |
335 |
|
declare $result |
336 |
|
declare %foo[100] |
337 |
|
while ($i < 100) |
338 |
|
$result := $result .or. %foo[$i] |
339 |
|
inc($i) |
340 |
|
end while |
341 |
|
exit($result) |
342 |
|
end on |
343 |
|
)NKSP_CODE", |
344 |
|
.expectIntExitResult = 0 |
345 |
|
}); |
346 |
|
|
347 |
|
// real array tests ... |
348 |
|
|
349 |
|
runScript({ |
350 |
|
.code = R"NKSP_CODE( |
351 |
|
on init |
352 |
|
declare ?foo[3] |
353 |
|
?foo[0] := 34.9 |
354 |
|
exit(?foo[0]) |
355 |
|
end on |
356 |
|
)NKSP_CODE", |
357 |
|
.expectRealExitResult = 34.9 |
358 |
|
}); |
359 |
|
|
360 |
|
runScript({ |
361 |
|
.code = R"NKSP_CODE( |
362 |
|
on init |
363 |
|
declare ?foo[3] := ( 0.3, 23.5, 900.1 ) |
364 |
|
exit(?foo[0]) |
365 |
|
end on |
366 |
|
)NKSP_CODE", |
367 |
|
.expectRealExitResult = 0.3 |
368 |
|
}); |
369 |
|
|
370 |
|
runScript({ |
371 |
|
.code = R"NKSP_CODE( |
372 |
|
on init |
373 |
|
declare ?foo[3] := ( 0.3, 23.5, 900.1 ) |
374 |
|
exit(?foo[1]) |
375 |
|
end on |
376 |
|
)NKSP_CODE", |
377 |
|
.expectRealExitResult = 23.5 |
378 |
|
}); |
379 |
|
|
380 |
|
runScript({ |
381 |
|
.code = R"NKSP_CODE( |
382 |
|
on init |
383 |
|
declare ?foo[3] := ( 0.3, 23.5, 900.1 ) |
384 |
|
exit(?foo[2]) |
385 |
|
end on |
386 |
|
)NKSP_CODE", |
387 |
|
.expectRealExitResult = 900.1 |
388 |
|
}); |
389 |
|
|
390 |
|
runScript({ // make sure array is entirely initialized with zeroes |
391 |
|
.code = R"NKSP_CODE( |
392 |
|
on init |
393 |
|
declare $i |
394 |
|
declare ?foo[100] |
395 |
|
while ($i < 100) |
396 |
|
if (?foo[$i] # 0.0) |
397 |
|
exit(-1) { test failed } |
398 |
|
end if |
399 |
|
inc($i) |
400 |
|
end while |
401 |
|
exit(0) { test succeeded } |
402 |
|
end on |
403 |
|
)NKSP_CODE", |
404 |
|
.expectIntExitResult = 0 |
405 |
|
}); |
406 |
|
|
407 |
// std unit tests ... |
// std unit tests ... |
408 |
|
|
409 |
runScript({ |
runScript({ |
1254 |
.expectExitResultFinal = false |
.expectExitResultFinal = false |
1255 |
}); |
}); |
1256 |
|
|
1257 |
|
//TODO: the following are unary '+' operator tests which should be moved to their own function (lazy me). |
1258 |
|
|
1259 |
|
runScript({ |
1260 |
|
.code = R"NKSP_CODE( |
1261 |
|
on init |
1262 |
|
exit(+54) |
1263 |
|
end on |
1264 |
|
)NKSP_CODE", |
1265 |
|
.expectIntExitResult = 54 |
1266 |
|
}); |
1267 |
|
|
1268 |
|
runScript({ |
1269 |
|
.code = R"NKSP_CODE( |
1270 |
|
on init |
1271 |
|
declare $foo := +54 |
1272 |
|
exit( $foo ) |
1273 |
|
end on |
1274 |
|
)NKSP_CODE", |
1275 |
|
.expectIntExitResult = 54 |
1276 |
|
}); |
1277 |
|
|
1278 |
|
runScript({ |
1279 |
|
.code = R"NKSP_CODE( |
1280 |
|
on init |
1281 |
|
exit(+0.45) |
1282 |
|
end on |
1283 |
|
)NKSP_CODE", |
1284 |
|
.expectRealExitResult = 0.45 |
1285 |
|
}); |
1286 |
|
|
1287 |
|
runScript({ |
1288 |
|
.code = R"NKSP_CODE( |
1289 |
|
on init |
1290 |
|
declare ~foo := +0.29 |
1291 |
|
exit( ~foo ) |
1292 |
|
end on |
1293 |
|
)NKSP_CODE", |
1294 |
|
.expectRealExitResult = 0.29 |
1295 |
|
}); |
1296 |
|
|
1297 |
#if !SILENT_TEST |
#if !SILENT_TEST |
1298 |
std::cout << std::endl; |
std::cout << std::endl; |
1299 |
#endif |
#endif |
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({ |
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({ |
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 |
|
.expectParseWarning = true // unusable 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 %a[] := ( 1, 2, 3 ) |
5808 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5809 |
|
end on |
5810 |
|
)NKSP_CODE", |
5811 |
|
.expectIntExitResult = (1 + 2 + 3) |
5812 |
|
}); |
5813 |
|
|
5814 |
|
runScript({ |
5815 |
|
.code = R"NKSP_CODE( |
5816 |
|
on init |
5817 |
|
declare %a[] |
5818 |
|
end on |
5819 |
|
)NKSP_CODE", |
5820 |
|
.expectParseWarning = true // unusable array size (zero) |
5821 |
|
}); |
5822 |
|
|
5823 |
|
runScript({ |
5824 |
|
.code = R"NKSP_CODE( |
5825 |
|
on init |
5826 |
|
declare const $sz := 3 |
5827 |
|
declare %a[$sz] := ( 1, 2, 3 ) |
5828 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5829 |
|
end on |
5830 |
|
)NKSP_CODE", |
5831 |
|
.expectIntExitResult = (1 + 2 + 3) |
5832 |
|
}); |
5833 |
|
|
5834 |
|
runScript({ |
5835 |
|
.code = R"NKSP_CODE( |
5836 |
|
on init |
5837 |
|
declare const $sz := 3 |
5838 |
|
declare const %a[$sz] := ( 1, 2, 3 ) |
5839 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5840 |
|
end on |
5841 |
|
)NKSP_CODE", |
5842 |
|
.expectIntExitResult = (1 + 2 + 3) |
5843 |
|
}); |
5844 |
|
|
5845 |
|
runScript({ |
5846 |
|
.code = R"NKSP_CODE( |
5847 |
|
on init |
5848 |
|
declare $sz := 3 |
5849 |
|
declare %a[$sz] := ( 1, 2, 3 ) |
5850 |
|
end on |
5851 |
|
)NKSP_CODE", |
5852 |
|
.expectParseError = true // array size must be constant expression |
5853 |
|
}); |
5854 |
|
|
5855 |
|
runScript({ |
5856 |
|
.code = R"NKSP_CODE( |
5857 |
|
on init |
5858 |
|
declare $sz := 3 |
5859 |
|
declare const %a[$sz] := ( 1, 2, 3 ) |
5860 |
|
end on |
5861 |
|
)NKSP_CODE", |
5862 |
|
.expectParseError = true // array size must be constant expression |
5863 |
|
}); |
5864 |
|
|
5865 |
|
runScript({ |
5866 |
|
.code = R"NKSP_CODE( |
5867 |
|
on init |
5868 |
|
declare const ~sz := 3.0 |
5869 |
|
declare const %a[~sz] := ( 1, 2, 3 ) |
5870 |
|
end on |
5871 |
|
)NKSP_CODE", |
5872 |
|
.expectParseError = true // array size must be integer type |
5873 |
|
}); |
5874 |
|
|
5875 |
|
runScript({ |
5876 |
|
.code = R"NKSP_CODE( |
5877 |
|
on init |
5878 |
|
declare %a[3s] := ( 1, 2, 3 ) |
5879 |
|
end on |
5880 |
|
)NKSP_CODE", |
5881 |
|
.expectParseError = true // units not allowed for array size |
5882 |
|
}); |
5883 |
|
|
5884 |
|
runScript({ |
5885 |
|
.code = R"NKSP_CODE( |
5886 |
|
on init |
5887 |
|
declare %a[3m] := ( 1, 2, 3 ) |
5888 |
|
end on |
5889 |
|
)NKSP_CODE", |
5890 |
|
.expectParseError = true // units not allowed for array size |
5891 |
|
}); |
5892 |
|
|
5893 |
|
runScript({ |
5894 |
|
.code = R"NKSP_CODE( |
5895 |
|
on init |
5896 |
|
declare const %a[!3] := ( 1, 2, 3 ) |
5897 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5898 |
|
end on |
5899 |
|
)NKSP_CODE", |
5900 |
|
.expectIntExitResult = (1 + 2 + 3), |
5901 |
|
.expectParseWarning = true // 'final' operator is meaningless for array size |
5902 |
|
}); |
5903 |
|
|
5904 |
|
runScript({ |
5905 |
|
.code = R"NKSP_CODE( |
5906 |
|
on init |
5907 |
|
declare %a[3] := ( 1, 2, 3 ) |
5908 |
|
%a[0] := 4 |
5909 |
|
%a[1] := 5 |
5910 |
|
%a[2] := 6 |
5911 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5912 |
|
end on |
5913 |
|
)NKSP_CODE", |
5914 |
|
.expectIntExitResult = (4 + 5 + 6) |
5915 |
|
}); |
5916 |
|
|
5917 |
|
runScript({ |
5918 |
|
.code = R"NKSP_CODE( |
5919 |
|
on init |
5920 |
|
declare %a[3] |
5921 |
|
declare %a[3] |
5922 |
|
end on |
5923 |
|
)NKSP_CODE", |
5924 |
|
.expectParseError = true // variable re-declaration |
5925 |
|
}); |
5926 |
|
|
5927 |
|
runScript({ |
5928 |
|
.code = R"NKSP_CODE( |
5929 |
|
on init |
5930 |
|
declare const %a[3] |
5931 |
|
end on |
5932 |
|
)NKSP_CODE", |
5933 |
|
.expectParseError = true // const variable declaration without assignment |
5934 |
|
}); |
5935 |
|
|
5936 |
|
runScript({ |
5937 |
|
.code = R"NKSP_CODE( |
5938 |
|
on init |
5939 |
|
declare const %a[3] := ( 1, 2, 3 ) |
5940 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5941 |
|
end on |
5942 |
|
)NKSP_CODE", |
5943 |
|
.expectIntExitResult = (1 + 2 + 3) |
5944 |
|
}); |
5945 |
|
|
5946 |
|
runScript({ |
5947 |
|
.code = R"NKSP_CODE( |
5948 |
|
on init |
5949 |
|
declare const %a[3] := ( 1, 2, 3, 4 ) |
5950 |
|
end on |
5951 |
|
)NKSP_CODE", |
5952 |
|
.expectParseError = true // incompatible array sizes |
5953 |
|
}); |
5954 |
|
|
5955 |
|
runScript({ |
5956 |
|
.code = R"NKSP_CODE( |
5957 |
|
on init |
5958 |
|
declare const %a[3] := ( 1, 2, 3 ) |
5959 |
|
%a[0] := 8 |
5960 |
|
end on |
5961 |
|
)NKSP_CODE", |
5962 |
|
.expectParseError = true // attempt to modify const variable |
5963 |
|
}); |
5964 |
|
|
5965 |
|
runScript({ |
5966 |
|
.code = R"NKSP_CODE( |
5967 |
|
on init |
5968 |
|
declare const %a[3] := ( 1, 2, 3 ) |
5969 |
|
declare const %b[3] := ( %a[0], %a[1], %a[2] ) |
5970 |
|
exit( %b[0] + %b[1] + %b[2] ) |
5971 |
|
end on |
5972 |
|
)NKSP_CODE", |
5973 |
|
.expectIntExitResult = (1 + 2 + 3) |
5974 |
|
}); |
5975 |
|
|
5976 |
|
runScript({ |
5977 |
|
.code = R"NKSP_CODE( |
5978 |
|
on init |
5979 |
|
declare %a[3] := ( 1, 2, 3 ) |
5980 |
|
declare const %b[3] := ( %a[0], %a[1], %a[2] ) |
5981 |
|
end on |
5982 |
|
)NKSP_CODE", |
5983 |
|
.expectParseError = true // const array defined with non-const assignment |
5984 |
|
}); |
5985 |
|
|
5986 |
|
runScript({ |
5987 |
|
.code = R"NKSP_CODE( |
5988 |
|
on init |
5989 |
|
declare polyphonic %a[3] |
5990 |
|
end on |
5991 |
|
)NKSP_CODE", |
5992 |
|
.expectParseError = true // polyphonic not allowed for array types |
5993 |
|
}); |
5994 |
|
|
5995 |
|
runScript({ |
5996 |
|
.code = R"NKSP_CODE( |
5997 |
|
on init |
5998 |
|
declare polyphonic %a[3] := ( 1, 2, 3 ) |
5999 |
|
end on |
6000 |
|
)NKSP_CODE", |
6001 |
|
.expectParseError = true // polyphonic not allowed for array types |
6002 |
|
}); |
6003 |
|
|
6004 |
|
runScript({ |
6005 |
|
.code = R"NKSP_CODE( |
6006 |
|
on init |
6007 |
|
declare const polyphonic %a[3] |
6008 |
|
end on |
6009 |
|
)NKSP_CODE", |
6010 |
|
.expectParseError = true // polyphonic not allowed for array types |
6011 |
|
}); |
6012 |
|
|
6013 |
|
runScript({ |
6014 |
|
.code = R"NKSP_CODE( |
6015 |
|
on init |
6016 |
|
declare const polyphonic %a[3] := ( 1, 2, 3 ) |
6017 |
|
end on |
6018 |
|
)NKSP_CODE", |
6019 |
|
.expectParseError = true // polyphonic not allowed for array types |
6020 |
|
}); |
6021 |
|
|
6022 |
|
runScript({ |
6023 |
|
.code = R"NKSP_CODE( |
6024 |
|
on init |
6025 |
|
declare polyphonic const %a[3] |
6026 |
|
end on |
6027 |
|
)NKSP_CODE", |
6028 |
|
.expectParseError = true // polyphonic not allowed for array types |
6029 |
|
}); |
6030 |
|
|
6031 |
|
runScript({ |
6032 |
|
.code = R"NKSP_CODE( |
6033 |
|
on init |
6034 |
|
declare polyphonic const %a[3] := ( 1, 2, 3 ) |
6035 |
|
end on |
6036 |
|
)NKSP_CODE", |
6037 |
|
.expectParseError = true // polyphonic not allowed for array types |
6038 |
|
}); |
6039 |
|
|
6040 |
|
runScript({ |
6041 |
|
.code = R"NKSP_CODE( |
6042 |
|
on init |
6043 |
|
declare %a[3] := ( 1, max(8,24), 3 ) |
6044 |
|
exit( %a[0] + %a[1] + %a[2] ) |
6045 |
|
end on |
6046 |
|
)NKSP_CODE", |
6047 |
|
.expectIntExitResult = ( 1 + 24 + 3 ) |
6048 |
|
}); |
6049 |
|
|
6050 |
|
runScript({ |
6051 |
|
.code = R"NKSP_CODE( |
6052 |
|
on init |
6053 |
|
declare %a[3] := ( 1, abort($NI_CALLBACK_ID), 3 ) |
6054 |
|
end on |
6055 |
|
)NKSP_CODE", |
6056 |
|
.expectParseError = true // assigned expression does not result in a value |
6057 |
|
}); |
6058 |
|
|
6059 |
|
runScript({ |
6060 |
|
.code = R"NKSP_CODE( |
6061 |
|
on init |
6062 |
|
declare const %a[3] := ( 1, abort($NI_CALLBACK_ID), 3 ) |
6063 |
|
end on |
6064 |
|
)NKSP_CODE", |
6065 |
|
.expectParseError = true // assigned expression does not result in a value |
6066 |
|
}); |
6067 |
|
|
6068 |
|
runScript({ |
6069 |
|
.code = R"NKSP_CODE( |
6070 |
|
on init |
6071 |
|
declare %a[3] := ( 1.0, 2.0, 3.0 ) |
6072 |
|
end on |
6073 |
|
)NKSP_CODE", |
6074 |
|
.expectParseError = true // int array declaration vs. real array assignment |
6075 |
|
}); |
6076 |
|
|
6077 |
|
runScript({ |
6078 |
|
.code = R"NKSP_CODE( |
6079 |
|
on init |
6080 |
|
declare %a[3] := ( 1, 2, 3.0 ) |
6081 |
|
end on |
6082 |
|
)NKSP_CODE", |
6083 |
|
.expectParseError = true // 3rd element not an integer |
6084 |
|
}); |
6085 |
|
|
6086 |
|
runScript({ |
6087 |
|
.code = R"NKSP_CODE( |
6088 |
|
on init |
6089 |
|
declare %a[3] := ( "x", "y", "z" ) |
6090 |
|
end on |
6091 |
|
)NKSP_CODE", |
6092 |
|
.expectParseError = true // int array declaration vs. string array assignment |
6093 |
|
}); |
6094 |
|
|
6095 |
|
runScript({ |
6096 |
|
.code = R"NKSP_CODE( |
6097 |
|
on init |
6098 |
|
declare a[3] := ( 1, 2, 3 ) |
6099 |
|
end on |
6100 |
|
)NKSP_CODE", |
6101 |
|
.expectParseError = true // missing type prefix character in variable name |
6102 |
|
}); |
6103 |
|
|
6104 |
|
runScript({ |
6105 |
|
.code = R"NKSP_CODE( |
6106 |
|
on init |
6107 |
|
declare a[3] |
6108 |
|
end on |
6109 |
|
)NKSP_CODE", |
6110 |
|
.expectParseError = true // missing type prefix character in variable name |
6111 |
|
}); |
6112 |
|
|
6113 |
|
runScript({ |
6114 |
|
.code = R"NKSP_CODE( |
6115 |
|
on init |
6116 |
|
declare const %a[3] := ( 1, 2s, 3 ) |
6117 |
|
end on |
6118 |
|
)NKSP_CODE", |
6119 |
|
.expectParseError = true // unit types not allowed for arrays |
6120 |
|
}); |
6121 |
|
|
6122 |
|
runScript({ |
6123 |
|
.code = R"NKSP_CODE( |
6124 |
|
on init |
6125 |
|
declare const %a[3] := ( 1, !2, 3 ) |
6126 |
|
end on |
6127 |
|
)NKSP_CODE", |
6128 |
|
.expectParseError = true // 'final' not allowed for arrays |
6129 |
|
}); |
6130 |
|
|
6131 |
|
#if !SILENT_TEST |
6132 |
|
std::cout << std::endl; |
6133 |
|
#endif |
6134 |
|
} |
6135 |
|
|
6136 |
|
static void testRealVarDeclaration() { |
6137 |
|
#if !SILENT_TEST |
6138 |
|
std::cout << "UNIT TEST: real var declaration\n"; |
6139 |
|
#endif |
6140 |
|
|
6141 |
|
runScript({ |
6142 |
|
.code = R"NKSP_CODE( |
6143 |
|
on init |
6144 |
|
declare ~a |
6145 |
|
exit(~a) |
6146 |
|
end on |
6147 |
|
)NKSP_CODE", |
6148 |
|
.expectRealExitResult = 0.0 |
6149 |
|
}); |
6150 |
|
|
6151 |
|
runScript({ |
6152 |
|
.code = R"NKSP_CODE( |
6153 |
|
on init |
6154 |
|
declare ~a := 24.8 |
6155 |
|
exit(~a) |
6156 |
|
end on |
6157 |
|
)NKSP_CODE", |
6158 |
|
.expectRealExitResult = 24.8 |
6159 |
|
}); |
6160 |
|
|
6161 |
|
runScript({ |
6162 |
|
.code = R"NKSP_CODE( |
6163 |
|
on init |
6164 |
|
declare ~a := 8.24 |
6165 |
|
~a := 24.8 |
6166 |
|
exit(~a) |
6167 |
|
end on |
6168 |
|
)NKSP_CODE", |
6169 |
|
.expectRealExitResult = 24.8 |
6170 |
|
}); |
6171 |
|
|
6172 |
|
runScript({ |
6173 |
|
.code = R"NKSP_CODE( |
6174 |
|
on init |
6175 |
|
declare ~a |
6176 |
|
declare ~a |
6177 |
|
end on |
6178 |
|
)NKSP_CODE", |
6179 |
|
.expectParseError = true // variable re-declaration |
6180 |
|
}); |
6181 |
|
|
6182 |
|
runScript({ |
6183 |
|
.code = R"NKSP_CODE( |
6184 |
|
on init |
6185 |
|
declare const ~a |
6186 |
|
end on |
6187 |
|
)NKSP_CODE", |
6188 |
|
.expectParseError = true // const variable declaration without assignment |
6189 |
|
}); |
6190 |
|
|
6191 |
|
runScript({ |
6192 |
|
.code = R"NKSP_CODE( |
6193 |
|
on init |
6194 |
|
declare const ~a := 8.24 |
6195 |
|
exit(~a) |
6196 |
|
end on |
6197 |
|
)NKSP_CODE", |
6198 |
|
.expectRealExitResult = 8.24 |
6199 |
|
}); |
6200 |
|
|
6201 |
|
runScript({ |
6202 |
|
.code = R"NKSP_CODE( |
6203 |
|
on init |
6204 |
|
declare const ~a := 28.0 |
6205 |
|
~a := 8.0 |
6206 |
|
end on |
6207 |
|
)NKSP_CODE", |
6208 |
|
.expectParseError = true // attempt to modify const variable |
6209 |
|
}); |
6210 |
|
|
6211 |
|
runScript({ |
6212 |
|
.code = R"NKSP_CODE( |
6213 |
|
on init |
6214 |
|
declare const ~a := 24.8 |
6215 |
|
declare const ~b := ~a |
6216 |
|
exit(~b) |
6217 |
|
end on |
6218 |
|
)NKSP_CODE", |
6219 |
|
.expectRealExitResult = 24.8 |
6220 |
|
}); |
6221 |
|
|
6222 |
|
runScript({ |
6223 |
|
.code = R"NKSP_CODE( |
6224 |
|
on init |
6225 |
|
declare ~a := 24.0 |
6226 |
|
declare const ~b := ~a |
6227 |
|
end on |
6228 |
|
)NKSP_CODE", |
6229 |
|
.expectParseError = true // const variable defined with non-const assignment |
6230 |
|
}); |
6231 |
|
|
6232 |
|
runScript({ |
6233 |
|
.code = R"NKSP_CODE( |
6234 |
|
on init |
6235 |
|
declare polyphonic ~a |
6236 |
|
exit(~a) |
6237 |
|
end on |
6238 |
|
)NKSP_CODE", |
6239 |
|
.expectRealExitResult = 0.0 |
6240 |
|
}); |
6241 |
|
|
6242 |
|
runScript({ |
6243 |
|
.code = R"NKSP_CODE( |
6244 |
|
on init |
6245 |
|
declare const polyphonic ~a |
6246 |
|
end on |
6247 |
|
)NKSP_CODE", |
6248 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
6249 |
|
}); |
6250 |
|
|
6251 |
|
runScript({ |
6252 |
|
.code = R"NKSP_CODE( |
6253 |
|
on init |
6254 |
|
declare polyphonic const ~a |
6255 |
|
end on |
6256 |
|
)NKSP_CODE", |
6257 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
6258 |
|
}); |
6259 |
|
|
6260 |
|
runScript({ |
6261 |
|
.code = R"NKSP_CODE( |
6262 |
|
on init |
6263 |
|
declare const polyphonic ~a := 3.0 |
6264 |
|
end on |
6265 |
|
)NKSP_CODE", |
6266 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
6267 |
|
}); |
6268 |
|
|
6269 |
|
runScript({ |
6270 |
|
.code = R"NKSP_CODE( |
6271 |
|
on init |
6272 |
|
declare polyphonic const ~a := 3.0 |
6273 |
|
end on |
6274 |
|
)NKSP_CODE", |
6275 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
6276 |
|
}); |
6277 |
|
|
6278 |
|
runScript({ |
6279 |
|
.code = R"NKSP_CODE( |
6280 |
|
on init |
6281 |
|
declare $a := 24.8 |
6282 |
|
exit($a) |
6283 |
|
end on |
6284 |
|
)NKSP_CODE", |
6285 |
|
.expectParseWarning = true, // int type declaration vs. real value assignment |
6286 |
|
.expectRealExitResult = 24.8 |
6287 |
|
}); |
6288 |
|
|
6289 |
|
runScript({ |
6290 |
|
.code = R"NKSP_CODE( |
6291 |
|
on init |
6292 |
|
declare %a := 24.8 |
6293 |
|
exit(%a) |
6294 |
|
end on |
6295 |
|
)NKSP_CODE", |
6296 |
|
.expectParseWarning = true, // int array type declaration vs. real scalar value assignment |
6297 |
|
.expectRealExitResult = 24.8 |
6298 |
|
}); |
6299 |
|
|
6300 |
|
runScript({ |
6301 |
|
.code = R"NKSP_CODE( |
6302 |
|
on init |
6303 |
|
declare const %a := 24.8 |
6304 |
|
exit(%a) |
6305 |
|
end on |
6306 |
|
)NKSP_CODE", |
6307 |
|
.expectParseWarning = true, // int array type declaration vs. real scalar value assignment |
6308 |
|
.expectRealExitResult = 24.8 |
6309 |
|
}); |
6310 |
|
|
6311 |
|
runScript({ |
6312 |
|
.code = R"NKSP_CODE( |
6313 |
|
on init |
6314 |
|
declare ?a := 24.8 |
6315 |
|
exit(?a) |
6316 |
|
end on |
6317 |
|
)NKSP_CODE", |
6318 |
|
.expectParseWarning = true, // real array type declaration vs. real scalar value assignment |
6319 |
|
.expectRealExitResult = 24.8 |
6320 |
|
}); |
6321 |
|
|
6322 |
|
runScript({ |
6323 |
|
.code = R"NKSP_CODE( |
6324 |
|
on init |
6325 |
|
declare const ?a := 24.8 |
6326 |
|
exit(?a) |
6327 |
|
end on |
6328 |
|
)NKSP_CODE", |
6329 |
|
.expectParseWarning = true, // real array type declaration vs. real scalar value assignment |
6330 |
|
.expectRealExitResult = 24.8 |
6331 |
|
}); |
6332 |
|
|
6333 |
|
runScript({ |
6334 |
|
.code = R"NKSP_CODE( |
6335 |
|
on init |
6336 |
|
declare @a := 24.8 |
6337 |
|
exit(@a) |
6338 |
|
end on |
6339 |
|
)NKSP_CODE", |
6340 |
|
.expectParseWarning = true, // string type declaration vs. real scalar value assignment |
6341 |
|
.expectRealExitResult = 24.8 |
6342 |
|
}); |
6343 |
|
|
6344 |
|
runScript({ |
6345 |
|
.code = R"NKSP_CODE( |
6346 |
|
on init |
6347 |
|
declare const @a := 24.8 |
6348 |
|
exit(@a) |
6349 |
|
end on |
6350 |
|
)NKSP_CODE", |
6351 |
|
.expectParseWarning = true, // string type declaration vs. real scalar value assignment |
6352 |
|
.expectRealExitResult = 24.8 |
6353 |
|
}); |
6354 |
|
|
6355 |
|
runScript({ |
6356 |
|
.code = R"NKSP_CODE( |
6357 |
|
on init |
6358 |
|
declare ~a := ( 0, 1, 2 ) |
6359 |
|
end on |
6360 |
|
)NKSP_CODE", |
6361 |
|
.expectParseError = true // real scalar type declaration vs. int array value assignment |
6362 |
|
}); |
6363 |
|
|
6364 |
|
runScript({ |
6365 |
|
.code = R"NKSP_CODE( |
6366 |
|
on init |
6367 |
|
declare const ~a := ( 0, 1, 2 ) |
6368 |
|
end on |
6369 |
|
)NKSP_CODE", |
6370 |
|
.expectParseError = true // real scalar type declaration vs. int array value assignment |
6371 |
|
}); |
6372 |
|
|
6373 |
|
runScript({ |
6374 |
|
.code = R"NKSP_CODE( |
6375 |
|
on init |
6376 |
|
declare a := 24.8 |
6377 |
|
end on |
6378 |
|
)NKSP_CODE", |
6379 |
|
.expectParseError = true // missing type prefix character in variable name |
6380 |
|
}); |
6381 |
|
|
6382 |
|
runScript({ |
6383 |
|
.code = R"NKSP_CODE( |
6384 |
|
on init |
6385 |
|
declare const a := 24.8 |
6386 |
|
end on |
6387 |
|
)NKSP_CODE", |
6388 |
|
.expectParseError = true // missing type prefix character in variable name |
6389 |
|
}); |
6390 |
|
|
6391 |
|
runScript({ |
6392 |
|
.code = R"NKSP_CODE( |
6393 |
|
on init |
6394 |
|
declare ~a := max(8.1,24.2) |
6395 |
|
exit(~a) |
6396 |
|
end on |
6397 |
|
)NKSP_CODE", |
6398 |
|
.expectRealExitResult = 24.2 |
6399 |
|
}); |
6400 |
|
|
6401 |
|
runScript({ |
6402 |
|
.code = R"NKSP_CODE( |
6403 |
|
on init |
6404 |
|
declare ~a := abort($NI_CALLBACK_ID) |
6405 |
|
end on |
6406 |
|
)NKSP_CODE", |
6407 |
|
.expectParseError = true // assigned expression does not result in a value |
6408 |
|
}); |
6409 |
|
|
6410 |
|
runScript({ |
6411 |
|
.code = R"NKSP_CODE( |
6412 |
|
on init |
6413 |
|
declare const ~a := abort($NI_CALLBACK_ID) |
6414 |
|
end on |
6415 |
|
)NKSP_CODE", |
6416 |
|
.expectParseError = true // assigned expression does not result in a value |
6417 |
|
}); |
6418 |
|
|
6419 |
|
#if !SILENT_TEST |
6420 |
|
std::cout << std::endl; |
6421 |
|
#endif |
6422 |
|
} |
6423 |
|
|
6424 |
|
static void testRealArrayVarDeclaration() { |
6425 |
|
#if !SILENT_TEST |
6426 |
|
std::cout << "UNIT TEST: real array var declaration\n"; |
6427 |
|
#endif |
6428 |
|
|
6429 |
|
runScript({ |
6430 |
|
.code = R"NKSP_CODE( |
6431 |
|
on init |
6432 |
|
declare ?a[3] |
6433 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6434 |
|
end on |
6435 |
|
)NKSP_CODE", |
6436 |
|
.expectRealExitResult = 0.0 |
6437 |
|
}); |
6438 |
|
|
6439 |
|
runScript({ |
6440 |
|
.code = R"NKSP_CODE( |
6441 |
|
on init |
6442 |
|
declare ?a[0] |
6443 |
|
end on |
6444 |
|
)NKSP_CODE", |
6445 |
|
.expectParseWarning = true // unusable array size |
6446 |
|
}); |
6447 |
|
|
6448 |
|
runScript({ |
6449 |
|
.code = R"NKSP_CODE( |
6450 |
|
on init |
6451 |
|
declare ?a[-1] |
6452 |
|
end on |
6453 |
|
)NKSP_CODE", |
6454 |
|
.expectParseError = true // illegal array size |
6455 |
|
}); |
6456 |
|
|
6457 |
|
runScript({ |
6458 |
|
.code = R"NKSP_CODE( |
6459 |
|
on init |
6460 |
|
declare ?a[3] := ( 1.1, 2.2, 3.3 ) |
6461 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6462 |
|
end on |
6463 |
|
)NKSP_CODE", |
6464 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6465 |
|
}); |
6466 |
|
|
6467 |
|
runScript({ |
6468 |
|
.code = R"NKSP_CODE( |
6469 |
|
on init |
6470 |
|
declare ?a[] := ( 1.1, 2.2, 3.3 ) |
6471 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6472 |
|
end on |
6473 |
|
)NKSP_CODE", |
6474 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6475 |
|
}); |
6476 |
|
|
6477 |
|
runScript({ |
6478 |
|
.code = R"NKSP_CODE( |
6479 |
|
on init |
6480 |
|
declare ?a[] |
6481 |
|
end on |
6482 |
|
)NKSP_CODE", |
6483 |
|
.expectParseWarning = true // unusable array size (zero) |
6484 |
|
}); |
6485 |
|
|
6486 |
|
runScript({ |
6487 |
|
.code = R"NKSP_CODE( |
6488 |
|
on init |
6489 |
|
declare const $sz := 3 |
6490 |
|
declare ?a[$sz] := ( 1.1, 2.2, 3.3 ) |
6491 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6492 |
|
end on |
6493 |
|
)NKSP_CODE", |
6494 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6495 |
|
}); |
6496 |
|
|
6497 |
|
runScript({ |
6498 |
|
.code = R"NKSP_CODE( |
6499 |
|
on init |
6500 |
|
declare const $sz := 3 |
6501 |
|
declare const ?a[$sz] := ( 1.1, 2.2, 3.3 ) |
6502 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6503 |
|
end on |
6504 |
|
)NKSP_CODE", |
6505 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6506 |
|
}); |
6507 |
|
|
6508 |
|
runScript({ |
6509 |
|
.code = R"NKSP_CODE( |
6510 |
|
on init |
6511 |
|
declare $sz := 3 |
6512 |
|
declare ?a[$sz] := ( 1.1, 2.2, 3.3 ) |
6513 |
|
end on |
6514 |
|
)NKSP_CODE", |
6515 |
|
.expectParseError = true // array size must be constant expression |
6516 |
|
}); |
6517 |
|
|
6518 |
|
runScript({ |
6519 |
|
.code = R"NKSP_CODE( |
6520 |
|
on init |
6521 |
|
declare $sz := 3 |
6522 |
|
declare const ?a[$sz] := ( 1.1, 2.2, 3.3 ) |
6523 |
|
end on |
6524 |
|
)NKSP_CODE", |
6525 |
|
.expectParseError = true // array size must be constant expression |
6526 |
|
}); |
6527 |
|
|
6528 |
|
runScript({ |
6529 |
|
.code = R"NKSP_CODE( |
6530 |
|
on init |
6531 |
|
declare const ~sz := 3.0 |
6532 |
|
declare const ?a[~sz] := ( 1.1, 2.2, 3.3 ) |
6533 |
|
end on |
6534 |
|
)NKSP_CODE", |
6535 |
|
.expectParseError = true // array size must be integer type |
6536 |
|
}); |
6537 |
|
|
6538 |
|
runScript({ |
6539 |
|
.code = R"NKSP_CODE( |
6540 |
|
on init |
6541 |
|
declare ?a[3s] := ( 1.1, 2.2, 3.3 ) |
6542 |
|
end on |
6543 |
|
)NKSP_CODE", |
6544 |
|
.expectParseError = true // units not allowed for array size |
6545 |
|
}); |
6546 |
|
|
6547 |
|
runScript({ |
6548 |
|
.code = R"NKSP_CODE( |
6549 |
|
on init |
6550 |
|
declare ?a[3m] := ( 1.1, 2.2, 3.3 ) |
6551 |
|
end on |
6552 |
|
)NKSP_CODE", |
6553 |
|
.expectParseError = true // units not allowed for array size |
6554 |
|
}); |
6555 |
|
|
6556 |
|
runScript({ |
6557 |
|
.code = R"NKSP_CODE( |
6558 |
|
on init |
6559 |
|
declare const ?a[!3] := ( 1.1, 2.2, 3.3 ) |
6560 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6561 |
|
end on |
6562 |
|
)NKSP_CODE", |
6563 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3), |
6564 |
|
.expectParseWarning = true // 'final' operator is meaningless for array size |
6565 |
|
}); |
6566 |
|
|
6567 |
|
runScript({ |
6568 |
|
.code = R"NKSP_CODE( |
6569 |
|
on init |
6570 |
|
declare ?a[3] := ( 1.0, 2.0, 3.0 ) |
6571 |
|
?a[0] := 4.5 |
6572 |
|
?a[1] := 5.5 |
6573 |
|
?a[2] := 6.5 |
6574 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6575 |
|
end on |
6576 |
|
)NKSP_CODE", |
6577 |
|
.expectRealExitResult = (4.5 + 5.5 + 6.5) |
6578 |
|
}); |
6579 |
|
|
6580 |
|
runScript({ |
6581 |
|
.code = R"NKSP_CODE( |
6582 |
|
on init |
6583 |
|
declare ?a[3] |
6584 |
|
declare ?a[3] |
6585 |
|
end on |
6586 |
|
)NKSP_CODE", |
6587 |
|
.expectParseError = true // variable re-declaration |
6588 |
|
}); |
6589 |
|
|
6590 |
|
runScript({ |
6591 |
|
.code = R"NKSP_CODE( |
6592 |
|
on init |
6593 |
|
declare const ?a[3] |
6594 |
|
end on |
6595 |
|
)NKSP_CODE", |
6596 |
|
.expectParseError = true // const variable declaration without assignment |
6597 |
|
}); |
6598 |
|
|
6599 |
|
runScript({ |
6600 |
|
.code = R"NKSP_CODE( |
6601 |
|
on init |
6602 |
|
declare const ?a[3] := ( 1.1, 2.2, 3.3 ) |
6603 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6604 |
|
end on |
6605 |
|
)NKSP_CODE", |
6606 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6607 |
|
}); |
6608 |
|
|
6609 |
|
runScript({ |
6610 |
|
.code = R"NKSP_CODE( |
6611 |
|
on init |
6612 |
|
declare const ?a[3] := ( 1.1, 2.2, 3.3, 4.4 ) |
6613 |
|
end on |
6614 |
|
)NKSP_CODE", |
6615 |
|
.expectParseError = true // incompatible array sizes |
6616 |
|
}); |
6617 |
|
|
6618 |
|
runScript({ |
6619 |
|
.code = R"NKSP_CODE( |
6620 |
|
on init |
6621 |
|
declare const ?a[3] := ( 1.0, 2.0, 3.0 ) |
6622 |
|
?a[0] := 8.0 |
6623 |
|
end on |
6624 |
|
)NKSP_CODE", |
6625 |
|
.expectParseError = true // attempt to modify const variable |
6626 |
|
}); |
6627 |
|
|
6628 |
|
runScript({ |
6629 |
|
.code = R"NKSP_CODE( |
6630 |
|
on init |
6631 |
|
declare const ?a[3] := ( 1.1, 2.2, 3.3 ) |
6632 |
|
declare const ?b[3] := ( ?a[0], ?a[1], ?a[2] ) |
6633 |
|
exit( ?b[0] + ?b[1] + ?b[2] ) |
6634 |
|
end on |
6635 |
|
)NKSP_CODE", |
6636 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6637 |
|
}); |
6638 |
|
|
6639 |
|
runScript({ |
6640 |
|
.code = R"NKSP_CODE( |
6641 |
|
on init |
6642 |
|
declare ?a[3] := ( 1.1, 2.2, 3.3 ) |
6643 |
|
declare const ?b[3] := ( ?a[0], ?a[1], ?a[2] ) |
6644 |
|
end on |
6645 |
|
)NKSP_CODE", |
6646 |
|
.expectParseError = true // const array defined with non-const assignment |
6647 |
|
}); |
6648 |
|
|
6649 |
|
runScript({ |
6650 |
|
.code = R"NKSP_CODE( |
6651 |
|
on init |
6652 |
|
declare polyphonic ?a[3] |
6653 |
|
end on |
6654 |
|
)NKSP_CODE", |
6655 |
|
.expectParseError = true // polyphonic not allowed for array types |
6656 |
|
}); |
6657 |
|
|
6658 |
|
runScript({ |
6659 |
|
.code = R"NKSP_CODE( |
6660 |
|
on init |
6661 |
|
declare polyphonic ?a[3] := ( 1.0, 2.0, 3.0 ) |
6662 |
|
end on |
6663 |
|
)NKSP_CODE", |
6664 |
|
.expectParseError = true // polyphonic not allowed for array types |
6665 |
|
}); |
6666 |
|
|
6667 |
|
runScript({ |
6668 |
|
.code = R"NKSP_CODE( |
6669 |
|
on init |
6670 |
|
declare const polyphonic ?a[3] |
6671 |
|
end on |
6672 |
|
)NKSP_CODE", |
6673 |
|
.expectParseError = true // polyphonic not allowed for array types |
6674 |
|
}); |
6675 |
|
|
6676 |
|
runScript({ |
6677 |
|
.code = R"NKSP_CODE( |
6678 |
|
on init |
6679 |
|
declare const polyphonic ?a[3] := ( 1.0, 2.0, 3.0 ) |
6680 |
|
end on |
6681 |
|
)NKSP_CODE", |
6682 |
|
.expectParseError = true // polyphonic not allowed for array types |
6683 |
|
}); |
6684 |
|
|
6685 |
|
runScript({ |
6686 |
|
.code = R"NKSP_CODE( |
6687 |
|
on init |
6688 |
|
declare polyphonic const ?a[3] |
6689 |
|
end on |
6690 |
|
)NKSP_CODE", |
6691 |
|
.expectParseError = true // polyphonic not allowed for array types |
6692 |
|
}); |
6693 |
|
|
6694 |
|
runScript({ |
6695 |
|
.code = R"NKSP_CODE( |
6696 |
|
on init |
6697 |
|
declare polyphonic const ?a[3] := ( 1.0, 2.0, 3.0 ) |
6698 |
|
end on |
6699 |
|
)NKSP_CODE", |
6700 |
|
.expectParseError = true // polyphonic not allowed for array types |
6701 |
|
}); |
6702 |
|
|
6703 |
|
runScript({ |
6704 |
|
.code = R"NKSP_CODE( |
6705 |
|
on init |
6706 |
|
declare ?a[3] := ( 1.0, max(8.3,24.6), 3.0 ) |
6707 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6708 |
|
end on |
6709 |
|
)NKSP_CODE", |
6710 |
|
.expectRealExitResult = ( 1.0 + 24.6 + 3.0 ) |
6711 |
|
}); |
6712 |
|
|
6713 |
|
runScript({ |
6714 |
|
.code = R"NKSP_CODE( |
6715 |
|
on init |
6716 |
|
declare ?a[3] := ( 1.0, abort($NI_CALLBACK_ID), 3.0 ) |
6717 |
|
end on |
6718 |
|
)NKSP_CODE", |
6719 |
|
.expectParseError = true // assigned expression does not result in a value |
6720 |
|
}); |
6721 |
|
|
6722 |
|
runScript({ |
6723 |
|
.code = R"NKSP_CODE( |
6724 |
|
on init |
6725 |
|
declare const ?a[3] := ( 1.0, abort($NI_CALLBACK_ID), 3.0 ) |
6726 |
|
end on |
6727 |
|
)NKSP_CODE", |
6728 |
|
.expectParseError = true // assigned expression does not result in a value |
6729 |
|
}); |
6730 |
|
|
6731 |
|
runScript({ |
6732 |
|
.code = R"NKSP_CODE( |
6733 |
|
on init |
6734 |
|
declare ?a[3] := ( 1, 2, 3 ) |
6735 |
|
end on |
6736 |
|
)NKSP_CODE", |
6737 |
|
.expectParseError = true // real array declaration vs. int array assignment |
6738 |
|
}); |
6739 |
|
|
6740 |
|
runScript({ |
6741 |
|
.code = R"NKSP_CODE( |
6742 |
|
on init |
6743 |
|
declare ?a[3] := ( 1.0, 2.0, 3 ) |
6744 |
|
end on |
6745 |
|
)NKSP_CODE", |
6746 |
|
.expectParseError = true // 3rd element not a real value |
6747 |
|
}); |
6748 |
|
|
6749 |
|
runScript({ |
6750 |
|
.code = R"NKSP_CODE( |
6751 |
|
on init |
6752 |
|
declare ?a[3] := ( "x", "y", "z" ) |
6753 |
|
end on |
6754 |
|
)NKSP_CODE", |
6755 |
|
.expectParseError = true // real array declaration vs. string array assignment |
6756 |
|
}); |
6757 |
|
|
6758 |
|
runScript({ |
6759 |
|
.code = R"NKSP_CODE( |
6760 |
|
on init |
6761 |
|
declare a[3] := ( 1.0, 2.0, 3.0 ) |
6762 |
|
end on |
6763 |
|
)NKSP_CODE", |
6764 |
|
.expectParseError = true // missing type prefix character in variable name |
6765 |
|
}); |
6766 |
|
|
6767 |
|
runScript({ |
6768 |
|
.code = R"NKSP_CODE( |
6769 |
|
on init |
6770 |
|
declare const ?a[3] := ( 1.0, 2.0s, 3.0 ) |
6771 |
|
end on |
6772 |
|
)NKSP_CODE", |
6773 |
|
.expectParseError = true // unit types not allowed for arrays |
6774 |
|
}); |
6775 |
|
|
6776 |
|
runScript({ |
6777 |
|
.code = R"NKSP_CODE( |
6778 |
|
on init |
6779 |
|
declare const ?a[3] := ( 1.0, !2.0, 3.0 ) |
6780 |
|
end on |
6781 |
|
)NKSP_CODE", |
6782 |
|
.expectParseError = true // 'final' not allowed for arrays |
6783 |
|
}); |
6784 |
|
|
6785 |
|
#if !SILENT_TEST |
6786 |
|
std::cout << std::endl; |
6787 |
|
#endif |
6788 |
|
} |
6789 |
|
|
6790 |
|
static void testStringVarDeclaration() { |
6791 |
|
#if !SILENT_TEST |
6792 |
|
std::cout << "UNIT TEST: string var declaration\n"; |
6793 |
|
#endif |
6794 |
|
|
6795 |
|
runScript({ |
6796 |
|
.code = R"NKSP_CODE( |
6797 |
|
on init |
6798 |
|
declare @a |
6799 |
|
exit(@a) |
6800 |
|
end on |
6801 |
|
)NKSP_CODE", |
6802 |
|
.expectStringExitResult = "" |
6803 |
|
}); |
6804 |
|
|
6805 |
|
runScript({ |
6806 |
|
.code = R"NKSP_CODE( |
6807 |
|
on init |
6808 |
|
declare @a := "foo" |
6809 |
|
exit(@a) |
6810 |
|
end on |
6811 |
|
)NKSP_CODE", |
6812 |
|
.expectStringExitResult = "foo" |
6813 |
|
}); |
6814 |
|
|
6815 |
|
runScript({ |
6816 |
|
.code = R"NKSP_CODE( |
6817 |
|
on init |
6818 |
|
declare @a := "foo" |
6819 |
|
@a := "bar" |
6820 |
|
exit(@a) |
6821 |
|
end on |
6822 |
|
)NKSP_CODE", |
6823 |
|
.expectStringExitResult = "bar" |
6824 |
|
}); |
6825 |
|
|
6826 |
|
runScript({ |
6827 |
|
.code = R"NKSP_CODE( |
6828 |
|
on init |
6829 |
|
declare @a |
6830 |
|
declare @a |
6831 |
|
end on |
6832 |
|
)NKSP_CODE", |
6833 |
|
.expectParseError = true // variable re-declaration |
6834 |
|
}); |
6835 |
|
|
6836 |
|
runScript({ |
6837 |
|
.code = R"NKSP_CODE( |
6838 |
|
on init |
6839 |
|
declare const @a |
6840 |
|
end on |
6841 |
|
)NKSP_CODE", |
6842 |
|
.expectParseError = true // const variable declaration without assignment |
6843 |
|
}); |
6844 |
|
|
6845 |
|
runScript({ |
6846 |
|
.code = R"NKSP_CODE( |
6847 |
|
on init |
6848 |
|
declare const @a := "foo" |
6849 |
|
exit(@a) |
6850 |
|
end on |
6851 |
|
)NKSP_CODE", |
6852 |
|
.expectStringExitResult = "foo" |
6853 |
|
}); |
6854 |
|
|
6855 |
|
runScript({ |
6856 |
|
.code = R"NKSP_CODE( |
6857 |
|
on init |
6858 |
|
declare const @a := "foo" |
6859 |
|
@a := "bar" |
6860 |
|
end on |
6861 |
|
)NKSP_CODE", |
6862 |
|
.expectParseError = true // attempt to modify const variable |
6863 |
|
}); |
6864 |
|
|
6865 |
|
runScript({ |
6866 |
|
.code = R"NKSP_CODE( |
6867 |
|
on init |
6868 |
|
declare const @a := "foo" |
6869 |
|
declare const @b := @a |
6870 |
|
exit(@b) |
6871 |
|
end on |
6872 |
|
)NKSP_CODE", |
6873 |
|
.expectStringExitResult = "foo" |
6874 |
|
}); |
6875 |
|
|
6876 |
|
runScript({ |
6877 |
|
.code = R"NKSP_CODE( |
6878 |
|
on init |
6879 |
|
declare @a := "foo" |
6880 |
|
declare const @b := @a |
6881 |
|
end on |
6882 |
|
)NKSP_CODE", |
6883 |
|
.expectParseError = true // const variable defined with non-const assignment |
6884 |
|
}); |
6885 |
|
|
6886 |
|
runScript({ |
6887 |
|
.code = R"NKSP_CODE( |
6888 |
|
on init |
6889 |
|
declare polyphonic @a |
6890 |
|
end on |
6891 |
|
)NKSP_CODE", |
6892 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
6893 |
|
}); |
6894 |
|
|
6895 |
|
runScript({ |
6896 |
|
.code = R"NKSP_CODE( |
6897 |
|
on init |
6898 |
|
declare const polyphonic @a |
6899 |
|
end on |
6900 |
|
)NKSP_CODE", |
6901 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
6902 |
|
}); |
6903 |
|
|
6904 |
|
runScript({ |
6905 |
|
.code = R"NKSP_CODE( |
6906 |
|
on init |
6907 |
|
declare polyphonic const @a |
6908 |
|
end on |
6909 |
|
)NKSP_CODE", |
6910 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
6911 |
|
}); |
6912 |
|
|
6913 |
|
runScript({ |
6914 |
|
.code = R"NKSP_CODE( |
6915 |
|
on init |
6916 |
|
declare polyphonic @a = "foo" |
6917 |
|
end on |
6918 |
|
)NKSP_CODE", |
6919 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
6920 |
|
}); |
6921 |
|
|
6922 |
|
runScript({ |
6923 |
|
.code = R"NKSP_CODE( |
6924 |
|
on init |
6925 |
|
declare polyphonic const @a = "foo" |
6926 |
|
end on |
6927 |
|
)NKSP_CODE", |
6928 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
6929 |
|
}); |
6930 |
|
|
6931 |
|
runScript({ |
6932 |
|
.code = R"NKSP_CODE( |
6933 |
|
on init |
6934 |
|
declare const polyphonic @a = "foo" |
6935 |
|
end on |
6936 |
|
)NKSP_CODE", |
6937 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
6938 |
|
}); |
6939 |
|
|
6940 |
|
runScript({ |
6941 |
|
.code = R"NKSP_CODE( |
6942 |
|
on init |
6943 |
|
declare $a := "foo" |
6944 |
|
exit($a) |
6945 |
|
end on |
6946 |
|
)NKSP_CODE", |
6947 |
|
.expectParseWarning = true, // int type declaration vs. string assignment |
6948 |
|
.expectStringExitResult = "foo" |
6949 |
|
}); |
6950 |
|
|
6951 |
|
runScript({ |
6952 |
|
.code = R"NKSP_CODE( |
6953 |
|
on init |
6954 |
|
declare ~a := "foo" |
6955 |
|
exit(~a) |
6956 |
|
end on |
6957 |
|
)NKSP_CODE", |
6958 |
|
.expectParseWarning = true, // real type declaration vs. string assignment |
6959 |
|
.expectStringExitResult = "foo" |
6960 |
|
}); |
6961 |
|
|
6962 |
|
runScript({ |
6963 |
|
.code = R"NKSP_CODE( |
6964 |
|
on init |
6965 |
|
declare %a := "foo" |
6966 |
|
exit(%a) |
6967 |
|
end on |
6968 |
|
)NKSP_CODE", |
6969 |
|
.expectParseWarning = true, // int array type declaration vs. string assignment |
6970 |
|
.expectStringExitResult = "foo" |
6971 |
|
}); |
6972 |
|
|
6973 |
|
runScript({ |
6974 |
|
.code = R"NKSP_CODE( |
6975 |
|
on init |
6976 |
|
declare const $a := "foo" |
6977 |
|
exit($a) |
6978 |
|
end on |
6979 |
|
)NKSP_CODE", |
6980 |
|
.expectParseWarning = true, // int type declaration vs. string assignment |
6981 |
|
.expectStringExitResult = "foo" |
6982 |
|
}); |
6983 |
|
|
6984 |
|
runScript({ |
6985 |
|
.code = R"NKSP_CODE( |
6986 |
|
on init |
6987 |
|
declare const ~a := "foo" |
6988 |
|
exit(~a) |
6989 |
|
end on |
6990 |
|
)NKSP_CODE", |
6991 |
|
.expectParseWarning = true, // real type declaration vs. string assignment |
6992 |
|
.expectStringExitResult = "foo" |
6993 |
|
}); |
6994 |
|
|
6995 |
|
runScript({ |
6996 |
|
.code = R"NKSP_CODE( |
6997 |
|
on init |
6998 |
|
declare const %a := "foo" |
6999 |
|
exit(%a) |
7000 |
|
end on |
7001 |
|
)NKSP_CODE", |
7002 |
|
.expectParseWarning = true, // int array type declaration vs. string assignment |
7003 |
|
.expectStringExitResult = "foo" |
7004 |
|
}); |
7005 |
|
|
7006 |
|
runScript({ |
7007 |
|
.code = R"NKSP_CODE( |
7008 |
|
on init |
7009 |
|
declare a := "foo" |
7010 |
|
end on |
7011 |
|
)NKSP_CODE", |
7012 |
|
.expectParseError = true // missing type prefix character in variable name |
7013 |
|
}); |
7014 |
|
|
7015 |
|
runScript({ |
7016 |
|
.code = R"NKSP_CODE( |
7017 |
|
on init |
7018 |
|
declare const a := "foo" |
7019 |
|
end on |
7020 |
|
)NKSP_CODE", |
7021 |
|
.expectParseError = true // missing type prefix character in variable name |
7022 |
|
}); |
7023 |
|
|
7024 |
|
runScript({ |
7025 |
|
.code = R"NKSP_CODE( |
7026 |
|
on init |
7027 |
|
declare @a := abort($NI_CALLBACK_ID) |
7028 |
|
end on |
7029 |
|
)NKSP_CODE", |
7030 |
|
.expectParseError = true // assigned expression does not result in a value |
7031 |
|
}); |
7032 |
|
|
7033 |
|
runScript({ |
7034 |
|
.code = R"NKSP_CODE( |
7035 |
|
on init |
7036 |
|
declare const @a := abort($NI_CALLBACK_ID) |
7037 |
|
end on |
7038 |
|
)NKSP_CODE", |
7039 |
|
.expectParseError = true // assigned expression does not result in a value |
7040 |
|
}); |
7041 |
|
|
7042 |
|
#if !SILENT_TEST |
7043 |
|
std::cout << std::endl; |
7044 |
|
#endif |
7045 |
|
} |
7046 |
|
|
7047 |
static void testBuiltInMinFunction() { |
static void testBuiltInMinFunction() { |
7048 |
#if !SILENT_TEST |
#if !SILENT_TEST |
7049 |
std::cout << "UNIT TEST: built-in min() function\n"; |
std::cout << "UNIT TEST: built-in min() function\n"; |
8772 |
#endif |
#endif |
8773 |
} |
} |
8774 |
|
|
8775 |
|
static void testBuiltInMsbFunction() { |
8776 |
|
#if !SILENT_TEST |
8777 |
|
std::cout << "UNIT TEST: built-in msb() function\n"; |
8778 |
|
#endif |
8779 |
|
|
8780 |
|
runScript({ |
8781 |
|
.code = R"NKSP_CODE( |
8782 |
|
on init |
8783 |
|
exit( msb(0) ) |
8784 |
|
end on |
8785 |
|
)NKSP_CODE", |
8786 |
|
.expectIntExitResult = 0 |
8787 |
|
}); |
8788 |
|
|
8789 |
|
runScript({ |
8790 |
|
.code = R"NKSP_CODE( |
8791 |
|
on init |
8792 |
|
exit( msb(127) ) |
8793 |
|
end on |
8794 |
|
)NKSP_CODE", |
8795 |
|
.expectIntExitResult = 0 |
8796 |
|
}); |
8797 |
|
|
8798 |
|
runScript({ |
8799 |
|
.code = R"NKSP_CODE( |
8800 |
|
on init |
8801 |
|
exit( msb(128) ) |
8802 |
|
end on |
8803 |
|
)NKSP_CODE", |
8804 |
|
.expectIntExitResult = 1 |
8805 |
|
}); |
8806 |
|
|
8807 |
|
runScript({ |
8808 |
|
.code = R"NKSP_CODE( |
8809 |
|
on init |
8810 |
|
exit( msb(16255) ) |
8811 |
|
end on |
8812 |
|
)NKSP_CODE", |
8813 |
|
.expectIntExitResult = 126 |
8814 |
|
}); |
8815 |
|
|
8816 |
|
runScript({ |
8817 |
|
.code = R"NKSP_CODE( |
8818 |
|
on init |
8819 |
|
exit( msb(16256) ) |
8820 |
|
end on |
8821 |
|
)NKSP_CODE", |
8822 |
|
.expectIntExitResult = 127 |
8823 |
|
}); |
8824 |
|
|
8825 |
|
runScript({ |
8826 |
|
.code = R"NKSP_CODE( |
8827 |
|
on init |
8828 |
|
exit( msb(16383) ) |
8829 |
|
end on |
8830 |
|
)NKSP_CODE", |
8831 |
|
.expectIntExitResult = 127 |
8832 |
|
}); |
8833 |
|
|
8834 |
|
#if !SILENT_TEST |
8835 |
|
std::cout << std::endl; |
8836 |
|
#endif |
8837 |
|
} |
8838 |
|
|
8839 |
|
static void testBuiltInLsbFunction() { |
8840 |
|
#if !SILENT_TEST |
8841 |
|
std::cout << "UNIT TEST: built-in lsb() function\n"; |
8842 |
|
#endif |
8843 |
|
|
8844 |
|
runScript({ |
8845 |
|
.code = R"NKSP_CODE( |
8846 |
|
on init |
8847 |
|
exit( lsb(0) ) |
8848 |
|
end on |
8849 |
|
)NKSP_CODE", |
8850 |
|
.expectIntExitResult = 0 |
8851 |
|
}); |
8852 |
|
|
8853 |
|
runScript({ |
8854 |
|
.code = R"NKSP_CODE( |
8855 |
|
on init |
8856 |
|
exit( lsb(1) ) |
8857 |
|
end on |
8858 |
|
)NKSP_CODE", |
8859 |
|
.expectIntExitResult = 1 |
8860 |
|
}); |
8861 |
|
|
8862 |
|
runScript({ |
8863 |
|
.code = R"NKSP_CODE( |
8864 |
|
on init |
8865 |
|
exit( lsb(126) ) |
8866 |
|
end on |
8867 |
|
)NKSP_CODE", |
8868 |
|
.expectIntExitResult = 126 |
8869 |
|
}); |
8870 |
|
|
8871 |
|
runScript({ |
8872 |
|
.code = R"NKSP_CODE( |
8873 |
|
on init |
8874 |
|
exit( lsb(127) ) |
8875 |
|
end on |
8876 |
|
)NKSP_CODE", |
8877 |
|
.expectIntExitResult = 127 |
8878 |
|
}); |
8879 |
|
|
8880 |
|
runScript({ |
8881 |
|
.code = R"NKSP_CODE( |
8882 |
|
on init |
8883 |
|
exit( lsb(128) ) |
8884 |
|
end on |
8885 |
|
)NKSP_CODE", |
8886 |
|
.expectIntExitResult = 0 |
8887 |
|
}); |
8888 |
|
|
8889 |
|
runScript({ |
8890 |
|
.code = R"NKSP_CODE( |
8891 |
|
on init |
8892 |
|
exit( lsb(16255) ) |
8893 |
|
end on |
8894 |
|
)NKSP_CODE", |
8895 |
|
.expectIntExitResult = 127 |
8896 |
|
}); |
8897 |
|
|
8898 |
|
runScript({ |
8899 |
|
.code = R"NKSP_CODE( |
8900 |
|
on init |
8901 |
|
exit( lsb(16256) ) |
8902 |
|
end on |
8903 |
|
)NKSP_CODE", |
8904 |
|
.expectIntExitResult = 0 |
8905 |
|
}); |
8906 |
|
|
8907 |
|
#if !SILENT_TEST |
8908 |
|
std::cout << std::endl; |
8909 |
|
#endif |
8910 |
|
} |
8911 |
|
|
8912 |
static void testBuiltInIntToRealFunction() { |
static void testBuiltInIntToRealFunction() { |
8913 |
#if !SILENT_TEST |
#if !SILENT_TEST |
8914 |
std::cout << "UNIT TEST: built-in int_to_real() function\n"; |
std::cout << "UNIT TEST: built-in int_to_real() function\n"; |
8958 |
.expectExitResultUnit = VM_BEL |
.expectExitResultUnit = VM_BEL |
8959 |
}); |
}); |
8960 |
|
|
8961 |
|
runScript({ |
8962 |
|
.code = R"NKSP_CODE( |
8963 |
|
on init |
8964 |
|
declare $foo := 7000ms |
8965 |
|
exit( int_to_real($foo) ) |
8966 |
|
end on |
8967 |
|
)NKSP_CODE", |
8968 |
|
.expectRealExitResult = 7000.0, |
8969 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
8970 |
|
.expectExitResultUnit = VM_SECOND |
8971 |
|
}); |
8972 |
|
|
8973 |
|
runScript({ |
8974 |
|
.code = R"NKSP_CODE( |
8975 |
|
on init |
8976 |
|
declare $foo := 7000ms |
8977 |
|
declare @s := "" & int_to_real($foo) |
8978 |
|
exit( @s ) |
8979 |
|
end on |
8980 |
|
)NKSP_CODE", |
8981 |
|
.expectStringExitResult = "7000ms", |
8982 |
|
}); |
8983 |
|
|
8984 |
|
runScript({ |
8985 |
|
.code = R"NKSP_CODE( |
8986 |
|
on init |
8987 |
|
declare $foo := 700ms |
8988 |
|
exit( int_to_real($foo) / 7.0 ) |
8989 |
|
end on |
8990 |
|
)NKSP_CODE", |
8991 |
|
.expectRealExitResult = 100.0, |
8992 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
8993 |
|
.expectExitResultUnit = VM_SECOND |
8994 |
|
}); |
8995 |
|
|
8996 |
|
runScript({ |
8997 |
|
.code = R"NKSP_CODE( |
8998 |
|
on init |
8999 |
|
declare $foo := 700ms |
9000 |
|
exit( int_to_real($foo) / 7.0 & "" ) |
9001 |
|
end on |
9002 |
|
)NKSP_CODE", |
9003 |
|
.expectStringExitResult = "100ms" |
9004 |
|
}); |
9005 |
|
|
9006 |
// 'final' ('!') operator tests ... |
// 'final' ('!') operator tests ... |
9007 |
|
|
9008 |
runScript({ |
runScript({ |
9081 |
.expectExitResultUnit = VM_BEL |
.expectExitResultUnit = VM_BEL |
9082 |
}); |
}); |
9083 |
|
|
9084 |
|
runScript({ |
9085 |
|
.code = R"NKSP_CODE( |
9086 |
|
on init |
9087 |
|
declare $foo := 7000ms |
9088 |
|
exit( real($foo) ) |
9089 |
|
end on |
9090 |
|
)NKSP_CODE", |
9091 |
|
.expectRealExitResult = 7000.0, |
9092 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
9093 |
|
.expectExitResultUnit = VM_SECOND |
9094 |
|
}); |
9095 |
|
|
9096 |
|
runScript({ |
9097 |
|
.code = R"NKSP_CODE( |
9098 |
|
on init |
9099 |
|
declare $foo := 7000ms |
9100 |
|
declare @s := "" & real($foo) |
9101 |
|
exit( @s ) |
9102 |
|
end on |
9103 |
|
)NKSP_CODE", |
9104 |
|
.expectStringExitResult = "7000ms", |
9105 |
|
}); |
9106 |
|
|
9107 |
|
runScript({ |
9108 |
|
.code = R"NKSP_CODE( |
9109 |
|
on init |
9110 |
|
declare $foo := 700ms |
9111 |
|
exit( real($foo) / 7.0 ) |
9112 |
|
end on |
9113 |
|
)NKSP_CODE", |
9114 |
|
.expectRealExitResult = 100.0, |
9115 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
9116 |
|
.expectExitResultUnit = VM_SECOND |
9117 |
|
}); |
9118 |
|
|
9119 |
|
runScript({ |
9120 |
|
.code = R"NKSP_CODE( |
9121 |
|
on init |
9122 |
|
declare $foo := 700ms |
9123 |
|
exit( real($foo) / 7.0 & "" ) |
9124 |
|
end on |
9125 |
|
)NKSP_CODE", |
9126 |
|
.expectStringExitResult = "100ms" |
9127 |
|
}); |
9128 |
|
|
9129 |
// 'final' ('!') operator tests ... |
// 'final' ('!') operator tests ... |
9130 |
|
|
9131 |
runScript({ |
runScript({ |
9193 |
.expectExitResultUnit = VM_BEL |
.expectExitResultUnit = VM_BEL |
9194 |
}); |
}); |
9195 |
|
|
9196 |
|
runScript({ |
9197 |
|
.code = R"NKSP_CODE( |
9198 |
|
on init |
9199 |
|
declare ~foo := 9000.0us |
9200 |
|
exit( real_to_int(~foo) ) |
9201 |
|
end on |
9202 |
|
)NKSP_CODE", |
9203 |
|
.expectIntExitResult = 9000.0, |
9204 |
|
.expectExitResultUnitPrefix = { VM_MICRO }, |
9205 |
|
.expectExitResultUnit = VM_SECOND |
9206 |
|
}); |
9207 |
|
|
9208 |
|
runScript({ |
9209 |
|
.code = R"NKSP_CODE( |
9210 |
|
on init |
9211 |
|
declare ~foo := 9000.0us |
9212 |
|
declare @s := "" & real_to_int(~foo) |
9213 |
|
exit( @s ) |
9214 |
|
end on |
9215 |
|
)NKSP_CODE", |
9216 |
|
.expectStringExitResult = "9000us", |
9217 |
|
}); |
9218 |
|
|
9219 |
|
runScript({ |
9220 |
|
.code = R"NKSP_CODE( |
9221 |
|
on init |
9222 |
|
declare ~foo := 700.0ms |
9223 |
|
exit( real_to_int(~foo) / 7 ) |
9224 |
|
end on |
9225 |
|
)NKSP_CODE", |
9226 |
|
.expectIntExitResult = 100, |
9227 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
9228 |
|
.expectExitResultUnit = VM_SECOND |
9229 |
|
}); |
9230 |
|
|
9231 |
|
runScript({ |
9232 |
|
.code = R"NKSP_CODE( |
9233 |
|
on init |
9234 |
|
declare ~foo := 700.0ms |
9235 |
|
exit( real_to_int(~foo) / 7 & "" ) |
9236 |
|
end on |
9237 |
|
)NKSP_CODE", |
9238 |
|
.expectStringExitResult = "100ms" |
9239 |
|
}); |
9240 |
|
|
9241 |
// 'final' ('!') operator tests ... |
// 'final' ('!') operator tests ... |
9242 |
|
|
9243 |
runScript({ |
runScript({ |
9305 |
.expectExitResultUnit = VM_BEL |
.expectExitResultUnit = VM_BEL |
9306 |
}); |
}); |
9307 |
|
|
9308 |
|
runScript({ |
9309 |
|
.code = R"NKSP_CODE( |
9310 |
|
on init |
9311 |
|
declare ~foo := 9000.0us |
9312 |
|
exit( int(~foo) ) |
9313 |
|
end on |
9314 |
|
)NKSP_CODE", |
9315 |
|
.expectIntExitResult = 9000.0, |
9316 |
|
.expectExitResultUnitPrefix = { VM_MICRO }, |
9317 |
|
.expectExitResultUnit = VM_SECOND |
9318 |
|
}); |
9319 |
|
|
9320 |
|
runScript({ |
9321 |
|
.code = R"NKSP_CODE( |
9322 |
|
on init |
9323 |
|
declare ~foo := 9000.0us |
9324 |
|
declare @s := "" & int(~foo) |
9325 |
|
exit( @s ) |
9326 |
|
end on |
9327 |
|
)NKSP_CODE", |
9328 |
|
.expectStringExitResult = "9000us", |
9329 |
|
}); |
9330 |
|
|
9331 |
|
runScript({ |
9332 |
|
.code = R"NKSP_CODE( |
9333 |
|
on init |
9334 |
|
declare ~foo := 700.0ms |
9335 |
|
exit( int(~foo) / 7 ) |
9336 |
|
end on |
9337 |
|
)NKSP_CODE", |
9338 |
|
.expectIntExitResult = 100, |
9339 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
9340 |
|
.expectExitResultUnit = VM_SECOND |
9341 |
|
}); |
9342 |
|
|
9343 |
|
runScript({ |
9344 |
|
.code = R"NKSP_CODE( |
9345 |
|
on init |
9346 |
|
declare ~foo := 700.0ms |
9347 |
|
exit( int(~foo) / 7 & "" ) |
9348 |
|
end on |
9349 |
|
)NKSP_CODE", |
9350 |
|
.expectStringExitResult = "100ms" |
9351 |
|
}); |
9352 |
|
|
9353 |
// 'final' ('!') operator tests ... |
// 'final' ('!') operator tests ... |
9354 |
|
|
9355 |
runScript({ |
runScript({ |
9885 |
#endif |
#endif |
9886 |
} |
} |
9887 |
|
|
9888 |
|
static void testBuiltInRoundFunction() { |
9889 |
|
#if !SILENT_TEST |
9890 |
|
std::cout << "UNIT TEST: built-in round() function\n"; |
9891 |
|
#endif |
9892 |
|
|
9893 |
|
// integer tests ... |
9894 |
|
// (ATM not allowed for this function) |
9895 |
|
|
9896 |
|
runScript({ |
9897 |
|
.code = R"NKSP_CODE( |
9898 |
|
on init |
9899 |
|
declare $foo := 1 |
9900 |
|
exit( round($foo) ) |
9901 |
|
end on |
9902 |
|
)NKSP_CODE", |
9903 |
|
.expectParseError = true // integer not allowed for this function ATM |
9904 |
|
}); |
9905 |
|
|
9906 |
|
// real number tests ... |
9907 |
|
|
9908 |
|
runScript({ |
9909 |
|
.code = R"NKSP_CODE( |
9910 |
|
on init |
9911 |
|
exit( round(99.4) ) |
9912 |
|
end on |
9913 |
|
)NKSP_CODE", |
9914 |
|
.expectRealExitResult = 99.0 |
9915 |
|
}); |
9916 |
|
|
9917 |
|
runScript({ |
9918 |
|
.code = R"NKSP_CODE( |
9919 |
|
on init |
9920 |
|
exit( round(99.5) ) |
9921 |
|
end on |
9922 |
|
)NKSP_CODE", |
9923 |
|
.expectRealExitResult = 100.0 |
9924 |
|
}); |
9925 |
|
|
9926 |
|
// std unit tests ... |
9927 |
|
|
9928 |
|
runScript({ |
9929 |
|
.code = R"NKSP_CODE( |
9930 |
|
on init |
9931 |
|
exit( round(2.4ms) ) |
9932 |
|
end on |
9933 |
|
)NKSP_CODE", |
9934 |
|
.expectRealExitResult = 2.0, |
9935 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
9936 |
|
.expectExitResultUnit = VM_SECOND |
9937 |
|
}); |
9938 |
|
|
9939 |
|
runScript({ |
9940 |
|
.code = R"NKSP_CODE( |
9941 |
|
on init |
9942 |
|
exit( round(2.6kHz) ) |
9943 |
|
end on |
9944 |
|
)NKSP_CODE", |
9945 |
|
.expectRealExitResult = 3.0, |
9946 |
|
.expectExitResultUnitPrefix = { VM_KILO }, |
9947 |
|
.expectExitResultUnit = VM_HERTZ |
9948 |
|
}); |
9949 |
|
|
9950 |
|
// 'final' ('!') operator tests ... |
9951 |
|
|
9952 |
|
runScript({ |
9953 |
|
.code = R"NKSP_CODE( |
9954 |
|
on init |
9955 |
|
exit( round(123.8) ) |
9956 |
|
end on |
9957 |
|
)NKSP_CODE", |
9958 |
|
.expectRealExitResult = 124.0, |
9959 |
|
.expectExitResultFinal = false |
9960 |
|
}); |
9961 |
|
|
9962 |
|
runScript({ |
9963 |
|
.code = R"NKSP_CODE( |
9964 |
|
on init |
9965 |
|
exit( round(!123.8) ) |
9966 |
|
end on |
9967 |
|
)NKSP_CODE", |
9968 |
|
.expectRealExitResult = 124.0, |
9969 |
|
.expectExitResultFinal = true |
9970 |
|
}); |
9971 |
|
|
9972 |
|
#if !SILENT_TEST |
9973 |
|
std::cout << std::endl; |
9974 |
|
#endif |
9975 |
|
} |
9976 |
|
|
9977 |
|
static void testBuiltInCeilFunction() { |
9978 |
|
#if !SILENT_TEST |
9979 |
|
std::cout << "UNIT TEST: built-in ceil() function\n"; |
9980 |
|
#endif |
9981 |
|
|
9982 |
|
// integer tests ... |
9983 |
|
// (ATM not allowed for this function) |
9984 |
|
|
9985 |
|
runScript({ |
9986 |
|
.code = R"NKSP_CODE( |
9987 |
|
on init |
9988 |
|
declare $foo := 1 |
9989 |
|
exit( ceil($foo) ) |
9990 |
|
end on |
9991 |
|
)NKSP_CODE", |
9992 |
|
.expectParseError = true // integer not allowed for this function ATM |
9993 |
|
}); |
9994 |
|
|
9995 |
|
// real number tests ... |
9996 |
|
|
9997 |
|
runScript({ |
9998 |
|
.code = R"NKSP_CODE( |
9999 |
|
on init |
10000 |
|
exit( ceil(99.0) ) |
10001 |
|
end on |
10002 |
|
)NKSP_CODE", |
10003 |
|
.expectRealExitResult = 99.0 |
10004 |
|
}); |
10005 |
|
|
10006 |
|
runScript({ |
10007 |
|
.code = R"NKSP_CODE( |
10008 |
|
on init |
10009 |
|
exit( ceil(99.1) ) |
10010 |
|
end on |
10011 |
|
)NKSP_CODE", |
10012 |
|
.expectRealExitResult = 100.0 |
10013 |
|
}); |
10014 |
|
|
10015 |
|
runScript({ |
10016 |
|
.code = R"NKSP_CODE( |
10017 |
|
on init |
10018 |
|
exit( ceil(99.9) ) |
10019 |
|
end on |
10020 |
|
)NKSP_CODE", |
10021 |
|
.expectRealExitResult = 100.0 |
10022 |
|
}); |
10023 |
|
|
10024 |
|
// std unit tests ... |
10025 |
|
|
10026 |
|
runScript({ |
10027 |
|
.code = R"NKSP_CODE( |
10028 |
|
on init |
10029 |
|
exit( ceil(2.4ms) ) |
10030 |
|
end on |
10031 |
|
)NKSP_CODE", |
10032 |
|
.expectRealExitResult = 3.0, |
10033 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
10034 |
|
.expectExitResultUnit = VM_SECOND |
10035 |
|
}); |
10036 |
|
|
10037 |
|
runScript({ |
10038 |
|
.code = R"NKSP_CODE( |
10039 |
|
on init |
10040 |
|
exit( ceil(2.6kHz) ) |
10041 |
|
end on |
10042 |
|
)NKSP_CODE", |
10043 |
|
.expectRealExitResult = 3.0, |
10044 |
|
.expectExitResultUnitPrefix = { VM_KILO }, |
10045 |
|
.expectExitResultUnit = VM_HERTZ |
10046 |
|
}); |
10047 |
|
|
10048 |
|
runScript({ |
10049 |
|
.code = R"NKSP_CODE( |
10050 |
|
on init |
10051 |
|
exit( ceil(9.4ms / 2.0) ) |
10052 |
|
end on |
10053 |
|
)NKSP_CODE", |
10054 |
|
.expectRealExitResult = 5.0, |
10055 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
10056 |
|
.expectExitResultUnit = VM_SECOND |
10057 |
|
}); |
10058 |
|
|
10059 |
|
runScript({ |
10060 |
|
.code = R"NKSP_CODE( |
10061 |
|
on init |
10062 |
|
exit( ceil( ceil(8.4us) / 2.0) ) |
10063 |
|
end on |
10064 |
|
)NKSP_CODE", |
10065 |
|
.expectRealExitResult = 5.0, |
10066 |
|
.expectExitResultUnitPrefix = { VM_MICRO }, |
10067 |
|
.expectExitResultUnit = VM_SECOND |
10068 |
|
}); |
10069 |
|
|
10070 |
|
// 'final' ('!') operator tests ... |
10071 |
|
|
10072 |
|
runScript({ |
10073 |
|
.code = R"NKSP_CODE( |
10074 |
|
on init |
10075 |
|
exit( ceil(123.1) ) |
10076 |
|
end on |
10077 |
|
)NKSP_CODE", |
10078 |
|
.expectRealExitResult = 124.0, |
10079 |
|
.expectExitResultFinal = false |
10080 |
|
}); |
10081 |
|
|
10082 |
|
runScript({ |
10083 |
|
.code = R"NKSP_CODE( |
10084 |
|
on init |
10085 |
|
exit( ceil(!123.8) ) |
10086 |
|
end on |
10087 |
|
)NKSP_CODE", |
10088 |
|
.expectRealExitResult = 124.0, |
10089 |
|
.expectExitResultFinal = true |
10090 |
|
}); |
10091 |
|
|
10092 |
|
#if !SILENT_TEST |
10093 |
|
std::cout << std::endl; |
10094 |
|
#endif |
10095 |
|
} |
10096 |
|
|
10097 |
|
static void testBuiltInFloorFunction() { |
10098 |
|
#if !SILENT_TEST |
10099 |
|
std::cout << "UNIT TEST: built-in floor() function\n"; |
10100 |
|
#endif |
10101 |
|
|
10102 |
|
// integer tests ... |
10103 |
|
// (ATM not allowed for this function) |
10104 |
|
|
10105 |
|
runScript({ |
10106 |
|
.code = R"NKSP_CODE( |
10107 |
|
on init |
10108 |
|
declare $foo := 1 |
10109 |
|
exit( floor($foo) ) |
10110 |
|
end on |
10111 |
|
)NKSP_CODE", |
10112 |
|
.expectParseError = true // integer not allowed for this function ATM |
10113 |
|
}); |
10114 |
|
|
10115 |
|
// real number tests ... |
10116 |
|
|
10117 |
|
runScript({ |
10118 |
|
.code = R"NKSP_CODE( |
10119 |
|
on init |
10120 |
|
exit( floor(99.0) ) |
10121 |
|
end on |
10122 |
|
)NKSP_CODE", |
10123 |
|
.expectRealExitResult = 99.0 |
10124 |
|
}); |
10125 |
|
|
10126 |
|
runScript({ |
10127 |
|
.code = R"NKSP_CODE( |
10128 |
|
on init |
10129 |
|
exit( floor(99.1) ) |
10130 |
|
end on |
10131 |
|
)NKSP_CODE", |
10132 |
|
.expectRealExitResult = 99.0 |
10133 |
|
}); |
10134 |
|
|
10135 |
|
runScript({ |
10136 |
|
.code = R"NKSP_CODE( |
10137 |
|
on init |
10138 |
|
exit( floor(99.9) ) |
10139 |
|
end on |
10140 |
|
)NKSP_CODE", |
10141 |
|
.expectRealExitResult = 99.0 |
10142 |
|
}); |
10143 |
|
|
10144 |
|
// std unit tests ... |
10145 |
|
|
10146 |
|
runScript({ |
10147 |
|
.code = R"NKSP_CODE( |
10148 |
|
on init |
10149 |
|
exit( floor(2.4ms) ) |
10150 |
|
end on |
10151 |
|
)NKSP_CODE", |
10152 |
|
.expectRealExitResult = 2.0, |
10153 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
10154 |
|
.expectExitResultUnit = VM_SECOND |
10155 |
|
}); |
10156 |
|
|
10157 |
|
runScript({ |
10158 |
|
.code = R"NKSP_CODE( |
10159 |
|
on init |
10160 |
|
exit( floor(2.6kHz) ) |
10161 |
|
end on |
10162 |
|
)NKSP_CODE", |
10163 |
|
.expectRealExitResult = 2.0, |
10164 |
|
.expectExitResultUnitPrefix = { VM_KILO }, |
10165 |
|
.expectExitResultUnit = VM_HERTZ |
10166 |
|
}); |
10167 |
|
|
10168 |
|
runScript({ |
10169 |
|
.code = R"NKSP_CODE( |
10170 |
|
on init |
10171 |
|
exit( floor(4.4ms / 2.0) ) |
10172 |
|
end on |
10173 |
|
)NKSP_CODE", |
10174 |
|
.expectRealExitResult = 2.0, |
10175 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
10176 |
|
.expectExitResultUnit = VM_SECOND |
10177 |
|
}); |
10178 |
|
|
10179 |
|
runScript({ |
10180 |
|
.code = R"NKSP_CODE( |
10181 |
|
on init |
10182 |
|
exit( floor( floor(8.4us) / 4.0) ) |
10183 |
|
end on |
10184 |
|
)NKSP_CODE", |
10185 |
|
.expectRealExitResult = 2.0, |
10186 |
|
.expectExitResultUnitPrefix = { VM_MICRO }, |
10187 |
|
.expectExitResultUnit = VM_SECOND |
10188 |
|
}); |
10189 |
|
|
10190 |
|
// 'final' ('!') operator tests ... |
10191 |
|
|
10192 |
|
runScript({ |
10193 |
|
.code = R"NKSP_CODE( |
10194 |
|
on init |
10195 |
|
exit( floor(123.1) ) |
10196 |
|
end on |
10197 |
|
)NKSP_CODE", |
10198 |
|
.expectRealExitResult = 123.0, |
10199 |
|
.expectExitResultFinal = false |
10200 |
|
}); |
10201 |
|
|
10202 |
|
runScript({ |
10203 |
|
.code = R"NKSP_CODE( |
10204 |
|
on init |
10205 |
|
exit( floor(!123.8) ) |
10206 |
|
end on |
10207 |
|
)NKSP_CODE", |
10208 |
|
.expectRealExitResult = 123.0, |
10209 |
|
.expectExitResultFinal = true |
10210 |
|
}); |
10211 |
|
|
10212 |
|
#if !SILENT_TEST |
10213 |
|
std::cout << std::endl; |
10214 |
|
#endif |
10215 |
|
} |
10216 |
|
|
10217 |
|
static void testBuiltInSqrtFunction() { |
10218 |
|
#if !SILENT_TEST |
10219 |
|
std::cout << "UNIT TEST: built-in sqrt() function\n"; |
10220 |
|
#endif |
10221 |
|
|
10222 |
|
// integer tests ... |
10223 |
|
// (ATM not allowed for this function) |
10224 |
|
|
10225 |
|
runScript({ |
10226 |
|
.code = R"NKSP_CODE( |
10227 |
|
on init |
10228 |
|
declare $foo := 1 |
10229 |
|
exit( sqrt($foo) ) |
10230 |
|
end on |
10231 |
|
)NKSP_CODE", |
10232 |
|
.expectParseError = true // integer not allowed for this function ATM |
10233 |
|
}); |
10234 |
|
|
10235 |
|
// real number tests ... |
10236 |
|
|
10237 |
|
runScript({ |
10238 |
|
.code = R"NKSP_CODE( |
10239 |
|
on init |
10240 |
|
exit( sqrt(36.0) ) |
10241 |
|
end on |
10242 |
|
)NKSP_CODE", |
10243 |
|
.expectRealExitResult = 6.0 |
10244 |
|
}); |
10245 |
|
|
10246 |
|
// std unit tests ... |
10247 |
|
|
10248 |
|
runScript({ |
10249 |
|
.code = R"NKSP_CODE( |
10250 |
|
on init |
10251 |
|
exit( sqrt(100.0ms) ) |
10252 |
|
end on |
10253 |
|
)NKSP_CODE", |
10254 |
|
.expectRealExitResult = 10.0, |
10255 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
10256 |
|
.expectExitResultUnit = VM_SECOND |
10257 |
|
}); |
10258 |
|
|
10259 |
|
runScript({ |
10260 |
|
.code = R"NKSP_CODE( |
10261 |
|
on init |
10262 |
|
exit( sqrt(5.76kHz) ) |
10263 |
|
end on |
10264 |
|
)NKSP_CODE", |
10265 |
|
.expectRealExitResult = 2.4, |
10266 |
|
.expectExitResultUnitPrefix = { VM_KILO }, |
10267 |
|
.expectExitResultUnit = VM_HERTZ |
10268 |
|
}); |
10269 |
|
|
10270 |
|
// 'final' ('!') operator tests ... |
10271 |
|
|
10272 |
|
runScript({ |
10273 |
|
.code = R"NKSP_CODE( |
10274 |
|
on init |
10275 |
|
exit( sqrt(25.0) ) |
10276 |
|
end on |
10277 |
|
)NKSP_CODE", |
10278 |
|
.expectRealExitResult = 5.0, |
10279 |
|
.expectExitResultFinal = false |
10280 |
|
}); |
10281 |
|
|
10282 |
|
runScript({ |
10283 |
|
.code = R"NKSP_CODE( |
10284 |
|
on init |
10285 |
|
exit( sqrt(!25.0) ) |
10286 |
|
end on |
10287 |
|
)NKSP_CODE", |
10288 |
|
.expectRealExitResult = 5.0, |
10289 |
|
.expectExitResultFinal = true |
10290 |
|
}); |
10291 |
|
|
10292 |
|
#if !SILENT_TEST |
10293 |
|
std::cout << std::endl; |
10294 |
|
#endif |
10295 |
|
} |
10296 |
|
|
10297 |
|
static void testBuiltInLogFunction() { |
10298 |
|
#if !SILENT_TEST |
10299 |
|
std::cout << "UNIT TEST: built-in log() function\n"; |
10300 |
|
#endif |
10301 |
|
|
10302 |
|
// integer tests ... |
10303 |
|
// (ATM not allowed for this function) |
10304 |
|
|
10305 |
|
runScript({ |
10306 |
|
.code = R"NKSP_CODE( |
10307 |
|
on init |
10308 |
|
declare $foo := 1 |
10309 |
|
exit( log($foo) ) |
10310 |
|
end on |
10311 |
|
)NKSP_CODE", |
10312 |
|
.expectParseError = true // integer not allowed for this function ATM |
10313 |
|
}); |
10314 |
|
|
10315 |
|
// real number tests ... |
10316 |
|
|
10317 |
|
runScript({ |
10318 |
|
.code = R"NKSP_CODE( |
10319 |
|
on init |
10320 |
|
exit( log(1.0) ) |
10321 |
|
end on |
10322 |
|
)NKSP_CODE", |
10323 |
|
.expectRealExitResult = 0.0 |
10324 |
|
}); |
10325 |
|
|
10326 |
|
runScript({ |
10327 |
|
.code = R"NKSP_CODE( |
10328 |
|
on init |
10329 |
|
exit( log(~NI_MATH_E) ) |
10330 |
|
end on |
10331 |
|
)NKSP_CODE", |
10332 |
|
.expectRealExitResult = 1.0 |
10333 |
|
}); |
10334 |
|
|
10335 |
|
// std unit tests ... |
10336 |
|
|
10337 |
|
runScript({ |
10338 |
|
.code = R"NKSP_CODE( |
10339 |
|
on init |
10340 |
|
exit( log(~NI_MATH_E * 1.0ms) ) |
10341 |
|
end on |
10342 |
|
)NKSP_CODE", |
10343 |
|
.expectRealExitResult = 1.0, |
10344 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
10345 |
|
.expectExitResultUnit = VM_SECOND |
10346 |
|
}); |
10347 |
|
|
10348 |
|
runScript({ |
10349 |
|
.code = R"NKSP_CODE( |
10350 |
|
on init |
10351 |
|
exit( log(~NI_MATH_E * 1.0kHz) ) |
10352 |
|
end on |
10353 |
|
)NKSP_CODE", |
10354 |
|
.expectRealExitResult = 1.0, |
10355 |
|
.expectExitResultUnitPrefix = { VM_KILO }, |
10356 |
|
.expectExitResultUnit = VM_HERTZ |
10357 |
|
}); |
10358 |
|
|
10359 |
|
// 'final' ('!') operator tests ... |
10360 |
|
|
10361 |
|
runScript({ |
10362 |
|
.code = R"NKSP_CODE( |
10363 |
|
on init |
10364 |
|
exit( log(~NI_MATH_E * 1.0) ) |
10365 |
|
end on |
10366 |
|
)NKSP_CODE", |
10367 |
|
.expectRealExitResult = 1.0, |
10368 |
|
.expectExitResultFinal = false |
10369 |
|
}); |
10370 |
|
|
10371 |
|
runScript({ |
10372 |
|
.code = R"NKSP_CODE( |
10373 |
|
on init |
10374 |
|
exit( log(!(~NI_MATH_E * 1.0)) ) |
10375 |
|
end on |
10376 |
|
)NKSP_CODE", |
10377 |
|
.expectRealExitResult = 1.0, |
10378 |
|
.expectExitResultFinal = true |
10379 |
|
}); |
10380 |
|
|
10381 |
|
#if !SILENT_TEST |
10382 |
|
std::cout << std::endl; |
10383 |
|
#endif |
10384 |
|
} |
10385 |
|
|
10386 |
|
static void testBuiltInLog2Function() { |
10387 |
|
#if !SILENT_TEST |
10388 |
|
std::cout << "UNIT TEST: built-in log2() function\n"; |
10389 |
|
#endif |
10390 |
|
|
10391 |
|
// integer tests ... |
10392 |
|
// (ATM not allowed for this function) |
10393 |
|
|
10394 |
|
runScript({ |
10395 |
|
.code = R"NKSP_CODE( |
10396 |
|
on init |
10397 |
|
declare $foo := 1 |
10398 |
|
exit( log2($foo) ) |
10399 |
|
end on |
10400 |
|
)NKSP_CODE", |
10401 |
|
.expectParseError = true // integer not allowed for this function ATM |
10402 |
|
}); |
10403 |
|
|
10404 |
|
// real number tests ... |
10405 |
|
|
10406 |
|
runScript({ |
10407 |
|
.code = R"NKSP_CODE( |
10408 |
|
on init |
10409 |
|
exit( log2(1.0) ) |
10410 |
|
end on |
10411 |
|
)NKSP_CODE", |
10412 |
|
.expectRealExitResult = 0.0 |
10413 |
|
}); |
10414 |
|
|
10415 |
|
runScript({ |
10416 |
|
.code = R"NKSP_CODE( |
10417 |
|
on init |
10418 |
|
exit( log2(32.0) ) |
10419 |
|
end on |
10420 |
|
)NKSP_CODE", |
10421 |
|
.expectRealExitResult = 5.0 |
10422 |
|
}); |
10423 |
|
|
10424 |
|
// std unit tests ... |
10425 |
|
|
10426 |
|
runScript({ |
10427 |
|
.code = R"NKSP_CODE( |
10428 |
|
on init |
10429 |
|
exit( log2(32.0ms) ) |
10430 |
|
end on |
10431 |
|
)NKSP_CODE", |
10432 |
|
.expectRealExitResult = 5.0, |
10433 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
10434 |
|
.expectExitResultUnit = VM_SECOND |
10435 |
|
}); |
10436 |
|
|
10437 |
|
runScript({ |
10438 |
|
.code = R"NKSP_CODE( |
10439 |
|
on init |
10440 |
|
exit( log2(32.0kHz) ) |
10441 |
|
end on |
10442 |
|
)NKSP_CODE", |
10443 |
|
.expectRealExitResult = 5.0, |
10444 |
|
.expectExitResultUnitPrefix = { VM_KILO }, |
10445 |
|
.expectExitResultUnit = VM_HERTZ |
10446 |
|
}); |
10447 |
|
|
10448 |
|
// 'final' ('!') operator tests ... |
10449 |
|
|
10450 |
|
runScript({ |
10451 |
|
.code = R"NKSP_CODE( |
10452 |
|
on init |
10453 |
|
exit( log2(32.0) ) |
10454 |
|
end on |
10455 |
|
)NKSP_CODE", |
10456 |
|
.expectRealExitResult = 5.0, |
10457 |
|
.expectExitResultFinal = false |
10458 |
|
}); |
10459 |
|
|
10460 |
|
runScript({ |
10461 |
|
.code = R"NKSP_CODE( |
10462 |
|
on init |
10463 |
|
exit( log2(!32.0) ) |
10464 |
|
end on |
10465 |
|
)NKSP_CODE", |
10466 |
|
.expectRealExitResult = 5.0, |
10467 |
|
.expectExitResultFinal = true |
10468 |
|
}); |
10469 |
|
|
10470 |
|
#if !SILENT_TEST |
10471 |
|
std::cout << std::endl; |
10472 |
|
#endif |
10473 |
|
} |
10474 |
|
|
10475 |
|
static void testBuiltInLog10Function() { |
10476 |
|
#if !SILENT_TEST |
10477 |
|
std::cout << "UNIT TEST: built-in log10() function\n"; |
10478 |
|
#endif |
10479 |
|
|
10480 |
|
// integer tests ... |
10481 |
|
// (ATM not allowed for this function) |
10482 |
|
|
10483 |
|
runScript({ |
10484 |
|
.code = R"NKSP_CODE( |
10485 |
|
on init |
10486 |
|
declare $foo := 1 |
10487 |
|
exit( log10($foo) ) |
10488 |
|
end on |
10489 |
|
)NKSP_CODE", |
10490 |
|
.expectParseError = true // integer not allowed for this function ATM |
10491 |
|
}); |
10492 |
|
|
10493 |
|
// real number tests ... |
10494 |
|
|
10495 |
|
runScript({ |
10496 |
|
.code = R"NKSP_CODE( |
10497 |
|
on init |
10498 |
|
exit( log10(1000.0) ) |
10499 |
|
end on |
10500 |
|
)NKSP_CODE", |
10501 |
|
.expectRealExitResult = 3.0 |
10502 |
|
}); |
10503 |
|
|
10504 |
|
runScript({ |
10505 |
|
.code = R"NKSP_CODE( |
10506 |
|
on init |
10507 |
|
exit( log10(1000.0) ) |
10508 |
|
end on |
10509 |
|
)NKSP_CODE", |
10510 |
|
.expectRealExitResult = 3.0 |
10511 |
|
}); |
10512 |
|
|
10513 |
|
// std unit tests ... |
10514 |
|
|
10515 |
|
runScript({ |
10516 |
|
.code = R"NKSP_CODE( |
10517 |
|
on init |
10518 |
|
exit( log10(1000.0ms) ) |
10519 |
|
end on |
10520 |
|
)NKSP_CODE", |
10521 |
|
.expectRealExitResult = 3.0, |
10522 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
10523 |
|
.expectExitResultUnit = VM_SECOND |
10524 |
|
}); |
10525 |
|
|
10526 |
|
runScript({ |
10527 |
|
.code = R"NKSP_CODE( |
10528 |
|
on init |
10529 |
|
exit( log10(1000.0kHz) ) |
10530 |
|
end on |
10531 |
|
)NKSP_CODE", |
10532 |
|
.expectRealExitResult = 3.0, |
10533 |
|
.expectExitResultUnitPrefix = { VM_KILO }, |
10534 |
|
.expectExitResultUnit = VM_HERTZ |
10535 |
|
}); |
10536 |
|
|
10537 |
|
// 'final' ('!') operator tests ... |
10538 |
|
|
10539 |
|
runScript({ |
10540 |
|
.code = R"NKSP_CODE( |
10541 |
|
on init |
10542 |
|
exit( log10(1000.0) ) |
10543 |
|
end on |
10544 |
|
)NKSP_CODE", |
10545 |
|
.expectRealExitResult = 3.0, |
10546 |
|
.expectExitResultFinal = false |
10547 |
|
}); |
10548 |
|
|
10549 |
|
runScript({ |
10550 |
|
.code = R"NKSP_CODE( |
10551 |
|
on init |
10552 |
|
exit( log10(!1000.0) ) |
10553 |
|
end on |
10554 |
|
)NKSP_CODE", |
10555 |
|
.expectRealExitResult = 3.0, |
10556 |
|
.expectExitResultFinal = true |
10557 |
|
}); |
10558 |
|
|
10559 |
|
#if !SILENT_TEST |
10560 |
|
std::cout << std::endl; |
10561 |
|
#endif |
10562 |
|
} |
10563 |
|
|
10564 |
|
static void testBuiltInExpFunction() { |
10565 |
|
#if !SILENT_TEST |
10566 |
|
std::cout << "UNIT TEST: built-in exp() function\n"; |
10567 |
|
#endif |
10568 |
|
|
10569 |
|
// integer tests ... |
10570 |
|
// (ATM not allowed for this function) |
10571 |
|
|
10572 |
|
runScript({ |
10573 |
|
.code = R"NKSP_CODE( |
10574 |
|
on init |
10575 |
|
declare $foo := 1 |
10576 |
|
exit( exp($foo) ) |
10577 |
|
end on |
10578 |
|
)NKSP_CODE", |
10579 |
|
.expectParseError = true // integer not allowed for this function ATM |
10580 |
|
}); |
10581 |
|
|
10582 |
|
// real number tests ... |
10583 |
|
|
10584 |
|
runScript({ |
10585 |
|
.code = R"NKSP_CODE( |
10586 |
|
on init |
10587 |
|
exit( exp(0.0) ) |
10588 |
|
end on |
10589 |
|
)NKSP_CODE", |
10590 |
|
.expectRealExitResult = 1.0 |
10591 |
|
}); |
10592 |
|
|
10593 |
|
runScript({ |
10594 |
|
.code = R"NKSP_CODE( |
10595 |
|
on init |
10596 |
|
exit( exp(1.0) ) |
10597 |
|
end on |
10598 |
|
)NKSP_CODE", |
10599 |
|
.expectRealExitResult = M_E |
10600 |
|
}); |
10601 |
|
|
10602 |
|
// std unit tests ... |
10603 |
|
|
10604 |
|
runScript({ |
10605 |
|
.code = R"NKSP_CODE( |
10606 |
|
on init |
10607 |
|
exit( exp(0.0ms) ) |
10608 |
|
end on |
10609 |
|
)NKSP_CODE", |
10610 |
|
.expectRealExitResult = 1.0, |
10611 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
10612 |
|
.expectExitResultUnit = VM_SECOND |
10613 |
|
}); |
10614 |
|
|
10615 |
|
runScript({ |
10616 |
|
.code = R"NKSP_CODE( |
10617 |
|
on init |
10618 |
|
exit( exp(0.0kHz) ) |
10619 |
|
end on |
10620 |
|
)NKSP_CODE", |
10621 |
|
.expectRealExitResult = 1.0, |
10622 |
|
.expectExitResultUnitPrefix = { VM_KILO }, |
10623 |
|
.expectExitResultUnit = VM_HERTZ |
10624 |
|
}); |
10625 |
|
|
10626 |
|
// 'final' ('!') operator tests ... |
10627 |
|
|
10628 |
|
runScript({ |
10629 |
|
.code = R"NKSP_CODE( |
10630 |
|
on init |
10631 |
|
exit( exp(0.0) ) |
10632 |
|
end on |
10633 |
|
)NKSP_CODE", |
10634 |
|
.expectRealExitResult = 1.0, |
10635 |
|
.expectExitResultFinal = false |
10636 |
|
}); |
10637 |
|
|
10638 |
|
runScript({ |
10639 |
|
.code = R"NKSP_CODE( |
10640 |
|
on init |
10641 |
|
exit( exp(!0.0) ) |
10642 |
|
end on |
10643 |
|
)NKSP_CODE", |
10644 |
|
.expectRealExitResult = 1.0, |
10645 |
|
.expectExitResultFinal = true |
10646 |
|
}); |
10647 |
|
|
10648 |
|
#if !SILENT_TEST |
10649 |
|
std::cout << std::endl; |
10650 |
|
#endif |
10651 |
|
} |
10652 |
|
|
10653 |
|
static void testBuiltInPowFunction() { |
10654 |
|
#if !SILENT_TEST |
10655 |
|
std::cout << "UNIT TEST: built-in pow() function\n"; |
10656 |
|
#endif |
10657 |
|
|
10658 |
|
// integer tests ... |
10659 |
|
// (ATM not allowed for this function) |
10660 |
|
|
10661 |
|
runScript({ |
10662 |
|
.code = R"NKSP_CODE( |
10663 |
|
on init |
10664 |
|
declare $foo := 1 |
10665 |
|
exit( pow($foo,$foo) ) |
10666 |
|
end on |
10667 |
|
)NKSP_CODE", |
10668 |
|
.expectParseError = true // integer not allowed for this function ATM |
10669 |
|
}); |
10670 |
|
|
10671 |
|
// real number tests ... |
10672 |
|
|
10673 |
|
runScript({ |
10674 |
|
.code = R"NKSP_CODE( |
10675 |
|
on init |
10676 |
|
exit( pow(1.0) ) |
10677 |
|
end on |
10678 |
|
)NKSP_CODE", |
10679 |
|
.expectParseError = true // because pow() requires exactly 2 arguments |
10680 |
|
}); |
10681 |
|
|
10682 |
|
runScript({ |
10683 |
|
.code = R"NKSP_CODE( |
10684 |
|
on init |
10685 |
|
exit( pow(3.0,4.0) ) |
10686 |
|
end on |
10687 |
|
)NKSP_CODE", |
10688 |
|
.expectRealExitResult = 81.0 |
10689 |
|
}); |
10690 |
|
|
10691 |
|
// std unit tests ... |
10692 |
|
|
10693 |
|
runScript({ |
10694 |
|
.code = R"NKSP_CODE( |
10695 |
|
on init |
10696 |
|
exit( pow(3.0ms,4.0ms) ) |
10697 |
|
end on |
10698 |
|
)NKSP_CODE", |
10699 |
|
.expectParseError = true // because units are prohibited for 2nd argument |
10700 |
|
}); |
10701 |
|
|
10702 |
|
runScript({ |
10703 |
|
.code = R"NKSP_CODE( |
10704 |
|
on init |
10705 |
|
exit( pow(3.0,4.0ms) ) |
10706 |
|
end on |
10707 |
|
)NKSP_CODE", |
10708 |
|
.expectParseError = true // because units are prohibited for 2nd argument |
10709 |
|
}); |
10710 |
|
|
10711 |
|
runScript({ |
10712 |
|
.code = R"NKSP_CODE( |
10713 |
|
on init |
10714 |
|
exit( pow(3.0ms,4.0) ) |
10715 |
|
end on |
10716 |
|
)NKSP_CODE", |
10717 |
|
.expectRealExitResult = 81.0, |
10718 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
10719 |
|
.expectExitResultUnit = VM_SECOND |
10720 |
|
}); |
10721 |
|
|
10722 |
|
runScript({ |
10723 |
|
.code = R"NKSP_CODE( |
10724 |
|
on init |
10725 |
|
exit( pow(3.0kHz,4.0) ) |
10726 |
|
end on |
10727 |
|
)NKSP_CODE", |
10728 |
|
.expectRealExitResult = 81.0, |
10729 |
|
.expectExitResultUnitPrefix = { VM_KILO }, |
10730 |
|
.expectExitResultUnit = VM_HERTZ |
10731 |
|
}); |
10732 |
|
|
10733 |
|
// 'final' ('!') operator tests ... |
10734 |
|
|
10735 |
|
runScript({ |
10736 |
|
.code = R"NKSP_CODE( |
10737 |
|
on init |
10738 |
|
exit( pow(3.0,4.0) ) |
10739 |
|
end on |
10740 |
|
)NKSP_CODE", |
10741 |
|
.expectRealExitResult = 81.0, |
10742 |
|
.expectExitResultFinal = false |
10743 |
|
}); |
10744 |
|
|
10745 |
|
runScript({ |
10746 |
|
.code = R"NKSP_CODE( |
10747 |
|
on init |
10748 |
|
exit( pow(!3.0,4.0) ) |
10749 |
|
end on |
10750 |
|
)NKSP_CODE", |
10751 |
|
.expectRealExitResult = 81.0, |
10752 |
|
.expectExitResultFinal = true |
10753 |
|
}); |
10754 |
|
|
10755 |
|
runScript({ |
10756 |
|
.code = R"NKSP_CODE( |
10757 |
|
on init |
10758 |
|
exit( pow(3.0,!4.0) ) |
10759 |
|
end on |
10760 |
|
)NKSP_CODE", |
10761 |
|
.expectParseError = true // because 'final' is meaningless for 2nd argument |
10762 |
|
}); |
10763 |
|
|
10764 |
|
#if !SILENT_TEST |
10765 |
|
std::cout << std::endl; |
10766 |
|
#endif |
10767 |
|
} |
10768 |
|
|
10769 |
|
static void testBuiltInSinFunction() { |
10770 |
|
#if !SILENT_TEST |
10771 |
|
std::cout << "UNIT TEST: built-in sin() function\n"; |
10772 |
|
#endif |
10773 |
|
|
10774 |
|
// integer tests ... |
10775 |
|
// (ATM not allowed for this function) |
10776 |
|
|
10777 |
|
runScript({ |
10778 |
|
.code = R"NKSP_CODE( |
10779 |
|
on init |
10780 |
|
declare $foo := 1 |
10781 |
|
exit( sin($foo) ) |
10782 |
|
end on |
10783 |
|
)NKSP_CODE", |
10784 |
|
.expectParseError = true // integer not allowed for this function ATM |
10785 |
|
}); |
10786 |
|
|
10787 |
|
// real number tests ... |
10788 |
|
|
10789 |
|
runScript({ |
10790 |
|
.code = R"NKSP_CODE( |
10791 |
|
on init |
10792 |
|
exit( sin(0.0) ) |
10793 |
|
end on |
10794 |
|
)NKSP_CODE", |
10795 |
|
.expectRealExitResult = 0.0 |
10796 |
|
}); |
10797 |
|
|
10798 |
|
runScript({ |
10799 |
|
.code = R"NKSP_CODE( |
10800 |
|
on init |
10801 |
|
exit( sin(0.5 * ~NI_MATH_PI) ) |
10802 |
|
end on |
10803 |
|
)NKSP_CODE", |
10804 |
|
.expectRealExitResult = 1.0 |
10805 |
|
}); |
10806 |
|
|
10807 |
|
runScript({ |
10808 |
|
.code = R"NKSP_CODE( |
10809 |
|
on init |
10810 |
|
exit( sin(~NI_MATH_PI) ) |
10811 |
|
end on |
10812 |
|
)NKSP_CODE", |
10813 |
|
.expectRealExitResult = 0.0 |
10814 |
|
}); |
10815 |
|
|
10816 |
|
runScript({ |
10817 |
|
.code = R"NKSP_CODE( |
10818 |
|
on init |
10819 |
|
exit( sin(1.5 * ~NI_MATH_PI) ) |
10820 |
|
end on |
10821 |
|
)NKSP_CODE", |
10822 |
|
.expectRealExitResult = -1.0 |
10823 |
|
}); |
10824 |
|
|
10825 |
|
// std unit tests ... |
10826 |
|
|
10827 |
|
runScript({ |
10828 |
|
.code = R"NKSP_CODE( |
10829 |
|
on init |
10830 |
|
exit( sin(0.0ms) ) |
10831 |
|
end on |
10832 |
|
)NKSP_CODE", |
10833 |
|
.expectRealExitResult = 0.0, |
10834 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
10835 |
|
.expectExitResultUnit = VM_SECOND |
10836 |
|
}); |
10837 |
|
|
10838 |
|
runScript({ |
10839 |
|
.code = R"NKSP_CODE( |
10840 |
|
on init |
10841 |
|
exit( sin(0.0kHz) ) |
10842 |
|
end on |
10843 |
|
)NKSP_CODE", |
10844 |
|
.expectRealExitResult = 0.0, |
10845 |
|
.expectExitResultUnitPrefix = { VM_KILO }, |
10846 |
|
.expectExitResultUnit = VM_HERTZ |
10847 |
|
}); |
10848 |
|
|
10849 |
|
// 'final' ('!') operator tests ... |
10850 |
|
|
10851 |
|
runScript({ |
10852 |
|
.code = R"NKSP_CODE( |
10853 |
|
on init |
10854 |
|
exit( sin(0.0) ) |
10855 |
|
end on |
10856 |
|
)NKSP_CODE", |
10857 |
|
.expectRealExitResult = 0.0, |
10858 |
|
.expectExitResultFinal = false |
10859 |
|
}); |
10860 |
|
|
10861 |
|
runScript({ |
10862 |
|
.code = R"NKSP_CODE( |
10863 |
|
on init |
10864 |
|
exit( sin(!0.0) ) |
10865 |
|
end on |
10866 |
|
)NKSP_CODE", |
10867 |
|
.expectRealExitResult = 0.0, |
10868 |
|
.expectExitResultFinal = true |
10869 |
|
}); |
10870 |
|
|
10871 |
|
#if !SILENT_TEST |
10872 |
|
std::cout << std::endl; |
10873 |
|
#endif |
10874 |
|
} |
10875 |
|
|
10876 |
|
static void testBuiltInCosFunction() { |
10877 |
|
#if !SILENT_TEST |
10878 |
|
std::cout << "UNIT TEST: built-in cos() function\n"; |
10879 |
|
#endif |
10880 |
|
|
10881 |
|
// integer tests ... |
10882 |
|
// (ATM not allowed for this function) |
10883 |
|
|
10884 |
|
runScript({ |
10885 |
|
.code = R"NKSP_CODE( |
10886 |
|
on init |
10887 |
|
declare $foo := 1 |
10888 |
|
exit( cos($foo) ) |
10889 |
|
end on |
10890 |
|
)NKSP_CODE", |
10891 |
|
.expectParseError = true // integer not allowed for this function ATM |
10892 |
|
}); |
10893 |
|
|
10894 |
|
// real number tests ... |
10895 |
|
|
10896 |
|
runScript({ |
10897 |
|
.code = R"NKSP_CODE( |
10898 |
|
on init |
10899 |
|
exit( cos(0.0) ) |
10900 |
|
end on |
10901 |
|
)NKSP_CODE", |
10902 |
|
.expectRealExitResult = 1.0 |
10903 |
|
}); |
10904 |
|
|
10905 |
|
runScript({ |
10906 |
|
.code = R"NKSP_CODE( |
10907 |
|
on init |
10908 |
|
exit( cos(0.5 * ~NI_MATH_PI) ) |
10909 |
|
end on |
10910 |
|
)NKSP_CODE", |
10911 |
|
.expectRealExitResult = 0.0 |
10912 |
|
}); |
10913 |
|
|
10914 |
|
runScript({ |
10915 |
|
.code = R"NKSP_CODE( |
10916 |
|
on init |
10917 |
|
exit( cos(~NI_MATH_PI) ) |
10918 |
|
end on |
10919 |
|
)NKSP_CODE", |
10920 |
|
.expectRealExitResult = -1.0 |
10921 |
|
}); |
10922 |
|
|
10923 |
|
runScript({ |
10924 |
|
.code = R"NKSP_CODE( |
10925 |
|
on init |
10926 |
|
exit( cos(1.5 * ~NI_MATH_PI) ) |
10927 |
|
end on |
10928 |
|
)NKSP_CODE", |
10929 |
|
.expectRealExitResult = 0.0 |
10930 |
|
}); |
10931 |
|
|
10932 |
|
// std unit tests ... |
10933 |
|
|
10934 |
|
runScript({ |
10935 |
|
.code = R"NKSP_CODE( |
10936 |
|
on init |
10937 |
|
exit( cos(0.0ms) ) |
10938 |
|
end on |
10939 |
|
)NKSP_CODE", |
10940 |
|
.expectRealExitResult = 1.0, |
10941 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
10942 |
|
.expectExitResultUnit = VM_SECOND |
10943 |
|
}); |
10944 |
|
|
10945 |
|
runScript({ |
10946 |
|
.code = R"NKSP_CODE( |
10947 |
|
on init |
10948 |
|
exit( cos(0.0kHz) ) |
10949 |
|
end on |
10950 |
|
)NKSP_CODE", |
10951 |
|
.expectRealExitResult = 1.0, |
10952 |
|
.expectExitResultUnitPrefix = { VM_KILO }, |
10953 |
|
.expectExitResultUnit = VM_HERTZ |
10954 |
|
}); |
10955 |
|
|
10956 |
|
// 'final' ('!') operator tests ... |
10957 |
|
|
10958 |
|
runScript({ |
10959 |
|
.code = R"NKSP_CODE( |
10960 |
|
on init |
10961 |
|
exit( cos(0.0) ) |
10962 |
|
end on |
10963 |
|
)NKSP_CODE", |
10964 |
|
.expectRealExitResult = 1.0, |
10965 |
|
.expectExitResultFinal = false |
10966 |
|
}); |
10967 |
|
|
10968 |
|
runScript({ |
10969 |
|
.code = R"NKSP_CODE( |
10970 |
|
on init |
10971 |
|
exit( cos(!0.0) ) |
10972 |
|
end on |
10973 |
|
)NKSP_CODE", |
10974 |
|
.expectRealExitResult = 1.0, |
10975 |
|
.expectExitResultFinal = true |
10976 |
|
}); |
10977 |
|
|
10978 |
|
#if !SILENT_TEST |
10979 |
|
std::cout << std::endl; |
10980 |
|
#endif |
10981 |
|
} |
10982 |
|
|
10983 |
|
static void testBuiltInTanFunction() { |
10984 |
|
#if !SILENT_TEST |
10985 |
|
std::cout << "UNIT TEST: built-in tan() function\n"; |
10986 |
|
#endif |
10987 |
|
|
10988 |
|
// integer tests ... |
10989 |
|
// (ATM not allowed for this function) |
10990 |
|
|
10991 |
|
runScript({ |
10992 |
|
.code = R"NKSP_CODE( |
10993 |
|
on init |
10994 |
|
declare $foo := 1 |
10995 |
|
exit( tan($foo) ) |
10996 |
|
end on |
10997 |
|
)NKSP_CODE", |
10998 |
|
.expectParseError = true // integer not allowed for this function ATM |
10999 |
|
}); |
11000 |
|
|
11001 |
|
// real number tests ... |
11002 |
|
|
11003 |
|
runScript({ |
11004 |
|
.code = R"NKSP_CODE( |
11005 |
|
on init |
11006 |
|
exit( tan(0.0) ) |
11007 |
|
end on |
11008 |
|
)NKSP_CODE", |
11009 |
|
.expectRealExitResult = 0.0 |
11010 |
|
}); |
11011 |
|
|
11012 |
|
runScript({ |
11013 |
|
.code = R"NKSP_CODE( |
11014 |
|
on init |
11015 |
|
exit( tan(0.25 * ~NI_MATH_PI) ) |
11016 |
|
end on |
11017 |
|
)NKSP_CODE", |
11018 |
|
.expectRealExitResult = 1.0 |
11019 |
|
}); |
11020 |
|
|
11021 |
|
// std unit tests ... |
11022 |
|
|
11023 |
|
runScript({ |
11024 |
|
.code = R"NKSP_CODE( |
11025 |
|
on init |
11026 |
|
exit( tan(0.0ms) ) |
11027 |
|
end on |
11028 |
|
)NKSP_CODE", |
11029 |
|
.expectRealExitResult = 0.0, |
11030 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
11031 |
|
.expectExitResultUnit = VM_SECOND |
11032 |
|
}); |
11033 |
|
|
11034 |
|
runScript({ |
11035 |
|
.code = R"NKSP_CODE( |
11036 |
|
on init |
11037 |
|
exit( tan(0.0kHz) ) |
11038 |
|
end on |
11039 |
|
)NKSP_CODE", |
11040 |
|
.expectRealExitResult = 0.0, |
11041 |
|
.expectExitResultUnitPrefix = { VM_KILO }, |
11042 |
|
.expectExitResultUnit = VM_HERTZ |
11043 |
|
}); |
11044 |
|
|
11045 |
|
// 'final' ('!') operator tests ... |
11046 |
|
|
11047 |
|
runScript({ |
11048 |
|
.code = R"NKSP_CODE( |
11049 |
|
on init |
11050 |
|
exit( tan(0.0) ) |
11051 |
|
end on |
11052 |
|
)NKSP_CODE", |
11053 |
|
.expectRealExitResult = 0.0, |
11054 |
|
.expectExitResultFinal = false |
11055 |
|
}); |
11056 |
|
|
11057 |
|
runScript({ |
11058 |
|
.code = R"NKSP_CODE( |
11059 |
|
on init |
11060 |
|
exit( tan(!0.0) ) |
11061 |
|
end on |
11062 |
|
)NKSP_CODE", |
11063 |
|
.expectRealExitResult = 0.0, |
11064 |
|
.expectExitResultFinal = true |
11065 |
|
}); |
11066 |
|
|
11067 |
|
#if !SILENT_TEST |
11068 |
|
std::cout << std::endl; |
11069 |
|
#endif |
11070 |
|
} |
11071 |
|
|
11072 |
|
static void testBuiltInAsinFunction() { |
11073 |
|
#if !SILENT_TEST |
11074 |
|
std::cout << "UNIT TEST: built-in asin() function\n"; |
11075 |
|
#endif |
11076 |
|
|
11077 |
|
// integer tests ... |
11078 |
|
// (ATM not allowed for this function) |
11079 |
|
|
11080 |
|
runScript({ |
11081 |
|
.code = R"NKSP_CODE( |
11082 |
|
on init |
11083 |
|
declare $foo := 1 |
11084 |
|
exit( asin($foo) ) |
11085 |
|
end on |
11086 |
|
)NKSP_CODE", |
11087 |
|
.expectParseError = true // integer not allowed for this function ATM |
11088 |
|
}); |
11089 |
|
|
11090 |
|
// real number tests ... |
11091 |
|
|
11092 |
|
runScript({ |
11093 |
|
.code = R"NKSP_CODE( |
11094 |
|
on init |
11095 |
|
exit( asin(0.0) ) |
11096 |
|
end on |
11097 |
|
)NKSP_CODE", |
11098 |
|
.expectRealExitResult = 0.0 |
11099 |
|
}); |
11100 |
|
|
11101 |
|
runScript({ |
11102 |
|
.code = R"NKSP_CODE( |
11103 |
|
on init |
11104 |
|
exit( asin(1.0) ) |
11105 |
|
end on |
11106 |
|
)NKSP_CODE", |
11107 |
|
.expectRealExitResult = 0.5 * M_PI |
11108 |
|
}); |
11109 |
|
|
11110 |
|
runScript({ |
11111 |
|
.code = R"NKSP_CODE( |
11112 |
|
on init |
11113 |
|
exit( asin(-1.0) ) |
11114 |
|
end on |
11115 |
|
)NKSP_CODE", |
11116 |
|
.expectRealExitResult = -0.5 * M_PI |
11117 |
|
}); |
11118 |
|
|
11119 |
|
// std unit tests ... |
11120 |
|
|
11121 |
|
runScript({ |
11122 |
|
.code = R"NKSP_CODE( |
11123 |
|
on init |
11124 |
|
exit( asin(0.0ms) ) |
11125 |
|
end on |
11126 |
|
)NKSP_CODE", |
11127 |
|
.expectRealExitResult = 0.0, |
11128 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
11129 |
|
.expectExitResultUnit = VM_SECOND |
11130 |
|
}); |
11131 |
|
|
11132 |
|
runScript({ |
11133 |
|
.code = R"NKSP_CODE( |
11134 |
|
on init |
11135 |
|
exit( asin(0.0kHz) ) |
11136 |
|
end on |
11137 |
|
)NKSP_CODE", |
11138 |
|
.expectRealExitResult = 0.0, |
11139 |
|
.expectExitResultUnitPrefix = { VM_KILO }, |
11140 |
|
.expectExitResultUnit = VM_HERTZ |
11141 |
|
}); |
11142 |
|
|
11143 |
|
// 'final' ('!') operator tests ... |
11144 |
|
|
11145 |
|
runScript({ |
11146 |
|
.code = R"NKSP_CODE( |
11147 |
|
on init |
11148 |
|
exit( asin(0.0) ) |
11149 |
|
end on |
11150 |
|
)NKSP_CODE", |
11151 |
|
.expectRealExitResult = 0.0, |
11152 |
|
.expectExitResultFinal = false |
11153 |
|
}); |
11154 |
|
|
11155 |
|
runScript({ |
11156 |
|
.code = R"NKSP_CODE( |
11157 |
|
on init |
11158 |
|
exit( asin(!0.0) ) |
11159 |
|
end on |
11160 |
|
)NKSP_CODE", |
11161 |
|
.expectRealExitResult = 0.0, |
11162 |
|
.expectExitResultFinal = true |
11163 |
|
}); |
11164 |
|
|
11165 |
|
#if !SILENT_TEST |
11166 |
|
std::cout << std::endl; |
11167 |
|
#endif |
11168 |
|
} |
11169 |
|
|
11170 |
|
static void testBuiltInAcosFunction() { |
11171 |
|
#if !SILENT_TEST |
11172 |
|
std::cout << "UNIT TEST: built-in acos() function\n"; |
11173 |
|
#endif |
11174 |
|
|
11175 |
|
// integer tests ... |
11176 |
|
// (ATM not allowed for this function) |
11177 |
|
|
11178 |
|
runScript({ |
11179 |
|
.code = R"NKSP_CODE( |
11180 |
|
on init |
11181 |
|
declare $foo := 1 |
11182 |
|
exit( acos($foo) ) |
11183 |
|
end on |
11184 |
|
)NKSP_CODE", |
11185 |
|
.expectParseError = true // integer not allowed for this function ATM |
11186 |
|
}); |
11187 |
|
|
11188 |
|
// real number tests ... |
11189 |
|
|
11190 |
|
runScript({ |
11191 |
|
.code = R"NKSP_CODE( |
11192 |
|
on init |
11193 |
|
exit( acos(1.0) ) |
11194 |
|
end on |
11195 |
|
)NKSP_CODE", |
11196 |
|
.expectRealExitResult = 0.0 |
11197 |
|
}); |
11198 |
|
|
11199 |
|
runScript({ |
11200 |
|
.code = R"NKSP_CODE( |
11201 |
|
on init |
11202 |
|
exit( acos(0.0) ) |
11203 |
|
end on |
11204 |
|
)NKSP_CODE", |
11205 |
|
.expectRealExitResult = 0.5 * M_PI |
11206 |
|
}); |
11207 |
|
|
11208 |
|
runScript({ |
11209 |
|
.code = R"NKSP_CODE( |
11210 |
|
on init |
11211 |
|
exit( acos(-1.0) ) |
11212 |
|
end on |
11213 |
|
)NKSP_CODE", |
11214 |
|
.expectRealExitResult = M_PI |
11215 |
|
}); |
11216 |
|
|
11217 |
|
// std unit tests ... |
11218 |
|
|
11219 |
|
runScript({ |
11220 |
|
.code = R"NKSP_CODE( |
11221 |
|
on init |
11222 |
|
exit( acos(1.0ms) ) |
11223 |
|
end on |
11224 |
|
)NKSP_CODE", |
11225 |
|
.expectRealExitResult = 0.0, |
11226 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
11227 |
|
.expectExitResultUnit = VM_SECOND |
11228 |
|
}); |
11229 |
|
|
11230 |
|
runScript({ |
11231 |
|
.code = R"NKSP_CODE( |
11232 |
|
on init |
11233 |
|
exit( acos(1.0kHz) ) |
11234 |
|
end on |
11235 |
|
)NKSP_CODE", |
11236 |
|
.expectRealExitResult = 0.0, |
11237 |
|
.expectExitResultUnitPrefix = { VM_KILO }, |
11238 |
|
.expectExitResultUnit = VM_HERTZ |
11239 |
|
}); |
11240 |
|
|
11241 |
|
// 'final' ('!') operator tests ... |
11242 |
|
|
11243 |
|
runScript({ |
11244 |
|
.code = R"NKSP_CODE( |
11245 |
|
on init |
11246 |
|
exit( acos(1.0) ) |
11247 |
|
end on |
11248 |
|
)NKSP_CODE", |
11249 |
|
.expectRealExitResult = 0.0, |
11250 |
|
.expectExitResultFinal = false |
11251 |
|
}); |
11252 |
|
|
11253 |
|
runScript({ |
11254 |
|
.code = R"NKSP_CODE( |
11255 |
|
on init |
11256 |
|
exit( acos(!1.0) ) |
11257 |
|
end on |
11258 |
|
)NKSP_CODE", |
11259 |
|
.expectRealExitResult = 0.0, |
11260 |
|
.expectExitResultFinal = true |
11261 |
|
}); |
11262 |
|
|
11263 |
|
#if !SILENT_TEST |
11264 |
|
std::cout << std::endl; |
11265 |
|
#endif |
11266 |
|
} |
11267 |
|
|
11268 |
|
static void testBuiltInAtanFunction() { |
11269 |
|
#if !SILENT_TEST |
11270 |
|
std::cout << "UNIT TEST: built-in atan() function\n"; |
11271 |
|
#endif |
11272 |
|
|
11273 |
|
// integer tests ... |
11274 |
|
// (ATM not allowed for this function) |
11275 |
|
|
11276 |
|
runScript({ |
11277 |
|
.code = R"NKSP_CODE( |
11278 |
|
on init |
11279 |
|
declare $foo := 1 |
11280 |
|
exit( atan($foo) ) |
11281 |
|
end on |
11282 |
|
)NKSP_CODE", |
11283 |
|
.expectParseError = true // integer not allowed for this function ATM |
11284 |
|
}); |
11285 |
|
|
11286 |
|
// real number tests ... |
11287 |
|
|
11288 |
|
runScript({ |
11289 |
|
.code = R"NKSP_CODE( |
11290 |
|
on init |
11291 |
|
exit( atan(0.0) ) |
11292 |
|
end on |
11293 |
|
)NKSP_CODE", |
11294 |
|
.expectRealExitResult = 0.0 |
11295 |
|
}); |
11296 |
|
|
11297 |
|
runScript({ |
11298 |
|
.code = R"NKSP_CODE( |
11299 |
|
on init |
11300 |
|
exit( atan(1.0) ) |
11301 |
|
end on |
11302 |
|
)NKSP_CODE", |
11303 |
|
.expectRealExitResult = 0.25 * M_PI |
11304 |
|
}); |
11305 |
|
|
11306 |
|
// std unit tests ... |
11307 |
|
|
11308 |
|
runScript({ |
11309 |
|
.code = R"NKSP_CODE( |
11310 |
|
on init |
11311 |
|
exit( atan(0.0ms) ) |
11312 |
|
end on |
11313 |
|
)NKSP_CODE", |
11314 |
|
.expectRealExitResult = 0.0, |
11315 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
11316 |
|
.expectExitResultUnit = VM_SECOND |
11317 |
|
}); |
11318 |
|
|
11319 |
|
runScript({ |
11320 |
|
.code = R"NKSP_CODE( |
11321 |
|
on init |
11322 |
|
exit( atan(0.0kHz) ) |
11323 |
|
end on |
11324 |
|
)NKSP_CODE", |
11325 |
|
.expectRealExitResult = 0.0, |
11326 |
|
.expectExitResultUnitPrefix = { VM_KILO }, |
11327 |
|
.expectExitResultUnit = VM_HERTZ |
11328 |
|
}); |
11329 |
|
|
11330 |
|
// 'final' ('!') operator tests ... |
11331 |
|
|
11332 |
|
runScript({ |
11333 |
|
.code = R"NKSP_CODE( |
11334 |
|
on init |
11335 |
|
exit( atan(0.0) ) |
11336 |
|
end on |
11337 |
|
)NKSP_CODE", |
11338 |
|
.expectRealExitResult = 0.0, |
11339 |
|
.expectExitResultFinal = false |
11340 |
|
}); |
11341 |
|
|
11342 |
|
runScript({ |
11343 |
|
.code = R"NKSP_CODE( |
11344 |
|
on init |
11345 |
|
exit( atan(!0.0) ) |
11346 |
|
end on |
11347 |
|
)NKSP_CODE", |
11348 |
|
.expectRealExitResult = 0.0, |
11349 |
|
.expectExitResultFinal = true |
11350 |
|
}); |
11351 |
|
|
11352 |
|
#if !SILENT_TEST |
11353 |
|
std::cout << std::endl; |
11354 |
|
#endif |
11355 |
|
} |
11356 |
|
|
11357 |
static void testBuiltInNumElementsFunction() { |
static void testBuiltInNumElementsFunction() { |
11358 |
#if !SILENT_TEST |
#if !SILENT_TEST |
11359 |
std::cout << "UNIT TEST: built-in num_elements() function\n"; |
std::cout << "UNIT TEST: built-in num_elements() function\n"; |
11610 |
#endif |
#endif |
11611 |
} |
} |
11612 |
|
|
11613 |
|
static void testBuiltInVars() { |
11614 |
|
#if !SILENT_TEST |
11615 |
|
std::cout << "UNIT TEST: built-in variables\n"; |
11616 |
|
#endif |
11617 |
|
|
11618 |
|
runScript({ |
11619 |
|
.code = R"NKSP_CODE( |
11620 |
|
on init |
11621 |
|
exit($NKSP_PERF_TIMER) |
11622 |
|
end on |
11623 |
|
)NKSP_CODE", |
11624 |
|
.expectExitResultIsInt = true, |
11625 |
|
.expectExitResultUnitPrefix = { VM_NO_PREFIX }, |
11626 |
|
.expectExitResultUnit = VM_NO_UNIT |
11627 |
|
}); |
11628 |
|
|
11629 |
|
runScript({ |
11630 |
|
.code = R"NKSP_CODE( |
11631 |
|
on init |
11632 |
|
exit($NKSP_REAL_TIMER) |
11633 |
|
end on |
11634 |
|
)NKSP_CODE", |
11635 |
|
.expectExitResultIsInt = true, |
11636 |
|
.expectExitResultUnitPrefix = { VM_NO_PREFIX }, |
11637 |
|
.expectExitResultUnit = VM_NO_UNIT |
11638 |
|
}); |
11639 |
|
|
11640 |
|
runScript({ |
11641 |
|
.code = R"NKSP_CODE( |
11642 |
|
on init |
11643 |
|
exit($KSP_TIMER) |
11644 |
|
end on |
11645 |
|
)NKSP_CODE", |
11646 |
|
.expectExitResultIsInt = true, |
11647 |
|
.expectExitResultUnitPrefix = { VM_NO_PREFIX }, |
11648 |
|
.expectExitResultUnit = VM_NO_UNIT |
11649 |
|
}); |
11650 |
|
|
11651 |
|
runScript({ |
11652 |
|
.code = R"NKSP_CODE( |
11653 |
|
on init |
11654 |
|
exit(~NI_MATH_PI) |
11655 |
|
end on |
11656 |
|
)NKSP_CODE", |
11657 |
|
.expectExitResultIsReal = true, |
11658 |
|
.expectExitResultUnitPrefix = { VM_NO_PREFIX }, |
11659 |
|
.expectExitResultUnit = VM_NO_UNIT |
11660 |
|
}); |
11661 |
|
|
11662 |
|
runScript({ |
11663 |
|
.code = R"NKSP_CODE( |
11664 |
|
on init |
11665 |
|
exit(~NI_MATH_E) |
11666 |
|
end on |
11667 |
|
)NKSP_CODE", |
11668 |
|
.expectExitResultIsReal = true, |
11669 |
|
.expectExitResultUnitPrefix = { VM_NO_PREFIX }, |
11670 |
|
.expectExitResultUnit = VM_NO_UNIT |
11671 |
|
}); |
11672 |
|
|
11673 |
|
runScript({ |
11674 |
|
.code = R"NKSP_CODE( |
11675 |
|
on init |
11676 |
|
exit($NI_CB_TYPE_INIT) |
11677 |
|
end on |
11678 |
|
)NKSP_CODE", |
11679 |
|
.expectIntExitResult = VM_EVENT_HANDLER_INIT, |
11680 |
|
.expectExitResultUnitPrefix = { VM_NO_PREFIX }, |
11681 |
|
.expectExitResultUnit = VM_NO_UNIT |
11682 |
|
}); |
11683 |
|
|
11684 |
|
runScript({ |
11685 |
|
.code = R"NKSP_CODE( |
11686 |
|
on init |
11687 |
|
exit($NI_CB_TYPE_NOTE) |
11688 |
|
end on |
11689 |
|
)NKSP_CODE", |
11690 |
|
.expectIntExitResult = VM_EVENT_HANDLER_NOTE, |
11691 |
|
.expectExitResultUnitPrefix = { VM_NO_PREFIX }, |
11692 |
|
.expectExitResultUnit = VM_NO_UNIT |
11693 |
|
}); |
11694 |
|
|
11695 |
|
runScript({ |
11696 |
|
.code = R"NKSP_CODE( |
11697 |
|
on init |
11698 |
|
exit($NI_CB_TYPE_RELEASE) |
11699 |
|
end on |
11700 |
|
)NKSP_CODE", |
11701 |
|
.expectIntExitResult = VM_EVENT_HANDLER_RELEASE, |
11702 |
|
.expectExitResultUnitPrefix = { VM_NO_PREFIX }, |
11703 |
|
.expectExitResultUnit = VM_NO_UNIT |
11704 |
|
}); |
11705 |
|
|
11706 |
|
runScript({ |
11707 |
|
.code = R"NKSP_CODE( |
11708 |
|
on init |
11709 |
|
exit($NI_CB_TYPE_CONTROLLER) |
11710 |
|
end on |
11711 |
|
)NKSP_CODE", |
11712 |
|
.expectIntExitResult = VM_EVENT_HANDLER_CONTROLLER, |
11713 |
|
.expectExitResultUnitPrefix = { VM_NO_PREFIX }, |
11714 |
|
.expectExitResultUnit = VM_NO_UNIT |
11715 |
|
}); |
11716 |
|
|
11717 |
|
runScript({ |
11718 |
|
.code = R"NKSP_CODE( |
11719 |
|
on init |
11720 |
|
exit($NI_CB_TYPE_RPN) |
11721 |
|
end on |
11722 |
|
)NKSP_CODE", |
11723 |
|
.expectIntExitResult = VM_EVENT_HANDLER_RPN, |
11724 |
|
.expectExitResultUnitPrefix = { VM_NO_PREFIX }, |
11725 |
|
.expectExitResultUnit = VM_NO_UNIT |
11726 |
|
}); |
11727 |
|
|
11728 |
|
runScript({ |
11729 |
|
.code = R"NKSP_CODE( |
11730 |
|
on init |
11731 |
|
exit($NI_CB_TYPE_NRPN) |
11732 |
|
end on |
11733 |
|
)NKSP_CODE", |
11734 |
|
.expectIntExitResult = VM_EVENT_HANDLER_NRPN, |
11735 |
|
.expectExitResultUnitPrefix = { VM_NO_PREFIX }, |
11736 |
|
.expectExitResultUnit = VM_NO_UNIT |
11737 |
|
}); |
11738 |
|
|
11739 |
|
#if !SILENT_TEST |
11740 |
|
std::cout << std::endl; |
11741 |
|
#endif |
11742 |
|
} |
11743 |
|
|
11744 |
#if !NO_MAIN |
#if !NO_MAIN |
11745 |
|
|
11746 |
int main() { |
int main() { |
11765 |
testBitwiseOrOperator(); |
testBitwiseOrOperator(); |
11766 |
testBitwiseNotOperator(); |
testBitwiseNotOperator(); |
11767 |
testPrecedenceOfOperators(); |
testPrecedenceOfOperators(); |
11768 |
|
testIntVarDeclaration(); |
11769 |
|
testIntArrayVarDeclaration(); |
11770 |
|
testRealVarDeclaration(); |
11771 |
|
testRealArrayVarDeclaration(); |
11772 |
|
testStringVarDeclaration(); |
11773 |
testBuiltInMinFunction(); |
testBuiltInMinFunction(); |
11774 |
testBuiltInMaxFunction(); |
testBuiltInMaxFunction(); |
11775 |
testBuiltInAbsFunction(); |
testBuiltInAbsFunction(); |
11779 |
testBuiltInRandomFunction(); |
testBuiltInRandomFunction(); |
11780 |
testBuiltInShiftLeftFunction(); |
testBuiltInShiftLeftFunction(); |
11781 |
testBuiltInShiftRightFunction(); |
testBuiltInShiftRightFunction(); |
11782 |
|
testBuiltInMsbFunction(); |
11783 |
|
testBuiltInLsbFunction(); |
11784 |
testBuiltInIntToRealFunction(); |
testBuiltInIntToRealFunction(); |
11785 |
testBuiltInRealFunction(); |
testBuiltInRealFunction(); |
11786 |
testBuiltInRealToIntFunction(); |
testBuiltInRealToIntFunction(); |
11787 |
testBuiltInIntFunction(); |
testBuiltInIntFunction(); |
11788 |
|
testBuiltInRoundFunction(); |
11789 |
|
testBuiltInCeilFunction(); |
11790 |
|
testBuiltInFloorFunction(); |
11791 |
|
testBuiltInSqrtFunction(); |
11792 |
|
testBuiltInLogFunction(); |
11793 |
|
testBuiltInLog2Function(); |
11794 |
|
testBuiltInLog10Function(); |
11795 |
|
testBuiltInExpFunction(); |
11796 |
|
testBuiltInPowFunction(); |
11797 |
|
testBuiltInSinFunction(); |
11798 |
|
testBuiltInCosFunction(); |
11799 |
|
testBuiltInTanFunction(); |
11800 |
|
testBuiltInAsinFunction(); |
11801 |
|
testBuiltInAcosFunction(); |
11802 |
|
testBuiltInAtanFunction(); |
11803 |
testBuiltInArrayEqualFunction(); |
testBuiltInArrayEqualFunction(); |
11804 |
testBuiltInSortFunction(); |
testBuiltInSortFunction(); |
11805 |
testBuiltInNumElementsFunction(); |
testBuiltInNumElementsFunction(); |
11806 |
testBuiltInSearchFunction(); |
testBuiltInSearchFunction(); |
11807 |
testIfStatement(); |
testIfStatement(); |
11808 |
testWhileStatement(); |
testWhileStatement(); |
11809 |
|
testBuiltInVars(); |
11810 |
std::cout << "\nAll tests passed successfully. :-)\n"; |
std::cout << "\nAll tests passed successfully. :-)\n"; |
11811 |
return 0; |
return 0; |
11812 |
} |
} |