47 lines
1.1 KiB
Go
47 lines
1.1 KiB
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 = parsekit.C, parsekit.A
|
|
|
|
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) {
|
|
parser := parsekit.New(test.matcher).Parse(test.input)
|
|
item, err, ok := parser.Next()
|
|
|
|
if test.mustMatch {
|
|
if !ok {
|
|
t.Errorf("Test %q failed with error: %s", test.input, err)
|
|
} else if item.Type != parsekit.MatchedItem {
|
|
t.Errorf("Test %q failed: should match, but it didn't", test.input)
|
|
} else if item.Value != test.expected {
|
|
t.Errorf("Test %q failed: not expected output:\nexpected: %q\nactual: %q\n", test.input, test.expected, item.Value)
|
|
}
|
|
} else {
|
|
if ok {
|
|
t.Errorf("Test %q failed: should not match, but it did", test.input)
|
|
}
|
|
}
|
|
}
|