Parser tests now show exact line and column where data is mismatched

This commit is contained in:
Sasha Koshka 2022-08-17 19:36:33 -04:00
parent e069569c3c
commit 6a5851c9eb

View File

@ -7,6 +7,7 @@ import "testing"
func checkTree (modulePath string, correct string, test *testing.T) {
tree, err := Parse(modulePath)
treeString := tree.ToString(0)
treeRunes := []rune(treeString)
test.Log("CORRECT TREE:")
test.Log(correct)
@ -20,11 +21,46 @@ func checkTree (modulePath string, correct string, test *testing.T) {
return
}
if treeString != correct {
test.Log("trees not equal!")
equal := true
line := 0
column := 0
for index, correctChar := range correct {
if index >= len(treeRunes) {
test.Log (
"parsed is too short at line", line + 1,
"col", column + 1)
test.Fail()
return
}
if correctChar != treeRunes[index] {
test.Log (
"trees not equal at line", line + 1,
"col", column + 1)
test.Log("correct: [" + string(correctChar) + "]")
test.Log("got: [" + string(treeRunes[index]) + "]")
test.Fail()
return
}
if correctChar == '\n' {
line ++
column = 0
} else {
column ++
}
}
if len(treeString) > len(correct) {
test.Log("parsed is too long")
test.Fail()
return
}
if !equal {
return
}
}
func TestMeta (test *testing.T) {