Add compiler test cases for loops

This commit is contained in:
Sasha Koshka
2024-03-20 11:35:14 -04:00
parent f5b90df837
commit 6bcf6004d6
7 changed files with 51 additions and 0 deletions

View File

@@ -91,3 +91,27 @@ testUnit (test,
"", "false\n",
0,
)}
func TestLoopBreakExitCode (test *testing.T) {
testUnit (test,
"/test-data/data/loop-break-exit-code", nil,
"", "",
5,
)}
func TestLoopBreakBranchExitCode (test *testing.T) {
testUnit (test,
"/test-data/data/loop-break-branch-exit-code", nil,
"", "",
2,
)}
func TestForStringArray (test *testing.T) {
dependencies := []string {
compileDependency(test, "io"),
}
testUnit (test,
"/test-data/data/for-string-array", dependencies,
"", "a\nb\nc\na\nb\nc\n",
0,
)}

View File

@@ -0,0 +1,2 @@
'cfb45339-4c4d-4519-9578-3abf0c698867'
+ 'io'

View File

@@ -0,0 +1,10 @@
[main]:I32 = {
;array
arr:5:String = (* 'a' 'b' 'c')
for e:String in arr io::[println e]
; slice
slice:*:String = arr
for e:String in slice io::[println e]
0
}

View File

@@ -0,0 +1 @@
'e8962449-6214-4622-afcf-f6b58046fab2'

View File

@@ -0,0 +1,10 @@
[main]:I32 'main' = {
y:I32 = 6
loop {
if [< y 3]
then [break y]
else {
y = [-- y]
}
}
}

View File

@@ -0,0 +1 @@
'779e632d-88a6-46c4-bfa2-7db4fc919f07'

View File

@@ -0,0 +1,3 @@
[main]:I32 'main' = loop {
[break 5]
}