1 |
/* |
/* |
2 |
* Copyright (c) 2019 Christian Schoenebeck |
* Copyright (c) 2019 - 2020 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
25 |
# define TEST_ASSERT assert |
# define TEST_ASSERT assert |
26 |
#endif |
#endif |
27 |
|
|
28 |
|
#define TEST_VERIFY(...) \ |
29 |
|
if (!(__VA_ARGS__)) { \ |
30 |
|
fprintf(stderr, "\n[ERROR]: The following NKSP test has failed:\n%s\n", \ |
31 |
|
opt.code.c_str()); \ |
32 |
|
fprintf(stderr, "Violated expectation for this failure was: " #__VA_ARGS__ "\n\n"); \ |
33 |
|
fprintf(stderr, "The overall expectations for this failed NKSP test were:\n\n"); \ |
34 |
|
printExpectations(opt); \ |
35 |
|
fprintf(stderr, "\n"); \ |
36 |
|
} \ |
37 |
|
TEST_ASSERT(__VA_ARGS__); \ |
38 |
|
|
39 |
|
#define TEST_PRINT_BOOL_EXPECTATION(e) \ |
40 |
|
printf(#e ": %s\n", (opt.e) ? "Yes" : "No"); \ |
41 |
|
|
42 |
|
#define TEST_PRINT_BOOL_EXPECTATION_OR(e,alt) \ |
43 |
|
printf(#e ": %s", (opt.e || opt.alt) ? "Yes" : "No"); \ |
44 |
|
if (!opt.e && opt.alt) { \ |
45 |
|
printf(" (implied by " #alt ")"); \ |
46 |
|
} \ |
47 |
|
printf("\n"); \ |
48 |
|
|
49 |
|
#define TEST_PRINT_BOOL_EXPECTATION_OR2(e,alt1,alt2) \ |
50 |
|
printf(#e ": %s", (opt.e || opt.alt1 || opt.alt2) ? "Yes" : "No"); \ |
51 |
|
if (!opt.e) { \ |
52 |
|
if (opt.alt1 && opt.alt2) { \ |
53 |
|
printf(" (implied by " #alt1 " and " #alt2 ")"); \ |
54 |
|
} else if (opt.alt1) { \ |
55 |
|
printf(" (implied by " #alt1 ")"); \ |
56 |
|
} else if (opt.alt2) { \ |
57 |
|
printf(" (implied by " #alt2 ")"); \ |
58 |
|
} \ |
59 |
|
} \ |
60 |
|
printf("\n"); \ |
61 |
|
|
62 |
|
#define TEST_PRINT_OPTIONAL_EXPECTATION(e) \ |
63 |
|
printf(#e ": %s\n", \ |
64 |
|
(opt.e) ? std::to_string(*opt.e).c_str() : "Not expected"); \ |
65 |
|
|
66 |
|
#define TEST_PRINT_OPTIONAL_STRING_EXPECTATION(e) \ |
67 |
|
printf(#e ": %s\n", \ |
68 |
|
(opt.e) ? ("'" + *opt.e + "'").c_str() : "Not expected"); \ |
69 |
|
|
70 |
|
#define TEST_PRINT_VECTOR_EXPECTATION(e) \ |
71 |
|
if (opt.e.empty()) { \ |
72 |
|
printf(#e ": Not expected\n"); \ |
73 |
|
} else { \ |
74 |
|
for (size_t i = 0; i < opt.e.size(); ++i) { \ |
75 |
|
printf(#e ": %s\n", std::to_string(opt.e[i]).c_str()); \ |
76 |
|
if (i < opt.e.size() - 1) printf(", "); \ |
77 |
|
} \ |
78 |
|
} \ |
79 |
|
|
80 |
using namespace LinuxSampler; |
using namespace LinuxSampler; |
81 |
using namespace std; |
using namespace std; |
82 |
|
|
98 |
optional<bool> expectExitResultFinal; |
optional<bool> expectExitResultFinal; |
99 |
}; |
}; |
100 |
|
|
101 |
|
static void printExpectations(RunScriptOpt opt) { |
102 |
|
TEST_PRINT_BOOL_EXPECTATION(expectParseError); |
103 |
|
TEST_PRINT_BOOL_EXPECTATION(expectParseWarning); |
104 |
|
TEST_PRINT_BOOL_EXPECTATION(expectRuntimeError); |
105 |
|
TEST_PRINT_BOOL_EXPECTATION(expectNoExitResult); |
106 |
|
TEST_PRINT_BOOL_EXPECTATION_OR2(expectExitResultIsInt, /* Or: */ expectIntExitResult, expectBoolExitResult); |
107 |
|
TEST_PRINT_BOOL_EXPECTATION_OR(expectExitResultIsReal, /* Or: */ expectRealExitResult); |
108 |
|
TEST_PRINT_BOOL_EXPECTATION(prohibitExitFunctionArguments); |
109 |
|
TEST_PRINT_OPTIONAL_EXPECTATION(expectIntExitResult); |
110 |
|
TEST_PRINT_OPTIONAL_EXPECTATION(expectBoolExitResult); |
111 |
|
TEST_PRINT_OPTIONAL_EXPECTATION(expectRealExitResult); |
112 |
|
TEST_PRINT_OPTIONAL_STRING_EXPECTATION(expectStringExitResult); |
113 |
|
TEST_PRINT_VECTOR_EXPECTATION(expectExitResultUnitPrefix); |
114 |
|
TEST_PRINT_OPTIONAL_EXPECTATION(expectExitResultUnit); |
115 |
|
TEST_PRINT_OPTIONAL_EXPECTATION(expectExitResultFinal); |
116 |
|
} |
117 |
|
|
118 |
static void runScript(const RunScriptOpt& opt) { |
static void runScript(const RunScriptOpt& opt) { |
119 |
ScriptVM vm; |
ScriptVM vm; |
120 |
vm.setAutoSuspendEnabled(false); |
vm.setAutoSuspendEnabled(false); |
126 |
vector<ParserIssue> errors = parserCtx->errors(); |
vector<ParserIssue> errors = parserCtx->errors(); |
127 |
vector<ParserIssue> warnings = parserCtx->warnings(); |
vector<ParserIssue> warnings = parserCtx->warnings(); |
128 |
if (opt.expectParseError) { |
if (opt.expectParseError) { |
129 |
TEST_ASSERT(!errors.empty()); |
TEST_VERIFY(!errors.empty()); |
130 |
return; |
return; |
131 |
} else { |
} else { |
132 |
for (ParserIssue& err : errors) { |
for (ParserIssue& err : errors) { |
133 |
err.dump(); |
err.dump(); |
134 |
} |
} |
135 |
TEST_ASSERT(errors.empty()); |
TEST_VERIFY(errors.empty()); |
136 |
} |
} |
137 |
if (opt.expectParseWarning) { |
if (opt.expectParseWarning) { |
138 |
TEST_ASSERT(!warnings.empty()); |
TEST_VERIFY(!warnings.empty()); |
139 |
} else { |
} else { |
140 |
for (ParserIssue& wrn : warnings) { |
for (ParserIssue& wrn : warnings) { |
141 |
wrn.dump(); |
wrn.dump(); |
142 |
} |
} |
143 |
} |
} |
144 |
TEST_ASSERT(parserCtx->eventHandler(0)); |
TEST_VERIFY(parserCtx->eventHandler(0)); |
145 |
unique_ptr<VMExecContext> execCtx( |
unique_ptr<VMExecContext> execCtx( |
146 |
vm.createExecContext(&*parserCtx) |
vm.createExecContext(&*parserCtx) |
147 |
); |
); |
149 |
VMEventHandler* handler = parserCtx->eventHandler(i); |
VMEventHandler* handler = parserCtx->eventHandler(i); |
150 |
VMExecStatus_t result = vm.exec(&*parserCtx, &*execCtx, handler); |
VMExecStatus_t result = vm.exec(&*parserCtx, &*execCtx, handler); |
151 |
if (opt.expectRuntimeError) { |
if (opt.expectRuntimeError) { |
152 |
TEST_ASSERT(result & VM_EXEC_ERROR); |
TEST_VERIFY(result & VM_EXEC_ERROR); |
153 |
} else { |
} else { |
154 |
TEST_ASSERT(!(result & VM_EXEC_ERROR)); |
TEST_VERIFY(!(result & VM_EXEC_ERROR)); |
155 |
} |
} |
156 |
if (opt.expectNoExitResult) { |
if (opt.expectNoExitResult) { |
157 |
VMExpr* resExpr = execCtx->exitResult(); |
VMExpr* resExpr = execCtx->exitResult(); |
158 |
TEST_ASSERT(!resExpr); |
TEST_VERIFY(!resExpr); |
159 |
} |
} |
160 |
if (opt.expectExitResultIsInt) { |
if (opt.expectExitResultIsInt) { |
161 |
VMExpr* resExpr = execCtx->exitResult(); |
VMExpr* resExpr = execCtx->exitResult(); |
162 |
TEST_ASSERT(resExpr); |
TEST_VERIFY(resExpr); |
163 |
TEST_ASSERT(resExpr->exprType() == INT_EXPR); |
TEST_VERIFY(resExpr->exprType() == INT_EXPR); |
164 |
} |
} |
165 |
if (opt.expectExitResultIsReal) { |
if (opt.expectExitResultIsReal) { |
166 |
VMExpr* resExpr = execCtx->exitResult(); |
VMExpr* resExpr = execCtx->exitResult(); |
167 |
TEST_ASSERT(resExpr); |
TEST_VERIFY(resExpr); |
168 |
TEST_ASSERT(resExpr->exprType() == REAL_EXPR); |
TEST_VERIFY(resExpr->exprType() == REAL_EXPR); |
169 |
} |
} |
170 |
if (opt.expectIntExitResult) { |
if (opt.expectIntExitResult) { |
171 |
VMExpr* resExpr = execCtx->exitResult(); |
VMExpr* resExpr = execCtx->exitResult(); |
172 |
TEST_ASSERT(resExpr); |
TEST_VERIFY(resExpr); |
173 |
TEST_ASSERT(resExpr->exprType() == INT_EXPR); |
TEST_VERIFY(resExpr->exprType() == INT_EXPR); |
174 |
TEST_ASSERT(resExpr->asInt()->evalInt() == *opt.expectIntExitResult); |
TEST_VERIFY(resExpr->asInt()->evalInt() == *opt.expectIntExitResult); |
175 |
} |
} |
176 |
if (opt.expectRealExitResult) { |
if (opt.expectRealExitResult) { |
177 |
VMExpr* resExpr = execCtx->exitResult(); |
VMExpr* resExpr = execCtx->exitResult(); |
178 |
TEST_ASSERT(resExpr); |
TEST_VERIFY(resExpr); |
179 |
TEST_ASSERT(resExpr->exprType() == REAL_EXPR); |
TEST_VERIFY(resExpr->exprType() == REAL_EXPR); |
180 |
if (sizeof(vmfloat) == sizeof(float)) { |
if (sizeof(vmfloat) == sizeof(float)) { |
181 |
TEST_ASSERT(RTMath::fEqual32(resExpr->asReal()->evalReal(), *opt.expectRealExitResult)); |
TEST_VERIFY(RTMath::fEqual32(resExpr->asReal()->evalReal(), *opt.expectRealExitResult)); |
182 |
} else { |
} else { |
183 |
TEST_ASSERT(RTMath::fEqual64(resExpr->asReal()->evalReal(), *opt.expectRealExitResult)); |
TEST_VERIFY(RTMath::fEqual64(resExpr->asReal()->evalReal(), *opt.expectRealExitResult)); |
184 |
} |
} |
185 |
} |
} |
186 |
if (opt.expectBoolExitResult) { |
if (opt.expectBoolExitResult) { |
187 |
VMExpr* resExpr = execCtx->exitResult(); |
VMExpr* resExpr = execCtx->exitResult(); |
188 |
TEST_ASSERT(resExpr); |
TEST_VERIFY(resExpr); |
189 |
TEST_ASSERT(resExpr->exprType() == INT_EXPR); |
TEST_VERIFY(resExpr->exprType() == INT_EXPR); |
190 |
TEST_ASSERT(bool(resExpr->asInt()->evalInt()) == *opt.expectBoolExitResult); |
TEST_VERIFY(bool(resExpr->asInt()->evalInt()) == *opt.expectBoolExitResult); |
191 |
} |
} |
192 |
if (opt.expectStringExitResult) { |
if (opt.expectStringExitResult) { |
193 |
VMExpr* resExpr = execCtx->exitResult(); |
VMExpr* resExpr = execCtx->exitResult(); |
194 |
TEST_ASSERT(resExpr); |
TEST_VERIFY(resExpr); |
195 |
TEST_ASSERT(resExpr->exprType() == STRING_EXPR); |
TEST_VERIFY(resExpr->exprType() == STRING_EXPR); |
196 |
TEST_ASSERT(resExpr->asString()->evalStr() == *opt.expectStringExitResult); |
TEST_VERIFY(resExpr->asString()->evalStr() == *opt.expectStringExitResult); |
197 |
} |
} |
198 |
if (opt.expectExitResultUnit) { |
if (opt.expectExitResultUnit) { |
199 |
VMExpr* resExpr = execCtx->exitResult(); |
VMExpr* resExpr = execCtx->exitResult(); |
200 |
TEST_ASSERT(resExpr); |
TEST_VERIFY(resExpr); |
201 |
VMNumberExpr* numberExpr = resExpr->asNumber(); |
VMNumberExpr* numberExpr = resExpr->asNumber(); |
202 |
TEST_ASSERT(numberExpr); |
TEST_VERIFY(numberExpr); |
203 |
TEST_ASSERT(numberExpr->unitType() == *opt.expectExitResultUnit); |
TEST_VERIFY(numberExpr->unitType() == *opt.expectExitResultUnit); |
204 |
} |
} |
205 |
if (!opt.expectExitResultUnitPrefix.empty()) { |
if (!opt.expectExitResultUnitPrefix.empty()) { |
206 |
VMExpr* resExpr = execCtx->exitResult(); |
VMExpr* resExpr = execCtx->exitResult(); |
207 |
TEST_ASSERT(resExpr); |
TEST_VERIFY(resExpr); |
208 |
VMNumberExpr* numberExpr = resExpr->asNumber(); |
VMNumberExpr* numberExpr = resExpr->asNumber(); |
209 |
TEST_ASSERT(numberExpr); |
TEST_VERIFY(numberExpr); |
210 |
auto prefixes = opt.expectExitResultUnitPrefix; |
auto prefixes = opt.expectExitResultUnitPrefix; |
211 |
if (*prefixes.rbegin() != VM_NO_PREFIX) |
if (*prefixes.rbegin() != VM_NO_PREFIX) |
212 |
prefixes.push_back(VM_NO_PREFIX); // VM_NO_PREFIX termination required by unitFactr() call |
prefixes.push_back(VM_NO_PREFIX); // VM_NO_PREFIX termination required by unitFactr() call |
213 |
vmfloat expectedFactor = VMUnit::unitFactor(&prefixes[0]); |
vmfloat expectedFactor = VMUnit::unitFactor(&prefixes[0]); |
214 |
vmfloat actualFactor = numberExpr->unitFactor(); |
vmfloat actualFactor = numberExpr->unitFactor(); |
215 |
if (sizeof(vmfloat) == sizeof(float)) { |
if (sizeof(vmfloat) == sizeof(float)) { |
216 |
TEST_ASSERT(RTMath::fEqual32(expectedFactor, actualFactor)); |
TEST_VERIFY(RTMath::fEqual32(expectedFactor, actualFactor)); |
217 |
} else { |
} else { |
218 |
TEST_ASSERT(RTMath::fEqual64(expectedFactor, actualFactor)); |
TEST_VERIFY(RTMath::fEqual64(expectedFactor, actualFactor)); |
219 |
} |
} |
220 |
} |
} |
221 |
if (opt.expectExitResultFinal) { |
if (opt.expectExitResultFinal) { |
222 |
VMExpr* resExpr = execCtx->exitResult(); |
VMExpr* resExpr = execCtx->exitResult(); |
223 |
TEST_ASSERT(resExpr); |
TEST_VERIFY(resExpr); |
224 |
VMNumberExpr* numberExpr = resExpr->asNumber(); |
VMNumberExpr* numberExpr = resExpr->asNumber(); |
225 |
TEST_ASSERT(numberExpr); |
TEST_VERIFY(numberExpr); |
226 |
TEST_ASSERT(numberExpr->isFinal() == *opt.expectExitResultFinal); |
TEST_VERIFY(numberExpr->isFinal() == *opt.expectExitResultFinal); |
227 |
} |
} |
228 |
} |
} |
229 |
} |
} |
1075 |
.expectParseError = true // assigning final to a non-final variable not allowed |
.expectParseError = true // assigning final to a non-final variable not allowed |
1076 |
}); |
}); |
1077 |
|
|
1078 |
|
// exit() acting as return statement ... |
1079 |
|
|
1080 |
|
runScript({ |
1081 |
|
.code = R"NKSP_CODE( |
1082 |
|
function doFoo |
1083 |
|
exit(2) { just return from this user function, i.e. don't stop init handler } |
1084 |
|
end function |
1085 |
|
|
1086 |
|
on init |
1087 |
|
call doFoo |
1088 |
|
exit(3) |
1089 |
|
end on |
1090 |
|
)NKSP_CODE", |
1091 |
|
.expectIntExitResult = 3 |
1092 |
|
}); |
1093 |
|
|
1094 |
|
runScript({ |
1095 |
|
.code = R"NKSP_CODE( |
1096 |
|
function doFoo1 |
1097 |
|
exit(2) { just return from this user function, i.e. don't stop init handler } |
1098 |
|
end function |
1099 |
|
|
1100 |
|
function doFoo2 |
1101 |
|
call doFoo1 |
1102 |
|
exit(3) { just return from this user function, i.e. don't stop init handler } |
1103 |
|
end function |
1104 |
|
|
1105 |
|
on init |
1106 |
|
call doFoo2 |
1107 |
|
exit(4) |
1108 |
|
end on |
1109 |
|
)NKSP_CODE", |
1110 |
|
.expectIntExitResult = 4 |
1111 |
|
}); |
1112 |
|
|
1113 |
|
runScript({ |
1114 |
|
.code = R"NKSP_CODE( |
1115 |
|
function doFoo |
1116 |
|
exit(2) { just return from this user function, i.e. don't stop init handler } |
1117 |
|
end function |
1118 |
|
|
1119 |
|
on init |
1120 |
|
call doFoo |
1121 |
|
exit(3) |
1122 |
|
{ dead code ... } |
1123 |
|
call doFoo |
1124 |
|
exit(4) |
1125 |
|
end on |
1126 |
|
)NKSP_CODE", |
1127 |
|
.expectIntExitResult = 3 |
1128 |
|
}); |
1129 |
|
|
1130 |
|
runScript({ |
1131 |
|
.code = R"NKSP_CODE( |
1132 |
|
function doFoo |
1133 |
|
exit(2) { just return from this user function, i.e. don't stop init handler } |
1134 |
|
end function |
1135 |
|
|
1136 |
|
on init |
1137 |
|
call doFoo |
1138 |
|
exit(3) |
1139 |
|
{ dead code ... } |
1140 |
|
call doFoo |
1141 |
|
end on |
1142 |
|
)NKSP_CODE", |
1143 |
|
.expectIntExitResult = 3 |
1144 |
|
}); |
1145 |
|
|
1146 |
#if !SILENT_TEST |
#if !SILENT_TEST |
1147 |
std::cout << std::endl; |
std::cout << std::endl; |
1148 |
#endif |
#endif |
2232 |
.expectExitResultUnit = VM_SECOND |
.expectExitResultUnit = VM_SECOND |
2233 |
}); |
}); |
2234 |
|
|
2235 |
|
runScript({ |
2236 |
|
.code = R"NKSP_CODE( |
2237 |
|
on init |
2238 |
|
declare ~foo := 1.0 { neutral } |
2239 |
|
declare $bar := 7000ms |
2240 |
|
exit(~foo * real($bar)) |
2241 |
|
end on |
2242 |
|
)NKSP_CODE", |
2243 |
|
.expectRealExitResult = 7000.0, |
2244 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
2245 |
|
.expectExitResultUnit = VM_SECOND |
2246 |
|
}); |
2247 |
|
|
2248 |
|
runScript({ |
2249 |
|
.code = R"NKSP_CODE( |
2250 |
|
on init |
2251 |
|
declare $foo := 1 { neutral } |
2252 |
|
declare $bar := 7000ms |
2253 |
|
exit(real($foo) * real($bar)) |
2254 |
|
end on |
2255 |
|
)NKSP_CODE", |
2256 |
|
.expectRealExitResult = 7000.0, |
2257 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
2258 |
|
.expectExitResultUnit = VM_SECOND |
2259 |
|
}); |
2260 |
|
|
2261 |
// 'final' ('!') operator tests ... |
// 'final' ('!') operator tests ... |
2262 |
|
|
2263 |
runScript({ |
runScript({ |
2515 |
.expectParseError = true // unit types are not matching |
.expectParseError = true // unit types are not matching |
2516 |
}); |
}); |
2517 |
|
|
2518 |
|
runScript({ |
2519 |
|
.code = R"NKSP_CODE( |
2520 |
|
on init |
2521 |
|
declare $foo := 1000000 |
2522 |
|
declare $bar := 7000ms |
2523 |
|
exit(real($foo) / 1000000.0 * real($bar)) |
2524 |
|
end on |
2525 |
|
)NKSP_CODE", |
2526 |
|
.expectRealExitResult = 7000.0, |
2527 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
2528 |
|
.expectExitResultUnit = VM_SECOND |
2529 |
|
}); |
2530 |
|
|
2531 |
// 'final' ('!') operator tests ... |
// 'final' ('!') operator tests ... |
2532 |
|
|
2533 |
runScript({ |
runScript({ |
5589 |
#endif |
#endif |
5590 |
} |
} |
5591 |
|
|
5592 |
|
static void testIntVarDeclaration() { |
5593 |
|
#if !SILENT_TEST |
5594 |
|
std::cout << "UNIT TEST: int var declaration\n"; |
5595 |
|
#endif |
5596 |
|
|
5597 |
|
runScript({ |
5598 |
|
.code = R"NKSP_CODE( |
5599 |
|
on init |
5600 |
|
declare $a |
5601 |
|
exit($a) |
5602 |
|
end on |
5603 |
|
)NKSP_CODE", |
5604 |
|
.expectIntExitResult = 0 |
5605 |
|
}); |
5606 |
|
|
5607 |
|
runScript({ |
5608 |
|
.code = R"NKSP_CODE( |
5609 |
|
on init |
5610 |
|
declare $a := 24 |
5611 |
|
exit($a) |
5612 |
|
end on |
5613 |
|
)NKSP_CODE", |
5614 |
|
.expectIntExitResult = 24 |
5615 |
|
}); |
5616 |
|
|
5617 |
|
runScript({ |
5618 |
|
.code = R"NKSP_CODE( |
5619 |
|
on init |
5620 |
|
declare $a := 24 |
5621 |
|
$a := 8 |
5622 |
|
exit($a) |
5623 |
|
end on |
5624 |
|
)NKSP_CODE", |
5625 |
|
.expectIntExitResult = 8 |
5626 |
|
}); |
5627 |
|
|
5628 |
|
runScript({ |
5629 |
|
.code = R"NKSP_CODE( |
5630 |
|
on init |
5631 |
|
declare $a |
5632 |
|
declare $a |
5633 |
|
end on |
5634 |
|
)NKSP_CODE", |
5635 |
|
.expectParseError = true // variable re-declaration |
5636 |
|
}); |
5637 |
|
|
5638 |
|
runScript({ |
5639 |
|
.code = R"NKSP_CODE( |
5640 |
|
on init |
5641 |
|
declare const $a |
5642 |
|
end on |
5643 |
|
)NKSP_CODE", |
5644 |
|
.expectParseError = true // const variable declaration without assignment |
5645 |
|
}); |
5646 |
|
|
5647 |
|
runScript({ |
5648 |
|
.code = R"NKSP_CODE( |
5649 |
|
on init |
5650 |
|
declare const $a := 24 |
5651 |
|
exit($a) |
5652 |
|
end on |
5653 |
|
)NKSP_CODE", |
5654 |
|
.expectIntExitResult = 24 |
5655 |
|
}); |
5656 |
|
|
5657 |
|
runScript({ |
5658 |
|
.code = R"NKSP_CODE( |
5659 |
|
on init |
5660 |
|
declare const $a := 24 |
5661 |
|
$a := 8 |
5662 |
|
end on |
5663 |
|
)NKSP_CODE", |
5664 |
|
.expectParseError = true // attempt to modify const variable |
5665 |
|
}); |
5666 |
|
|
5667 |
|
runScript({ |
5668 |
|
.code = R"NKSP_CODE( |
5669 |
|
on init |
5670 |
|
declare const $a := 24 |
5671 |
|
declare const $b := $a |
5672 |
|
exit($b) |
5673 |
|
end on |
5674 |
|
)NKSP_CODE", |
5675 |
|
.expectIntExitResult = 24 |
5676 |
|
}); |
5677 |
|
|
5678 |
|
runScript({ |
5679 |
|
.code = R"NKSP_CODE( |
5680 |
|
on init |
5681 |
|
declare $a := 24 |
5682 |
|
declare const $b := $a |
5683 |
|
end on |
5684 |
|
)NKSP_CODE", |
5685 |
|
.expectParseError = true // const variable defined with non-const assignment |
5686 |
|
}); |
5687 |
|
|
5688 |
|
runScript({ |
5689 |
|
.code = R"NKSP_CODE( |
5690 |
|
on init |
5691 |
|
declare polyphonic $a |
5692 |
|
exit($a) |
5693 |
|
end on |
5694 |
|
)NKSP_CODE", |
5695 |
|
.expectIntExitResult = 0 |
5696 |
|
}); |
5697 |
|
|
5698 |
|
runScript({ |
5699 |
|
.code = R"NKSP_CODE( |
5700 |
|
on init |
5701 |
|
declare const polyphonic $a |
5702 |
|
end on |
5703 |
|
)NKSP_CODE", |
5704 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
5705 |
|
}); |
5706 |
|
|
5707 |
|
runScript({ |
5708 |
|
.code = R"NKSP_CODE( |
5709 |
|
on init |
5710 |
|
declare polyphonic const $a |
5711 |
|
end on |
5712 |
|
)NKSP_CODE", |
5713 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
5714 |
|
}); |
5715 |
|
|
5716 |
|
runScript({ |
5717 |
|
.code = R"NKSP_CODE( |
5718 |
|
on init |
5719 |
|
declare const polyphonic $a := 3 |
5720 |
|
end on |
5721 |
|
)NKSP_CODE", |
5722 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
5723 |
|
}); |
5724 |
|
|
5725 |
|
runScript({ |
5726 |
|
.code = R"NKSP_CODE( |
5727 |
|
on init |
5728 |
|
declare polyphonic const $a := 3 |
5729 |
|
end on |
5730 |
|
)NKSP_CODE", |
5731 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
5732 |
|
}); |
5733 |
|
|
5734 |
|
runScript({ |
5735 |
|
.code = R"NKSP_CODE( |
5736 |
|
on init |
5737 |
|
declare ~a := 24 |
5738 |
|
exit(~a) |
5739 |
|
end on |
5740 |
|
)NKSP_CODE", |
5741 |
|
.expectParseWarning = true, // real type declaration vs. int value assignment |
5742 |
|
.expectIntExitResult = 24 |
5743 |
|
}); |
5744 |
|
|
5745 |
|
runScript({ |
5746 |
|
.code = R"NKSP_CODE( |
5747 |
|
on init |
5748 |
|
declare %a := 24 |
5749 |
|
exit(%a) |
5750 |
|
end on |
5751 |
|
)NKSP_CODE", |
5752 |
|
.expectParseWarning = true, // int array type declaration vs. int scalar value assignment |
5753 |
|
.expectIntExitResult = 24 |
5754 |
|
}); |
5755 |
|
|
5756 |
|
runScript({ |
5757 |
|
.code = R"NKSP_CODE( |
5758 |
|
on init |
5759 |
|
declare const %a := 24 |
5760 |
|
exit(%a) |
5761 |
|
end on |
5762 |
|
)NKSP_CODE", |
5763 |
|
.expectParseWarning = true, // int array type declaration vs. int scalar value assignment |
5764 |
|
.expectIntExitResult = 24 |
5765 |
|
}); |
5766 |
|
|
5767 |
|
runScript({ |
5768 |
|
.code = R"NKSP_CODE( |
5769 |
|
on init |
5770 |
|
declare ?a := 24 |
5771 |
|
exit(?a) |
5772 |
|
end on |
5773 |
|
)NKSP_CODE", |
5774 |
|
.expectParseWarning = true, // real array type declaration vs. int scalar value assignment |
5775 |
|
.expectIntExitResult = 24 |
5776 |
|
}); |
5777 |
|
|
5778 |
|
runScript({ |
5779 |
|
.code = R"NKSP_CODE( |
5780 |
|
on init |
5781 |
|
declare const ?a := 24 |
5782 |
|
exit(?a) |
5783 |
|
end on |
5784 |
|
)NKSP_CODE", |
5785 |
|
.expectParseWarning = true, // real array type declaration vs. int scalar value assignment |
5786 |
|
.expectIntExitResult = 24 |
5787 |
|
}); |
5788 |
|
|
5789 |
|
runScript({ |
5790 |
|
.code = R"NKSP_CODE( |
5791 |
|
on init |
5792 |
|
declare @a := 24 |
5793 |
|
exit(@a) |
5794 |
|
end on |
5795 |
|
)NKSP_CODE", |
5796 |
|
.expectParseWarning = true, // string type declaration vs. int scalar value assignment |
5797 |
|
.expectIntExitResult = 24 |
5798 |
|
}); |
5799 |
|
|
5800 |
|
runScript({ |
5801 |
|
.code = R"NKSP_CODE( |
5802 |
|
on init |
5803 |
|
declare const @a := 24 |
5804 |
|
exit(@a) |
5805 |
|
end on |
5806 |
|
)NKSP_CODE", |
5807 |
|
.expectParseWarning = true, // string type declaration vs. int scalar value assignment |
5808 |
|
.expectIntExitResult = 24 |
5809 |
|
}); |
5810 |
|
|
5811 |
|
runScript({ |
5812 |
|
.code = R"NKSP_CODE( |
5813 |
|
on init |
5814 |
|
declare $a := ( 0, 1, 2 ) |
5815 |
|
end on |
5816 |
|
)NKSP_CODE", |
5817 |
|
.expectParseError = true // int scalar type declaration vs. int array value assignment |
5818 |
|
}); |
5819 |
|
|
5820 |
|
runScript({ |
5821 |
|
.code = R"NKSP_CODE( |
5822 |
|
on init |
5823 |
|
declare const $a := ( 0, 1, 2 ) |
5824 |
|
end on |
5825 |
|
)NKSP_CODE", |
5826 |
|
.expectParseError = true // int scalar type declaration vs. int array value assignment |
5827 |
|
}); |
5828 |
|
|
5829 |
|
runScript({ |
5830 |
|
.code = R"NKSP_CODE( |
5831 |
|
on init |
5832 |
|
declare a |
5833 |
|
end on |
5834 |
|
)NKSP_CODE", |
5835 |
|
.expectParseError = true // missing type prefix character in variable name |
5836 |
|
}); |
5837 |
|
|
5838 |
|
runScript({ |
5839 |
|
.code = R"NKSP_CODE( |
5840 |
|
on init |
5841 |
|
declare a := 24 |
5842 |
|
end on |
5843 |
|
)NKSP_CODE", |
5844 |
|
.expectParseError = true // missing type prefix character in variable name |
5845 |
|
}); |
5846 |
|
|
5847 |
|
runScript({ |
5848 |
|
.code = R"NKSP_CODE( |
5849 |
|
on init |
5850 |
|
declare const a := 24 |
5851 |
|
end on |
5852 |
|
)NKSP_CODE", |
5853 |
|
.expectParseError = true // missing type prefix character in variable name |
5854 |
|
}); |
5855 |
|
|
5856 |
|
runScript({ |
5857 |
|
.code = R"NKSP_CODE( |
5858 |
|
on init |
5859 |
|
declare polyphonic a |
5860 |
|
end on |
5861 |
|
)NKSP_CODE", |
5862 |
|
.expectParseError = true // missing type prefix character in variable name |
5863 |
|
}); |
5864 |
|
|
5865 |
|
runScript({ |
5866 |
|
.code = R"NKSP_CODE( |
5867 |
|
on init |
5868 |
|
declare $a := max(8,24) |
5869 |
|
exit($a) |
5870 |
|
end on |
5871 |
|
)NKSP_CODE", |
5872 |
|
.expectIntExitResult = 24 |
5873 |
|
}); |
5874 |
|
|
5875 |
|
runScript({ |
5876 |
|
.code = R"NKSP_CODE( |
5877 |
|
on init |
5878 |
|
declare $a := abort($NI_CALLBACK_ID) |
5879 |
|
end on |
5880 |
|
)NKSP_CODE", |
5881 |
|
.expectParseError = true // assigned expression does not result in a value |
5882 |
|
}); |
5883 |
|
|
5884 |
|
runScript({ |
5885 |
|
.code = R"NKSP_CODE( |
5886 |
|
on init |
5887 |
|
declare const $a := abort($NI_CALLBACK_ID) |
5888 |
|
end on |
5889 |
|
)NKSP_CODE", |
5890 |
|
.expectParseError = true // assigned expression does not result in a value |
5891 |
|
}); |
5892 |
|
|
5893 |
|
#if !SILENT_TEST |
5894 |
|
std::cout << std::endl; |
5895 |
|
#endif |
5896 |
|
} |
5897 |
|
|
5898 |
|
static void testIntArrayVarDeclaration() { |
5899 |
|
#if !SILENT_TEST |
5900 |
|
std::cout << "UNIT TEST: int array var declaration\n"; |
5901 |
|
#endif |
5902 |
|
|
5903 |
|
runScript({ |
5904 |
|
.code = R"NKSP_CODE( |
5905 |
|
on init |
5906 |
|
declare %a[3] |
5907 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5908 |
|
end on |
5909 |
|
)NKSP_CODE", |
5910 |
|
.expectIntExitResult = 0 |
5911 |
|
}); |
5912 |
|
|
5913 |
|
runScript({ |
5914 |
|
.code = R"NKSP_CODE( |
5915 |
|
on init |
5916 |
|
declare %a[0] |
5917 |
|
end on |
5918 |
|
)NKSP_CODE", |
5919 |
|
.expectParseWarning = true // unusable array size |
5920 |
|
}); |
5921 |
|
|
5922 |
|
runScript({ |
5923 |
|
.code = R"NKSP_CODE( |
5924 |
|
on init |
5925 |
|
declare %a[-1] |
5926 |
|
end on |
5927 |
|
)NKSP_CODE", |
5928 |
|
.expectParseError = true // illegal array size |
5929 |
|
}); |
5930 |
|
|
5931 |
|
runScript({ |
5932 |
|
.code = R"NKSP_CODE( |
5933 |
|
on init |
5934 |
|
declare %a[3] := ( 1, 2, 3 ) |
5935 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5936 |
|
end on |
5937 |
|
)NKSP_CODE", |
5938 |
|
.expectIntExitResult = (1 + 2 + 3) |
5939 |
|
}); |
5940 |
|
|
5941 |
|
runScript({ |
5942 |
|
.code = R"NKSP_CODE( |
5943 |
|
on init |
5944 |
|
declare %a[4] := ( 1, 2, 3 ) |
5945 |
|
exit( %a[0] + %a[1] + %a[2] + %a[3] ) |
5946 |
|
end on |
5947 |
|
)NKSP_CODE", |
5948 |
|
.expectParseWarning = true, // less values assigned than array size declared |
5949 |
|
.expectIntExitResult = (1 + 2 + 3 + 0) |
5950 |
|
}); |
5951 |
|
|
5952 |
|
runScript({ |
5953 |
|
.code = R"NKSP_CODE( |
5954 |
|
on init |
5955 |
|
declare %a[] := ( 1, 2, 3 ) |
5956 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5957 |
|
end on |
5958 |
|
)NKSP_CODE", |
5959 |
|
.expectIntExitResult = (1 + 2 + 3) |
5960 |
|
}); |
5961 |
|
|
5962 |
|
runScript({ |
5963 |
|
.code = R"NKSP_CODE( |
5964 |
|
on init |
5965 |
|
declare %a[] |
5966 |
|
end on |
5967 |
|
)NKSP_CODE", |
5968 |
|
.expectParseWarning = true // unusable array size (zero) |
5969 |
|
}); |
5970 |
|
|
5971 |
|
runScript({ |
5972 |
|
.code = R"NKSP_CODE( |
5973 |
|
on init |
5974 |
|
declare const $sz := 3 |
5975 |
|
declare %a[$sz] := ( 1, 2, 3 ) |
5976 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5977 |
|
end on |
5978 |
|
)NKSP_CODE", |
5979 |
|
.expectIntExitResult = (1 + 2 + 3) |
5980 |
|
}); |
5981 |
|
|
5982 |
|
runScript({ |
5983 |
|
.code = R"NKSP_CODE( |
5984 |
|
on init |
5985 |
|
declare const $sz := 3 |
5986 |
|
declare const %a[$sz] := ( 1, 2, 3 ) |
5987 |
|
exit( %a[0] + %a[1] + %a[2] ) |
5988 |
|
end on |
5989 |
|
)NKSP_CODE", |
5990 |
|
.expectIntExitResult = (1 + 2 + 3) |
5991 |
|
}); |
5992 |
|
|
5993 |
|
runScript({ |
5994 |
|
.code = R"NKSP_CODE( |
5995 |
|
on init |
5996 |
|
declare $sz := 3 |
5997 |
|
declare %a[$sz] := ( 1, 2, 3 ) |
5998 |
|
end on |
5999 |
|
)NKSP_CODE", |
6000 |
|
.expectParseError = true // array size must be constant expression |
6001 |
|
}); |
6002 |
|
|
6003 |
|
runScript({ |
6004 |
|
.code = R"NKSP_CODE( |
6005 |
|
on init |
6006 |
|
declare $sz := 3 |
6007 |
|
declare const %a[$sz] := ( 1, 2, 3 ) |
6008 |
|
end on |
6009 |
|
)NKSP_CODE", |
6010 |
|
.expectParseError = true // array size must be constant expression |
6011 |
|
}); |
6012 |
|
|
6013 |
|
runScript({ |
6014 |
|
.code = R"NKSP_CODE( |
6015 |
|
on init |
6016 |
|
declare const ~sz := 3.0 |
6017 |
|
declare const %a[~sz] := ( 1, 2, 3 ) |
6018 |
|
end on |
6019 |
|
)NKSP_CODE", |
6020 |
|
.expectParseError = true // array size must be integer type |
6021 |
|
}); |
6022 |
|
|
6023 |
|
runScript({ |
6024 |
|
.code = R"NKSP_CODE( |
6025 |
|
on init |
6026 |
|
declare %a[3s] := ( 1, 2, 3 ) |
6027 |
|
end on |
6028 |
|
)NKSP_CODE", |
6029 |
|
.expectParseError = true // units not allowed for array size |
6030 |
|
}); |
6031 |
|
|
6032 |
|
runScript({ |
6033 |
|
.code = R"NKSP_CODE( |
6034 |
|
on init |
6035 |
|
declare %a[3m] := ( 1, 2, 3 ) |
6036 |
|
end on |
6037 |
|
)NKSP_CODE", |
6038 |
|
.expectParseError = true // units not allowed for array size |
6039 |
|
}); |
6040 |
|
|
6041 |
|
runScript({ |
6042 |
|
.code = R"NKSP_CODE( |
6043 |
|
on init |
6044 |
|
declare const %a[!3] := ( 1, 2, 3 ) |
6045 |
|
exit( %a[0] + %a[1] + %a[2] ) |
6046 |
|
end on |
6047 |
|
)NKSP_CODE", |
6048 |
|
.expectIntExitResult = (1 + 2 + 3), |
6049 |
|
.expectParseWarning = true // 'final' operator is meaningless for array size |
6050 |
|
}); |
6051 |
|
|
6052 |
|
runScript({ |
6053 |
|
.code = R"NKSP_CODE( |
6054 |
|
on init |
6055 |
|
declare %a[3] := ( 1, 2, 3 ) |
6056 |
|
%a[0] := 4 |
6057 |
|
%a[1] := 5 |
6058 |
|
%a[2] := 6 |
6059 |
|
exit( %a[0] + %a[1] + %a[2] ) |
6060 |
|
end on |
6061 |
|
)NKSP_CODE", |
6062 |
|
.expectIntExitResult = (4 + 5 + 6) |
6063 |
|
}); |
6064 |
|
|
6065 |
|
runScript({ |
6066 |
|
.code = R"NKSP_CODE( |
6067 |
|
on init |
6068 |
|
declare %a[3] |
6069 |
|
declare %a[3] |
6070 |
|
end on |
6071 |
|
)NKSP_CODE", |
6072 |
|
.expectParseError = true // variable re-declaration |
6073 |
|
}); |
6074 |
|
|
6075 |
|
runScript({ |
6076 |
|
.code = R"NKSP_CODE( |
6077 |
|
on init |
6078 |
|
declare const %a[3] |
6079 |
|
end on |
6080 |
|
)NKSP_CODE", |
6081 |
|
.expectParseError = true // const variable declaration without assignment |
6082 |
|
}); |
6083 |
|
|
6084 |
|
runScript({ |
6085 |
|
.code = R"NKSP_CODE( |
6086 |
|
on init |
6087 |
|
declare const %a[3] := ( 1, 2, 3 ) |
6088 |
|
exit( %a[0] + %a[1] + %a[2] ) |
6089 |
|
end on |
6090 |
|
)NKSP_CODE", |
6091 |
|
.expectIntExitResult = (1 + 2 + 3) |
6092 |
|
}); |
6093 |
|
|
6094 |
|
runScript({ |
6095 |
|
.code = R"NKSP_CODE( |
6096 |
|
on init |
6097 |
|
declare const %a[3] := ( 1, 2, 3, 4 ) |
6098 |
|
end on |
6099 |
|
)NKSP_CODE", |
6100 |
|
.expectParseError = true // incompatible array sizes |
6101 |
|
}); |
6102 |
|
|
6103 |
|
runScript({ |
6104 |
|
.code = R"NKSP_CODE( |
6105 |
|
on init |
6106 |
|
declare const %a[3] := ( 1, 2, 3 ) |
6107 |
|
%a[0] := 8 |
6108 |
|
end on |
6109 |
|
)NKSP_CODE", |
6110 |
|
.expectParseError = true // attempt to modify const variable |
6111 |
|
}); |
6112 |
|
|
6113 |
|
runScript({ |
6114 |
|
.code = R"NKSP_CODE( |
6115 |
|
on init |
6116 |
|
declare const %a[3] := ( 1, 2, 3 ) |
6117 |
|
declare const %b[3] := ( %a[0], %a[1], %a[2] ) |
6118 |
|
exit( %b[0] + %b[1] + %b[2] ) |
6119 |
|
end on |
6120 |
|
)NKSP_CODE", |
6121 |
|
.expectIntExitResult = (1 + 2 + 3) |
6122 |
|
}); |
6123 |
|
|
6124 |
|
runScript({ |
6125 |
|
.code = R"NKSP_CODE( |
6126 |
|
on init |
6127 |
|
declare %a[3] := ( 1, 2, 3 ) |
6128 |
|
declare const %b[3] := ( %a[0], %a[1], %a[2] ) |
6129 |
|
end on |
6130 |
|
)NKSP_CODE", |
6131 |
|
.expectParseError = true // const array defined with non-const assignment |
6132 |
|
}); |
6133 |
|
|
6134 |
|
runScript({ |
6135 |
|
.code = R"NKSP_CODE( |
6136 |
|
on init |
6137 |
|
declare polyphonic %a[3] |
6138 |
|
end on |
6139 |
|
)NKSP_CODE", |
6140 |
|
.expectParseError = true // polyphonic not allowed for array types |
6141 |
|
}); |
6142 |
|
|
6143 |
|
runScript({ |
6144 |
|
.code = R"NKSP_CODE( |
6145 |
|
on init |
6146 |
|
declare polyphonic %a[3] := ( 1, 2, 3 ) |
6147 |
|
end on |
6148 |
|
)NKSP_CODE", |
6149 |
|
.expectParseError = true // polyphonic not allowed for array types |
6150 |
|
}); |
6151 |
|
|
6152 |
|
runScript({ |
6153 |
|
.code = R"NKSP_CODE( |
6154 |
|
on init |
6155 |
|
declare const polyphonic %a[3] |
6156 |
|
end on |
6157 |
|
)NKSP_CODE", |
6158 |
|
.expectParseError = true // polyphonic not allowed for array types |
6159 |
|
}); |
6160 |
|
|
6161 |
|
runScript({ |
6162 |
|
.code = R"NKSP_CODE( |
6163 |
|
on init |
6164 |
|
declare const polyphonic %a[3] := ( 1, 2, 3 ) |
6165 |
|
end on |
6166 |
|
)NKSP_CODE", |
6167 |
|
.expectParseError = true // polyphonic not allowed for array types |
6168 |
|
}); |
6169 |
|
|
6170 |
|
runScript({ |
6171 |
|
.code = R"NKSP_CODE( |
6172 |
|
on init |
6173 |
|
declare polyphonic const %a[3] |
6174 |
|
end on |
6175 |
|
)NKSP_CODE", |
6176 |
|
.expectParseError = true // polyphonic not allowed for array types |
6177 |
|
}); |
6178 |
|
|
6179 |
|
runScript({ |
6180 |
|
.code = R"NKSP_CODE( |
6181 |
|
on init |
6182 |
|
declare polyphonic const %a[3] := ( 1, 2, 3 ) |
6183 |
|
end on |
6184 |
|
)NKSP_CODE", |
6185 |
|
.expectParseError = true // polyphonic not allowed for array types |
6186 |
|
}); |
6187 |
|
|
6188 |
|
runScript({ |
6189 |
|
.code = R"NKSP_CODE( |
6190 |
|
on init |
6191 |
|
declare %a[3] := ( 1, max(8,24), 3 ) |
6192 |
|
exit( %a[0] + %a[1] + %a[2] ) |
6193 |
|
end on |
6194 |
|
)NKSP_CODE", |
6195 |
|
.expectIntExitResult = ( 1 + 24 + 3 ) |
6196 |
|
}); |
6197 |
|
|
6198 |
|
runScript({ |
6199 |
|
.code = R"NKSP_CODE( |
6200 |
|
on init |
6201 |
|
declare %a[3] := ( 1, abort($NI_CALLBACK_ID), 3 ) |
6202 |
|
end on |
6203 |
|
)NKSP_CODE", |
6204 |
|
.expectParseError = true // assigned expression does not result in a value |
6205 |
|
}); |
6206 |
|
|
6207 |
|
runScript({ |
6208 |
|
.code = R"NKSP_CODE( |
6209 |
|
on init |
6210 |
|
declare const %a[3] := ( 1, abort($NI_CALLBACK_ID), 3 ) |
6211 |
|
end on |
6212 |
|
)NKSP_CODE", |
6213 |
|
.expectParseError = true // assigned expression does not result in a value |
6214 |
|
}); |
6215 |
|
|
6216 |
|
runScript({ |
6217 |
|
.code = R"NKSP_CODE( |
6218 |
|
on init |
6219 |
|
declare %a[3] := ( 1.0, 2.0, 3.0 ) |
6220 |
|
end on |
6221 |
|
)NKSP_CODE", |
6222 |
|
.expectParseError = true // int array declaration vs. real array assignment |
6223 |
|
}); |
6224 |
|
|
6225 |
|
runScript({ |
6226 |
|
.code = R"NKSP_CODE( |
6227 |
|
on init |
6228 |
|
declare %a[3] := ( 1, 2, 3.0 ) |
6229 |
|
end on |
6230 |
|
)NKSP_CODE", |
6231 |
|
.expectParseError = true // 3rd element not an integer |
6232 |
|
}); |
6233 |
|
|
6234 |
|
runScript({ |
6235 |
|
.code = R"NKSP_CODE( |
6236 |
|
on init |
6237 |
|
declare %a[3] := ( "x", "y", "z" ) |
6238 |
|
end on |
6239 |
|
)NKSP_CODE", |
6240 |
|
.expectParseError = true // int array declaration vs. string array assignment |
6241 |
|
}); |
6242 |
|
|
6243 |
|
runScript({ |
6244 |
|
.code = R"NKSP_CODE( |
6245 |
|
on init |
6246 |
|
declare a[3] := ( 1, 2, 3 ) |
6247 |
|
end on |
6248 |
|
)NKSP_CODE", |
6249 |
|
.expectParseError = true // missing type prefix character in variable name |
6250 |
|
}); |
6251 |
|
|
6252 |
|
runScript({ |
6253 |
|
.code = R"NKSP_CODE( |
6254 |
|
on init |
6255 |
|
declare a[3] |
6256 |
|
end on |
6257 |
|
)NKSP_CODE", |
6258 |
|
.expectParseError = true // missing type prefix character in variable name |
6259 |
|
}); |
6260 |
|
|
6261 |
|
runScript({ |
6262 |
|
.code = R"NKSP_CODE( |
6263 |
|
on init |
6264 |
|
declare const %a[3] := ( 1, 2s, 3 ) |
6265 |
|
end on |
6266 |
|
)NKSP_CODE", |
6267 |
|
.expectParseError = true // unit types not allowed for arrays |
6268 |
|
}); |
6269 |
|
|
6270 |
|
runScript({ |
6271 |
|
.code = R"NKSP_CODE( |
6272 |
|
on init |
6273 |
|
declare const %a[3] := ( 1, !2, 3 ) |
6274 |
|
end on |
6275 |
|
)NKSP_CODE", |
6276 |
|
.expectParseError = true // 'final' not allowed for arrays |
6277 |
|
}); |
6278 |
|
|
6279 |
|
#if !SILENT_TEST |
6280 |
|
std::cout << std::endl; |
6281 |
|
#endif |
6282 |
|
} |
6283 |
|
|
6284 |
|
static void testRealVarDeclaration() { |
6285 |
|
#if !SILENT_TEST |
6286 |
|
std::cout << "UNIT TEST: real var declaration\n"; |
6287 |
|
#endif |
6288 |
|
|
6289 |
|
runScript({ |
6290 |
|
.code = R"NKSP_CODE( |
6291 |
|
on init |
6292 |
|
declare ~a |
6293 |
|
exit(~a) |
6294 |
|
end on |
6295 |
|
)NKSP_CODE", |
6296 |
|
.expectRealExitResult = 0.0 |
6297 |
|
}); |
6298 |
|
|
6299 |
|
runScript({ |
6300 |
|
.code = R"NKSP_CODE( |
6301 |
|
on init |
6302 |
|
declare ~a := 24.8 |
6303 |
|
exit(~a) |
6304 |
|
end on |
6305 |
|
)NKSP_CODE", |
6306 |
|
.expectRealExitResult = 24.8 |
6307 |
|
}); |
6308 |
|
|
6309 |
|
runScript({ |
6310 |
|
.code = R"NKSP_CODE( |
6311 |
|
on init |
6312 |
|
declare ~a := 8.24 |
6313 |
|
~a := 24.8 |
6314 |
|
exit(~a) |
6315 |
|
end on |
6316 |
|
)NKSP_CODE", |
6317 |
|
.expectRealExitResult = 24.8 |
6318 |
|
}); |
6319 |
|
|
6320 |
|
runScript({ |
6321 |
|
.code = R"NKSP_CODE( |
6322 |
|
on init |
6323 |
|
declare ~a |
6324 |
|
declare ~a |
6325 |
|
end on |
6326 |
|
)NKSP_CODE", |
6327 |
|
.expectParseError = true // variable re-declaration |
6328 |
|
}); |
6329 |
|
|
6330 |
|
runScript({ |
6331 |
|
.code = R"NKSP_CODE( |
6332 |
|
on init |
6333 |
|
declare const ~a |
6334 |
|
end on |
6335 |
|
)NKSP_CODE", |
6336 |
|
.expectParseError = true // const variable declaration without assignment |
6337 |
|
}); |
6338 |
|
|
6339 |
|
runScript({ |
6340 |
|
.code = R"NKSP_CODE( |
6341 |
|
on init |
6342 |
|
declare const ~a := 8.24 |
6343 |
|
exit(~a) |
6344 |
|
end on |
6345 |
|
)NKSP_CODE", |
6346 |
|
.expectRealExitResult = 8.24 |
6347 |
|
}); |
6348 |
|
|
6349 |
|
runScript({ |
6350 |
|
.code = R"NKSP_CODE( |
6351 |
|
on init |
6352 |
|
declare const ~a := 28.0 |
6353 |
|
~a := 8.0 |
6354 |
|
end on |
6355 |
|
)NKSP_CODE", |
6356 |
|
.expectParseError = true // attempt to modify const variable |
6357 |
|
}); |
6358 |
|
|
6359 |
|
runScript({ |
6360 |
|
.code = R"NKSP_CODE( |
6361 |
|
on init |
6362 |
|
declare const ~a := 24.8 |
6363 |
|
declare const ~b := ~a |
6364 |
|
exit(~b) |
6365 |
|
end on |
6366 |
|
)NKSP_CODE", |
6367 |
|
.expectRealExitResult = 24.8 |
6368 |
|
}); |
6369 |
|
|
6370 |
|
runScript({ |
6371 |
|
.code = R"NKSP_CODE( |
6372 |
|
on init |
6373 |
|
declare ~a := 24.0 |
6374 |
|
declare const ~b := ~a |
6375 |
|
end on |
6376 |
|
)NKSP_CODE", |
6377 |
|
.expectParseError = true // const variable defined with non-const assignment |
6378 |
|
}); |
6379 |
|
|
6380 |
|
runScript({ |
6381 |
|
.code = R"NKSP_CODE( |
6382 |
|
on init |
6383 |
|
declare polyphonic ~a |
6384 |
|
exit(~a) |
6385 |
|
end on |
6386 |
|
)NKSP_CODE", |
6387 |
|
.expectRealExitResult = 0.0 |
6388 |
|
}); |
6389 |
|
|
6390 |
|
runScript({ |
6391 |
|
.code = R"NKSP_CODE( |
6392 |
|
on init |
6393 |
|
declare const polyphonic ~a |
6394 |
|
end on |
6395 |
|
)NKSP_CODE", |
6396 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
6397 |
|
}); |
6398 |
|
|
6399 |
|
runScript({ |
6400 |
|
.code = R"NKSP_CODE( |
6401 |
|
on init |
6402 |
|
declare polyphonic const ~a |
6403 |
|
end on |
6404 |
|
)NKSP_CODE", |
6405 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
6406 |
|
}); |
6407 |
|
|
6408 |
|
runScript({ |
6409 |
|
.code = R"NKSP_CODE( |
6410 |
|
on init |
6411 |
|
declare const polyphonic ~a := 3.0 |
6412 |
|
end on |
6413 |
|
)NKSP_CODE", |
6414 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
6415 |
|
}); |
6416 |
|
|
6417 |
|
runScript({ |
6418 |
|
.code = R"NKSP_CODE( |
6419 |
|
on init |
6420 |
|
declare polyphonic const ~a := 3.0 |
6421 |
|
end on |
6422 |
|
)NKSP_CODE", |
6423 |
|
.expectParseError = true // combination of qualifiers 'const' and 'polyphonic' is pointless |
6424 |
|
}); |
6425 |
|
|
6426 |
|
runScript({ |
6427 |
|
.code = R"NKSP_CODE( |
6428 |
|
on init |
6429 |
|
declare $a := 24.8 |
6430 |
|
exit($a) |
6431 |
|
end on |
6432 |
|
)NKSP_CODE", |
6433 |
|
.expectParseWarning = true, // int type declaration vs. real value assignment |
6434 |
|
.expectRealExitResult = 24.8 |
6435 |
|
}); |
6436 |
|
|
6437 |
|
runScript({ |
6438 |
|
.code = R"NKSP_CODE( |
6439 |
|
on init |
6440 |
|
declare %a := 24.8 |
6441 |
|
exit(%a) |
6442 |
|
end on |
6443 |
|
)NKSP_CODE", |
6444 |
|
.expectParseWarning = true, // int array type declaration vs. real scalar value assignment |
6445 |
|
.expectRealExitResult = 24.8 |
6446 |
|
}); |
6447 |
|
|
6448 |
|
runScript({ |
6449 |
|
.code = R"NKSP_CODE( |
6450 |
|
on init |
6451 |
|
declare const %a := 24.8 |
6452 |
|
exit(%a) |
6453 |
|
end on |
6454 |
|
)NKSP_CODE", |
6455 |
|
.expectParseWarning = true, // int array type declaration vs. real scalar value assignment |
6456 |
|
.expectRealExitResult = 24.8 |
6457 |
|
}); |
6458 |
|
|
6459 |
|
runScript({ |
6460 |
|
.code = R"NKSP_CODE( |
6461 |
|
on init |
6462 |
|
declare ?a := 24.8 |
6463 |
|
exit(?a) |
6464 |
|
end on |
6465 |
|
)NKSP_CODE", |
6466 |
|
.expectParseWarning = true, // real array type declaration vs. real scalar value assignment |
6467 |
|
.expectRealExitResult = 24.8 |
6468 |
|
}); |
6469 |
|
|
6470 |
|
runScript({ |
6471 |
|
.code = R"NKSP_CODE( |
6472 |
|
on init |
6473 |
|
declare const ?a := 24.8 |
6474 |
|
exit(?a) |
6475 |
|
end on |
6476 |
|
)NKSP_CODE", |
6477 |
|
.expectParseWarning = true, // real array type declaration vs. real scalar value assignment |
6478 |
|
.expectRealExitResult = 24.8 |
6479 |
|
}); |
6480 |
|
|
6481 |
|
runScript({ |
6482 |
|
.code = R"NKSP_CODE( |
6483 |
|
on init |
6484 |
|
declare @a := 24.8 |
6485 |
|
exit(@a) |
6486 |
|
end on |
6487 |
|
)NKSP_CODE", |
6488 |
|
.expectParseWarning = true, // string type declaration vs. real scalar value assignment |
6489 |
|
.expectRealExitResult = 24.8 |
6490 |
|
}); |
6491 |
|
|
6492 |
|
runScript({ |
6493 |
|
.code = R"NKSP_CODE( |
6494 |
|
on init |
6495 |
|
declare const @a := 24.8 |
6496 |
|
exit(@a) |
6497 |
|
end on |
6498 |
|
)NKSP_CODE", |
6499 |
|
.expectParseWarning = true, // string type declaration vs. real scalar value assignment |
6500 |
|
.expectRealExitResult = 24.8 |
6501 |
|
}); |
6502 |
|
|
6503 |
|
runScript({ |
6504 |
|
.code = R"NKSP_CODE( |
6505 |
|
on init |
6506 |
|
declare ~a := ( 0, 1, 2 ) |
6507 |
|
end on |
6508 |
|
)NKSP_CODE", |
6509 |
|
.expectParseError = true // real scalar type declaration vs. int array value assignment |
6510 |
|
}); |
6511 |
|
|
6512 |
|
runScript({ |
6513 |
|
.code = R"NKSP_CODE( |
6514 |
|
on init |
6515 |
|
declare const ~a := ( 0, 1, 2 ) |
6516 |
|
end on |
6517 |
|
)NKSP_CODE", |
6518 |
|
.expectParseError = true // real scalar type declaration vs. int array value assignment |
6519 |
|
}); |
6520 |
|
|
6521 |
|
runScript({ |
6522 |
|
.code = R"NKSP_CODE( |
6523 |
|
on init |
6524 |
|
declare a := 24.8 |
6525 |
|
end on |
6526 |
|
)NKSP_CODE", |
6527 |
|
.expectParseError = true // missing type prefix character in variable name |
6528 |
|
}); |
6529 |
|
|
6530 |
|
runScript({ |
6531 |
|
.code = R"NKSP_CODE( |
6532 |
|
on init |
6533 |
|
declare const a := 24.8 |
6534 |
|
end on |
6535 |
|
)NKSP_CODE", |
6536 |
|
.expectParseError = true // missing type prefix character in variable name |
6537 |
|
}); |
6538 |
|
|
6539 |
|
runScript({ |
6540 |
|
.code = R"NKSP_CODE( |
6541 |
|
on init |
6542 |
|
declare ~a := max(8.1,24.2) |
6543 |
|
exit(~a) |
6544 |
|
end on |
6545 |
|
)NKSP_CODE", |
6546 |
|
.expectRealExitResult = 24.2 |
6547 |
|
}); |
6548 |
|
|
6549 |
|
runScript({ |
6550 |
|
.code = R"NKSP_CODE( |
6551 |
|
on init |
6552 |
|
declare ~a := abort($NI_CALLBACK_ID) |
6553 |
|
end on |
6554 |
|
)NKSP_CODE", |
6555 |
|
.expectParseError = true // assigned expression does not result in a value |
6556 |
|
}); |
6557 |
|
|
6558 |
|
runScript({ |
6559 |
|
.code = R"NKSP_CODE( |
6560 |
|
on init |
6561 |
|
declare const ~a := abort($NI_CALLBACK_ID) |
6562 |
|
end on |
6563 |
|
)NKSP_CODE", |
6564 |
|
.expectParseError = true // assigned expression does not result in a value |
6565 |
|
}); |
6566 |
|
|
6567 |
|
#if !SILENT_TEST |
6568 |
|
std::cout << std::endl; |
6569 |
|
#endif |
6570 |
|
} |
6571 |
|
|
6572 |
|
static void testRealArrayVarDeclaration() { |
6573 |
|
#if !SILENT_TEST |
6574 |
|
std::cout << "UNIT TEST: real array var declaration\n"; |
6575 |
|
#endif |
6576 |
|
|
6577 |
|
runScript({ |
6578 |
|
.code = R"NKSP_CODE( |
6579 |
|
on init |
6580 |
|
declare ?a[3] |
6581 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6582 |
|
end on |
6583 |
|
)NKSP_CODE", |
6584 |
|
.expectRealExitResult = 0.0 |
6585 |
|
}); |
6586 |
|
|
6587 |
|
runScript({ |
6588 |
|
.code = R"NKSP_CODE( |
6589 |
|
on init |
6590 |
|
declare ?a[0] |
6591 |
|
end on |
6592 |
|
)NKSP_CODE", |
6593 |
|
.expectParseWarning = true // unusable array size |
6594 |
|
}); |
6595 |
|
|
6596 |
|
runScript({ |
6597 |
|
.code = R"NKSP_CODE( |
6598 |
|
on init |
6599 |
|
declare ?a[-1] |
6600 |
|
end on |
6601 |
|
)NKSP_CODE", |
6602 |
|
.expectParseError = true // illegal array size |
6603 |
|
}); |
6604 |
|
|
6605 |
|
runScript({ |
6606 |
|
.code = R"NKSP_CODE( |
6607 |
|
on init |
6608 |
|
declare ?a[3] := ( 1.1, 2.2, 3.3 ) |
6609 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6610 |
|
end on |
6611 |
|
)NKSP_CODE", |
6612 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6613 |
|
}); |
6614 |
|
|
6615 |
|
runScript({ |
6616 |
|
.code = R"NKSP_CODE( |
6617 |
|
on init |
6618 |
|
declare ?a[4] := ( 1.1, 2.2, 3.3 ) |
6619 |
|
exit( ?a[0] + ?a[1] + ?a[2] + ?a[3] ) |
6620 |
|
end on |
6621 |
|
)NKSP_CODE", |
6622 |
|
.expectParseWarning = true, // less values assigned than array size declared |
6623 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3 + 0.0) |
6624 |
|
}); |
6625 |
|
|
6626 |
|
runScript({ |
6627 |
|
.code = R"NKSP_CODE( |
6628 |
|
on init |
6629 |
|
declare ?a[] := ( 1.1, 2.2, 3.3 ) |
6630 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6631 |
|
end on |
6632 |
|
)NKSP_CODE", |
6633 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6634 |
|
}); |
6635 |
|
|
6636 |
|
runScript({ |
6637 |
|
.code = R"NKSP_CODE( |
6638 |
|
on init |
6639 |
|
declare ?a[] |
6640 |
|
end on |
6641 |
|
)NKSP_CODE", |
6642 |
|
.expectParseWarning = true // unusable array size (zero) |
6643 |
|
}); |
6644 |
|
|
6645 |
|
runScript({ |
6646 |
|
.code = R"NKSP_CODE( |
6647 |
|
on init |
6648 |
|
declare const $sz := 3 |
6649 |
|
declare ?a[$sz] := ( 1.1, 2.2, 3.3 ) |
6650 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6651 |
|
end on |
6652 |
|
)NKSP_CODE", |
6653 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6654 |
|
}); |
6655 |
|
|
6656 |
|
runScript({ |
6657 |
|
.code = R"NKSP_CODE( |
6658 |
|
on init |
6659 |
|
declare const $sz := 3 |
6660 |
|
declare const ?a[$sz] := ( 1.1, 2.2, 3.3 ) |
6661 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6662 |
|
end on |
6663 |
|
)NKSP_CODE", |
6664 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6665 |
|
}); |
6666 |
|
|
6667 |
|
runScript({ |
6668 |
|
.code = R"NKSP_CODE( |
6669 |
|
on init |
6670 |
|
declare $sz := 3 |
6671 |
|
declare ?a[$sz] := ( 1.1, 2.2, 3.3 ) |
6672 |
|
end on |
6673 |
|
)NKSP_CODE", |
6674 |
|
.expectParseError = true // array size must be constant expression |
6675 |
|
}); |
6676 |
|
|
6677 |
|
runScript({ |
6678 |
|
.code = R"NKSP_CODE( |
6679 |
|
on init |
6680 |
|
declare $sz := 3 |
6681 |
|
declare const ?a[$sz] := ( 1.1, 2.2, 3.3 ) |
6682 |
|
end on |
6683 |
|
)NKSP_CODE", |
6684 |
|
.expectParseError = true // array size must be constant expression |
6685 |
|
}); |
6686 |
|
|
6687 |
|
runScript({ |
6688 |
|
.code = R"NKSP_CODE( |
6689 |
|
on init |
6690 |
|
declare const ~sz := 3.0 |
6691 |
|
declare const ?a[~sz] := ( 1.1, 2.2, 3.3 ) |
6692 |
|
end on |
6693 |
|
)NKSP_CODE", |
6694 |
|
.expectParseError = true // array size must be integer type |
6695 |
|
}); |
6696 |
|
|
6697 |
|
runScript({ |
6698 |
|
.code = R"NKSP_CODE( |
6699 |
|
on init |
6700 |
|
declare ?a[3s] := ( 1.1, 2.2, 3.3 ) |
6701 |
|
end on |
6702 |
|
)NKSP_CODE", |
6703 |
|
.expectParseError = true // units not allowed for array size |
6704 |
|
}); |
6705 |
|
|
6706 |
|
runScript({ |
6707 |
|
.code = R"NKSP_CODE( |
6708 |
|
on init |
6709 |
|
declare ?a[3m] := ( 1.1, 2.2, 3.3 ) |
6710 |
|
end on |
6711 |
|
)NKSP_CODE", |
6712 |
|
.expectParseError = true // units not allowed for array size |
6713 |
|
}); |
6714 |
|
|
6715 |
|
runScript({ |
6716 |
|
.code = R"NKSP_CODE( |
6717 |
|
on init |
6718 |
|
declare const ?a[!3] := ( 1.1, 2.2, 3.3 ) |
6719 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6720 |
|
end on |
6721 |
|
)NKSP_CODE", |
6722 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3), |
6723 |
|
.expectParseWarning = true // 'final' operator is meaningless for array size |
6724 |
|
}); |
6725 |
|
|
6726 |
|
runScript({ |
6727 |
|
.code = R"NKSP_CODE( |
6728 |
|
on init |
6729 |
|
declare ?a[3] := ( 1.0, 2.0, 3.0 ) |
6730 |
|
?a[0] := 4.5 |
6731 |
|
?a[1] := 5.5 |
6732 |
|
?a[2] := 6.5 |
6733 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6734 |
|
end on |
6735 |
|
)NKSP_CODE", |
6736 |
|
.expectRealExitResult = (4.5 + 5.5 + 6.5) |
6737 |
|
}); |
6738 |
|
|
6739 |
|
runScript({ |
6740 |
|
.code = R"NKSP_CODE( |
6741 |
|
on init |
6742 |
|
declare ?a[3] |
6743 |
|
declare ?a[3] |
6744 |
|
end on |
6745 |
|
)NKSP_CODE", |
6746 |
|
.expectParseError = true // variable re-declaration |
6747 |
|
}); |
6748 |
|
|
6749 |
|
runScript({ |
6750 |
|
.code = R"NKSP_CODE( |
6751 |
|
on init |
6752 |
|
declare const ?a[3] |
6753 |
|
end on |
6754 |
|
)NKSP_CODE", |
6755 |
|
.expectParseError = true // const variable declaration without assignment |
6756 |
|
}); |
6757 |
|
|
6758 |
|
runScript({ |
6759 |
|
.code = R"NKSP_CODE( |
6760 |
|
on init |
6761 |
|
declare const ?a[3] := ( 1.1, 2.2, 3.3 ) |
6762 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6763 |
|
end on |
6764 |
|
)NKSP_CODE", |
6765 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6766 |
|
}); |
6767 |
|
|
6768 |
|
runScript({ |
6769 |
|
.code = R"NKSP_CODE( |
6770 |
|
on init |
6771 |
|
declare const ?a[3] := ( 1.1, 2.2, 3.3, 4.4 ) |
6772 |
|
end on |
6773 |
|
)NKSP_CODE", |
6774 |
|
.expectParseError = true // incompatible array sizes |
6775 |
|
}); |
6776 |
|
|
6777 |
|
runScript({ |
6778 |
|
.code = R"NKSP_CODE( |
6779 |
|
on init |
6780 |
|
declare const ?a[3] := ( 1.0, 2.0, 3.0 ) |
6781 |
|
?a[0] := 8.0 |
6782 |
|
end on |
6783 |
|
)NKSP_CODE", |
6784 |
|
.expectParseError = true // attempt to modify const variable |
6785 |
|
}); |
6786 |
|
|
6787 |
|
runScript({ |
6788 |
|
.code = R"NKSP_CODE( |
6789 |
|
on init |
6790 |
|
declare const ?a[3] := ( 1.1, 2.2, 3.3 ) |
6791 |
|
declare const ?b[3] := ( ?a[0], ?a[1], ?a[2] ) |
6792 |
|
exit( ?b[0] + ?b[1] + ?b[2] ) |
6793 |
|
end on |
6794 |
|
)NKSP_CODE", |
6795 |
|
.expectRealExitResult = (1.1 + 2.2 + 3.3) |
6796 |
|
}); |
6797 |
|
|
6798 |
|
runScript({ |
6799 |
|
.code = R"NKSP_CODE( |
6800 |
|
on init |
6801 |
|
declare ?a[3] := ( 1.1, 2.2, 3.3 ) |
6802 |
|
declare const ?b[3] := ( ?a[0], ?a[1], ?a[2] ) |
6803 |
|
end on |
6804 |
|
)NKSP_CODE", |
6805 |
|
.expectParseError = true // const array defined with non-const assignment |
6806 |
|
}); |
6807 |
|
|
6808 |
|
runScript({ |
6809 |
|
.code = R"NKSP_CODE( |
6810 |
|
on init |
6811 |
|
declare polyphonic ?a[3] |
6812 |
|
end on |
6813 |
|
)NKSP_CODE", |
6814 |
|
.expectParseError = true // polyphonic not allowed for array types |
6815 |
|
}); |
6816 |
|
|
6817 |
|
runScript({ |
6818 |
|
.code = R"NKSP_CODE( |
6819 |
|
on init |
6820 |
|
declare polyphonic ?a[3] := ( 1.0, 2.0, 3.0 ) |
6821 |
|
end on |
6822 |
|
)NKSP_CODE", |
6823 |
|
.expectParseError = true // polyphonic not allowed for array types |
6824 |
|
}); |
6825 |
|
|
6826 |
|
runScript({ |
6827 |
|
.code = R"NKSP_CODE( |
6828 |
|
on init |
6829 |
|
declare const polyphonic ?a[3] |
6830 |
|
end on |
6831 |
|
)NKSP_CODE", |
6832 |
|
.expectParseError = true // polyphonic not allowed for array types |
6833 |
|
}); |
6834 |
|
|
6835 |
|
runScript({ |
6836 |
|
.code = R"NKSP_CODE( |
6837 |
|
on init |
6838 |
|
declare const polyphonic ?a[3] := ( 1.0, 2.0, 3.0 ) |
6839 |
|
end on |
6840 |
|
)NKSP_CODE", |
6841 |
|
.expectParseError = true // polyphonic not allowed for array types |
6842 |
|
}); |
6843 |
|
|
6844 |
|
runScript({ |
6845 |
|
.code = R"NKSP_CODE( |
6846 |
|
on init |
6847 |
|
declare polyphonic const ?a[3] |
6848 |
|
end on |
6849 |
|
)NKSP_CODE", |
6850 |
|
.expectParseError = true // polyphonic not allowed for array types |
6851 |
|
}); |
6852 |
|
|
6853 |
|
runScript({ |
6854 |
|
.code = R"NKSP_CODE( |
6855 |
|
on init |
6856 |
|
declare polyphonic const ?a[3] := ( 1.0, 2.0, 3.0 ) |
6857 |
|
end on |
6858 |
|
)NKSP_CODE", |
6859 |
|
.expectParseError = true // polyphonic not allowed for array types |
6860 |
|
}); |
6861 |
|
|
6862 |
|
runScript({ |
6863 |
|
.code = R"NKSP_CODE( |
6864 |
|
on init |
6865 |
|
declare ?a[3] := ( 1.0, max(8.3,24.6), 3.0 ) |
6866 |
|
exit( ?a[0] + ?a[1] + ?a[2] ) |
6867 |
|
end on |
6868 |
|
)NKSP_CODE", |
6869 |
|
.expectRealExitResult = ( 1.0 + 24.6 + 3.0 ) |
6870 |
|
}); |
6871 |
|
|
6872 |
|
runScript({ |
6873 |
|
.code = R"NKSP_CODE( |
6874 |
|
on init |
6875 |
|
declare ?a[3] := ( 1.0, abort($NI_CALLBACK_ID), 3.0 ) |
6876 |
|
end on |
6877 |
|
)NKSP_CODE", |
6878 |
|
.expectParseError = true // assigned expression does not result in a value |
6879 |
|
}); |
6880 |
|
|
6881 |
|
runScript({ |
6882 |
|
.code = R"NKSP_CODE( |
6883 |
|
on init |
6884 |
|
declare const ?a[3] := ( 1.0, abort($NI_CALLBACK_ID), 3.0 ) |
6885 |
|
end on |
6886 |
|
)NKSP_CODE", |
6887 |
|
.expectParseError = true // assigned expression does not result in a value |
6888 |
|
}); |
6889 |
|
|
6890 |
|
runScript({ |
6891 |
|
.code = R"NKSP_CODE( |
6892 |
|
on init |
6893 |
|
declare ?a[3] := ( 1, 2, 3 ) |
6894 |
|
end on |
6895 |
|
)NKSP_CODE", |
6896 |
|
.expectParseError = true // real array declaration vs. int array assignment |
6897 |
|
}); |
6898 |
|
|
6899 |
|
runScript({ |
6900 |
|
.code = R"NKSP_CODE( |
6901 |
|
on init |
6902 |
|
declare ?a[3] := ( 1.0, 2.0, 3 ) |
6903 |
|
end on |
6904 |
|
)NKSP_CODE", |
6905 |
|
.expectParseError = true // 3rd element not a real value |
6906 |
|
}); |
6907 |
|
|
6908 |
|
runScript({ |
6909 |
|
.code = R"NKSP_CODE( |
6910 |
|
on init |
6911 |
|
declare ?a[3] := ( "x", "y", "z" ) |
6912 |
|
end on |
6913 |
|
)NKSP_CODE", |
6914 |
|
.expectParseError = true // real array declaration vs. string array assignment |
6915 |
|
}); |
6916 |
|
|
6917 |
|
runScript({ |
6918 |
|
.code = R"NKSP_CODE( |
6919 |
|
on init |
6920 |
|
declare a[3] := ( 1.0, 2.0, 3.0 ) |
6921 |
|
end on |
6922 |
|
)NKSP_CODE", |
6923 |
|
.expectParseError = true // missing type prefix character in variable name |
6924 |
|
}); |
6925 |
|
|
6926 |
|
runScript({ |
6927 |
|
.code = R"NKSP_CODE( |
6928 |
|
on init |
6929 |
|
declare const ?a[3] := ( 1.0, 2.0s, 3.0 ) |
6930 |
|
end on |
6931 |
|
)NKSP_CODE", |
6932 |
|
.expectParseError = true // unit types not allowed for arrays |
6933 |
|
}); |
6934 |
|
|
6935 |
|
runScript({ |
6936 |
|
.code = R"NKSP_CODE( |
6937 |
|
on init |
6938 |
|
declare const ?a[3] := ( 1.0, !2.0, 3.0 ) |
6939 |
|
end on |
6940 |
|
)NKSP_CODE", |
6941 |
|
.expectParseError = true // 'final' not allowed for arrays |
6942 |
|
}); |
6943 |
|
|
6944 |
|
#if !SILENT_TEST |
6945 |
|
std::cout << std::endl; |
6946 |
|
#endif |
6947 |
|
} |
6948 |
|
|
6949 |
|
static void testStringVarDeclaration() { |
6950 |
|
#if !SILENT_TEST |
6951 |
|
std::cout << "UNIT TEST: string var declaration\n"; |
6952 |
|
#endif |
6953 |
|
|
6954 |
|
runScript({ |
6955 |
|
.code = R"NKSP_CODE( |
6956 |
|
on init |
6957 |
|
declare @a |
6958 |
|
exit(@a) |
6959 |
|
end on |
6960 |
|
)NKSP_CODE", |
6961 |
|
.expectStringExitResult = "" |
6962 |
|
}); |
6963 |
|
|
6964 |
|
runScript({ |
6965 |
|
.code = R"NKSP_CODE( |
6966 |
|
on init |
6967 |
|
declare @a := "foo" |
6968 |
|
exit(@a) |
6969 |
|
end on |
6970 |
|
)NKSP_CODE", |
6971 |
|
.expectStringExitResult = "foo" |
6972 |
|
}); |
6973 |
|
|
6974 |
|
runScript({ |
6975 |
|
.code = R"NKSP_CODE( |
6976 |
|
on init |
6977 |
|
declare @a := "foo" |
6978 |
|
@a := "bar" |
6979 |
|
exit(@a) |
6980 |
|
end on |
6981 |
|
)NKSP_CODE", |
6982 |
|
.expectStringExitResult = "bar" |
6983 |
|
}); |
6984 |
|
|
6985 |
|
runScript({ |
6986 |
|
.code = R"NKSP_CODE( |
6987 |
|
on init |
6988 |
|
declare @a |
6989 |
|
declare @a |
6990 |
|
end on |
6991 |
|
)NKSP_CODE", |
6992 |
|
.expectParseError = true // variable re-declaration |
6993 |
|
}); |
6994 |
|
|
6995 |
|
runScript({ |
6996 |
|
.code = R"NKSP_CODE( |
6997 |
|
on init |
6998 |
|
declare const @a |
6999 |
|
end on |
7000 |
|
)NKSP_CODE", |
7001 |
|
.expectParseError = true // const variable declaration without assignment |
7002 |
|
}); |
7003 |
|
|
7004 |
|
runScript({ |
7005 |
|
.code = R"NKSP_CODE( |
7006 |
|
on init |
7007 |
|
declare const @a := "foo" |
7008 |
|
exit(@a) |
7009 |
|
end on |
7010 |
|
)NKSP_CODE", |
7011 |
|
.expectStringExitResult = "foo" |
7012 |
|
}); |
7013 |
|
|
7014 |
|
runScript({ |
7015 |
|
.code = R"NKSP_CODE( |
7016 |
|
on init |
7017 |
|
declare const @a := "foo" |
7018 |
|
@a := "bar" |
7019 |
|
end on |
7020 |
|
)NKSP_CODE", |
7021 |
|
.expectParseError = true // attempt to modify const variable |
7022 |
|
}); |
7023 |
|
|
7024 |
|
runScript({ |
7025 |
|
.code = R"NKSP_CODE( |
7026 |
|
on init |
7027 |
|
declare const @a := "foo" |
7028 |
|
declare const @b := @a |
7029 |
|
exit(@b) |
7030 |
|
end on |
7031 |
|
)NKSP_CODE", |
7032 |
|
.expectStringExitResult = "foo" |
7033 |
|
}); |
7034 |
|
|
7035 |
|
runScript({ |
7036 |
|
.code = R"NKSP_CODE( |
7037 |
|
on init |
7038 |
|
declare @a := "foo" |
7039 |
|
declare const @b := @a |
7040 |
|
end on |
7041 |
|
)NKSP_CODE", |
7042 |
|
.expectParseError = true // const variable defined with non-const assignment |
7043 |
|
}); |
7044 |
|
|
7045 |
|
runScript({ |
7046 |
|
.code = R"NKSP_CODE( |
7047 |
|
on init |
7048 |
|
declare polyphonic @a |
7049 |
|
end on |
7050 |
|
)NKSP_CODE", |
7051 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
7052 |
|
}); |
7053 |
|
|
7054 |
|
runScript({ |
7055 |
|
.code = R"NKSP_CODE( |
7056 |
|
on init |
7057 |
|
declare const polyphonic @a |
7058 |
|
end on |
7059 |
|
)NKSP_CODE", |
7060 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
7061 |
|
}); |
7062 |
|
|
7063 |
|
runScript({ |
7064 |
|
.code = R"NKSP_CODE( |
7065 |
|
on init |
7066 |
|
declare polyphonic const @a |
7067 |
|
end on |
7068 |
|
)NKSP_CODE", |
7069 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
7070 |
|
}); |
7071 |
|
|
7072 |
|
runScript({ |
7073 |
|
.code = R"NKSP_CODE( |
7074 |
|
on init |
7075 |
|
declare polyphonic @a = "foo" |
7076 |
|
end on |
7077 |
|
)NKSP_CODE", |
7078 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
7079 |
|
}); |
7080 |
|
|
7081 |
|
runScript({ |
7082 |
|
.code = R"NKSP_CODE( |
7083 |
|
on init |
7084 |
|
declare polyphonic const @a = "foo" |
7085 |
|
end on |
7086 |
|
)NKSP_CODE", |
7087 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
7088 |
|
}); |
7089 |
|
|
7090 |
|
runScript({ |
7091 |
|
.code = R"NKSP_CODE( |
7092 |
|
on init |
7093 |
|
declare const polyphonic @a = "foo" |
7094 |
|
end on |
7095 |
|
)NKSP_CODE", |
7096 |
|
.expectParseError = true // 'polyphonic' not allowed for string type |
7097 |
|
}); |
7098 |
|
|
7099 |
|
runScript({ |
7100 |
|
.code = R"NKSP_CODE( |
7101 |
|
on init |
7102 |
|
declare $a := "foo" |
7103 |
|
exit($a) |
7104 |
|
end on |
7105 |
|
)NKSP_CODE", |
7106 |
|
.expectParseWarning = true, // int type declaration vs. string assignment |
7107 |
|
.expectStringExitResult = "foo" |
7108 |
|
}); |
7109 |
|
|
7110 |
|
runScript({ |
7111 |
|
.code = R"NKSP_CODE( |
7112 |
|
on init |
7113 |
|
declare ~a := "foo" |
7114 |
|
exit(~a) |
7115 |
|
end on |
7116 |
|
)NKSP_CODE", |
7117 |
|
.expectParseWarning = true, // real type declaration vs. string assignment |
7118 |
|
.expectStringExitResult = "foo" |
7119 |
|
}); |
7120 |
|
|
7121 |
|
runScript({ |
7122 |
|
.code = R"NKSP_CODE( |
7123 |
|
on init |
7124 |
|
declare %a := "foo" |
7125 |
|
exit(%a) |
7126 |
|
end on |
7127 |
|
)NKSP_CODE", |
7128 |
|
.expectParseWarning = true, // int array type declaration vs. string assignment |
7129 |
|
.expectStringExitResult = "foo" |
7130 |
|
}); |
7131 |
|
|
7132 |
|
runScript({ |
7133 |
|
.code = R"NKSP_CODE( |
7134 |
|
on init |
7135 |
|
declare const $a := "foo" |
7136 |
|
exit($a) |
7137 |
|
end on |
7138 |
|
)NKSP_CODE", |
7139 |
|
.expectParseWarning = true, // int type declaration vs. string assignment |
7140 |
|
.expectStringExitResult = "foo" |
7141 |
|
}); |
7142 |
|
|
7143 |
|
runScript({ |
7144 |
|
.code = R"NKSP_CODE( |
7145 |
|
on init |
7146 |
|
declare const ~a := "foo" |
7147 |
|
exit(~a) |
7148 |
|
end on |
7149 |
|
)NKSP_CODE", |
7150 |
|
.expectParseWarning = true, // real type declaration vs. string assignment |
7151 |
|
.expectStringExitResult = "foo" |
7152 |
|
}); |
7153 |
|
|
7154 |
|
runScript({ |
7155 |
|
.code = R"NKSP_CODE( |
7156 |
|
on init |
7157 |
|
declare const %a := "foo" |
7158 |
|
exit(%a) |
7159 |
|
end on |
7160 |
|
)NKSP_CODE", |
7161 |
|
.expectParseWarning = true, // int array type declaration vs. string assignment |
7162 |
|
.expectStringExitResult = "foo" |
7163 |
|
}); |
7164 |
|
|
7165 |
|
runScript({ |
7166 |
|
.code = R"NKSP_CODE( |
7167 |
|
on init |
7168 |
|
declare a := "foo" |
7169 |
|
end on |
7170 |
|
)NKSP_CODE", |
7171 |
|
.expectParseError = true // missing type prefix character in variable name |
7172 |
|
}); |
7173 |
|
|
7174 |
|
runScript({ |
7175 |
|
.code = R"NKSP_CODE( |
7176 |
|
on init |
7177 |
|
declare const a := "foo" |
7178 |
|
end on |
7179 |
|
)NKSP_CODE", |
7180 |
|
.expectParseError = true // missing type prefix character in variable name |
7181 |
|
}); |
7182 |
|
|
7183 |
|
runScript({ |
7184 |
|
.code = R"NKSP_CODE( |
7185 |
|
on init |
7186 |
|
declare @a := abort($NI_CALLBACK_ID) |
7187 |
|
end on |
7188 |
|
)NKSP_CODE", |
7189 |
|
.expectParseError = true // assigned expression does not result in a value |
7190 |
|
}); |
7191 |
|
|
7192 |
|
runScript({ |
7193 |
|
.code = R"NKSP_CODE( |
7194 |
|
on init |
7195 |
|
declare const @a := abort($NI_CALLBACK_ID) |
7196 |
|
end on |
7197 |
|
)NKSP_CODE", |
7198 |
|
.expectParseError = true // assigned expression does not result in a value |
7199 |
|
}); |
7200 |
|
|
7201 |
|
#if !SILENT_TEST |
7202 |
|
std::cout << std::endl; |
7203 |
|
#endif |
7204 |
|
} |
7205 |
|
|
7206 |
static void testBuiltInMinFunction() { |
static void testBuiltInMinFunction() { |
7207 |
#if !SILENT_TEST |
#if !SILENT_TEST |
7208 |
std::cout << "UNIT TEST: built-in min() function\n"; |
std::cout << "UNIT TEST: built-in min() function\n"; |
9117 |
.expectExitResultUnit = VM_BEL |
.expectExitResultUnit = VM_BEL |
9118 |
}); |
}); |
9119 |
|
|
9120 |
|
runScript({ |
9121 |
|
.code = R"NKSP_CODE( |
9122 |
|
on init |
9123 |
|
declare $foo := 7000ms |
9124 |
|
exit( int_to_real($foo) ) |
9125 |
|
end on |
9126 |
|
)NKSP_CODE", |
9127 |
|
.expectRealExitResult = 7000.0, |
9128 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
9129 |
|
.expectExitResultUnit = VM_SECOND |
9130 |
|
}); |
9131 |
|
|
9132 |
|
runScript({ |
9133 |
|
.code = R"NKSP_CODE( |
9134 |
|
on init |
9135 |
|
declare $foo := 7000ms |
9136 |
|
declare @s := "" & int_to_real($foo) |
9137 |
|
exit( @s ) |
9138 |
|
end on |
9139 |
|
)NKSP_CODE", |
9140 |
|
.expectStringExitResult = "7000ms", |
9141 |
|
}); |
9142 |
|
|
9143 |
|
runScript({ |
9144 |
|
.code = R"NKSP_CODE( |
9145 |
|
on init |
9146 |
|
declare $foo := 700ms |
9147 |
|
exit( int_to_real($foo) / 7.0 ) |
9148 |
|
end on |
9149 |
|
)NKSP_CODE", |
9150 |
|
.expectRealExitResult = 100.0, |
9151 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
9152 |
|
.expectExitResultUnit = VM_SECOND |
9153 |
|
}); |
9154 |
|
|
9155 |
|
runScript({ |
9156 |
|
.code = R"NKSP_CODE( |
9157 |
|
on init |
9158 |
|
declare $foo := 700ms |
9159 |
|
exit( int_to_real($foo) / 7.0 & "" ) |
9160 |
|
end on |
9161 |
|
)NKSP_CODE", |
9162 |
|
.expectStringExitResult = "100ms" |
9163 |
|
}); |
9164 |
|
|
9165 |
// 'final' ('!') operator tests ... |
// 'final' ('!') operator tests ... |
9166 |
|
|
9167 |
runScript({ |
runScript({ |
9240 |
.expectExitResultUnit = VM_BEL |
.expectExitResultUnit = VM_BEL |
9241 |
}); |
}); |
9242 |
|
|
9243 |
|
runScript({ |
9244 |
|
.code = R"NKSP_CODE( |
9245 |
|
on init |
9246 |
|
declare $foo := 7000ms |
9247 |
|
exit( real($foo) ) |
9248 |
|
end on |
9249 |
|
)NKSP_CODE", |
9250 |
|
.expectRealExitResult = 7000.0, |
9251 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
9252 |
|
.expectExitResultUnit = VM_SECOND |
9253 |
|
}); |
9254 |
|
|
9255 |
|
runScript({ |
9256 |
|
.code = R"NKSP_CODE( |
9257 |
|
on init |
9258 |
|
declare $foo := 7000ms |
9259 |
|
declare @s := "" & real($foo) |
9260 |
|
exit( @s ) |
9261 |
|
end on |
9262 |
|
)NKSP_CODE", |
9263 |
|
.expectStringExitResult = "7000ms", |
9264 |
|
}); |
9265 |
|
|
9266 |
|
runScript({ |
9267 |
|
.code = R"NKSP_CODE( |
9268 |
|
on init |
9269 |
|
declare $foo := 700ms |
9270 |
|
exit( real($foo) / 7.0 ) |
9271 |
|
end on |
9272 |
|
)NKSP_CODE", |
9273 |
|
.expectRealExitResult = 100.0, |
9274 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
9275 |
|
.expectExitResultUnit = VM_SECOND |
9276 |
|
}); |
9277 |
|
|
9278 |
|
runScript({ |
9279 |
|
.code = R"NKSP_CODE( |
9280 |
|
on init |
9281 |
|
declare $foo := 700ms |
9282 |
|
exit( real($foo) / 7.0 & "" ) |
9283 |
|
end on |
9284 |
|
)NKSP_CODE", |
9285 |
|
.expectStringExitResult = "100ms" |
9286 |
|
}); |
9287 |
|
|
9288 |
// 'final' ('!') operator tests ... |
// 'final' ('!') operator tests ... |
9289 |
|
|
9290 |
runScript({ |
runScript({ |
9352 |
.expectExitResultUnit = VM_BEL |
.expectExitResultUnit = VM_BEL |
9353 |
}); |
}); |
9354 |
|
|
9355 |
|
runScript({ |
9356 |
|
.code = R"NKSP_CODE( |
9357 |
|
on init |
9358 |
|
declare ~foo := 9000.0us |
9359 |
|
exit( real_to_int(~foo) ) |
9360 |
|
end on |
9361 |
|
)NKSP_CODE", |
9362 |
|
.expectIntExitResult = 9000.0, |
9363 |
|
.expectExitResultUnitPrefix = { VM_MICRO }, |
9364 |
|
.expectExitResultUnit = VM_SECOND |
9365 |
|
}); |
9366 |
|
|
9367 |
|
runScript({ |
9368 |
|
.code = R"NKSP_CODE( |
9369 |
|
on init |
9370 |
|
declare ~foo := 9000.0us |
9371 |
|
declare @s := "" & real_to_int(~foo) |
9372 |
|
exit( @s ) |
9373 |
|
end on |
9374 |
|
)NKSP_CODE", |
9375 |
|
.expectStringExitResult = "9000us", |
9376 |
|
}); |
9377 |
|
|
9378 |
|
runScript({ |
9379 |
|
.code = R"NKSP_CODE( |
9380 |
|
on init |
9381 |
|
declare ~foo := 700.0ms |
9382 |
|
exit( real_to_int(~foo) / 7 ) |
9383 |
|
end on |
9384 |
|
)NKSP_CODE", |
9385 |
|
.expectIntExitResult = 100, |
9386 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
9387 |
|
.expectExitResultUnit = VM_SECOND |
9388 |
|
}); |
9389 |
|
|
9390 |
|
runScript({ |
9391 |
|
.code = R"NKSP_CODE( |
9392 |
|
on init |
9393 |
|
declare ~foo := 700.0ms |
9394 |
|
exit( real_to_int(~foo) / 7 & "" ) |
9395 |
|
end on |
9396 |
|
)NKSP_CODE", |
9397 |
|
.expectStringExitResult = "100ms" |
9398 |
|
}); |
9399 |
|
|
9400 |
// 'final' ('!') operator tests ... |
// 'final' ('!') operator tests ... |
9401 |
|
|
9402 |
runScript({ |
runScript({ |
9464 |
.expectExitResultUnit = VM_BEL |
.expectExitResultUnit = VM_BEL |
9465 |
}); |
}); |
9466 |
|
|
9467 |
|
runScript({ |
9468 |
|
.code = R"NKSP_CODE( |
9469 |
|
on init |
9470 |
|
declare ~foo := 9000.0us |
9471 |
|
exit( int(~foo) ) |
9472 |
|
end on |
9473 |
|
)NKSP_CODE", |
9474 |
|
.expectIntExitResult = 9000.0, |
9475 |
|
.expectExitResultUnitPrefix = { VM_MICRO }, |
9476 |
|
.expectExitResultUnit = VM_SECOND |
9477 |
|
}); |
9478 |
|
|
9479 |
|
runScript({ |
9480 |
|
.code = R"NKSP_CODE( |
9481 |
|
on init |
9482 |
|
declare ~foo := 9000.0us |
9483 |
|
declare @s := "" & int(~foo) |
9484 |
|
exit( @s ) |
9485 |
|
end on |
9486 |
|
)NKSP_CODE", |
9487 |
|
.expectStringExitResult = "9000us", |
9488 |
|
}); |
9489 |
|
|
9490 |
|
runScript({ |
9491 |
|
.code = R"NKSP_CODE( |
9492 |
|
on init |
9493 |
|
declare ~foo := 700.0ms |
9494 |
|
exit( int(~foo) / 7 ) |
9495 |
|
end on |
9496 |
|
)NKSP_CODE", |
9497 |
|
.expectIntExitResult = 100, |
9498 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
9499 |
|
.expectExitResultUnit = VM_SECOND |
9500 |
|
}); |
9501 |
|
|
9502 |
|
runScript({ |
9503 |
|
.code = R"NKSP_CODE( |
9504 |
|
on init |
9505 |
|
declare ~foo := 700.0ms |
9506 |
|
exit( int(~foo) / 7 & "" ) |
9507 |
|
end on |
9508 |
|
)NKSP_CODE", |
9509 |
|
.expectStringExitResult = "100ms" |
9510 |
|
}); |
9511 |
|
|
9512 |
// 'final' ('!') operator tests ... |
// 'final' ('!') operator tests ... |
9513 |
|
|
9514 |
runScript({ |
runScript({ |
10204 |
.expectExitResultUnit = VM_HERTZ |
.expectExitResultUnit = VM_HERTZ |
10205 |
}); |
}); |
10206 |
|
|
10207 |
|
runScript({ |
10208 |
|
.code = R"NKSP_CODE( |
10209 |
|
on init |
10210 |
|
exit( ceil(9.4ms / 2.0) ) |
10211 |
|
end on |
10212 |
|
)NKSP_CODE", |
10213 |
|
.expectRealExitResult = 5.0, |
10214 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
10215 |
|
.expectExitResultUnit = VM_SECOND |
10216 |
|
}); |
10217 |
|
|
10218 |
|
runScript({ |
10219 |
|
.code = R"NKSP_CODE( |
10220 |
|
on init |
10221 |
|
exit( ceil( ceil(8.4us) / 2.0) ) |
10222 |
|
end on |
10223 |
|
)NKSP_CODE", |
10224 |
|
.expectRealExitResult = 5.0, |
10225 |
|
.expectExitResultUnitPrefix = { VM_MICRO }, |
10226 |
|
.expectExitResultUnit = VM_SECOND |
10227 |
|
}); |
10228 |
|
|
10229 |
// 'final' ('!') operator tests ... |
// 'final' ('!') operator tests ... |
10230 |
|
|
10231 |
runScript({ |
runScript({ |
10324 |
.expectExitResultUnit = VM_HERTZ |
.expectExitResultUnit = VM_HERTZ |
10325 |
}); |
}); |
10326 |
|
|
10327 |
|
runScript({ |
10328 |
|
.code = R"NKSP_CODE( |
10329 |
|
on init |
10330 |
|
exit( floor(4.4ms / 2.0) ) |
10331 |
|
end on |
10332 |
|
)NKSP_CODE", |
10333 |
|
.expectRealExitResult = 2.0, |
10334 |
|
.expectExitResultUnitPrefix = { VM_MILLI }, |
10335 |
|
.expectExitResultUnit = VM_SECOND |
10336 |
|
}); |
10337 |
|
|
10338 |
|
runScript({ |
10339 |
|
.code = R"NKSP_CODE( |
10340 |
|
on init |
10341 |
|
exit( floor( floor(8.4us) / 4.0) ) |
10342 |
|
end on |
10343 |
|
)NKSP_CODE", |
10344 |
|
.expectRealExitResult = 2.0, |
10345 |
|
.expectExitResultUnitPrefix = { VM_MICRO }, |
10346 |
|
.expectExitResultUnit = VM_SECOND |
10347 |
|
}); |
10348 |
|
|
10349 |
// 'final' ('!') operator tests ... |
// 'final' ('!') operator tests ... |
10350 |
|
|
10351 |
runScript({ |
runScript({ |
11924 |
testBitwiseOrOperator(); |
testBitwiseOrOperator(); |
11925 |
testBitwiseNotOperator(); |
testBitwiseNotOperator(); |
11926 |
testPrecedenceOfOperators(); |
testPrecedenceOfOperators(); |
11927 |
|
testIntVarDeclaration(); |
11928 |
|
testIntArrayVarDeclaration(); |
11929 |
|
testRealVarDeclaration(); |
11930 |
|
testRealArrayVarDeclaration(); |
11931 |
|
testStringVarDeclaration(); |
11932 |
testBuiltInMinFunction(); |
testBuiltInMinFunction(); |
11933 |
testBuiltInMaxFunction(); |
testBuiltInMaxFunction(); |
11934 |
testBuiltInAbsFunction(); |
testBuiltInAbsFunction(); |