Add some match statement tests

This commit is contained in:
Sasha Koshka 2024-03-04 13:34:22 -05:00
parent cd91f9dc20
commit ce79e16de7
1 changed files with 47 additions and 0 deletions

47
analyzer/match_test.go Normal file
View File

@ -0,0 +1,47 @@
package analyzer
import "testing"
func TestMatch (test *testing.T) {
testString (test,
`
U: (| Int F64)
[matchToInt u:U]:Int = match u in
| u:Int u
| u:F64 [~Int u]
`)
}
func TestMatchErrUnionOverComplete (test *testing.T) {
testStringErr (test,
"UInt is not included within U", 5, 6,
`
U: (| Int F64)
[matchToInt u:U]:Int = match u in
| u:Int u
| u:UInt [~Int u]
| u:F64 [~Int u]
`)
}
func TestMatchErrUnionUnderComplete (test *testing.T) {
testStringErr (test,
"match statement does not cover all types within U", 3, 25,
`
U: (| Int F64 UInt)
[matchToInt u:U]:Int = match u in
| u:Int u
| u:F64 [~Int u]
`)
}
func TestMatchUnionUnderComplete (test *testing.T) {
testString (test,
`
U: (| Int F64 UInt)
[print str:String]
[matchToInt u:U] = match u in
| u:Int [print 'Int']
| u:F64 [print 'F64']
`)
}