From 3d84b5b594639980dc297e8e15c07a5527599dbe Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Thu, 9 Nov 2023 09:25:43 +0100 Subject: [PATCH] fix #3092: a typo in an error message when converting a string into a number --- HISTORY.md | 1 + docs/expressions/syntax.md | 2 +- src/type/number.js | 4 ++-- test/unit-tests/expression/parse.test.js | 6 +++--- test/unit-tests/function/statistics/max.test.js | 2 +- test/unit-tests/function/statistics/min.test.js | 2 +- test/unit-tests/function/statistics/prod.test.js | 2 +- test/unit-tests/function/statistics/sum.test.js | 2 +- test/unit-tests/type/numeric.test.js | 8 ++++---- 9 files changed, 15 insertions(+), 14 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 864a0b55bd..f64cd86a71 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,6 +5,7 @@ - Fix #3087: extend function `mod` with support for negative divisors in when using `BigNumber` or `Fraction`. +- Fix #3092: a typo in an error message when converting a string into a number. # 2023-10-26, 12.0.0 diff --git a/docs/expressions/syntax.md b/docs/expressions/syntax.md index 6b4db1be20..8e8681c823 100644 --- a/docs/expressions/syntax.md +++ b/docs/expressions/syntax.md @@ -475,7 +475,7 @@ const parser = math.parser() parser.evaluate('a = 2 + 3i') // Complex, 2 + 3i parser.evaluate('b = a - 3i') // Complex, 2 + 0i parser.evaluate('number(b)') // Number, 2 -parser.evaluate('number(a)') // Error: 2 + i is no valid number +parser.evaluate('number(a)') // Error: unexpected type of argument ``` diff --git a/src/type/number.js b/src/type/number.js index b1f2883e76..cf21703c68 100644 --- a/src/type/number.js +++ b/src/type/number.js @@ -35,7 +35,7 @@ function makeNumberFromNonDecimalParts (parts) { } const result = n + f if (isNaN(result)) { - throw new SyntaxError('String "' + parts.input + '" is no valid number') + throw new SyntaxError('String "' + parts.input + '" is not a valid number') } return result } @@ -91,7 +91,7 @@ export const createNumber = /* #__PURE__ */ factory(name, dependencies, ({ typed } let num = Number(x) if (isNaN(num)) { - throw new SyntaxError('String "' + x + '" is no valid number') + throw new SyntaxError('String "' + x + '" is not a valid number') } if (wordSizeSuffixMatch) { // x is a signed bin, oct, or hex literal diff --git a/test/unit-tests/expression/parse.test.js b/test/unit-tests/expression/parse.test.js index 9af98d4a44..e7d919b828 100644 --- a/test/unit-tests/expression/parse.test.js +++ b/test/unit-tests/expression/parse.test.js @@ -308,9 +308,9 @@ describe('parse', function () { assert.throws(function () { parseAndEval('0x12u') }) assert.throws(function () { parseAndEval('0x12i-8') }) - assert.throws(function () { parseAndEval('0b123.45') }, /SyntaxError: String "0b123\.45" is no valid number/) - assert.throws(function () { parseAndEval('0o89.89') }, /SyntaxError: String "0o89\.89" is no valid number/) - assert.throws(function () { parseAndEval('0xghji.xyz') }, /SyntaxError: String "0x" is no valid number/) + assert.throws(function () { parseAndEval('0b123.45') }, /SyntaxError: String "0b123\.45" is not a valid number/) + assert.throws(function () { parseAndEval('0o89.89') }, /SyntaxError: String "0o89\.89" is not a valid number/) + assert.throws(function () { parseAndEval('0xghji.xyz') }, /SyntaxError: String "0x" is not a valid number/) }) }) diff --git a/test/unit-tests/function/statistics/max.test.js b/test/unit-tests/function/statistics/max.test.js index bd035cacda..fcb6016bbb 100644 --- a/test/unit-tests/function/statistics/max.test.js +++ b/test/unit-tests/function/statistics/max.test.js @@ -100,7 +100,7 @@ describe('max', function () { assert.throws(function () { max([2, null, 4]) }, /TypeError: Cannot calculate max, unexpected type of argument/) assert.throws(function () { max([[2, 5], [4, null], [1, 7]], 0) }, /TypeError: Cannot calculate max, unexpected type of argument/) assert.throws(function () { max('a', 'b') }, /Error: Cannot convert "b" to a number/) - assert.throws(function () { max('a') }, /SyntaxError: String "a" is no valid number/) + assert.throws(function () { max('a') }, /SyntaxError: String "a" is not a valid number/) }) it('should return undefined if called with an empty array', function () { diff --git a/test/unit-tests/function/statistics/min.test.js b/test/unit-tests/function/statistics/min.test.js index 30fe610572..8e690eda50 100644 --- a/test/unit-tests/function/statistics/min.test.js +++ b/test/unit-tests/function/statistics/min.test.js @@ -113,7 +113,7 @@ describe('min', function () { assert.throws(function () { min([2, null, 4]) }, /TypeError: Cannot calculate min, unexpected type of argument/) assert.throws(function () { min([[2, 5], [4, null], [1, 7]], 0) }, /TypeError: Cannot calculate min, unexpected type of argument/) assert.throws(function () { min('a', 'b') }, /Error: Cannot convert "b" to a number/) - assert.throws(function () { min('a') }, /SyntaxError: String "a" is no valid number/) + assert.throws(function () { min('a') }, /SyntaxError: String "a" is not a valid number/) }) it('should LaTeX min', function () { diff --git a/test/unit-tests/function/statistics/prod.test.js b/test/unit-tests/function/statistics/prod.test.js index d1d5553bb5..d280724188 100644 --- a/test/unit-tests/function/statistics/prod.test.js +++ b/test/unit-tests/function/statistics/prod.test.js @@ -81,7 +81,7 @@ describe('prod', function () { assert.throws(function () { prod([[2, new Date(), 4]]) }, /TypeError: Cannot calculate prod, unexpected type of argument/) assert.throws(function () { prod([2, null, 4]) }, /TypeError: Cannot calculate prod, unexpected type of argument/) assert.throws(function () { prod('a', 'b') }, /Error: Cannot convert "a" to a number/) - assert.throws(function () { prod('a') }, /SyntaxError: String "a" is no valid number/) + assert.throws(function () { prod('a') }, /SyntaxError: String "a" is not a valid number/) }) it('should LaTeX prod', function () { diff --git a/test/unit-tests/function/statistics/sum.test.js b/test/unit-tests/function/statistics/sum.test.js index 79f0f5601f..6c785c65c1 100644 --- a/test/unit-tests/function/statistics/sum.test.js +++ b/test/unit-tests/function/statistics/sum.test.js @@ -117,7 +117,7 @@ describe('sum', function () { assert.throws(function () { sum(2, 3, null) }, /Cannot calculate sum, unexpected type of argument/) assert.throws(function () { sum([2, 3, null]) }, /Cannot calculate sum, unexpected type of argument/) assert.throws(function () { sum('a', 'b') }, /Error: Cannot convert "a" to a number/) - assert.throws(function () { sum('a') }, /SyntaxError: String "a" is no valid number/) + assert.throws(function () { sum('a') }, /SyntaxError: String "a" is not a valid number/) }) it('should LaTeX sum', function () { diff --git a/test/unit-tests/type/numeric.test.js b/test/unit-tests/type/numeric.test.js index 6994d08b09..1c244d083d 100644 --- a/test/unit-tests/type/numeric.test.js +++ b/test/unit-tests/type/numeric.test.js @@ -17,10 +17,10 @@ describe('numeric', function () { assert.throws(() => { numeric(null, 'number') }, /Cannot convert/) assert.throws(() => { numeric([], 'number') }, /Cannot convert/) assert.throws(() => { numeric({}, 'number') }, /Cannot convert/) - assert.throws(() => { numeric('foo', 'number') }, /is no valid number/) - assert.throws(() => { numeric('2.3.4', 'number') }, /is no valid number/) - assert.throws(() => { numeric('234a', 'number') }, /is no valid number/) - assert.throws(() => { numeric('234 1', 'number') }, /is no valid number/) + assert.throws(() => { numeric('foo', 'number') }, /is not a valid number/) + assert.throws(() => { numeric('2.3.4', 'number') }, /is not a valid number/) + assert.throws(() => { numeric('234a', 'number') }, /is not a valid number/) + assert.throws(() => { numeric('234 1', 'number') }, /is not a valid number/) }) it('should return Infinity', function () {