Skip to content

Commit

Permalink
Add failing tests and change tokenprio for unary
Browse files Browse the repository at this point in the history
  • Loading branch information
rreusser committed Jul 19, 2016
1 parent 4df3380 commit 8265f06
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parser.js
Expand Up @@ -585,7 +585,7 @@ var Parser = (function (scope) {
if (this.isOperator()) {
if (this.isSign() && (expected & SIGN)) {
if (this.isNegativeSign()) {
this.tokenprio = 2;
this.tokenprio = 5;
this.tokenindex = "-";
noperators++;
this.addfunc(tokenstack, operstack, TOP1);
Expand Down
32 changes: 32 additions & 0 deletions test/parserSpec.js
Expand Up @@ -34,6 +34,38 @@ describe("Parser", function() {
it("2 + 3 * foo.bar.baz", function() {
expect(Parser.evaluate("2 + 3 * foo.bar.baz", {foo: {bar: {baz: 4}}})).to.equal(14);
});

it('10/-1', function () {
expect(Parser.evaluate('10/-1')).to.equal(-10);
});

it('10*-1', function () {
expect(Parser.evaluate('10*-1')).to.equal(-10);
});

it('10*-x', function () {
expect(Parser.evaluate('10*-x', {x: 1})).to.equal(-10);
});

it('10+-1', function () {
expect(Parser.evaluate('10+-1')).to.equal(9);
});

it('10/+1', function () {
expect(Parser.evaluate('10/+1')).to.equal(10);
});

it('10*+1', function () {
expect(Parser.evaluate('10*+1')).to.equal(10);
});

it('10*+x', function () {
expect(Parser.evaluate('10*+x', {x: 1})).to.equal(10);
});

it('10+ +1', function () {
expect(Parser.evaluate('10+ +1')).to.equal(11);
});
});
describe("#substitute()", function() {
var expr = Parser.parse("2 * x + 1");
Expand Down

0 comments on commit 8265f06

Please sign in to comment.