1 |
/* |
/* |
2 |
* Copyright (c) 2019 Christian Schoenebeck |
* Copyright (c) 2019 - 2020 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
5413 |
#endif |
#endif |
5414 |
} |
} |
5415 |
|
|
5416 |
|
static void testIntVarDeclaration() { |
5417 |
|
#if !SILENT_TEST |
5418 |
|
std::cout << "UNIT TEST: int var declaration\n"; |
5419 |
|
#endif |
5420 |
|
|
5421 |
|
runScript({ |
5422 |
|
.code = R"NKSP_CODE( |
5423 |
|
on init |
5424 |
|
declare $a |
5425 |
|
exit($a) |
5426 |
|
end on |
5427 |
|
)NKSP_CODE", |
5428 |
|
.expectIntExitResult = 0 |
5429 |
|
}); |
5430 |
|
|
5431 |
|
runScript({ |
5432 |
|
.code = R"NKSP_CODE( |
5433 |
|
on init |
5434 |
|
declare $a := 24 |
5435 |
|
exit($a) |
5436 |
|
end on |
5437 |
|
)NKSP_CODE", |
5438 |
|
.expectIntExitResult = 24 |
5439 |
|
}); |
5440 |
|
|
5441 |
|
runScript({ |
5442 |
|
.code = R"NKSP_CODE( |
5443 |
|
on init |
5444 |
|
declare $a := 24 |
5445 |
|
$a := 8 |
5446 |
|
exit($a) |
5447 |
|
end on |
5448 |
|
)NKSP_CODE", |
5449 |
|
.expectIntExitResult = 8 |
5450 |
|
}); |
5451 |
|
|
5452 |
|
runScript({ |
5453 |
|
.code = R"NKSP_CODE( |
5454 |
|
on init |
5455 |
|
declare $a |
5456 |
|
declare $a |
5457 |
|
end on |
5458 |
|
)NKSP_CODE", |
5459 |
|
.expectParseError = true // variable re-declaration |
5460 |
|
}); |
5461 |
|
|
5462 |
|
runScript({ |
5463 |
|
.code = R"NKSP_CODE( |
5464 |
|
on init |
5465 |
|
declare const $a |
5466 |
|
end on |
5467 |
|
)NKSP_CODE", |
5468 |
|
.expectParseError = true // const variable declaration without assignment |
5469 |
|
}); |
5470 |
|
|
5471 |
|
runScript({ |
5472 |
|
.code = R"NKSP_CODE( |
5473 |
|
on init |
5474 |
|
declare const $a := 24 |
5475 |
|
exit($a) |
5476 |
|
end on |
5477 |
|
)NKSP_CODE", |
5478 |
|
.expectIntExitResult = 24 |
5479 |
|
}); |
5480 |
|
|
5481 |
|
runScript({ |
5482 |
|
.code = R"NKSP_CODE( |
5483 |
|
on init |
5484 |
|
declare const $a := 24 |
5485 |
|
$a := 8 |
5486 |
|
end on |
5487 |
|
)NKSP_CODE", |
5488 |
|
.expectParseError = true // attempt to modify const variable |
5489 |
|
}); |
5490 |
|
|
5491 |
|
runScript({ |
5492 |
|
.code = R"NKSP_CODE( |
5493 |
|
on init |
5494 |
|
declare const $a := 24 |
5495 |
|
declare const $b := $a |
5496 |
|
exit($b) |
5497 |
|
end on |
5498 |
|
)NKSP_CODE", |
5499 |
|
.expectIntExitResult = 24 |
5500 |
|
}); |
5501 |
|
|
5502 |
|
runScript({ |
5503 |
|
.code = R"NKSP_CODE( |
5504 |
|
on init |
5505 |
|
declare $a := 24 |
5506 |
|
declare const $b := $a |
5507 |
|
end on |
5508 |
|
)NKSP_CODE", |
5509 |
|
.expectParseError = true // const variable defined with non-const assignment |
5510 |
|
}); |
5511 |
|
|
5512 |
|
runScript({ |
5513 |
|
.code = R"NKSP_CODE( |
5514 |
|
on init |
5515 |
|
declare polyphonic $a |
5516 |
|
exit($a) |
5517 |
|
end on |
5518 |
|
)NKSP_CODE", |
5519 |
|
.expectIntExitResult = 0 |
5520 |
|
}); |
5521 |
|
|
5522 |
|
runScript({ |
5523 |
|
.code = R"NKSP_CODE( |
5524 |
|
on init |
5525 |
|
declare const polyphonic $a |
5526 |
|
end on |
5527 |
|
)NKSP_CODE", |
5528 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
5529 |
|
}); |
5530 |
|
|
5531 |
|
runScript({ |
5532 |
|
.code = R"NKSP_CODE( |
5533 |
|
on init |
5534 |
|
declare polyphonic const $a |
5535 |
|
end on |
5536 |
|
)NKSP_CODE", |
5537 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
5538 |
|
}); |
5539 |
|
|
5540 |
|
runScript({ |
5541 |
|
.code = R"NKSP_CODE( |
5542 |
|
on init |
5543 |
|
declare const polyphonic $a := 3 |
5544 |
|
end on |
5545 |
|
)NKSP_CODE", |
5546 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
5547 |
|
}); |
5548 |
|
|
5549 |
|
runScript({ |
5550 |
|
.code = R"NKSP_CODE( |
5551 |
|
on init |
5552 |
|
declare polyphonic const $a := 3 |
5553 |
|
end on |
5554 |
|
)NKSP_CODE", |
5555 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
5556 |
|
}); |
5557 |
|
|
5558 |
|
runScript({ |
5559 |
|
.code = R"NKSP_CODE( |
5560 |
|
on init |
5561 |
|
declare ~a := 24 |
5562 |
|
exit(~a) |
5563 |
|
end on |
5564 |
|
)NKSP_CODE", |
5565 |
|
.expectParseWarning = true, // real type declaration vs. int value assignment |
5566 |
|
.expectIntExitResult = 24 |
5567 |
|
}); |
5568 |
|
|
5569 |
|
runScript({ |
5570 |
|
.code = R"NKSP_CODE( |
5571 |
|
on init |
5572 |
|
declare %a := 24 |
5573 |
|
exit(%a) |
5574 |
|
end on |
5575 |
|
)NKSP_CODE", |
5576 |
|
.expectParseWarning = true, // int array type declaration vs. int scalar value assignment |
5577 |
|
.expectIntExitResult = 24 |
5578 |
|
}); |
5579 |
|
|
5580 |
|
runScript({ |
5581 |
|
.code = R"NKSP_CODE( |
5582 |
|
on init |
5583 |
|
declare const %a := 24 |
5584 |
|
exit(%a) |
5585 |
|
end on |
5586 |
|
)NKSP_CODE", |
5587 |
|
.expectParseWarning = true, // int array type declaration vs. int scalar value assignment |
5588 |
|
.expectIntExitResult = 24 |
5589 |
|
}); |
5590 |
|
|
5591 |
|
runScript({ |
5592 |
|
.code = R"NKSP_CODE( |
5593 |
|
on init |
5594 |
|
declare ?a := 24 |
5595 |
|
exit(?a) |
5596 |
|
end on |
5597 |
|
)NKSP_CODE", |
5598 |
|
.expectParseWarning = true, // real array type declaration vs. int scalar value assignment |
5599 |
|
.expectIntExitResult = 24 |
5600 |
|
}); |
5601 |
|
|
5602 |
|
runScript({ |
5603 |
|
.code = R"NKSP_CODE( |
5604 |
|
on init |
5605 |
|
declare const ?a := 24 |
5606 |
|
exit(?a) |
5607 |
|
end on |
5608 |
|
)NKSP_CODE", |
5609 |
|
.expectParseWarning = true, // real array type declaration vs. int scalar value assignment |
5610 |
|
.expectIntExitResult = 24 |
5611 |
|
}); |
5612 |
|
|
5613 |
|
runScript({ |
5614 |
|
.code = R"NKSP_CODE( |
5615 |
|
on init |
5616 |
|
declare @a := 24 |
5617 |
|
exit(@a) |
5618 |
|
end on |
5619 |
|
)NKSP_CODE", |
5620 |
|
.expectParseWarning = true, // string type declaration vs. int scalar value assignment |
5621 |
|
.expectIntExitResult = 24 |
5622 |
|
}); |
5623 |
|
|
5624 |
|
runScript({ |
5625 |
|
.code = R"NKSP_CODE( |
5626 |
|
on init |
5627 |
|
declare const @a := 24 |
5628 |
|
exit(@a) |
5629 |
|
end on |
5630 |
|
)NKSP_CODE", |
5631 |
|
.expectParseWarning = true, // string type declaration vs. int scalar value assignment |
5632 |
|
.expectIntExitResult = 24 |
5633 |
|
}); |
5634 |
|
|
5635 |
|
runScript({ |
5636 |
|
.code = R"NKSP_CODE( |
5637 |
|
on init |
5638 |
|
declare $a := ( 0, 1, 2 ) |
5639 |
|
end on |
5640 |
|
)NKSP_CODE", |
5641 |
|
.expectParseError = true // int scalar type declaration vs. int array value assignment |
5642 |
|
}); |
5643 |
|
|
5644 |
|
runScript({ |
5645 |
|
.code = R"NKSP_CODE( |
5646 |
|
on init |
5647 |
|
declare const $a := ( 0, 1, 2 ) |
5648 |
|
end on |
5649 |
|
)NKSP_CODE", |
5650 |
|
.expectParseError = true // int scalar type declaration vs. int array value assignment |
5651 |
|
}); |
5652 |
|
|
5653 |
|
runScript({ |
5654 |
|
.code = R"NKSP_CODE( |
5655 |
|
on init |
5656 |
|
declare a |
5657 |
|
end on |
5658 |
|
)NKSP_CODE", |
5659 |
|
.expectParseError = true // missing type prefix character in variable name |
5660 |
|
}); |
5661 |
|
|
5662 |
|
runScript({ |
5663 |
|
.code = R"NKSP_CODE( |
5664 |
|
on init |
5665 |
|
declare a := 24 |
5666 |
|
end on |
5667 |
|
)NKSP_CODE", |
5668 |
|
.expectParseError = true // missing type prefix character in variable name |
5669 |
|
}); |
5670 |
|
|
5671 |
|
runScript({ |
5672 |
|
.code = R"NKSP_CODE( |
5673 |
|
on init |
5674 |
|
declare const a := 24 |
5675 |
|
end on |
5676 |
|
)NKSP_CODE", |
5677 |
|
.expectParseError = true // missing type prefix character in variable name |
5678 |
|
}); |
5679 |
|
|
5680 |
|
runScript({ |
5681 |
|
.code = R"NKSP_CODE( |
5682 |
|
on init |
5683 |
|
declare polyphonic a |
5684 |
|
end on |
5685 |
|
)NKSP_CODE", |
5686 |
|
.expectParseError = true // missing type prefix character in variable name |
5687 |
|
}); |
5688 |
|
|
5689 |
|
runScript({ |
5690 |
|
.code = R"NKSP_CODE( |
5691 |
|
on init |
5692 |
|
declare $a := max(8,24) |
5693 |
|
exit($a) |
5694 |
|
end on |
5695 |
|
)NKSP_CODE", |
5696 |
|
.expectIntExitResult = 24 |
5697 |
|
}); |
5698 |
|
|
5699 |
|
runScript({ |
5700 |
|
.code = R"NKSP_CODE( |
5701 |
|
on init |
5702 |
|
declare $a := abort($NI_CALLBACK_ID) |
5703 |
|
end on |
5704 |
|
)NKSP_CODE", |
5705 |
|
.expectParseError = true // assigned expression does not result in a value |
5706 |
|
}); |
5707 |
|
|
5708 |
|
runScript({ |
5709 |
|
.code = R"NKSP_CODE( |
5710 |
|
on init |
5711 |
|
declare const $a := abort($NI_CALLBACK_ID) |
5712 |
|
end on |
5713 |
|
)NKSP_CODE", |
5714 |
|
.expectParseError = true // assigned expression does not result in a value |
5715 |
|
}); |
5716 |
|
|
5717 |
|
#if !SILENT_TEST |
5718 |
|
std::cout << std::endl; |
5719 |
|
#endif |
5720 |
|
} |
5721 |
|
|
5722 |
|
static void testIntArrayVarDeclaration() { |
5723 |
|
#if !SILENT_TEST |
5724 |
|
std::cout << "UNIT TEST: int array var declaration\n"; |
5725 |
|
#endif |
5726 |
|
|
5727 |
|
runScript({ |
5728 |
|
.code = R"NKSP_CODE( |
5729 |
|
on init |
5730 |
|
declare %a[3] |
5731 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5732 |
|
end on |
5733 |
|
)NKSP_CODE", |
5734 |
|
.expectIntExitResult = 0 |
5735 |
|
}); |
5736 |
|
|
5737 |
|
runScript({ |
5738 |
|
.code = R"NKSP_CODE( |
5739 |
|
on init |
5740 |
|
declare %a[0] |
5741 |
|
end on |
5742 |
|
)NKSP_CODE", |
5743 |
|
.expectParseError = true // illegal array size |
5744 |
|
}); |
5745 |
|
|
5746 |
|
runScript({ |
5747 |
|
.code = R"NKSP_CODE( |
5748 |
|
on init |
5749 |
|
declare %a[-1] |
5750 |
|
end on |
5751 |
|
)NKSP_CODE", |
5752 |
|
.expectParseError = true // illegal array size |
5753 |
|
}); |
5754 |
|
|
5755 |
|
runScript({ |
5756 |
|
.code = R"NKSP_CODE( |
5757 |
|
on init |
5758 |
|
declare %a[3] := ( 1, 2, 3 ) |
5759 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5760 |
|
end on |
5761 |
|
)NKSP_CODE", |
5762 |
|
.expectIntExitResult = (1 + 2 + 3) |
5763 |
|
}); |
5764 |
|
|
5765 |
|
runScript({ |
5766 |
|
.code = R"NKSP_CODE( |
5767 |
|
on init |
5768 |
|
declare const $sz := 3 |
5769 |
|
declare %a[$sz] := ( 1, 2, 3 ) |
5770 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5771 |
|
end on |
5772 |
|
)NKSP_CODE", |
5773 |
|
.expectIntExitResult = (1 + 2 + 3) |
5774 |
|
}); |
5775 |
|
|
5776 |
|
runScript({ |
5777 |
|
.code = R"NKSP_CODE( |
5778 |
|
on init |
5779 |
|
declare const $sz := 3 |
5780 |
|
declare const %a[$sz] := ( 1, 2, 3 ) |
5781 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5782 |
|
end on |
5783 |
|
)NKSP_CODE", |
5784 |
|
.expectIntExitResult = (1 + 2 + 3) |
5785 |
|
}); |
5786 |
|
|
5787 |
|
runScript({ |
5788 |
|
.code = R"NKSP_CODE( |
5789 |
|
on init |
5790 |
|
declare $sz := 3 |
5791 |
|
declare %a[$sz] := ( 1, 2, 3 ) |
5792 |
|
end on |
5793 |
|
)NKSP_CODE", |
5794 |
|
.expectParseError = true // array size must be constant expression |
5795 |
|
}); |
5796 |
|
|
5797 |
|
runScript({ |
5798 |
|
.code = R"NKSP_CODE( |
5799 |
|
on init |
5800 |
|
declare $sz := 3 |
5801 |
|
declare const %a[$sz] := ( 1, 2, 3 ) |
5802 |
|
end on |
5803 |
|
)NKSP_CODE", |
5804 |
|
.expectParseError = true // array size must be constant expression |
5805 |
|
}); |
5806 |
|
|
5807 |
|
runScript({ |
5808 |
|
.code = R"NKSP_CODE( |
5809 |
|
on init |
5810 |
|
declare const ~sz := 3.0 |
5811 |
|
declare const %a[~sz] := ( 1, 2, 3 ) |
5812 |
|
end on |
5813 |
|
)NKSP_CODE", |
5814 |
|
.expectParseError = true // array size must be integer type |
5815 |
|
}); |
5816 |
|
|
5817 |
|
runScript({ |
5818 |
|
.code = R"NKSP_CODE( |
5819 |
|
on init |
5820 |
|
declare %a[3s] := ( 1, 2, 3 ) |
5821 |
|
end on |
5822 |
|
)NKSP_CODE", |
5823 |
|
.expectParseError = true // units not allowed for array size |
5824 |
|
}); |
5825 |
|
|
5826 |
|
runScript({ |
5827 |
|
.code = R"NKSP_CODE( |
5828 |
|
on init |
5829 |
|
declare %a[3m] := ( 1, 2, 3 ) |
5830 |
|
end on |
5831 |
|
)NKSP_CODE", |
5832 |
|
.expectParseError = true // units not allowed for array size |
5833 |
|
}); |
5834 |
|
|
5835 |
|
runScript({ |
5836 |
|
.code = R"NKSP_CODE( |
5837 |
|
on init |
5838 |
|
declare const %a[!3] := ( 1, 2, 3 ) |
5839 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5840 |
|
end on |
5841 |
|
)NKSP_CODE", |
5842 |
|
.expectIntExitResult = (1 + 2 + 3), |
5843 |
|
.expectParseWarning = true // 'final' operator is meaningless for array size |
5844 |
|
}); |
5845 |
|
|
5846 |
|
runScript({ |
5847 |
|
.code = R"NKSP_CODE( |
5848 |
|
on init |
5849 |
|
declare %a[3] := ( 1, 2, 3 ) |
5850 |
|
%a[0] := 4 |
5851 |
|
%a[1] := 5 |
5852 |
|
%a[2] := 6 |
5853 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5854 |
|
end on |
5855 |
|
)NKSP_CODE", |
5856 |
|
.expectIntExitResult = (4 + 5 + 6) |
5857 |
|
}); |
5858 |
|
|
5859 |
|
runScript({ |
5860 |
|
.code = R"NKSP_CODE( |
5861 |
|
on init |
5862 |
|
declare %a[3] |
5863 |
|
declare %a[3] |
5864 |
|
end on |
5865 |
|
)NKSP_CODE", |
5866 |
|
.expectParseError = true // variable re-declaration |
5867 |
|
}); |
5868 |
|
|
5869 |
|
runScript({ |
5870 |
|
.code = R"NKSP_CODE( |
5871 |
|
on init |
5872 |
|
declare const %a[3] |
5873 |
|
end on |
5874 |
|
)NKSP_CODE", |
5875 |
|
.expectParseError = true // const variable declaration without assignment |
5876 |
|
}); |
5877 |
|
|
5878 |
|
runScript({ |
5879 |
|
.code = R"NKSP_CODE( |
5880 |
|
on init |
5881 |
|
declare const %a[3] := ( 1, 2, 3 ) |
5882 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5883 |
|
end on |
5884 |
|
)NKSP_CODE", |
5885 |
|
.expectIntExitResult = (1 + 2 + 3) |
5886 |
|
}); |
5887 |
|
|
5888 |
|
runScript({ |
5889 |
|
.code = R"NKSP_CODE( |
5890 |
|
on init |
5891 |
|
declare const %a[3] := ( 1, 2, 3, 4 ) |
5892 |
|
end on |
5893 |
|
)NKSP_CODE", |
5894 |
|
.expectParseError = true // incompatible array sizes |
5895 |
|
}); |
5896 |
|
|
5897 |
|
runScript({ |
5898 |
|
.code = R"NKSP_CODE( |
5899 |
|
on init |
5900 |
|
declare const %a[3] := ( 1, 2, 3 ) |
5901 |
|
%a[0] := 8 |
5902 |
|
end on |
5903 |
|
)NKSP_CODE", |
5904 |
|
.expectParseError = true // attempt to modify const variable |
5905 |
|
}); |
5906 |
|
|
5907 |
|
runScript({ |
5908 |
|
.code = R"NKSP_CODE( |
5909 |
|
on init |
5910 |
|
declare const %a[3] := ( 1, 2, 3 ) |
5911 |
|
declare const %b[3] := ( %a[0], %a[1], %a[2] ) |
5912 |
|
exit( %b[0] + %b[1] + %b[2] ) |
5913 |
|
end on |
5914 |
|
)NKSP_CODE", |
5915 |
|
.expectIntExitResult = (1 + 2 + 3) |
5916 |
|
}); |
5917 |
|
|
5918 |
|
runScript({ |
5919 |
|
.code = R"NKSP_CODE( |
5920 |
|
on init |
5921 |
|
declare %a[3] := ( 1, 2, 3 ) |
5922 |
|
declare const %b[3] := ( %a[0], %a[1], %a[2] ) |
5923 |
|
end on |
5924 |
|
)NKSP_CODE", |
5925 |
|
.expectParseError = true // const array defined with non-const assignment |
5926 |
|
}); |
5927 |
|
|
5928 |
|
runScript({ |
5929 |
|
.code = R"NKSP_CODE( |
5930 |
|
on init |
5931 |
|
declare polyphonic %a[3] |
5932 |
|
end on |
5933 |
|
)NKSP_CODE", |
5934 |
|
.expectParseError = true // polyphonic not allowed for array types |
5935 |
|
}); |
5936 |
|
|
5937 |
|
runScript({ |
5938 |
|
.code = R"NKSP_CODE( |
5939 |
|
on init |
5940 |
|
declare polyphonic %a[3] := ( 1, 2, 3 ) |
5941 |
|
end on |
5942 |
|
)NKSP_CODE", |
5943 |
|
.expectParseError = true // polyphonic not allowed for array types |
5944 |
|
}); |
5945 |
|
|
5946 |
|
runScript({ |
5947 |
|
.code = R"NKSP_CODE( |
5948 |
|
on init |
5949 |
|
declare const polyphonic %a[3] |
5950 |
|
end on |
5951 |
|
)NKSP_CODE", |
5952 |
|
.expectParseError = true // polyphonic not allowed for array types |
5953 |
|
}); |
5954 |
|
|
5955 |
|
runScript({ |
5956 |
|
.code = R"NKSP_CODE( |
5957 |
|
on init |
5958 |
|
declare const polyphonic %a[3] := ( 1, 2, 3 ) |
5959 |
|
end on |
5960 |
|
)NKSP_CODE", |
5961 |
|
.expectParseError = true // polyphonic not allowed for array types |
5962 |
|
}); |
5963 |
|
|
5964 |
|
runScript({ |
5965 |
|
.code = R"NKSP_CODE( |
5966 |
|
on init |
5967 |
|
declare polyphonic const %a[3] |
5968 |
|
end on |
5969 |
|
)NKSP_CODE", |
5970 |
|
.expectParseError = true // polyphonic not allowed for array types |
5971 |
|
}); |
5972 |
|
|
5973 |
|
runScript({ |
5974 |
|
.code = R"NKSP_CODE( |
5975 |
|
on init |
5976 |
|
declare polyphonic const %a[3] := ( 1, 2, 3 ) |
5977 |
|
end on |
5978 |
|
)NKSP_CODE", |
5979 |
|
.expectParseError = true // polyphonic not allowed for array types |
5980 |
|
}); |
5981 |
|
|
5982 |
|
runScript({ |
5983 |
|
.code = R"NKSP_CODE( |
5984 |
|
on init |
5985 |
|
declare %a[3] := ( 1, max(8,24), 3 ) |
5986 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5987 |
|
end on |
5988 |
|
)NKSP_CODE", |
5989 |
|
.expectIntExitResult = ( 1 + 24 + 3 ) |
5990 |
|
}); |
5991 |
|
|
5992 |
|
runScript({ |
5993 |
|
.code = R"NKSP_CODE( |
5994 |
|
on init |
5995 |
|
declare %a[3] := ( 1, abort($NI_CALLBACK_ID), 3 ) |
5996 |
|
end on |
5997 |
|
)NKSP_CODE", |
5998 |
|
.expectParseError = true // assigned expression does not result in a value |
5999 |
|
}); |
6000 |
|
|
6001 |
|
runScript({ |
6002 |
|
.code = R"NKSP_CODE( |
6003 |
|
on init |
6004 |
|
declare const %a[3] := ( 1, abort($NI_CALLBACK_ID), 3 ) |
6005 |
|
end on |
6006 |
|
)NKSP_CODE", |
6007 |
|
.expectParseError = true // assigned expression does not result in a value |
6008 |
|
}); |
6009 |
|
|
6010 |
|
runScript({ |
6011 |
|
.code = R"NKSP_CODE( |
6012 |
|
on init |
6013 |
|
declare %a[3] := ( 1.0, 2.0, 3.0 ) |
6014 |
|
end on |
6015 |
|
)NKSP_CODE", |
6016 |
|
.expectParseError = true // int array declaration vs. real array assignment |
6017 |
|
}); |
6018 |
|
|
6019 |
|
runScript({ |
6020 |
|
.code = R"NKSP_CODE( |
6021 |
|
on init |
6022 |
|
declare %a[3] := ( 1, 2, 3.0 ) |
6023 |
|
end on |
6024 |
|
)NKSP_CODE", |
6025 |
|
.expectParseError = true // 3rd element not an integer |
6026 |
|
}); |
6027 |
|
|
6028 |
|
runScript({ |
6029 |
|
.code = R"NKSP_CODE( |
6030 |
|
on init |
6031 |
|
declare %a[3] := ( "x", "y", "z" ) |
6032 |
|
end on |
6033 |
|
)NKSP_CODE", |
6034 |
|
.expectParseError = true // int array declaration vs. string array assignment |
6035 |
|
}); |
6036 |
|
|
6037 |
|
runScript({ |
6038 |
|
.code = R"NKSP_CODE( |
6039 |
|
on init |
6040 |
|
declare a[3] := ( 1, 2, 3 ) |
6041 |
|
end on |
6042 |
|
)NKSP_CODE", |
6043 |
|
.expectParseError = true // missing type prefix character in variable name |
6044 |
|
}); |
6045 |
|
|
6046 |
|
runScript({ |
6047 |
|
.code = R"NKSP_CODE( |
6048 |
|
on init |
6049 |
|
declare a[3] |
6050 |
|
end on |
6051 |
|
)NKSP_CODE", |
6052 |
|
.expectParseError = true // missing type prefix character in variable name |
6053 |
|
}); |
6054 |
|
|
6055 |
|
runScript({ |
6056 |
|
.code = R"NKSP_CODE( |
6057 |
|
on init |
6058 |
|
declare const %a[3] := ( 1, 2s, 3 ) |
6059 |
|
end on |
6060 |
|
)NKSP_CODE", |
6061 |
|
.expectParseError = true // unit types not allowed for arrays |
6062 |
|
}); |
6063 |
|
|
6064 |
|
runScript({ |
6065 |
|
.code = R"NKSP_CODE( |
6066 |
|
on init |
6067 |
|
declare const %a[3] := ( 1, !2, 3 ) |
6068 |
|
end on |
6069 |
|
)NKSP_CODE", |
6070 |
|
.expectParseError = true // 'final' not allowed for arrays |
6071 |
|
}); |
6072 |
|
|
6073 |
|
#if !SILENT_TEST |
6074 |
|
std::cout << std::endl; |
6075 |
|
#endif |
6076 |
|
} |
6077 |
|
|
6078 |
|
static void testRealVarDeclaration() { |
6079 |
|
#if !SILENT_TEST |
6080 |
|
std::cout << "UNIT TEST: real var declaration\n"; |
6081 |
|
#endif |
6082 |
|
|
6083 |
|
runScript({ |
6084 |
|
.code = R"NKSP_CODE( |
6085 |
|
on init |
6086 |
|
declare ~a |
6087 |
|
exit(~a) |
6088 |
|
end on |
6089 |
|
)NKSP_CODE", |
6090 |
|
.expectRealExitResult = 0.0 |
6091 |
|
}); |
6092 |
|
|
6093 |
|
runScript({ |
6094 |
|
.code = R"NKSP_CODE( |
6095 |
|
on init |
6096 |
|
declare ~a := 24.8 |
6097 |
|
exit(~a) |
6098 |
|
end on |
6099 |
|
)NKSP_CODE", |
6100 |
|
.expectRealExitResult = 24.8 |
6101 |
|
}); |
6102 |
|
|
6103 |
|
runScript({ |
6104 |
|
.code = R"NKSP_CODE( |
6105 |
|
on init |
6106 |
|
declare ~a := 8.24 |
6107 |
|
~a := 24.8 |
6108 |
|
exit(~a) |
6109 |
|
end on |
6110 |
|
)NKSP_CODE", |
6111 |
|
.expectRealExitResult = 24.8 |
6112 |
|
}); |
6113 |
|
|
6114 |
|
runScript({ |
6115 |
|
.code = R"NKSP_CODE( |
6116 |
|
on init |
6117 |
|
declare ~a |
6118 |
|
declare ~a |
6119 |
|
end on |
6120 |
|
)NKSP_CODE", |
6121 |
|
.expectParseError = true // variable re-declaration |
6122 |
|
}); |
6123 |
|
|
6124 |
|
runScript({ |
6125 |
|
.code = R"NKSP_CODE( |
6126 |
|
on init |
6127 |
|
declare const ~a |
6128 |
|
end on |
6129 |
|
)NKSP_CODE", |
6130 |
|
.expectParseError = true // const variable declaration without assignment |
6131 |
|
}); |
6132 |
|
|
6133 |
|
runScript({ |
6134 |
|
.code = R"NKSP_CODE( |
6135 |
|
on init |
6136 |
|
declare const ~a := 8.24 |
6137 |
|
exit(~a) |
6138 |
|
end on |
6139 |
|
)NKSP_CODE", |
6140 |
|
.expectRealExitResult = 8.24 |
6141 |
|
}); |
6142 |
|
|
6143 |
|
runScript({ |
6144 |
|
.code = R"NKSP_CODE( |
6145 |
|
on init |
6146 |
|
declare const ~a := 28.0 |
6147 |
|
~a := 8.0 |
6148 |
|
end on |
6149 |
|
)NKSP_CODE", |
6150 |
|
.expectParseError = true // attempt to modify const variable |
6151 |
|
}); |
6152 |
|
|
6153 |
|
runScript({ |
6154 |
|
.code = R"NKSP_CODE( |
6155 |
|
on init |
6156 |
|
declare const ~a := 24.8 |
6157 |
|
declare const ~b := ~a |
6158 |
|
exit(~b) |
6159 |
|
end on |
6160 |
|
)NKSP_CODE", |
6161 |
|
.expectRealExitResult = 24.8 |
6162 |
|
}); |
6163 |
|
|
6164 |
|
runScript({ |
6165 |
|
.code = R"NKSP_CODE( |
6166 |
|
on init |
6167 |
|
declare ~a := 24.0 |
6168 |
|
declare const ~b := ~a |
6169 |
|
end on |
6170 |
|
)NKSP_CODE", |
6171 |
|
.expectParseError = true // const variable defined with non-const assignment |
6172 |
|
}); |
6173 |
|
|
6174 |
|
runScript({ |
6175 |
|
.code = R"NKSP_CODE( |
6176 |
|
on init |
6177 |
|
declare polyphonic ~a |
6178 |
|
exit(~a) |
6179 |
|
end on |
6180 |
|
)NKSP_CODE", |
6181 |
|
.expectRealExitResult = 0.0 |
6182 |
|
}); |
6183 |
|
|
6184 |
|
runScript({ |
6185 |
|
.code = R"NKSP_CODE( |
6186 |
|
on init |
6187 |
|
declare const polyphonic ~a |
6188 |
|
end on |
6189 |
|
)NKSP_CODE", |
6190 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
6191 |
|
}); |
6192 |
|
|
6193 |
|
runScript({ |
6194 |
|
.code = R"NKSP_CODE( |
6195 |
|
on init |
6196 |
|
declare polyphonic const ~a |
6197 |
|
end on |
6198 |
|
)NKSP_CODE", |
6199 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
6200 |
|
}); |
6201 |
|
|
6202 |
|
runScript({ |
6203 |
|
.code = R"NKSP_CODE( |
6204 |
|
on init |
6205 |
|
declare const polyphonic ~a := 3.0 |
6206 |
|
end on |
6207 |
|
)NKSP_CODE", |
6208 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
6209 |
|
}); |
6210 |
|
|
6211 |
|
runScript({ |
6212 |
|
.code = R"NKSP_CODE( |
6213 |
|
on init |
6214 |
|
declare polyphonic const ~a := 3.0 |
6215 |
|
end on |
6216 |
|
)NKSP_CODE", |
6217 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
6218 |
|
}); |
6219 |
|
|
6220 |
|
runScript({ |
6221 |
|
.code = R"NKSP_CODE( |
6222 |
|
on init |
6223 |
|
declare $a := 24.8 |
6224 |
|
exit($a) |
6225 |
|
end on |
6226 |
|
)NKSP_CODE", |
6227 |
|
.expectParseWarning = true, // int type declaration vs. real value assignment |
6228 |
|
.expectRealExitResult = 24.8 |
6229 |
|
}); |
6230 |
|
|
6231 |
|
runScript({ |
6232 |
|
.code = R"NKSP_CODE( |
6233 |
|
on init |
6234 |
|
declare %a := 24.8 |
6235 |
|
exit(%a) |
6236 |
|
end on |
6237 |
|
)NKSP_CODE", |
6238 |
|
.expectParseWarning = true, // int array type declaration vs. real scalar value assignment |
6239 |
|
.expectRealExitResult = 24.8 |
6240 |
|
}); |
6241 |
|
|
6242 |
|
runScript({ |
6243 |
|
.code = R"NKSP_CODE( |
6244 |
|
on init |
6245 |
|
declare const %a := 24.8 |
6246 |
|
exit(%a) |
6247 |
|
end on |
6248 |
|
)NKSP_CODE", |
6249 |
|
.expectParseWarning = true, // int array type declaration vs. real scalar value assignment |
6250 |
|
.expectRealExitResult = 24.8 |
6251 |
|
}); |
6252 |
|
|
6253 |
|
runScript({ |
6254 |
|
.code = R"NKSP_CODE( |
6255 |
|
on init |
6256 |
|
declare ?a := 24.8 |
6257 |
|
exit(?a) |
6258 |
|
end on |
6259 |
|
)NKSP_CODE", |
6260 |
|
.expectParseWarning = true, // real array type declaration vs. real scalar value assignment |
6261 |
|
.expectRealExitResult = 24.8 |
6262 |
|
}); |
6263 |
|
|
6264 |
|
runScript({ |
6265 |
|
.code = R"NKSP_CODE( |
6266 |
|
on init |
6267 |
|
declare const ?a := 24.8 |
6268 |
|
exit(?a) |
6269 |
|
end on |
6270 |
|
)NKSP_CODE", |
6271 |
|
.expectParseWarning = true, // real array type declaration vs. real scalar value assignment |
6272 |
|
.expectRealExitResult = 24.8 |
6273 |
|
}); |
6274 |
|
|
6275 |
|
runScript({ |
6276 |
|
.code = R"NKSP_CODE( |
6277 |
|
on init |
6278 |
|
declare @a := 24.8 |
6279 |
|
exit(@a) |
6280 |
|
end on |
6281 |
|
)NKSP_CODE", |
6282 |
|
.expectParseWarning = true, // string type declaration vs. real scalar value assignment |
6283 |
|
.expectRealExitResult = 24.8 |
6284 |
|
}); |
6285 |
|
|
6286 |
|
runScript({ |
6287 |
|
.code = R"NKSP_CODE( |
6288 |
|
on init |
6289 |
|
declare const @a := 24.8 |
6290 |
|
exit(@a) |
6291 |
|
end on |
6292 |
|
)NKSP_CODE", |
6293 |
|
.expectParseWarning = true, // string type declaration vs. real scalar value assignment |
6294 |
|
.expectRealExitResult = 24.8 |
6295 |
|
}); |
6296 |
|
|
6297 |
|
runScript({ |
6298 |
|
.code = R"NKSP_CODE( |
6299 |
|
on init |
6300 |
|
declare ~a := ( 0, 1, 2 ) |
6301 |
|
end on |
6302 |
|
)NKSP_CODE", |
6303 |
|
.expectParseError = true // real scalar type declaration vs. int array value assignment |
6304 |
|
}); |
6305 |
|
|
6306 |
|
runScript({ |
6307 |
|
.code = R"NKSP_CODE( |
6308 |
|
on init |
6309 |
|
declare const ~a := ( 0, 1, 2 ) |
6310 |
|
end on |
6311 |
|
)NKSP_CODE", |
6312 |
|
.expectParseError = true // real scalar type declaration vs. int array value assignment |
6313 |
|
}); |
6314 |
|
|
6315 |
|
runScript({ |
6316 |
|
.code = R"NKSP_CODE( |
6317 |
|
on init |
6318 |
|
declare a := 24.8 |
6319 |
|
end on |
6320 |
|
)NKSP_CODE", |
6321 |
|
.expectParseError = true // missing type prefix character in variable name |
6322 |
|
}); |
6323 |
|
|
6324 |
|
runScript({ |
6325 |
|
.code = R"NKSP_CODE( |
6326 |
|
on init |
6327 |
|
declare const a := 24.8 |
6328 |
|
end on |
6329 |
|
)NKSP_CODE", |
6330 |
|
.expectParseError = true // missing type prefix character in variable name |
6331 |
|
}); |
6332 |
|
|
6333 |
|
runScript({ |
6334 |
|
.code = R"NKSP_CODE( |
6335 |
|
on init |
6336 |
|
declare ~a := max(8.1,24.2) |
6337 |
|
exit(~a) |
6338 |
|
end on |
6339 |
|
)NKSP_CODE", |
6340 |
|
.expectRealExitResult = 24.2 |
6341 |
|
}); |
6342 |
|
|
6343 |
|
runScript({ |
6344 |
|
.code = R"NKSP_CODE( |
6345 |
|
on init |
6346 |
|
declare ~a := abort($NI_CALLBACK_ID) |
6347 |
|
end on |
6348 |
|
)NKSP_CODE", |
6349 |
|
.expectParseError = true // assigned expression does not result in a value |
6350 |
|
}); |
6351 |
|
|
6352 |
|
runScript({ |
6353 |
|
.code = R"NKSP_CODE( |
6354 |
|
on init |
6355 |
|
declare const ~a := abort($NI_CALLBACK_ID) |
6356 |
|
end on |
6357 |
|
)NKSP_CODE", |
6358 |
|
.expectParseError = true // assigned expression does not result in a value |
6359 |
|
}); |
6360 |
|
|
6361 |
|
#if !SILENT_TEST |
6362 |
|
std::cout << std::endl; |
6363 |
|
#endif |
6364 |
|
} |
6365 |
|
|
6366 |
|
static void testRealArrayVarDeclaration() { |
6367 |
|
#if !SILENT_TEST |
6368 |
|
std::cout << "UNIT TEST: real array var declaration\n"; |
6369 |
|
#endif |
6370 |
|
|
6371 |
|
runScript({ |
6372 |
|
.code = R"NKSP_CODE( |
6373 |
|
on init |
6374 |
|
declare ?a[3] |
6375 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6376 |
|
end on |
6377 |
|
)NKSP_CODE", |
6378 |
|
.expectRealExitResult = 0.0 |
6379 |
|
}); |
6380 |
|
|
6381 |
|
runScript({ |
6382 |
|
.code = R"NKSP_CODE( |
6383 |
|
on init |
6384 |
|
declare ?a[0] |
6385 |
|
end on |
6386 |
|
)NKSP_CODE", |
6387 |
|
.expectParseError = true // illegal array size |
6388 |
|
}); |
6389 |
|
|
6390 |
|
runScript({ |
6391 |
|
.code = R"NKSP_CODE( |
6392 |
|
on init |
6393 |
|
declare ?a[-1] |
6394 |
|
end on |
6395 |
|
)NKSP_CODE", |
6396 |
|
.expectParseError = true // illegal array size |
6397 |
|
}); |
6398 |
|
|
6399 |
|
runScript({ |
6400 |
|
.code = R"NKSP_CODE( |
6401 |
|
on init |
6402 |
|
declare ?a[3] := ( 1.1, 2.2, 3.3 ) |
6403 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6404 |
|
end on |
6405 |
|
)NKSP_CODE", |
6406 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6407 |
|
}); |
6408 |
|
|
6409 |
|
runScript({ |
6410 |
|
.code = R"NKSP_CODE( |
6411 |
|
on init |
6412 |
|
declare const $sz := 3 |
6413 |
|
declare ?a[$sz] := ( 1.1, 2.2, 3.3 ) |
6414 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6415 |
|
end on |
6416 |
|
)NKSP_CODE", |
6417 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6418 |
|
}); |
6419 |
|
|
6420 |
|
runScript({ |
6421 |
|
.code = R"NKSP_CODE( |
6422 |
|
on init |
6423 |
|
declare const $sz := 3 |
6424 |
|
declare const ?a[$sz] := ( 1.1, 2.2, 3.3 ) |
6425 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6426 |
|
end on |
6427 |
|
)NKSP_CODE", |
6428 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6429 |
|
}); |
6430 |
|
|
6431 |
|
runScript({ |
6432 |
|
.code = R"NKSP_CODE( |
6433 |
|
on init |
6434 |
|
declare $sz := 3 |
6435 |
|
declare ?a[$sz] := ( 1.1, 2.2, 3.3 ) |
6436 |
|
end on |
6437 |
|
)NKSP_CODE", |
6438 |
|
.expectParseError = true // array size must be constant expression |
6439 |
|
}); |
6440 |
|
|
6441 |
|
runScript({ |
6442 |
|
.code = R"NKSP_CODE( |
6443 |
|
on init |
6444 |
|
declare $sz := 3 |
6445 |
|
declare const ?a[$sz] := ( 1.1, 2.2, 3.3 ) |
6446 |
|
end on |
6447 |
|
)NKSP_CODE", |
6448 |
|
.expectParseError = true // array size must be constant expression |
6449 |
|
}); |
6450 |
|
|
6451 |
|
runScript({ |
6452 |
|
.code = R"NKSP_CODE( |
6453 |
|
on init |
6454 |
|
declare const ~sz := 3.0 |
6455 |
|
declare const ?a[~sz] := ( 1.1, 2.2, 3.3 ) |
6456 |
|
end on |
6457 |
|
)NKSP_CODE", |
6458 |
|
.expectParseError = true // array size must be integer type |
6459 |
|
}); |
6460 |
|
|
6461 |
|
runScript({ |
6462 |
|
.code = R"NKSP_CODE( |
6463 |
|
on init |
6464 |
|
declare ?a[3s] := ( 1.1, 2.2, 3.3 ) |
6465 |
|
end on |
6466 |
|
)NKSP_CODE", |
6467 |
|
.expectParseError = true // units not allowed for array size |
6468 |
|
}); |
6469 |
|
|
6470 |
|
runScript({ |
6471 |
|
.code = R"NKSP_CODE( |
6472 |
|
on init |
6473 |
|
declare ?a[3m] := ( 1.1, 2.2, 3.3 ) |
6474 |
|
end on |
6475 |
|
)NKSP_CODE", |
6476 |
|
.expectParseError = true // units not allowed for array size |
6477 |
|
}); |
6478 |
|
|
6479 |
|
runScript({ |
6480 |
|
.code = R"NKSP_CODE( |
6481 |
|
on init |
6482 |
|
declare const ?a[!3] := ( 1.1, 2.2, 3.3 ) |
6483 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6484 |
|
end on |
6485 |
|
)NKSP_CODE", |
6486 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3), |
6487 |
|
.expectParseWarning = true // 'final' operator is meaningless for array size |
6488 |
|
}); |
6489 |
|
|
6490 |
|
runScript({ |
6491 |
|
.code = R"NKSP_CODE( |
6492 |
|
on init |
6493 |
|
declare ?a[3] := ( 1.0, 2.0, 3.0 ) |
6494 |
|
?a[0] := 4.5 |
6495 |
|
?a[1] := 5.5 |
6496 |
|
?a[2] := 6.5 |
6497 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6498 |
|
end on |
6499 |
|
)NKSP_CODE", |
6500 |
|
.expectRealExitResult = (4.5 + 5.5 + 6.5) |
6501 |
|
}); |
6502 |
|
|
6503 |
|
runScript({ |
6504 |
|
.code = R"NKSP_CODE( |
6505 |
|
on init |
6506 |
|
declare ?a[3] |
6507 |
|
declare ?a[3] |
6508 |
|
end on |
6509 |
|
)NKSP_CODE", |
6510 |
|
.expectParseError = true // variable re-declaration |
6511 |
|
}); |
6512 |
|
|
6513 |
|
runScript({ |
6514 |
|
.code = R"NKSP_CODE( |
6515 |
|
on init |
6516 |
|
declare const ?a[3] |
6517 |
|
end on |
6518 |
|
)NKSP_CODE", |
6519 |
|
.expectParseError = true // const variable declaration without assignment |
6520 |
|
}); |
6521 |
|
|
6522 |
|
runScript({ |
6523 |
|
.code = R"NKSP_CODE( |
6524 |
|
on init |
6525 |
|
declare const ?a[3] := ( 1.1, 2.2, 3.3 ) |
6526 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6527 |
|
end on |
6528 |
|
)NKSP_CODE", |
6529 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6530 |
|
}); |
6531 |
|
|
6532 |
|
runScript({ |
6533 |
|
.code = R"NKSP_CODE( |
6534 |
|
on init |
6535 |
|
declare const ?a[3] := ( 1.1, 2.2, 3.3, 4.4 ) |
6536 |
|
end on |
6537 |
|
)NKSP_CODE", |
6538 |
|
.expectParseError = true // incompatible array sizes |
6539 |
|
}); |
6540 |
|
|
6541 |
|
runScript({ |
6542 |
|
.code = R"NKSP_CODE( |
6543 |
|
on init |
6544 |
|
declare const ?a[3] := ( 1.0, 2.0, 3.0 ) |
6545 |
|
?a[0] := 8.0 |
6546 |
|
end on |
6547 |
|
)NKSP_CODE", |
6548 |
|
.expectParseError = true // attempt to modify const variable |
6549 |
|
}); |
6550 |
|
|
6551 |
|
runScript({ |
6552 |
|
.code = R"NKSP_CODE( |
6553 |
|
on init |
6554 |
|
declare const ?a[3] := ( 1.1, 2.2, 3.3 ) |
6555 |
|
declare const ?b[3] := ( ?a[0], ?a[1], ?a[2] ) |
6556 |
|
exit( ?b[0] + ?b[1] + ?b[2] ) |
6557 |
|
end on |
6558 |
|
)NKSP_CODE", |
6559 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6560 |
|
}); |
6561 |
|
|
6562 |
|
runScript({ |
6563 |
|
.code = R"NKSP_CODE( |
6564 |
|
on init |
6565 |
|
declare ?a[3] := ( 1.1, 2.2, 3.3 ) |
6566 |
|
declare const ?b[3] := ( ?a[0], ?a[1], ?a[2] ) |
6567 |
|
end on |
6568 |
|
)NKSP_CODE", |
6569 |
|
.expectParseError = true // const array defined with non-const assignment |
6570 |
|
}); |
6571 |
|
|
6572 |
|
runScript({ |
6573 |
|
.code = R"NKSP_CODE( |
6574 |
|
on init |
6575 |
|
declare polyphonic ?a[3] |
6576 |
|
end on |
6577 |
|
)NKSP_CODE", |
6578 |
|
.expectParseError = true // polyphonic not allowed for array types |
6579 |
|
}); |
6580 |
|
|
6581 |
|
runScript({ |
6582 |
|
.code = R"NKSP_CODE( |
6583 |
|
on init |
6584 |
|
declare polyphonic ?a[3] := ( 1.0, 2.0, 3.0 ) |
6585 |
|
end on |
6586 |
|
)NKSP_CODE", |
6587 |
|
.expectParseError = true // polyphonic not allowed for array types |
6588 |
|
}); |
6589 |
|
|
6590 |
|
runScript({ |
6591 |
|
.code = R"NKSP_CODE( |
6592 |
|
on init |
6593 |
|
declare const polyphonic ?a[3] |
6594 |
|
end on |
6595 |
|
)NKSP_CODE", |
6596 |
|
.expectParseError = true // polyphonic not allowed for array types |
6597 |
|
}); |
6598 |
|
|
6599 |
|
runScript({ |
6600 |
|
.code = R"NKSP_CODE( |
6601 |
|
on init |
6602 |
|
declare const polyphonic ?a[3] := ( 1.0, 2.0, 3.0 ) |
6603 |
|
end on |
6604 |
|
)NKSP_CODE", |
6605 |
|
.expectParseError = true // polyphonic not allowed for array types |
6606 |
|
}); |
6607 |
|
|
6608 |
|
runScript({ |
6609 |
|
.code = R"NKSP_CODE( |
6610 |
|
on init |
6611 |
|
declare polyphonic const ?a[3] |
6612 |
|
end on |
6613 |
|
)NKSP_CODE", |
6614 |
|
.expectParseError = true // polyphonic not allowed for array types |
6615 |
|
}); |
6616 |
|
|
6617 |
|
runScript({ |
6618 |
|
.code = R"NKSP_CODE( |
6619 |
|
on init |
6620 |
|
declare polyphonic const ?a[3] := ( 1.0, 2.0, 3.0 ) |
6621 |
|
end on |
6622 |
|
)NKSP_CODE", |
6623 |
|
.expectParseError = true // polyphonic not allowed for array types |
6624 |
|
}); |
6625 |
|
|
6626 |
|
runScript({ |
6627 |
|
.code = R"NKSP_CODE( |
6628 |
|
on init |
6629 |
|
declare ?a[3] := ( 1.0, max(8.3,24.6), 3.0 ) |
6630 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6631 |
|
end on |
6632 |
|
)NKSP_CODE", |
6633 |
|
.expectRealExitResult = ( 1.0 + 24.6 + 3.0 ) |
6634 |
|
}); |
6635 |
|
|
6636 |
|
runScript({ |
6637 |
|
.code = R"NKSP_CODE( |
6638 |
|
on init |
6639 |
|
declare ?a[3] := ( 1.0, abort($NI_CALLBACK_ID), 3.0 ) |
6640 |
|
end on |
6641 |
|
)NKSP_CODE", |
6642 |
|
.expectParseError = true // assigned expression does not result in a value |
6643 |
|
}); |
6644 |
|
|
6645 |
|
runScript({ |
6646 |
|
.code = R"NKSP_CODE( |
6647 |
|
on init |
6648 |
|
declare const ?a[3] := ( 1.0, abort($NI_CALLBACK_ID), 3.0 ) |
6649 |
|
end on |
6650 |
|
)NKSP_CODE", |
6651 |
|
.expectParseError = true // assigned expression does not result in a value |
6652 |
|
}); |
6653 |
|
|
6654 |
|
runScript({ |
6655 |
|
.code = R"NKSP_CODE( |
6656 |
|
on init |
6657 |
|
declare ?a[3] := ( 1, 2, 3 ) |
6658 |
|
end on |
6659 |
|
)NKSP_CODE", |
6660 |
|
.expectParseError = true // real array declaration vs. int array assignment |
6661 |
|
}); |
6662 |
|
|
6663 |
|
runScript({ |
6664 |
|
.code = R"NKSP_CODE( |
6665 |
|
on init |
6666 |
|
declare ?a[3] := ( 1.0, 2.0, 3 ) |
6667 |
|
end on |
6668 |
|
)NKSP_CODE", |
6669 |
|
.expectParseError = true // 3rd element not a real value |
6670 |
|
}); |
6671 |
|
|
6672 |
|
runScript({ |
6673 |
|
.code = R"NKSP_CODE( |
6674 |
|
on init |
6675 |
|
declare ?a[3] := ( "x", "y", "z" ) |
6676 |
|
end on |
6677 |
|
)NKSP_CODE", |
6678 |
|
.expectParseError = true // real array declaration vs. string array assignment |
6679 |
|
}); |
6680 |
|
|
6681 |
|
runScript({ |
6682 |
|
.code = R"NKSP_CODE( |
6683 |
|
on init |
6684 |
|
declare a[3] := ( 1.0, 2.0, 3.0 ) |
6685 |
|
end on |
6686 |
|
)NKSP_CODE", |
6687 |
|
.expectParseError = true // missing type prefix character in variable name |
6688 |
|
}); |
6689 |
|
|
6690 |
|
runScript({ |
6691 |
|
.code = R"NKSP_CODE( |
6692 |
|
on init |
6693 |
|
declare const ?a[3] := ( 1.0, 2.0s, 3.0 ) |
6694 |
|
end on |
6695 |
|
)NKSP_CODE", |
6696 |
|
.expectParseError = true // unit types not allowed for arrays |
6697 |
|
}); |
6698 |
|
|
6699 |
|
runScript({ |
6700 |
|
.code = R"NKSP_CODE( |
6701 |
|
on init |
6702 |
|
declare const ?a[3] := ( 1.0, !2.0, 3.0 ) |
6703 |
|
end on |
6704 |
|
)NKSP_CODE", |
6705 |
|
.expectParseError = true // 'final' not allowed for arrays |
6706 |
|
}); |
6707 |
|
|
6708 |
|
#if !SILENT_TEST |
6709 |
|
std::cout << std::endl; |
6710 |
|
#endif |
6711 |
|
} |
6712 |
|
|
6713 |
|
static void testStringVarDeclaration() { |
6714 |
|
#if !SILENT_TEST |
6715 |
|
std::cout << "UNIT TEST: string var declaration\n"; |
6716 |
|
#endif |
6717 |
|
|
6718 |
|
runScript({ |
6719 |
|
.code = R"NKSP_CODE( |
6720 |
|
on init |
6721 |
|
declare @a |
6722 |
|
exit(@a) |
6723 |
|
end on |
6724 |
|
)NKSP_CODE", |
6725 |
|
.expectStringExitResult = "" |
6726 |
|
}); |
6727 |
|
|
6728 |
|
runScript({ |
6729 |
|
.code = R"NKSP_CODE( |
6730 |
|
on init |
6731 |
|
declare @a := "foo" |
6732 |
|
exit(@a) |
6733 |
|
end on |
6734 |
|
)NKSP_CODE", |
6735 |
|
.expectStringExitResult = "foo" |
6736 |
|
}); |
6737 |
|
|
6738 |
|
runScript({ |
6739 |
|
.code = R"NKSP_CODE( |
6740 |
|
on init |
6741 |
|
declare @a := "foo" |
6742 |
|
@a := "bar" |
6743 |
|
exit(@a) |
6744 |
|
end on |
6745 |
|
)NKSP_CODE", |
6746 |
|
.expectStringExitResult = "bar" |
6747 |
|
}); |
6748 |
|
|
6749 |
|
runScript({ |
6750 |
|
.code = R"NKSP_CODE( |
6751 |
|
on init |
6752 |
|
declare @a |
6753 |
|
declare @a |
6754 |
|
end on |
6755 |
|
)NKSP_CODE", |
6756 |
|
.expectParseError = true // variable re-declaration |
6757 |
|
}); |
6758 |
|
|
6759 |
|
runScript({ |
6760 |
|
.code = R"NKSP_CODE( |
6761 |
|
on init |
6762 |
|
declare const @a |
6763 |
|
end on |
6764 |
|
)NKSP_CODE", |
6765 |
|
.expectParseError = true // const variable declaration without assignment |
6766 |
|
}); |
6767 |
|
|
6768 |
|
runScript({ |
6769 |
|
.code = R"NKSP_CODE( |
6770 |
|
on init |
6771 |
|
declare const @a := "foo" |
6772 |
|
exit(@a) |
6773 |
|
end on |
6774 |
|
)NKSP_CODE", |
6775 |
|
.expectStringExitResult = "foo" |
6776 |
|
}); |
6777 |
|
|
6778 |
|
runScript({ |
6779 |
|
.code = R"NKSP_CODE( |
6780 |
|
on init |
6781 |
|
declare const @a := "foo" |
6782 |
|
@a := "bar" |
6783 |
|
end on |
6784 |
|
)NKSP_CODE", |
6785 |
|
.expectParseError = true // attempt to modify const variable |
6786 |
|
}); |
6787 |
|
|
6788 |
|
runScript({ |
6789 |
|
.code = R"NKSP_CODE( |
6790 |
|
on init |
6791 |
|
declare const @a := "foo" |
6792 |
|
declare const @b := @a |
6793 |
|
exit(@b) |
6794 |
|
end on |
6795 |
|
)NKSP_CODE", |
6796 |
|
.expectStringExitResult = "foo" |
6797 |
|
}); |
6798 |
|
|
6799 |
|
runScript({ |
6800 |
|
.code = R"NKSP_CODE( |
6801 |
|
on init |
6802 |
|
declare @a := "foo" |
6803 |
|
declare const @b := @a |
6804 |
|
end on |
6805 |
|
)NKSP_CODE", |
6806 |
|
.expectParseError = true // const variable defined with non-const assignment |
6807 |
|
}); |
6808 |
|
|
6809 |
|
runScript({ |
6810 |
|
.code = R"NKSP_CODE( |
6811 |
|
on init |
6812 |
|
declare polyphonic @a |
6813 |
|
end on |
6814 |
|
)NKSP_CODE", |
6815 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
6816 |
|
}); |
6817 |
|
|
6818 |
|
runScript({ |
6819 |
|
.code = R"NKSP_CODE( |
6820 |
|
on init |
6821 |
|
declare const polyphonic @a |
6822 |
|
end on |
6823 |
|
)NKSP_CODE", |
6824 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
6825 |
|
}); |
6826 |
|
|
6827 |
|
runScript({ |
6828 |
|
.code = R"NKSP_CODE( |
6829 |
|
on init |
6830 |
|
declare polyphonic const @a |
6831 |
|
end on |
6832 |
|
)NKSP_CODE", |
6833 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
6834 |
|
}); |
6835 |
|
|
6836 |
|
runScript({ |
6837 |
|
.code = R"NKSP_CODE( |
6838 |
|
on init |
6839 |
|
declare polyphonic @a = "foo" |
6840 |
|
end on |
6841 |
|
)NKSP_CODE", |
6842 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
6843 |
|
}); |
6844 |
|
|
6845 |
|
runScript({ |
6846 |
|
.code = R"NKSP_CODE( |
6847 |
|
on init |
6848 |
|
declare polyphonic const @a = "foo" |
6849 |
|
end on |
6850 |
|
)NKSP_CODE", |
6851 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
6852 |
|
}); |
6853 |
|
|
6854 |
|
runScript({ |
6855 |
|
.code = R"NKSP_CODE( |
6856 |
|
on init |
6857 |
|
declare const polyphonic @a = "foo" |
6858 |
|
end on |
6859 |
|
)NKSP_CODE", |
6860 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
6861 |
|
}); |
6862 |
|
|
6863 |
|
runScript({ |
6864 |
|
.code = R"NKSP_CODE( |
6865 |
|
on init |
6866 |
|
declare $a := "foo" |
6867 |
|
exit($a) |
6868 |
|
end on |
6869 |
|
)NKSP_CODE", |
6870 |
|
.expectParseWarning = true, // int type declaration vs. string assignment |
6871 |
|
.expectStringExitResult = "foo" |
6872 |
|
}); |
6873 |
|
|
6874 |
|
runScript({ |
6875 |
|
.code = R"NKSP_CODE( |
6876 |
|
on init |
6877 |
|
declare ~a := "foo" |
6878 |
|
exit(~a) |
6879 |
|
end on |
6880 |
|
)NKSP_CODE", |
6881 |
|
.expectParseWarning = true, // real type declaration vs. string assignment |
6882 |
|
.expectStringExitResult = "foo" |
6883 |
|
}); |
6884 |
|
|
6885 |
|
runScript({ |
6886 |
|
.code = R"NKSP_CODE( |
6887 |
|
on init |
6888 |
|
declare %a := "foo" |
6889 |
|
exit(%a) |
6890 |
|
end on |
6891 |
|
)NKSP_CODE", |
6892 |
|
.expectParseWarning = true, // int array type declaration vs. string assignment |
6893 |
|
.expectStringExitResult = "foo" |
6894 |
|
}); |
6895 |
|
|
6896 |
|
runScript({ |
6897 |
|
.code = R"NKSP_CODE( |
6898 |
|
on init |
6899 |
|
declare const $a := "foo" |
6900 |
|
exit($a) |
6901 |
|
end on |
6902 |
|
)NKSP_CODE", |
6903 |
|
.expectParseWarning = true, // int type declaration vs. string assignment |
6904 |
|
.expectStringExitResult = "foo" |
6905 |
|
}); |
6906 |
|
|
6907 |
|
runScript({ |
6908 |
|
.code = R"NKSP_CODE( |
6909 |
|
on init |
6910 |
|
declare const ~a := "foo" |
6911 |
|
exit(~a) |
6912 |
|
end on |
6913 |
|
)NKSP_CODE", |
6914 |
|
.expectParseWarning = true, // real type declaration vs. string assignment |
6915 |
|
.expectStringExitResult = "foo" |
6916 |
|
}); |
6917 |
|
|
6918 |
|
runScript({ |
6919 |
|
.code = R"NKSP_CODE( |
6920 |
|
on init |
6921 |
|
declare const %a := "foo" |
6922 |
|
exit(%a) |
6923 |
|
end on |
6924 |
|
)NKSP_CODE", |
6925 |
|
.expectParseWarning = true, // int array type declaration vs. string assignment |
6926 |
|
.expectStringExitResult = "foo" |
6927 |
|
}); |
6928 |
|
|
6929 |
|
runScript({ |
6930 |
|
.code = R"NKSP_CODE( |
6931 |
|
on init |
6932 |
|
declare a := "foo" |
6933 |
|
end on |
6934 |
|
)NKSP_CODE", |
6935 |
|
.expectParseError = true // missing type prefix character in variable name |
6936 |
|
}); |
6937 |
|
|
6938 |
|
runScript({ |
6939 |
|
.code = R"NKSP_CODE( |
6940 |
|
on init |
6941 |
|
declare const a := "foo" |
6942 |
|
end on |
6943 |
|
)NKSP_CODE", |
6944 |
|
.expectParseError = true // missing type prefix character in variable name |
6945 |
|
}); |
6946 |
|
|
6947 |
|
runScript({ |
6948 |
|
.code = R"NKSP_CODE( |
6949 |
|
on init |
6950 |
|
declare @a := abort($NI_CALLBACK_ID) |
6951 |
|
end on |
6952 |
|
)NKSP_CODE", |
6953 |
|
.expectParseError = true // assigned expression does not result in a value |
6954 |
|
}); |
6955 |
|
|
6956 |
|
runScript({ |
6957 |
|
.code = R"NKSP_CODE( |
6958 |
|
on init |
6959 |
|
declare const @a := abort($NI_CALLBACK_ID) |
6960 |
|
end on |
6961 |
|
)NKSP_CODE", |
6962 |
|
.expectParseError = true // assigned expression does not result in a value |
6963 |
|
}); |
6964 |
|
|
6965 |
|
#if !SILENT_TEST |
6966 |
|
std::cout << std::endl; |
6967 |
|
#endif |
6968 |
|
} |
6969 |
|
|
6970 |
static void testBuiltInMinFunction() { |
static void testBuiltInMinFunction() { |
6971 |
#if !SILENT_TEST |
#if !SILENT_TEST |
6972 |
std::cout << "UNIT TEST: built-in min() function\n"; |
std::cout << "UNIT TEST: built-in min() function\n"; |
11464 |
testBitwiseOrOperator(); |
testBitwiseOrOperator(); |
11465 |
testBitwiseNotOperator(); |
testBitwiseNotOperator(); |
11466 |
testPrecedenceOfOperators(); |
testPrecedenceOfOperators(); |
11467 |
|
testIntVarDeclaration(); |
11468 |
|
testIntArrayVarDeclaration(); |
11469 |
|
testRealVarDeclaration(); |
11470 |
|
testRealArrayVarDeclaration(); |
11471 |
|
testStringVarDeclaration(); |
11472 |
testBuiltInMinFunction(); |
testBuiltInMinFunction(); |
11473 |
testBuiltInMaxFunction(); |
testBuiltInMaxFunction(); |
11474 |
testBuiltInAbsFunction(); |
testBuiltInAbsFunction(); |