Expectation refactoring 2/7: Restructure "class" expectations

Changes:

  * Remove the "value" property (it is replaced by other properties).

  * Add the "parts", "inverted", and "ignoreCase" properties (which
    allow more structured access to expectation data).
redux
David Majda 9 years ago
parent eda2a34c7f
commit c6e8c53f1b

@ -603,7 +603,7 @@ function generateBytecode(ast) {
},
"class": function(node) {
var regexp, description, regexpIndex, expectedIndex;
var regexp, parts, description, regexpIndex, expectedIndex;
if (node.parts.length > 0) {
regexp = '/^['
@ -624,6 +624,14 @@ function generateBytecode(ast) {
regexp = node.inverted ? '/^[\\S\\s]/' : '/^(?!)/';
}
parts = '['
+ arrays.map(node.parts, function(part) {
return part instanceof Array
? '["' + js.stringEscape(part[0]) + '", "' + js.stringEscape(part[1]) + '"]'
: '"' + js.stringEscape(part) + '"';
}).join(', ')
+ ']';
description = "["
+ (node.inverted ? "^" : "")
+ arrays.map(node.parts, function(part) {
@ -639,7 +647,9 @@ function generateBytecode(ast) {
expectedIndex = addConst([
'{',
'type: "class",',
'value: "' + js.stringEscape(node.rawText) + '",',
'parts: ' + parts + ',',
'inverted: ' + node.inverted + ',',
'ignoreCase: ' + node.ignoreCase + ',',
'description: "' + js.stringEscape(description) + '"',
'}'
].join(' '));

@ -344,7 +344,7 @@ describe("generated parser behavior", function() {
var parser = peg.generate('start = [a]', options);
expect(parser).toFailToParse("b", {
expected: [{ type: "class", value: "[a]", description: "[a]" }]
expected: [{ type: "class", parts: ["a"], inverted: false, ignoreCase: false, description: "[a]" }]
});
});
});

@ -598,7 +598,7 @@ describe("compiler pass |generateBytecode|", function() {
it("defines correct constants", function() {
expect(pass).toChangeAST('start = [a]', constsDetails([
'/^[a]/',
'{ type: "class", value: "[a]", description: "[a]" }'
'{ type: "class", parts: ["a"], inverted: false, ignoreCase: false, description: "[a]" }'
]));
});
});
@ -607,7 +607,7 @@ describe("compiler pass |generateBytecode|", function() {
it("defines correct constants", function() {
expect(pass).toChangeAST('start = [^a]', constsDetails([
'/^[^a]/',
'{ type: "class", value: "[^a]", description: "[^a]" }'
'{ type: "class", parts: ["a"], inverted: true, ignoreCase: false, description: "[^a]" }'
]));
});
});
@ -616,7 +616,7 @@ describe("compiler pass |generateBytecode|", function() {
it("defines correct constants", function() {
expect(pass).toChangeAST('start = [a]i', constsDetails([
'/^[a]/i',
'{ type: "class", value: "[a]i", description: "[a]" }'
'{ type: "class", parts: ["a"], inverted: false, ignoreCase: true, description: "[a]" }'
]));
});
});
@ -625,7 +625,7 @@ describe("compiler pass |generateBytecode|", function() {
it("defines correct constants", function() {
expect(pass).toChangeAST('start = [ab-def-hij-l]', constsDetails([
'/^[ab-def-hij-l]/',
'{ type: "class", value: "[ab-def-hij-l]", description: "[ab-def-hij-l]" }'
'{ type: "class", parts: ["a", ["b", "d"], "e", ["f", "h"], "i", ["j", "l"]], inverted: false, ignoreCase: false, description: "[ab-def-hij-l]" }'
]));
});
});
@ -634,7 +634,7 @@ describe("compiler pass |generateBytecode|", function() {
it("defines correct constants", function() {
expect(pass).toChangeAST('start = []', constsDetails([
'/^(?!)/',
'{ type: "class", value: "[]", description: "[]" }'
'{ type: "class", parts: [], inverted: false, ignoreCase: false, description: "[]" }'
]));
});
});
@ -643,7 +643,7 @@ describe("compiler pass |generateBytecode|", function() {
it("defines correct constants", function() {
expect(pass).toChangeAST('start = [^]', constsDetails([
'/^[\\S\\s]/',
'{ type: "class", value: "[^]", description: "[^]" }'
'{ type: "class", parts: [], inverted: true, ignoreCase: false, description: "[^]" }'
]));
});
});

Loading…
Cancel
Save