Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix <<command()>> and <<command("parameters")>> crashing bondage.js #37

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ const grammar = {
// Extremely ugly hack because a command with spaces (e.g. <<foo bar>>)
// Lexes as BeginCommand Identifier Text EndCommand
['BeginCommand Identifier Text EndCommand', '$$ = new yy.CommandNode($2 + " " + $3);'],
['BeginCommand Identifier LeftParen RightParen EndCommand', '$$ = new yy.CommandNode($2 + "()");'], /// <<myfunction()>>
['BeginCommand Identifier LeftParen arguments RightParen EndCommand', '$$ = new yy.CommandNode($2 + "()");'], /// <<myfunction("test",true,22)>>
],

arguments: [
Expand All @@ -125,6 +127,8 @@ const grammar = {
['Number', '$$ = new yy.NumericLiteralNode($1);'],
['String', '$$ = new yy.StringLiteralNode($1);'],
['Variable', '$$ = new yy.VariableNode($1.substring(1));'],
['True', '$$ = new yy.BooleanLiteralNode($1);'],
['False', '$$ = new yy.BooleanLiteralNode($1);'],
],
},
};
Expand Down
88 changes: 88 additions & 0 deletions tests/test_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,92 @@ describe('Parser', () => {

expect(results).to.deep.equal(expected);
});

it('can pass commands with myCommand() formatting - can parse some text followed a command', () => {
const results = parser.parse('some text<<commandtext()>>');

const expected = [
new nodes.TextNode('some text'),
new nodes.CommandNode('commandtext()'),
];

expect(results).to.deep.equal(expected);
});

it('can pass commands with myCommand() formatting - can parse some text followed by a newline and a command', () => {
const results = parser.parse('some text\n<<commandtext()>>');

const expected = [
new nodes.TextNode('some text'),
new nodes.CommandNode('commandtext()'),
];

expect(results).to.deep.equal(expected);
});

it('can pass commands with myCommand() formatting - correctly ignores a double newline', () => {
const results = parser.parse('some text\n\n<<commandtext()>>');

const expected = [
new nodes.TextNode('some text'),
new nodes.CommandNode('commandtext()'),
];

expect(results).to.deep.equal(expected);
});

it('can pass commands with myCommand() formatting - correctly ignores a bunch of newlines', () => {
const results = parser.parse('some text\n\n\n\n\n\n<<commandtext()>>\n');

const expected = [
new nodes.TextNode('some text'),
new nodes.CommandNode('commandtext()'),
];

expect(results).to.deep.equal(expected);
});

it('can pass commands with myCommand("test",true,22) formatting - can parse some text followed a command', () => {
const results = parser.parse('some text<<commandtext("test",true,22)>>');

const expected = [
new nodes.TextNode('some text'),
new nodes.CommandNode('commandtext()'), // will also add parameter parsing when this pull gets approved. Command node needs refactoring to support it
];

expect(results).to.deep.equal(expected);
});

it('can pass commands with myCommand("test",true,22) formatting - can parse some text followed by a newline and a command', () => {
const results = parser.parse('some text\n<<commandtext("test",true,22)>>');

const expected = [
new nodes.TextNode('some text'),
new nodes.CommandNode('commandtext()'), // will also add parameter parsing when this pull gets approved. Command node needs refactoring to support it
];

expect(results).to.deep.equal(expected);
});

it('can pass commands with myCommand("test",true,22) formatting - correctly ignores a double newline', () => {
const results = parser.parse('some text\n\n<<commandtext("test",true,22)>>');

const expected = [
new nodes.TextNode('some text'),
new nodes.CommandNode('commandtext()'), // will also add parameter parsing when this pull gets approved. Command node needs refactoring to support it
];

expect(results).to.deep.equal(expected);
});

it('can pass commands with myCommand("test",true,22) formatting - correctly ignores a bunch of newlines', () => {
const results = parser.parse('some text\n\n\n\n\n\n<<commandtext("test",true,22)>>\n');

const expected = [
new nodes.TextNode('some text'),
new nodes.CommandNode('commandtext()'), // will also add parameter parsing when this pull gets approved. Command node needs refactoring to support it
];

expect(results).to.deep.equal(expected);
});
});