aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/ebnf/ebnf_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/ebnf/ebnf_test.go')
-rw-r--r--libgo/go/ebnf/ebnf_test.go35
1 files changed, 25 insertions, 10 deletions
diff --git a/libgo/go/ebnf/ebnf_test.go b/libgo/go/ebnf/ebnf_test.go
index e77cf64..b086fac 100644
--- a/libgo/go/ebnf/ebnf_test.go
+++ b/libgo/go/ebnf/ebnf_test.go
@@ -10,11 +10,9 @@ import (
"testing"
)
-
var fset = token.NewFileSet()
-
-var grammars = []string{
+var goodGrammars = []string{
`Program = .`,
`Program = foo .
@@ -22,7 +20,7 @@ var grammars = []string{
`Program = "a" | "b" "c" .`,
- `Program = "a" ... "z" .`,
+ `Program = "a" … "z" .`,
`Program = Song .
Song = { Note } .
@@ -37,8 +35,18 @@ var grammars = []string{
ti = "b" .`,
}
+var badGrammars = []string{
+ `Program = | .`,
+ `Program = | b .`,
+ `Program = a … b .`,
+ `Program = "a" … .`,
+ `Program = … "b" .`,
+ `Program = () .`,
+ `Program = [] .`,
+ `Program = {} .`,
+}
-func check(t *testing.T, filename string, src []byte) {
+func checkGood(t *testing.T, filename string, src []byte) {
grammar, err := Parse(fset, filename, src)
if err != nil {
t.Errorf("Parse(%s) failed: %v", src, err)
@@ -48,25 +56,32 @@ func check(t *testing.T, filename string, src []byte) {
}
}
+func checkBad(t *testing.T, filename string, src []byte) {
+ _, err := Parse(fset, filename, src)
+ if err == nil {
+ t.Errorf("Parse(%s) should have failed", src)
+ }
+}
func TestGrammars(t *testing.T) {
- for _, src := range grammars {
- check(t, "", []byte(src))
+ for _, src := range goodGrammars {
+ checkGood(t, "", []byte(src))
+ }
+ for _, src := range badGrammars {
+ checkBad(t, "", []byte(src))
}
}
-
var files = []string{
// TODO(gri) add some test files
}
-
func TestFiles(t *testing.T) {
for _, filename := range files {
src, err := ioutil.ReadFile(filename)
if err != nil {
t.Fatal(err)
}
- check(t, filename, src)
+ checkGood(t, filename, src)
}
}