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 // Easy access to the parsekit definitions. var c, a, m = parsekit.C, parsekit.A, parsekit.M type TokenHandlerTest struct { input string tokenHandler parsekit.TokenHandler mustMatch bool expected string } func RunTokenHandlerTests(t *testing.T, testSet []TokenHandlerTest) { for _, test := range testSet { RunTokenHandlerTest(t, test) } } func RunTokenHandlerTest(t *testing.T, test TokenHandlerTest) { output, err, ok := parsekit.NewMatcher(test.tokenHandler, "a match").Parse(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) } } }