Added tests checking that the expression parser throws one-based IndexErrors.

This commit is contained in:
josdejong 2014-04-12 19:34:38 +02:00
parent fdc7c8db03
commit 49e7e00a65
2 changed files with 14 additions and 0 deletions

View File

@ -17,6 +17,8 @@ https://github.com/josdejong/mathjs
- Changed configuration option `decimals` to `precision` (applies to BigNumbers
only).
- Fixed support for element-wise comparisons between a string and a matrix.
- Fixed: expression parser now trows IndexErrors with one-based indices instead
of zero-based.
- Minor bug fixes.

View File

@ -906,6 +906,18 @@ describe('parse', function() {
});
describe('errors', function () {
it('should return IndexErrors with one based indices', function () {
// functions throw a zero-based error
assert.throws(function () {math.subset([1,2,3], math.index(4))}, /Index out of range \(4 > 2\)/);
assert.throws(function () {math.subset([1,2,3], math.index(-2))}, /Index out of range \(-2 < 0\)/);
// evaluation via parser throws one-based error
assert.throws(function () {math.eval('[1,2,3][4]')}, /Index out of range \(4 > 3\)/);
assert.throws(function () {math.eval('[1,2,3][-2]')}, /Index out of range \(-2 < 1\)/);
})
});
describe('node tree', function () {