commit b9d302c027021d4ec9af4749ad49810104e71083
parent 16f55e41373fcd71ccf26dad2e6a7f0238861ee6
Author: Eyal Sawady <ecs@d2evs.net>
Date: Tue, 12 Jan 2021 18:35:35 -0500
Add break/continue test
Diffstat:
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/tests/12-control.ha b/tests/12-control.ha
@@ -0,0 +1,48 @@
+fn rt::compile(src: str) int;
+
+export fn main() void = {
+ for (let i: int = 0; i < 1; i += 1) {
+ let j: int = 0;
+ for (j < 10) {
+ j += 1;
+ if (j == 5) {
+ break;
+ };
+ };
+ assert(j == 5, "Failed to break out of while");
+ };
+ let done: bool = false;
+ for (!done) {
+ for (let i: int = 0; i < 10; i += 1) {
+ if (i == 5) {
+ true;
+ continue;
+ };
+ assert(i != 5, "Broken continue");
+ if (i >= 7) {
+ break;
+ };
+ assert(i < 7, "Broken break");
+ };
+ done = true;
+ };
+ let i = 0;
+ :outer for (i < 10) {
+ :inner for (let j = 0; j < 7; j += 1) {
+ :outer for (true) {
+ break :outer;
+ };
+ i += 1;
+ if (j == 6) {
+ continue :inner;
+ };
+ assert(j != 6);
+ if (i > 7) {
+ break :outer;
+ };
+ };
+ };
+ assert(i == 8);
+ assert(rt::compile("fn test() void = { :foo for (true) { break :bar; }; };") != 0);
+ assert(rt::compile("fn test() void = { break :bar; };") != 0);
+};
diff --git a/tests/configure b/tests/configure
@@ -14,7 +14,8 @@ tests() {
08-slices \
09-funcs \
10-binarithms \
- 11-globals
+ 11-globals \
+ 12-control
do
cat <<EOF
tests/$t: libhart.a tests/$t.ha