Skip to content
This repository has been archived by the owner on Jul 15, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/1.0.18'
Browse files Browse the repository at this point in the history
  • Loading branch information
budnix committed Sep 12, 2016
2 parents f3c20c0 + f9e7e5e commit 2cce3ab
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 81 deletions.
188 changes: 138 additions & 50 deletions dist/formula-parser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/formula-parser.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/formula-parser.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/formula-parser.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hot-formula-parser",
"version": "1.0.17",
"version": "1.0.18",
"description": "Formula parser",
"main": "dist/formula-parser.js",
"scripts": {
Expand Down
26 changes: 22 additions & 4 deletions src/grammar-parser/grammar-parser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,35 @@ cell
: ABSOLUTE_CELL {
$$ = yy.cellValue($1);
}
| RELATIVE_CELL {
$$ = yy.cellValue($1);
}
| MIXED_CELL {
$$ = yy.cellValue($1);
}
| ABSOLUTE_CELL ':' ABSOLUTE_CELL {
$$ = yy.rangeValue($1, $3);
}
| RELATIVE_CELL {
$$ = yy.cellValue($1);
| ABSOLUTE_CELL ':' RELATIVE_CELL {
$$ = yy.rangeValue($1, $3);
}
| ABSOLUTE_CELL ':' MIXED_CELL {
$$ = yy.rangeValue($1, $3);
}
| RELATIVE_CELL ':' ABSOLUTE_CELL {
$$ = yy.rangeValue($1, $3);
}
| RELATIVE_CELL ':' RELATIVE_CELL {
$$ = yy.rangeValue($1, $3);
}
| MIXED_CELL {
$$ = yy.cellValue($1);
| RELATIVE_CELL ':' MIXED_CELL {
$$ = yy.rangeValue($1, $3);
}
| MIXED_CELL ':' ABSOLUTE_CELL {
$$ = yy.rangeValue($1, $3);
}
| MIXED_CELL ':' RELATIVE_CELL {
$$ = yy.rangeValue($1, $3);
}
| MIXED_CELL ':' MIXED_CELL {
$$ = yy.rangeValue($1, $3);
Expand Down
36 changes: 18 additions & 18 deletions src/grammar-parser/grammar-parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions test/integration/parsing/coordinates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {Parser} from '../../../src/parser';

describe('.parse() coordinates', () => {
let parser;

beforeEach(() => {
parser = new Parser();

parser.on('callCellValue', function(cell, done) {
done(55);
});
parser.on('callRangeValue', function(startCellCoord, endCellCoord, done) {
done([[3, 6, 10]]);
});
});
afterEach(() => {
parser = null;
});

it('should parse relative cell', () => {
expect(parser.parse('A1')).to.deep.equal({error: null, result: 55});
});

it('should parse absolute cell', () => {
expect(parser.parse('$A$1')).to.deep.equal({error: null, result: 55});
});

it('should parse mixed cell', () => {
expect(parser.parse('$A1')).to.deep.equal({error: null, result: 55});
expect(parser.parse('A$1')).to.deep.equal({error: null, result: 55});
});

it('should parse relative cells range', () => {
expect(parser.parse('A1:B2')).to.deep.equal({error: null, result: [[3, 6, 10]]});
});

it('should parse absolute cells range', () => {
expect(parser.parse('$A$1:$B$2')).to.deep.equal({error: null, result: [[3, 6, 10]]});
});

it('should parse mixed cells range', () => {
expect(parser.parse('$A$1:B2')).to.deep.equal({error: null, result: [[3, 6, 10]]});
expect(parser.parse('A1:$B$2')).to.deep.equal({error: null, result: [[3, 6, 10]]});
expect(parser.parse('$A$1:B$2')).to.deep.equal({error: null, result: [[3, 6, 10]]});
expect(parser.parse('A1:$B2')).to.deep.equal({error: null, result: [[3, 6, 10]]});
expect(parser.parse('A$1:B2')).to.deep.equal({error: null, result: [[3, 6, 10]]});
expect(parser.parse('A$1:$B$2')).to.deep.equal({error: null, result: [[3, 6, 10]]});
expect(parser.parse('A$1:$B2')).to.deep.equal({error: null, result: [[3, 6, 10]]});
});
});
4 changes: 2 additions & 2 deletions test/integration/parsing/variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ describe('.parse() variable', () => {
parser = null;
});

it('defaults', () => {
it('should evaluate defaults variables', () => {
expect(parser.parse('TRUE')).to.deep.equal({error: null, result: true});
expect(parser.parse('FALSE')).to.deep.equal({error: null, result: false});
expect(parser.parse('NULL')).to.deep.equal({error: null, result: null});
});

it('custom', () => {
it('should evaluate custom variables', () => {
expect(parser.parse('foo')).to.deep.equal({error: '#NAME?', result: null});

parser.setVariable('foo', 'bar');
Expand Down
38 changes: 38 additions & 0 deletions test/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,42 @@ describe('Parser', () => {
sinon.assert.calledWithMatch(obj.cb, startCell, endCell);
});
});

describe('._throwError()', () => {
it('should throw general error', () => {
expect(() => parser._throwError('#ERROR!')).to.throw('ERROR');
});

it('should throw dividing by 0 error', () => {
expect(() => parser._throwError('#DIV/0!')).to.throw('DIV/0');
});

it('should throw name error', () => {
expect(() => parser._throwError('#NAME?')).to.throw('NAME');
});

it('should throw not available error', () => {
expect(() => parser._throwError('#N/A')).to.throw('N/A');
});

it('should throw null error', () => {
expect(() => parser._throwError('#NULL!')).to.throw('NULL');
});

it('should throw num error', () => {
expect(() => parser._throwError('#NUM!')).to.throw('NUM');
});

it('should throw ref error', () => {
expect(() => parser._throwError('#REF!')).to.throw('REF');
});

it('should throw value error', () => {
expect(() => parser._throwError('#VALUE!')).to.throw('VALUE');
});

it('should return value if not matched to any of defined error', () => {
expect(parser._throwError('VALUE foo')).to.be.eq('VALUE foo');
});
});
});

0 comments on commit 2cce3ab

Please sign in to comment.