diff --git a/analyzer/control-flow_test.go b/analyzer/control-flow_test.go index 223cbe0..dd9ff34 100644 --- a/analyzer/control-flow_test.go +++ b/analyzer/control-flow_test.go @@ -109,3 +109,47 @@ testString (test, } `) } + +func TestFor (test *testing.T) { +testString (test, +` +[f str:String] = for c:Byte in str { } +[g str:String] = for i:Index c:Byte in str { } +`)} + +func TestForBreak (test *testing.T) { +testString (test, +` +[f str:String]:Byte = for c:Byte in str [break c] +`)} + +func TestForBreakBadType (test *testing.T) { +testStringErr (test, +"expected Byte", 2, 56, +` +[f str:String]:Byte = for i:Index c:Byte in str [break i] +`)} + +func TestForErrBadIndex (test *testing.T) { +testStringErr (test, +"expected Index", 2, 22, +` +[f str:String] = for i:Int c:Byte in str { } +`)} + +func TestForErrBadOver (test *testing.T) { +testStringErr (test, +"cannot use U8 as Int", 2, 31, +` +[f str:String] = for c:Int in str { } +`)} + +func TestForErrDeclarationScoped (test *testing.T) { +testStringErr (test, +"no variable named c", 4, 2, +` +[f str:String] = { + for c:Byte in str { } + c = 'a' +} +`)}