Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #27 #28

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ validators.register(xsd.boolean, value => (
value === 'false'
))

const decimalSeg = `${signSeg}\\d+(\\.\\d+)?`
const decimalSeg = `${signSeg}(\\d+\\.?\\d*|\\.\\d+)`

const decimalPattern = new RegExp(`^${signSeg}${decimalSeg}$`)
validators.register(xsd.decimal, value => decimalPattern.test(value))
Expand Down
16 changes: 13 additions & 3 deletions test/test-validate-term.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,22 @@ describe('#validateTerm', () => {
['false', xsd.boolean, true],
['test', xsd.boolean, false],

['0.4', xsd.decimal, true],
['244.14', xsd.decimal, true],
['0', xsd.decimal, true, 'zero'],
['0.4', xsd.decimal, true, 'decimal point'],
['244.14', xsd.decimal, true, 'with decimal digits'],
['244', xsd.decimal, true, 'without decimal digits'],
['-24.4', xsd.decimal, true, 'minus sign'],
['+24.4', xsd.decimal, true, 'plus sign'],
['test', xsd.decimal, false],
['test', xsd.decimal, false, 'non-numeric characters'],
['NaN', xsd.decimal, false, 'NaN'],
['.4', xsd.decimal, true, 'leading decimal point'],
['4.', xsd.decimal, true, 'trailing decimal point'],
['003.500', xsd.decimal, true, 'leading zeros'],
['-003.500', xsd.decimal, true, 'negative number with leading zeros'],
['+003.500', xsd.decimal, true, 'positive number with leading zeros'],
['3.0000', xsd.decimal, true, 'trailing zeros'],
['3,5', xsd.decimal, false, 'comma instead of decimal point'],
['24.4.4', xsd.decimal, false, 'two decimal points'],

['-1E4', xsd.float, true],
['1267.43233E12', xsd.float, true],
Expand Down
Loading