package main import ( "io/ioutil" "testing" ) func BenchmarkLongToml(b *testing.B) { benchmarkFile(b, "long.toml") } func BenchmarkNormalToml(b *testing.B) { benchmarkFile(b, "normal.toml") } func BenchmarkShortToml(b *testing.B) { benchmarkFile(b, "short.toml") } func benchmarkFile(b *testing.B, file string) { toml := BuildGrammar() inputBytes, err := ioutil.ReadFile(file) if err != nil { b.Fatalf("Cannot read input file (%s): %s", file, err) } inputStr := string(inputBytes) for i := 0; i < b.N; i++ { _, err := toml.Match(inputStr) if err != nil { b.Fatalf("Error in parsing TOML input: %s\n", err) } } } func TestBugfix(t *testing.T) { toml := BuildGrammar() inputBytes, err := ioutil.ReadFile("short.toml") if err != nil { t.Fatalf("Cannot read input file (%s): %s", "short.toml", err) } inputStr := string(inputBytes) _, err = toml.Match(inputStr) if err != nil { t.Fatalf("Error in parsing TOML input: %s\n", err) } }