Add analyzer tests to switch statements
This commit is contained in:
parent
a50a5febb9
commit
f3bdfef5c5
|
@ -100,6 +100,78 @@ U: (| Int F64 UInt)
|
|||
`)
|
||||
}
|
||||
|
||||
func TestSwitch (test *testing.T) {
|
||||
testString (test,
|
||||
`
|
||||
[switch x:Int]:Int = switch x
|
||||
| 0 5
|
||||
| 1 4
|
||||
| 2 3
|
||||
* 0
|
||||
`)
|
||||
}
|
||||
|
||||
func TestSwitchReturn (test *testing.T) {
|
||||
testString (test,
|
||||
`
|
||||
[is5 x:Int]:Bool = {
|
||||
switch x | 5 [return true]
|
||||
false
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
func TestSwitchReturnValueUsed (test *testing.T) {
|
||||
testString (test,
|
||||
`
|
||||
[is5 x:Int]:Bool = switch x
|
||||
| 5 [return true]
|
||||
* false
|
||||
`)
|
||||
}
|
||||
|
||||
func TestSwitchErrBadLiteral (test *testing.T) {
|
||||
testStringErr (test,
|
||||
"cannot use array literal as Int", 4, 4,
|
||||
`
|
||||
[switch x:Int]:Int = switch x
|
||||
| 0 5
|
||||
| (1) 4
|
||||
| 2 3
|
||||
* 0
|
||||
`)
|
||||
}
|
||||
|
||||
func TestSwitchErrNotConstant (test *testing.T) {
|
||||
testStringErr (test,
|
||||
"y cannot represent a constant integer", 7, 4,
|
||||
`
|
||||
[switch x:Int]:Int = {
|
||||
y:Int = 1
|
||||
|
||||
switch x
|
||||
| 0 5
|
||||
| y 4
|
||||
| 2 3
|
||||
* 0
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
func TestSwitchErrDuplicate (test *testing.T) {
|
||||
testStringErr (test,
|
||||
"65 already listed in match at stream0.fspl:6:2", 7, 4,
|
||||
`
|
||||
[switch x:I8]:Int = switch x
|
||||
| 0 5
|
||||
| 1 4
|
||||
| 2 3
|
||||
| 65 2
|
||||
| 'A' 1
|
||||
* 0
|
||||
`)
|
||||
}
|
||||
|
||||
func TestIfElseReturnValueUsed (test *testing.T) {
|
||||
testString (test,
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue