Example #1
0
func test(t *testing.T, name string, g *ast.Grammar, p parser.Interface, expected bool, desc string, record bool) {
	if interp.HasRecursion(g) {
		t.Skipf("convert was not designed to handle recursion")
	}
	if strings.HasPrefix(name, "GoBigOr") {
		t.Skipf("too big to fail: the number of Ors creates a state space explosion")
	}
	var a *auto.Auto
	var err error
	if record {
		a, err = auto.CompileRecord(g)
	} else {
		a, err = auto.Compile(g)
	}
	if err != nil {
		t.Fatal(err)
	}
	match, err := a.Validate(p)
	if err != nil {
		t.Fatal(err)
	}
	if match != expected {
		t.Fatalf("Expected %v on given \n%s\n on \n%s", expected, g.String(), desc)
	}
}
Example #2
0
func bench(b *testing.B, grammar *ast.Grammar, parsers []testsuite.ResetParser, record bool) {
	num := len(parsers)
	var a *auto.Auto
	var err error
	if record {
		a, err = auto.CompileRecord(grammar)
	} else {
		a, err = auto.Compile(grammar)
	}
	if err != nil {
		b.Fatal(err)
	}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		if err := parsers[i%num].Reset(); err != nil {
			b.Fatal(err)
		}
		if _, err := a.Validate(parsers[i%num]); err != nil {
			b.Fatal(err)
		}
	}
	b.ReportAllocs()
}