Add some match statement tests
This commit is contained in:
parent
cd91f9dc20
commit
ce79e16de7
47
analyzer/match_test.go
Normal file
47
analyzer/match_test.go
Normal 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']
|
||||||
|
`)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user