-
-
Notifications
You must be signed in to change notification settings - Fork 891
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1219 from issacgerges/strict-numbers
Add option for strictNumbers. Resolves #1128.
- Loading branch information
Showing
6 changed files
with
71 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
|
||
var Ajv = require('../ajv'); | ||
|
||
describe('structNumbers option', function() { | ||
var ajv; | ||
describe('strictNumbers default', testWithoutStrictNumbers(new Ajv())); | ||
describe('strictNumbers = false', testWithoutStrictNumbers(new Ajv({strictNumbers: false}))); | ||
describe('strictNumbers = true', function() { | ||
beforeEach(function () { | ||
ajv = new Ajv({strictNumbers: true}); | ||
}); | ||
|
||
it('should fail validation for NaN/Infinity as type number', function() { | ||
var validate = ajv.compile({type: 'number'}); | ||
validate("1.1").should.equal(false); | ||
validate(1.1).should.equal(true); | ||
validate(1).should.equal(true); | ||
validate(NaN).should.equal(false); | ||
validate(Infinity).should.equal(false); | ||
}); | ||
|
||
it('should fail validation for NaN as type integer', function() { | ||
var validate = ajv.compile({type: 'integer'}); | ||
validate("1.1").should.equal(false); | ||
validate(1.1).should.equal(false); | ||
validate(1).should.equal(true); | ||
validate(NaN).should.equal(false); | ||
validate(Infinity).should.equal(false); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
function testWithoutStrictNumbers(_ajv) { | ||
return function () { | ||
it('should NOT fail validation for NaN/Infinity as type number', function() { | ||
var validate = _ajv.compile({type: 'number'}); | ||
validate("1.1").should.equal(false); | ||
validate(1.1).should.equal(true); | ||
validate(1).should.equal(true); | ||
validate(NaN).should.equal(true); | ||
validate(Infinity).should.equal(true); | ||
}); | ||
|
||
it('should NOT fail validation for NaN/Infinity as type integer', function() { | ||
var validate = _ajv.compile({type: 'integer'}); | ||
validate("1.1").should.equal(false); | ||
validate(1.1).should.equal(false); | ||
validate(1).should.equal(true); | ||
validate(NaN).should.equal(false); | ||
validate(Infinity).should.equal(true); | ||
}); | ||
}; | ||
} |