Add test cases for #55

This commit is contained in:
Sasha Koshka 2024-03-06 15:31:47 -05:00
parent 3d6a258873
commit 4df8a45a16
2 changed files with 63 additions and 0 deletions

View File

@ -23,6 +23,16 @@ U: (| Int F64)
`)
}
func TestMatchReturnValueUsed (test *testing.T) {
testString (test,
`
U: (| Int F64)
[isInt u:U]:Bool = match u in
| u:Int [return true]
| u:F64 false
`)
}
func TestMatchUnionUnderComplete (test *testing.T) {
testString (test,
`
@ -79,3 +89,23 @@ U: (| Int F64 UInt)
| u:Int u
`)
}
func TestIfElseReturnValueUsed (test *testing.T) {
testString (test,
`
[is5 x:Int]:Bool = if [= x 5]
then true
else [return false]
`)
}
func TestIfElseBreakValueUsed (test *testing.T) {
testString (test,
`
[f x:Int]: Int = loop {
y:Int = if [= x 5]
then [break 0]
else x
}
`)
}

View File

@ -230,6 +230,17 @@ U: (| Int F64)
`)
}
func TestMatchReturnValueUsed (test *testing.T) {
testString (test,
``,
`
U: (| Int F64)
[isInt u:U]:Bool = match u in
| u:Int [return true]
| u:F64 false
`)
}
func TestMatchUnionUnderComplete (test *testing.T) {
testString (test,
`%"0zNZN147MN2wzMAQ6NS2dQ==::U" = type { i64, i64 }
@ -298,3 +309,25 @@ U: (| Int F64 UInt)
| u:F64 [print 'F64']
`)
}
func TestIfElseReturnValueUsed (test *testing.T) {
testString (test,
``,
`
[is5 x:Int]:Bool = if [= x 5]
then true
else [return false]
`)
}
func TestIfElseBreakValueUsed (test *testing.T) {
testString (test,
``,
`
[f x:Int]: Int = loop {
y:Int = if [= x 5]
then [break 0]
else x
}
`)
}