fspl/parser/fspl/test-common.go

45 lines
1.1 KiB
Go
Raw Normal View History

2024-02-13 18:03:22 +00:00
package fsplParser
2023-09-18 05:55:38 +00:00
import "io"
import "testing"
import "strings"
2024-02-23 00:22:53 +00:00
import "git.tebibyte.media/fspl/fspl/lexer"
import "git.tebibyte.media/fspl/fspl/errors"
import "git.tebibyte.media/fspl/fspl/testcommon"
2023-09-18 05:55:38 +00:00
func testString (test *testing.T, correct string, input string) {
2024-02-14 22:35:44 +00:00
testStringInternal(test, correct, input, false)
}
func testStringSkim (test *testing.T, correct string, input string) {
testStringInternal(test, correct, input, true)
}
func testStringInternal (test *testing.T, correct string, input string, skim bool) {
ast := Tree { }
2024-02-09 08:59:00 +00:00
lx, err := lexer.LexReader("input.fspl", strings.NewReader(input))
if err != nil && err != io.EOF{
test.Error("lexer returned error:\n" + errors.Format(err))
return
}
2024-02-14 22:35:44 +00:00
if skim {
err = ast.Skim(lx)
} else {
err = ast.Parse(lx)
}
if err != nil && err != io.EOF{
2024-02-08 21:51:48 +00:00
test.Error("parser returned error:\n" + errors.Format(err))
return
2023-09-18 05:55:38 +00:00
}
got := ast.String()
2023-09-18 05:55:38 +00:00
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")
2023-09-18 05:55:38 +00:00
test.Fail()
}
}