Parser test-common uses testcommon package

This commit is contained in:
Sasha Koshka 2024-02-06 00:49:28 -05:00
parent f7636ab410
commit c323715505
1 changed files with 15 additions and 21 deletions

View File

@ -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()
}
}