Skip to content

Commit 5910258

Browse files
committed
tests is now more consistent with Python version, Grammar and RuleName fixes (underscore, numbers)
1 parent da352c2 commit 5910258

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+364
-6
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ root = true
44
# Unix-style newlines with a newline ending every file
55
[*]
66
end_of_line = lf
7-
insert_final_newline = true
7+
insert_final_newline = false
88

99
# Matches multiple files with brace expansion notation
1010
# Set default charset

src/speg_parser.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function parsing_rule() {
4040

4141
function parsing_rule_name() {
4242
return rd.action('noop', rd.sequence([
43-
rd.regex_char('[a-zA-Z]'),
44-
rd.zero_or_more(rd.regex_char('[a-zA-Z_]'))
43+
rd.regex_char('[a-zA-Z_]'),
44+
rd.zero_or_more(rd.regex_char('[a-zA-Z0-9_]'))
4545
]));
4646
}
4747

test/speg.fixtures.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ var SPEG = require('./../src/speg').SPEG;
22
var fs = require('fs');
33
var path = require('path');
44
var recursiveReadSync = require('recursive-readdir-sync');
5-
var valid_files = recursiveReadSync('./test/speg_fixtures/grammar');
5+
var valid_files = recursiveReadSync('./test/speg_fixtures');
66

77
describe('speg - fixtures - ', function() {
8+
valid_files = valid_files.filter(function(filename) {
9+
return filename.endsWith('.peg');
10+
})
811
for (var i = 0, len = valid_files.length; i < len; i++) {
912
it('should parse - ' + valid_files[i], (function (filename) {
1013
return function () {
1114
var name = path.basename(filename);
1215
var grammar = fs.readFileSync(filename, "utf8");
13-
var text = fs.readFileSync(path.join('./test/speg_fixtures/text', name + '.txt'), "utf8");
14-
var result = fs.readFileSync(path.join('./test/speg_fixtures/result', name + '.json'), "utf8");
16+
var text = fs.readFileSync(path.join('./test/speg_fixtures/', name + '.txt'), "utf8");
17+
var result = fs.readFileSync(path.join('./test/speg_fixtures/', name + '.json'), "utf8");
1518
var speg = new SPEG();
1619
var ast = speg.parse(grammar, text);
1720
ast.should.deep.equal(JSON.parse(result));

test/speg_fixtures/pegjs_example.peg

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
GRAMMAR Math_Expression_Grammar
2+
3+
Math -> Expression EOF;
4+
5+
Expression -> Term (_ ("+" / "-") _ Term)*;
6+
7+
Term -> Factor (_ ("*" / "/") _ Factor)*;
8+
9+
Factor -> ("(" _ Expression _ ")") / Integer;
10+
11+
Integer -> [0-9]+;
12+
13+
_ -> [ \t\n\r]*;

test/speg_fixtures/pegjs_example.peg.json

+300
Large diffs are not rendered by default.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2 * (3 + 4)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
GRAMMAR test
2+
3+
a -> _;
4+
_ -> "A";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "string",
3+
"start_position": 0,
4+
"match": "A",
5+
"end_position": 1
6+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GRAMMAR 123numbers
2+
3+
test -> "test";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
GRAMMAR numbers_at_start
2+
3+
a -> 1b b2 b3 b999;
4+
1b -> "test";
5+
b2 -> "test";
6+
b3 -> "test";
7+
b999 -> "test";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GRAMMAR CamelCase
2+
3+
test -> "test";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GRAMMAR numbers123
2+
3+
test -> "test";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GRAMMAR lower_case_underscore
2+
3+
test -> "test";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
GRAMMAR url
2+
3+
a -> b1 b2 b3 b999;
4+
b1 -> "test";
5+
b2 -> "test";
6+
b3 -> "test";
7+
b999 -> "test";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
GRAMMAR url
2+
3+
a -> _;
4+
_ -> "test";

0 commit comments

Comments
 (0)