diff --git a/analyzer/control-flow_test.go b/analyzer/control-flow_test.go index d2437a2..02e9da7 100644 --- a/analyzer/control-flow_test.go +++ b/analyzer/control-flow_test.go @@ -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, `