Add tests for for loop analysis

This commit is contained in:
Sasha Koshka
2024-03-16 13:23:35 -04:00
parent 83b0dda171
commit 24bfb30a24

View File

@@ -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'
}
`)}