Skip to content

Commit

Permalink
Remove arguments mutation 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
abukurov committed Jan 31, 2017
1 parent f1f7c96 commit 5a01a59
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .jestrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"automock": false,
"transformIgnorePatterns": ["./node_modules"],
"testPathIgnorePatterns": ["./__tests__/helpers", "./node_modules"]
"testPathIgnorePatterns": ["./node_modules"]
}
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ language: node_js
node_js:
- stable

before_script:
- npm run lint

after_script:
- npm run test:publish
49 changes: 34 additions & 15 deletions __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('Morph expressions', function () {
expect(parser.parseAndEval('0')).to.equal(0);
expect(parser.parseAndEval('5')).to.equal(5);
expect(parser.parseAndEval('5.4')).to.equal(5.4);
expect(parser.parseAndEval('.4')).to.equal(.4);
expect(parser.parseAndEval('005.4')).to.equal(5.4);
expect(parser.parseAndEval('005.400')).to.equal(5.4);
expect(parser.parseAndEval('2.')).to.equal(2);
Expand All @@ -26,8 +27,7 @@ describe('Morph expressions', function () {

describe('when number is not valid', function () {
it('should throw an SyntaxError', function () {
expect(() => parser.parseAndEval('.')).to.throw(SyntaxError);
expect(() => parser.parseAndEval('3.2.1')).to.throw(SyntaxError);
expect(() => parser.parseAndEval('3.2.1')).to.throw(SyntaxError, 'Invalid number \'3.2.1\'');
});
});
});
Expand All @@ -42,10 +42,10 @@ describe('Morph expressions', function () {

describe('when string is not valid', function () {
it('should throw an SyntaxError', function () {
expect(() => parser.parseAndEval('"string')).to.throw(SyntaxError);
expect(() => parser.parseAndEval('string"')).to.throw(SyntaxError);
expect(() => parser.parseAndEval('\'string"')).to.throw(SyntaxError);
expect(() => parser.parseAndEval('"string\'')).to.throw(SyntaxError);
expect(() => parser.parseAndEval('"string')).to.throw(SyntaxError, 'Unterminated quote "');
expect(() => parser.parseAndEval('string"')).to.throw(SyntaxError, 'Unterminated quote "');
expect(() => parser.parseAndEval('\'string"')).to.throw(SyntaxError, 'Unterminated quote \'');
expect(() => parser.parseAndEval('"string\'')).to.throw(SyntaxError, 'Unterminated quote "');
});
});
});
Expand Down Expand Up @@ -103,6 +103,7 @@ describe('Morph expressions', function () {

it('should eval in precedence order', function () {
expect(parser.parseAndEval('2 * -2')).to.equal(-4);
expect(parser.parseAndEval('-2 * 2')).to.equal(-4);
});
});

Expand All @@ -114,6 +115,7 @@ describe('Morph expressions', function () {

it('should eval in precedence order', function () {
expect(parser.parseAndEval('2 / -2')).to.equal(-1);
expect(parser.parseAndEval('-2 / 2')).to.equal(-1);
});
});

Expand All @@ -124,6 +126,7 @@ describe('Morph expressions', function () {

it('should eval in precedence order', function () {
expect(parser.parseAndEval('5 % -2')).to.equal(1);
expect(parser.parseAndEval('-5 % 2')).to.equal(-1);
});
});

Expand All @@ -135,6 +138,7 @@ describe('Morph expressions', function () {

it('should eval in precedence order', function () {
expect(parser.parseAndEval('true == 2 > 1')).to.be.true;
expect(parser.parseAndEval('2 > 1 == true')).to.be.true;
});
});

Expand All @@ -146,6 +150,7 @@ describe('Morph expressions', function () {

it('should eval in precedence order', function () {
expect(parser.parseAndEval('true != 1 > 2')).to.be.true;
expect(parser.parseAndEval('1 > 2 != true')).to.be.true;
});
});

Expand All @@ -158,6 +163,7 @@ describe('Morph expressions', function () {

it('should eval in precedence order', function () {
expect(parser.parseAndEval('1 > 2 - 3')).to.be.true;
expect(parser.parseAndEval('4 - 2 > 1')).to.be.true;
});
});

Expand All @@ -182,6 +188,7 @@ describe('Morph expressions', function () {

it('should eval in precedence order', function () {
expect(parser.parseAndEval('1 < 2 - 1')).to.be.false;
expect(parser.parseAndEval('5 - 3 < 3')).to.be.true;
});
});

Expand All @@ -194,6 +201,7 @@ describe('Morph expressions', function () {

it('should eval in precedence order', function () {
expect(parser.parseAndEval('1 <= 2 - 1')).to.be.true;
expect(parser.parseAndEval('2 - 1 <= 1')).to.be.true;
});
});

Expand Down Expand Up @@ -267,6 +275,19 @@ describe('Morph expressions', function () {
parser.unRegisterFunction('constant');
parser.unRegisterFunction('sum');
});

it('should throw an SyntaxError when function has been already declared', function () {
expect(() => parser.registerFunction('sqr', value => value * value))
.to.throw(SyntaxError, 'Function \'sqr\' has already been declared');
});

it('should throw an ReferenceError when function has not been already declared', function () {
expect(() => parser.parseAndEval('fooBar()')).to.throw(ReferenceError, 'Function \'fooBar\' isn\'t declared');
});

it('should throw an SyntaxError when function does not contains close parentheses', function () {
expect(() => parser.parseAndEval('sqr(2')).to.throw(SyntaxError, 'Unexpected end of expression');
});

it('should parse and eval function without parameters', function () {
expect(parser.parseAndEval('constant()')).to.equal('constant');
Expand All @@ -287,7 +308,7 @@ describe('Morph expressions', function () {

describe('when function definition does not contains close parentheses', function () {
it('should throw an SyntaxError', function () {
expect(() => parser.parseAndEval('unRegistered(')).to.throw(SyntaxError);
expect(() => parser.parseAndEval('unRegistered(')).to.throw(SyntaxError, 'Unexpected end of expression');
});
});
});
Expand All @@ -300,16 +321,14 @@ describe('Morph expressions', function () {
expect(parser.parseAndEval('(2 + 1) * 3')).to.equal(9);
});

describe('when expression does not contains close parentheses', function () {
it('should throw an SyntaxError', function () {
expect(() => parser.parseAndEval('3 * (1 + 2')).to.throw(SyntaxError);
});
it('should throw an SyntaxError when expression does not contains close parentheses', function () {
expect(() => parser.parseAndEval('3 * (1 + 2')).to.throw(SyntaxError, 'Unexpected end of expression');
});

describe('when expression does not contains open parentheses', function () {
it('should throw an SyntaxError', function () {
expect(() => parser.parseAndEval('1 + 2)')).to.throw(SyntaxError);
});
it('should throw an SyntaxError when expression does not contains open parentheses', function () {
expect(() => parser.parseAndEval('1 + 2)')).to.throw(SyntaxError, 'Unexpected end of expression');
expect(() => parser.parseAndEval('(1 + 2)) - 2')).to.throw(SyntaxError, 'Unexpected end of expression');
expect(() => parser.parseAndEval(')')).to.throw(SyntaxError, 'Unexpected end of expression');
});
});
});
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"lint": "eslint src specs",
"build": "npm run clean && babel ./src --presets babel-preset-es2015 --out-dir ./dist",
"clean": "rimraf ./dist ./tmp",
"test": "npm run lint && jest --no-cache --config ./.jestrc.json --coverage",
"test": "jest --no-cache --config ./.jestrc.json --coverage",
"test:publish": "coveralls < coverage/lcov.info && rimraf coverage",
"prepublish": "npm run lint && npm test && npm run build",
"precommit": "npm test",
"prepush": "npm test"
"precommit": "npm run lint && npm test",
"prepush": "npm run lint && npm test"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 5a01a59

Please sign in to comment.