Skip to content

Commit

Permalink
fix #3092: a typo in an error message when converting a string into a…
Browse files Browse the repository at this point in the history
… number
  • Loading branch information
josdejong committed Nov 9, 2023
1 parent 8679c07 commit 3d84b5b
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/expressions/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```


Expand Down
4 changes: 2 additions & 2 deletions src/type/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/unit-tests/expression/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
})
})

Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/function/statistics/max.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/function/statistics/min.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/function/statistics/prod.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/function/statistics/sum.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
8 changes: 4 additions & 4 deletions test/unit-tests/type/numeric.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 3d84b5b

Please sign in to comment.