NaN validation, closes #182
parent
dc551094a8
commit
81f442b325
|
@ -45,7 +45,8 @@ function checkDataType(dataType, data, negate) {
|
|||
'typeof ' + data + EQUAL + '"object"' + AND +
|
||||
NOT + 'Array.isArray(' + data + '))';
|
||||
case 'integer': return '(typeof ' + data + EQUAL + '"number"' + AND +
|
||||
NOT + '(' + data + ' % 1))';
|
||||
NOT + '(' + data + ' % 1)' +
|
||||
AND + data + EQUAL + data + ')';
|
||||
default: return 'typeof ' + data + EQUAL + '"' + dataType + '"';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,8 @@
|
|||
} else if({{# def.$dataNotType:'number' }}
|
||||
((exclusive{{=$lvl}} = {{=$schemaValueExcl}} === true)
|
||||
? {{=$data}} {{=$notOp}}= {{=$schemaValue}}
|
||||
: {{=$data}} {{=$notOp}} {{=$schemaValue}})) {
|
||||
: {{=$data}} {{=$notOp}} {{=$schemaValue}})
|
||||
|| {{=$data}} !== {{=$data}}) {
|
||||
var op{{=$lvl}} = exclusive{{=$lvl}} ? '{{=$op}}' : '{{=$op}}=';
|
||||
{{??}}
|
||||
{{
|
||||
|
@ -39,7 +40,9 @@
|
|||
var $opExpr = '\'' + $opStr + '\''; /*used in error*/
|
||||
}}
|
||||
|
||||
if ({{# def.$dataNotType:'number' }} {{=$data}} {{=$notOp}}{{?$exclusive}}={{?}} {{=$schemaValue}}) {
|
||||
if ({{# def.$dataNotType:'number' }}
|
||||
{{=$data}} {{=$notOp}}{{?$exclusive}}={{?}} {{=$schemaValue}}
|
||||
|| {{=$data}} !== {{=$data}}) {
|
||||
{{?}}
|
||||
{{ var $errorKeyword = $keyword; }}
|
||||
{{# def.error:'_limit' }}
|
||||
|
|
|
@ -7,7 +7,7 @@ var Ajv = require('./ajv')
|
|||
describe('issue #8: schema with shared references', function() {
|
||||
it('should be supported by addSchema', spec('addSchema'));
|
||||
|
||||
it('should be supported by compile', spec('addSchema'));
|
||||
it('should be supported by compile', spec('compile'));
|
||||
|
||||
function spec(method) {
|
||||
return function() {
|
||||
|
@ -82,3 +82,30 @@ describe('issue #50: references with "definitions"', function () {
|
|||
};
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
describe('issue #182, NaN validation', function() {
|
||||
var ajv;
|
||||
|
||||
before(function(){
|
||||
ajv = Ajv();
|
||||
});
|
||||
|
||||
it('should not pass minimum/maximum validation', function() {
|
||||
testNaN({ minimum: 1 }, false);
|
||||
testNaN({ maximum: 1 }, false);
|
||||
});
|
||||
|
||||
it('should pass type: number validation', function() {
|
||||
testNaN({ type: 'number' }, true);
|
||||
});
|
||||
|
||||
it('should not pass type: integer validation', function() {
|
||||
testNaN({ type: 'integer' }, false);
|
||||
});
|
||||
|
||||
function testNaN(schema, NaNisValid) {
|
||||
var validate = Ajv().compile(schema);
|
||||
validate(NaN) .should.equal(NaNisValid);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue