Files
fspl/analyzer/match_test.go
Sasha Koshka 863abddc4a One last test
2024-03-06 15:16:15 -05:00

82 lines
1.3 KiB
Go

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 TestMatchReturn (test *testing.T) {
testString (test,
`
U: (| Int F64)
[isInt u:U]:Bool = {
match u in | u:Int [return true]
false
}
`)
}
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']
`)
}
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 TestMatchErrNotUnion (test *testing.T) {
testStringErr (test,
"type U is not a union", 3, 24,
`
U: Int
[matchToInt u:U]:Int = match u in
| u:Int u
| u:F64 [~Int u]
`)
}
func TestMatchErrUnionUnderComplete (test *testing.T) {
testStringErr (test,
"match does not cover all types within U", 3, 24,
`
U: (| Int F64 UInt)
[matchToInt u:U]:Int = match u in
| u:Int u
| u:F64 [~Int u]
`)
}
func TestMatchErrDuplicate (test *testing.T) {
testStringErr (test,
"Int already listed in match at stream0.fspl:4:6", 6, 6,
`
U: (| Int F64 UInt)
[matchToInt u:U]:Int = match u in
| u:Int u
| u:F64 [~Int u]
| u:Int u
`)
}