go-parsekit/parsekit_test.go

44 lines
995 B
Go

package parsekit_test
// This file only provides building blocks for writing tests.
// No actual tests belong in this file.
import (
"testing"
"git.makaay.nl/mauricem/go-parsekit"
)
const TestItem parsekit.ItemType = 1
var c, a, m = parsekit.C, parsekit.A, parsekit.M
type MatcherTest struct {
input string
matcher parsekit.Matcher
mustMatch bool
expected string
}
func RunMatcherTests(t *testing.T, testSet []MatcherTest) {
for _, test := range testSet {
RunMatcherTest(t, test)
}
}
func RunMatcherTest(t *testing.T, test MatcherTest) {
output, err, ok := parsekit.NewMatcherWrapper(test.matcher).Match(test.input)
if test.mustMatch {
if !ok {
t.Errorf("Test %q failed with error: %s", test.input, err)
} else if output != test.expected {
t.Errorf("Test %q failed: not expected output:\nexpected: %q\nactual: %q\n", test.input, test.expected, output)
}
} else {
if ok {
t.Errorf("Test %q failed: should not match, but it did", test.input)
}
}
}