From 24bfb30a2455e0c9a5fe2a3d42703f6b8f2c232e Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 16 Mar 2024 13:23:35 -0400 Subject: [PATCH] Add tests for for loop analysis --- analyzer/control-flow_test.go | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) 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' +} +`)}