diff --git a/parser/test-common.go b/parser/test-common.go index fe5d9cd..b011015 100644 --- a/parser/test-common.go +++ b/parser/test-common.go @@ -1,30 +1,24 @@ package parser import "io" -import "fmt" import "testing" import "strings" +import "git.tebibyte.media/sashakoshka/fspl/testcommon" -func testString (test *testing.T, correct, input string) { - testReader(test, correct, strings.NewReader(input)) -} - -func testReader (test *testing.T, correct string, inputs ...io.Reader) { - tree := Tree { } - for index, stream := range inputs { - err := tree.Parse(fmt.Sprintf("stream%d.fspl", index), stream) - if err != nil { - test.Error("parser returned error: ", err) - return - } - } - - got := tree.String() - if got != correct { - test.Log("strings do not match") - test.Log("tree.String():\n" + got) - test.Log("correct:\n" + correct) - test.Fail() +func testString (test *testing.T, correct string, input string) { + ast := Tree { } + err := ast.Parse("input.fspl", strings.NewReader(input)) + if err != nil && err != io.EOF{ + test.Error("parser returned error:", err) return } + + got := ast.String() + if got != correct { + test.Logf("results do not match") + testcommon.Compare(test, correct, got) + test.Log("SOURCE FSPL CODE:") + test.Log("\033[32m" + input + "\033[0m") + test.Fail() + } }