Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Fix #583
Browse files Browse the repository at this point in the history
  • Loading branch information
jiggzson committed Feb 15, 2021
1 parent eba066c commit c7c7229
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
17 changes: 13 additions & 4 deletions nerdamer.core.js
Expand Up @@ -1220,10 +1220,12 @@ var nerdamer = (function (imports) {
var ValueLimitExceededError = customError('ValueLimitExceededError');
// Is throw if the value is an incorrect LH or RH value
var NerdamerValueError = customError('NerdamerValueError');
// Is throw if the value is an incorrect LH or RH value
// Is thrown if the value is an incorrect LH or RH value
var SolveError = customError('SolveError');
// Is thrown for an infinite loop
var InfiniteLoopError = customError('InfiniteLoopError');
// Is thrown if an operator is found when there shouldn't be one
var UnexpectedTokenError = customError('UnexpectedTokenError');

var exceptions = {
DivisionByZero: DivisionByZero,
Expand All @@ -1239,7 +1241,8 @@ var nerdamer = (function (imports) {
ValueLimitExceededError: ValueLimitExceededError,
NerdamerValueError: NerdamerValueError,
SolveError: SolveError,
InfiniteLoopError: InfiniteLoopError
InfiniteLoopError: InfiniteLoopError,
UnexpectedTokenError: UnexpectedTokenError
};
//Big ==========================================================================
var Big = {
Expand Down Expand Up @@ -6764,8 +6767,14 @@ var nerdamer = (function (imports) {
}
}
}

var retval = Q[0];

return Q[0];
if(['undefined', 'string', 'number'].indexOf(typeof retval) !== -1) {
throw new UnexpectedTokenError('Unexpected token!');
}

return retval;
}
catch(error) {
throw new ParseError(error.message+': '+e.column);
Expand Down Expand Up @@ -12100,4 +12109,4 @@ var nerdamer = (function (imports) {

if ((typeof module) !== 'undefined') {
module.exports = nerdamer;
};
};
24 changes: 9 additions & 15 deletions spec/core.spec.js
Expand Up @@ -7,7 +7,8 @@ var nerdamer = require('../nerdamer.core.js');
var utils = require('./support/utils');
var _ = utils.toFixed;
var run = utils.run;
var round = nerdamer.getCore().Utils.round;
var core = nerdamer.getCore();
var round = core.Utils.round;


//, x=2.1, y=3.3, z=1, a=7.42
Expand Down Expand Up @@ -2547,20 +2548,13 @@ describe('trigonometric functions', function () {
}
});
it('should throw for malformed expression', function () {
// given
var testCases = [
'5+'
];

for (var i = 0; i < testCases.length; ++i) {
var threwError = false;
try {
nerdamer(testCases[i]);
} catch (e) {
threwError = true;
}
expect(threwError).toBe(true);
}
expect(function(){nerdamer('+')}).toThrowError();
expect(function(){nerdamer('(+)')}).toThrowError();
expect(function(){nerdamer('cos(')}).toThrowError();
expect(function(){nerdamer('(x+1))')}).toThrowError();
expect(function(){nerdamer('/2')}).toThrowError();
expect(function(){nerdamer('()')}).toThrowError();
expect(function(){nerdamer('5+')}).toThrowError();
});
it('should calculate correctly with variables', function () {
// given
Expand Down

0 comments on commit c7c7229

Please sign in to comment.