From 6a5851c9eb6de1daaaf88c6656f2d27b8097df49 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 17 Aug 2022 19:36:33 -0400 Subject: [PATCH] Parser tests now show exact line and column where data is mismatched --- parser/parser_test.go | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/parser/parser_test.go b/parser/parser_test.go index 18e2ee0..737d3a6 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -5,8 +5,9 @@ import "testing" // import "git.tebibyte.media/sashakoshka/arf/types" func checkTree (modulePath string, correct string, test *testing.T) { - tree, err := Parse(modulePath) + 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) {