mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
Added tests checking that the expression parser throws one-based IndexErrors.
This commit is contained in:
parent
fdc7c8db03
commit
49e7e00a65
@ -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.
|
||||
|
||||
|
||||
|
||||
@ -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 () {
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user