Parser tests now show exact line and column where data is mismatched
This commit is contained in:
parent
e069569c3c
commit
6a5851c9eb
@ -7,6 +7,7 @@ import "testing"
|
|||||||
func checkTree (modulePath string, correct string, test *testing.T) {
|
func checkTree (modulePath string, correct string, test *testing.T) {
|
||||||
tree, err := Parse(modulePath)
|
tree, err := Parse(modulePath)
|
||||||
treeString := tree.ToString(0)
|
treeString := tree.ToString(0)
|
||||||
|
treeRunes := []rune(treeString)
|
||||||
|
|
||||||
test.Log("CORRECT TREE:")
|
test.Log("CORRECT TREE:")
|
||||||
test.Log(correct)
|
test.Log(correct)
|
||||||
@ -20,11 +21,46 @@ func checkTree (modulePath string, correct string, test *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if treeString != correct {
|
equal := true
|
||||||
test.Log("trees not equal!")
|
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()
|
test.Fail()
|
||||||
return
|
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) {
|
func TestMeta (test *testing.T) {
|
||||||
|
Reference in New Issue
Block a user