Add compiler test cases for loops
This commit is contained in:
@@ -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,
|
||||
)}
|
||||
|
||||
2
compiler/test-data/data/for-string-array/fspl.mod
Normal file
2
compiler/test-data/data/for-string-array/fspl.mod
Normal file
@@ -0,0 +1,2 @@
|
||||
'cfb45339-4c4d-4519-9578-3abf0c698867'
|
||||
+ 'io'
|
||||
10
compiler/test-data/data/for-string-array/main.fspl
Normal file
10
compiler/test-data/data/for-string-array/main.fspl
Normal 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
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
'e8962449-6214-4622-afcf-f6b58046fab2'
|
||||
@@ -0,0 +1,10 @@
|
||||
[main]:I32 'main' = {
|
||||
y:I32 = 6
|
||||
loop {
|
||||
if [< y 3]
|
||||
then [break y]
|
||||
else {
|
||||
y = [-- y]
|
||||
}
|
||||
}
|
||||
}
|
||||
1
compiler/test-data/data/loop-break-exit-code/fspl.mod
Normal file
1
compiler/test-data/data/loop-break-exit-code/fspl.mod
Normal file
@@ -0,0 +1 @@
|
||||
'779e632d-88a6-46c4-bfa2-7db4fc919f07'
|
||||
3
compiler/test-data/data/loop-break-exit-code/main.fspl
Normal file
3
compiler/test-data/data/loop-break-exit-code/main.fspl
Normal file
@@ -0,0 +1,3 @@
|
||||
[main]:I32 'main' = loop {
|
||||
[break 5]
|
||||
}
|
||||
Reference in New Issue
Block a user