summaryrefslogtreecommitdiff
path: root/src/pkg/ebnf/ebnf_test.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2009-07-13 10:10:56 -0700
committerRobert Griesemer <gri@golang.org>2009-07-13 10:10:56 -0700
commit60bd46d9a77d7fed38bd6edb50a89808e12903f4 (patch)
tree7435fbce76ad33f476c3af6a6795e01e4dc1b59f /src/pkg/ebnf/ebnf_test.go
parentff651150b8a77a79ceb50d63f9803b67e9a159d6 (diff)
downloadgolang-60bd46d9a77d7fed38bd6edb50a89808e12903f4.tar.gz
Basic EBNF package:
- parsing of EBNF grammars - basic consistency checks R=rsc DELTA=695 (695 added, 0 deleted, 0 changed) OCL=31479 CL=31516
Diffstat (limited to 'src/pkg/ebnf/ebnf_test.go')
-rw-r--r--src/pkg/ebnf/ebnf_test.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/pkg/ebnf/ebnf_test.go b/src/pkg/ebnf/ebnf_test.go
new file mode 100644
index 000000000..ab4ea4c95
--- /dev/null
+++ b/src/pkg/ebnf/ebnf_test.go
@@ -0,0 +1,75 @@
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package ebnf
+
+import (
+ "ebnf";
+ "io";
+ "strings";
+ "testing";
+)
+
+
+var grammars = []string {
+ `Program = .
+ `,
+
+ `Program = foo .
+ foo = "foo" .
+ `,
+
+ `Program = "a" | "b" "c" .
+ `,
+
+ `Program = "a" ... "z" .
+ `,
+
+ `Program = Song .
+ Song = { Note } .
+ Note = Do | (Re | Mi | Fa | So | La) | Ti .
+ Do = "c" .
+ Re = "d" .
+ Mi = "e" .
+ Fa = "f" .
+ So = "g" .
+ La = "a" .
+ Ti = ti .
+ ti = "b" .
+ `,
+}
+
+
+func check(t *testing.T, src []byte) {
+ grammar, err := Parse(src);
+ if err != nil {
+ t.Errorf("Parse(%s) failed: %v", src, err);
+ }
+ if err = Verify(grammar, "Program"); err != nil {
+ t.Errorf("Verify(%s) failed: %v", src, err);
+ }
+}
+
+
+func TestGrammars(t *testing.T) {
+ for _, src := range grammars {
+ check(t, strings.Bytes(src));
+ }
+}
+
+
+var files = []string {
+ // TODO(gri) add some test files
+}
+
+
+func TestFiles(t *testing.T) {
+ for _, filename := range files {
+ src, err := io.ReadFile(filename);
+ if err != nil {
+ t.Fatal(err);
+ }
+ check(t, src);
+ }
+}