Permalink
Browse files

Split-off |PEG.compiler.checks| tests

  • Loading branch information...
1 parent b15eb0b commit 1b75a7b9b33ca8afb7e696c28e40c330780003b2 @dmajda dmajda committed Aug 18, 2010
Showing with 59 additions and 53 deletions.
  1. +58 −0 test/checks-test.js
  2. +0 −53 test/compiler-test.js
  3. +1 −0 test/index.html
View
@@ -0,0 +1,58 @@
+(function(global) {
+
+module("PEG.compiler.checks");
+
+test("reports missing referenced rules", function() {
+ var grammars = [
+ 'start = missing',
+ 'start = missing / "a" / "b"',
+ 'start = "a" / "b" / missing',
+ 'start = missing "a" "b"',
+ 'start = "a" "b" missing',
+ 'start = label:missing',
+ 'start = &missing',
+ 'start = !missing',
+ 'start = missing?',
+ 'start = missing*',
+ 'start = missing+',
+ 'start = missing { }'
+ ];
+
+ for (var i = 0; i < grammars.length; i++) {
+ throws(
+ function() { PEG.buildParser(grammars[i]); },
+ PEG.GrammarError,
+ { message: "Referenced rule \"missing\" does not exist." }
+ );
+ }
+});
+
+test("reports left recursion", function() {
+ var grammars = [
+ /* Direct */
+ 'start = start',
+ 'start = start / "a" / "b"',
+ 'start = "a" / "b" / start',
+ 'start = start "a" "b"',
+ 'start = label:start',
+ 'start = &start',
+ 'start = !start',
+ 'start = start?',
+ 'start = start*',
+ 'start = start+',
+ 'start = start { }',
+
+ /* Indirect */
+ 'start = stop; stop = start'
+ ];
+
+ for (var i = 0; i < grammars.length; i++) {
+ throws(
+ function() { PEG.buildParser(grammars[i]); },
+ PEG.GrammarError,
+ { message: "Left recursion detected for rule \"start\"." }
+ );
+ }
+});
+
+})(this);
View
@@ -66,59 +66,6 @@ test("buildParser reports syntax errors in the grammar", function() {
);
});
-test("buildParser reports missing referenced rules", function() {
- var grammars = [
- 'start = missing',
- 'start = missing / "a" / "b"',
- 'start = "a" / "b" / missing',
- 'start = missing "a" "b"',
- 'start = "a" "b" missing',
- 'start = label:missing',
- 'start = &missing',
- 'start = !missing',
- 'start = missing?',
- 'start = missing*',
- 'start = missing+',
- 'start = missing { }'
- ];
-
- for (var i = 0; i < grammars.length; i++) {
- throws(
- function() { PEG.buildParser(grammars[i]); },
- PEG.GrammarError,
- { message: "Referenced rule \"missing\" does not exist." }
- );
- }
-});
-
-test("buildParser reports left recursion", function() {
- var grammars = [
- /* Direct */
- 'start = start',
- 'start = start / "a" / "b"',
- 'start = "a" / "b" / start',
- 'start = start "a" "b"',
- 'start = label:start',
- 'start = &start',
- 'start = !start',
- 'start = start?',
- 'start = start*',
- 'start = start+',
- 'start = start { }',
-
- /* Indirect */
- 'start = stop; stop = start'
- ];
-
- for (var i = 0; i < grammars.length; i++) {
- throws(
- function() { PEG.buildParser(grammars[i]); },
- PEG.GrammarError,
- { message: "Left recursion detected for rule \"start\"." }
- );
- }
-});
-
test("buildParser allows custom start rule", function() {
var parser = PEG.buildParser('s = "abcd"', "s");
parses(parser, "abcd", "abcd");
View
@@ -7,6 +7,7 @@
<script src="vendor/qunit/qunit.js"></script>
<script src="../lib/peg.js"></script>
<script src="compiler-test.js"></script>
+ <script src="checks-test.js"></script>
<script src="parser-test.js"></script>
</head>
<body>

0 comments on commit 1b75a7b

Please sign in to comment.