support $data ref in formatMaximum/Minimum and exclusiveFormatMaximum/Minimum, #81

master
Evgeny Poberezkin 2015-12-24 17:43:48 +00:00
parent 94f0d6e784
commit 10c6685027
10 changed files with 1356 additions and 26 deletions

View File

@ -133,27 +133,31 @@ function regex(str) {
function compareDate(d1, d2) {
if (!(d1 && d2)) return;
if (d1 > d2) return 1;
if (d1 < d2) return -1;
return 0;
if (d1 === d2) return 0;
}
function compareTime(t1, t2) {
if (!(t1 && t2)) return;
t1 = t1.match(TIME);
t2 = t2.match(TIME);
if (!(t1 && t2)) return 0;
if (!(t1 && t2)) return;
t1 = t1[1] + t1[2] + t1[3] + (t1[4]||'');
t2 = t2[1] + t2[2] + t2[3] + (t2[4]||'');
if (t1 > t2) return 1;
if (t1 < t2) return -1;
return 0;
if (t1 === t2) return 0;
}
function compareDateTime(dt1, dt2) {
if (!(dt1 && dt2)) return;
dt1 = dt1.split(DATE_TIME_SEPARATOR);
dt2 = dt2.split(DATE_TIME_SEPARATOR);
return compareDate(dt1[0], dt2[0])
|| compareTime(dt1[1], dt2[1]);
var res = compareDate(dt1[0], dt2[0]);
if (res === undefined) return;
return res || compareTime(dt1[1], dt2[1]);
}

View File

@ -111,6 +111,11 @@
#}}
{{## def.$dataType:_type:
{{?$isData}} typeof {{=$schemaValue}} == _type && {{?}}
#}}
{{## def.$dataNotType:_type:
{{?$isData}} typeof {{=$schemaValue}} != _type || {{?}}
#}}

View File

@ -94,7 +94,9 @@
custom: "'should pass \"{{=$rule.keyword}}\" keyword validation'",
patternGroups: "'should NOT have {{=$moreOrLess}} than {{=$limit}} properties matching pattern \"{{=it.util.escapeQuotes($pgProperty)}}\"'",
switch: "'should pass \"switch\" keyword validation'",
constant: "'should be equal to constant'"
constant: "'should be equal to constant'",
_formatLimit: "'should be {{=$opStr}} \"{{#def.concatSchemaEQ}}\"'",
_exclusiveFormatLimit: "'{{=$exclusiveKeyword}} should be boolean'"
} #}}
@ -124,7 +126,9 @@
custom: "validate.schema{{=$schemaPath}}",
patternGroups: "validate.schema{{=$schemaPath}}",
switch: "validate.schema{{=$schemaPath}}",
constant: "validate.schema{{=$schemaPath}}"
constant: "validate.schema{{=$schemaPath}}",
_formatLimit: "{{#def.schemaRefOrQS}}",
_exclusiveFormatLimit: "validate.schema{{=$schemaPath}}"
} #}}
@ -153,5 +157,7 @@
custom: "{ keyword: '{{=$rule.keyword}}' }",
patternGroups: "{ reason: '{{=$reason}}', limit: {{=$limit}}, pattern: '{{=it.util.escapeQuotes($pgProperty)}}' }",
switch: "{ caseIndex: {{=$caseIndex}} }",
constant: "{}"
constant: "{}",
_formatLimit: "{ limit: {{#def.schemaValueQS}} }",
_exclusiveFormatLimit: "{}"
} #}}

113
lib/dot/v5/_formatLimit.jst Normal file
View File

@ -0,0 +1,113 @@
{{# def.definitions }}
{{# def.errors }}
{{# def.setupKeyword }}
var {{=$valid}} = undefined;
{{## def.skipFormatLimit:
{{=$valid}} = true;
{{ return out; }}
#}}
{{## def.compareFormat:
{{? $isData }}
if (typeof {{=$schemaValue}} != 'string') {{=$valid}} = false;
else {
{{ $closingBraces += '}'; }}
{{?}}
{{? $isDataFormat }}
if (!{{=$compare}}) {{=$valid}} = true;
else {
{{ $closingBraces += '}'; }}
{{?}}
var {{=$result}} = {{=$compare}}({{=$data}}, {{# def.schemaValueQS }});
if ({{=$result}} === undefined) {{=$valid}} = false;
#}}
{{? it.opts.format === false }}{{# def.skipFormatLimit }}{{?}}
{{
var $schemaFormat = it.schema.format
, $isDataFormat = it.opts.v5 && $schemaFormat.$data
, $closingBraces = '';
}}
{{? $isDataFormat }}
{{
var $schemaValueFormat = it.util.getData($schemaFormat.$data, $dataLvl, it.dataPathArr)
, $format = 'format' + $lvl
, $compare = 'compare' + $lvl;
}}
var {{=$format}} = formats[{{=$schemaValueFormat}}]
, {{=$compare}} = {{=$format}} && {{=$format}}.compare;
{{??}}
{{ var $format = it.formats[$schemaFormat]; }}
{{? !($format && $format.compare) }}
{{# def.skipFormatLimit }}
{{?}}
{{ var $compare = 'formats' + it.util.getProperty($schemaFormat) + '.compare'; }}
{{?}}
{{
var $isMax = $keyword == 'formatMaximum'
, $exclusiveKeyword = 'exclusiveFormat' + ($isMax ? 'Maximum' : 'Minimum')
, $schemaExcl = it.schema[$exclusiveKeyword]
, $isDataExcl = it.opts.v5 && $schemaExcl && $schemaExcl.$data
, $op = $isMax ? '<' : '>'
, $result = 'result' + $lvl;
}}
{{# def.$data }}
{{? $isDataExcl }}
{{
var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr)
, $exclusive = 'exclusive' + $lvl
, $opExpr = 'op' + $lvl
, $opStr = '\' + ' + $opExpr + ' + \'';
}}
if (typeof {{=$schemaValueExcl}} != 'boolean' && typeof {{=$schemaValueExcl}} != 'undefined') {
{{=$valid}} = false;
{{ var $errorKeyword = $exclusiveKeyword; }}
{{# def.error:'_exclusiveFormatLimit' }}
}
{{# def.elseIfValid }}
{{# def.compareFormat }}
var exclusive{{=$lvl}} = {{=$schemaValueExcl}} === true;
if ({{=$valid}} === undefined) {
{{=$valid}} = exclusive{{=$lvl}}
? {{=$result}} {{=$op}} 0
: {{=$result}} {{=$op}}= 0;
}
if (!{{=$valid}}) var op{{=$lvl}} = exclusive{{=$lvl}} ? '{{=$op}}' : '{{=$op}}=';
{{??}}
{{
var $exclusive = $schemaExcl === true
, $opStr = $op; /*used in error*/
if (!$exclusive) $opStr += '=';
var $opExpr = '\'' + $opStr + '\''; /*used in error*/
}}
{{# def.compareFormat }}
if ({{=$valid}} === undefined)
{{=$valid}} = {{=$result}} {{=$op}}{{?!$exclusive}}={{?}} 0;
{{?}}
{{= $closingBraces }}
if (!{{=$valid}}) {
{{ var $errorKeyword = $keyword; }}
{{# def.error:'_formatLimit' }}
}

View File

@ -15,10 +15,13 @@ function enableV5(ajv) {
}
ajv.addKeyword('constant', { inline: require('./dotjs/constant'), statements: true, errors: 'full' });
ajv.addKeyword('contains', { macro: containsMacro });
ajv.addKeyword('formatMaximum', { type: 'string', inline: formatLimit, errors: false });
ajv.addKeyword('formatMinimum', { type: 'string', inline: formatLimit, errors: false });
var formatLimit = require('./dotjs/_formatLimit');
ajv.addKeyword('formatMaximum', { type: 'string', inline: formatLimit, statements: true, errors: 'full' });
ajv.addKeyword('formatMinimum', { type: 'string', inline: formatLimit, statements: true, errors: 'full' });
ajv.addKeyword('exclusiveFormatMaximum');
ajv.addKeyword('exclusiveFormatMinimum');
ajv.addKeyword('patternGroups'); // implemented in properties.jst
ajv.addKeyword('switch', { inline: require('./dotjs/switch'), statements: true, errors: 'full' });
}
@ -31,19 +34,3 @@ function containsMacro(schema) {
}
};
}
function formatLimit(it, keyword, schema, parentSchema) {
var isMax = keyword == 'formatMaximum'
, operation = isMax ? '<' : '>'
, exclusiveLimit = 'exclusiveFormat' + (isMax ? 'Maximum' : 'Minimum')
, format = parentSchema.format
, compare = it.formats[format].compare;
if (!compare) return 'true';
var exclusive = parentSchema[exclusiveLimit]
, data = 'data' + (it.dataLevel || '')
, op = operation;
if (!exclusive) op += '=';
return 'formats' + it.util.getProperty(format) + '.compare('
+ data + ', ' + it.util.toQuotedString(schema)
+ ') ' + op + ' 0';
}

View File

@ -399,6 +399,17 @@ describe('Custom keywords', function () {
});
});
it('should define "inline" keyword without errors', function() {
var inlineRangeTemplate = customRules.range;
testRangeKeyword({
type: 'number',
inline: inlineRangeTemplate,
statements: true,
errors: false
});
});
it('should allow defining optional errors', function() {
var inlineRangeTemplate = customRules.rangeWithErrors;

View File

@ -178,6 +178,20 @@ describe('Ajv Options', function () {
ajv.validate(schema, invalideDateTime) .should.equal(false);
ajvFF.validate(schema, invalideDateTime) .should.equal(true);
});
it('should not validate formatMaximum/Minimum if option format == false', function() {
var ajv = Ajv({ v5: true, allErrors: true })
, ajvFF = Ajv({ v5: true, allErrors: true, format: false });
var schema = {
format: 'date',
formatMaximum: '2015-08-01'
};
var date = '2015-09-01';
ajv.validate(schema, date) .should.equal(false);
ajvFF.validate(schema, date) .should.equal(true);
});
});

View File

@ -0,0 +1,588 @@
[
{
"description": "formatMaximum in the property",
"schema": {
"properties": {
"finalDate": {
"format": "date",
"formatMaximum": { "$data": "1/beforeThan" }
},
"beforeThan": {}
}
},
"tests": [
{
"description": "after the maximum date is invalid",
"data": {
"finalDate": "2015-11-09",
"beforeThan": "2015-08-17"
},
"valid": false
},
{
"description": "boundary point is valid",
"data": {
"finalDate": "2015-08-17",
"beforeThan": "2015-08-17"
},
"valid": true
},
{
"description": "before the maximum date is valid",
"data": {
"finalDate": "2014-12-03",
"beforeThan": "2015-08-17"
},
"valid": true
},
{
"description": "ignores non-strings",
"data": {
"finalDate": 2015,
"beforeThan": "2015-08-17"
},
"valid": true
},
{
"description": "fails if value of formatMaximum is not string",
"data": {
"finalDate": "2014-12-03",
"beforeThan": 2015
},
"valid": false
}
]
},
{
"description": "formatMaximum in the property with exclusiveFormatMaximum",
"schema": {
"properties": {
"finalDate": {
"format": "date",
"formatMaximum": { "$data": "1/beforeThan" },
"exclusiveFormatMaximum": true
},
"beforeThan": {}
}
},
"tests": [
{
"description": "after the maximum date is still invalid",
"data": {
"finalDate": "2015-11-09",
"beforeThan": "2015-08-17"
},
"valid": false
},
{
"description": "boundary point is invalid",
"data": {
"finalDate": "2015-08-17",
"beforeThan": "2015-08-17"
},
"valid": false
},
{
"description": "before the maximum date is still valid",
"data": {
"finalDate": "2014-12-03",
"beforeThan": "2015-08-17"
},
"valid": true
}
]
},
{
"description": "formatMaximum with format in the property",
"schema": {
"properties": {
"when": {
"format": { "$data": "1/whenFormat" },
"formatMaximum": "2015-08-17"
},
"whenFormat": {}
}
},
"tests": [
{
"description": "after the maximum date is invalid",
"data": {
"when": "2015-11-09",
"whenFormat": "date"
},
"valid": false
},
{
"description": "boundary point is valid",
"data": {
"when": "2015-08-17",
"whenFormat": "date"
},
"valid": true
},
{
"description": "before the maximum date is valid",
"data": {
"when": "2014-12-03",
"whenFormat": "date"
},
"valid": true
},
{
"description": "ignores non-strings",
"data": {
"when": 2015,
"whenFormat": "date"
},
"valid": true
}
]
},
{
"description": "formatMaximum with format in the property and with exclusiveFormatMaximum",
"schema": {
"properties": {
"when": {
"format": { "$data": "1/whenFormat" },
"formatMaximum": "2015-08-17",
"exclusiveFormatMaximum": true
},
"whenFormat": {}
}
},
"tests": [
{
"description": "after the maximum date is still invalid",
"data": {
"when": "2015-11-09",
"whenFormat": "date"
},
"valid": false
},
{
"description": "boundary point is invalid",
"data": {
"when": "2015-08-17",
"whenFormat": "date"
},
"valid": false
},
{
"description": "before the maximum date is still valid",
"data": {
"when": "2014-12-03",
"whenFormat": "date"
},
"valid": true
}
]
},
{
"description": "formatMaximum and format in the properties",
"schema": {
"properties": {
"when": {
"format": { "$data": "1/whenFormat" },
"formatMaximum": { "$data": "1/beforeThan" }
},
"whenFormat": {},
"beforeThan": {}
}
},
"tests": [
{
"description": "after the maximum date is invalid",
"data": {
"when": "2015-11-09",
"whenFormat": "date",
"beforeThan": "2015-08-17"
},
"valid": false
},
{
"description": "boundary point is valid",
"data": {
"when": "2015-08-17",
"whenFormat": "date",
"beforeThan": "2015-08-17"
},
"valid": true
},
{
"description": "before the maximum date is valid",
"data": {
"when": "2014-12-03",
"whenFormat": "date",
"beforeThan": "2015-08-17"
},
"valid": true
}
]
},
{
"description": "formatMaximum and format in the properties with exclusiveFormatMaximum",
"schema": {
"properties": {
"when": {
"format": { "$data": "1/whenFormat" },
"formatMaximum": { "$data": "1/beforeThan" },
"exclusiveFormatMaximum": true
},
"whenFormat": {},
"beforeThan": {}
}
},
"tests": [
{
"description": "after the maximum date is still invalid",
"data": {
"when": "2015-11-09",
"whenFormat": "date",
"beforeThan": "2015-08-17"
},
"valid": false
},
{
"description": "boundary point is invalid",
"data": {
"when": "2015-08-17",
"whenFormat": "date",
"beforeThan": "2015-08-17"
},
"valid": false
},
{
"description": "before the maximum date is still valid",
"data": {
"when": "2014-12-03",
"whenFormat": "date",
"beforeThan": "2015-08-17"
},
"valid": true
}
]
},
{
"description": "exclusiveFormatMaximum in the property",
"schema": {
"properties": {
"finalDate": {
"format": "date",
"formatMaximum": "2015-08-17",
"exclusiveFormatMaximum": { "$data": "1/maxIsExclusive" }
},
"maxIsExclusive": {}
}
},
"tests": [
{
"description": "after the maximum date is invalid",
"data": {
"finalDate": "2015-11-09",
"maxIsExclusive": false
},
"valid": false
},
{
"description": "boundary point is valid",
"data": {
"finalDate": "2015-08-17"
},
"valid": true
},
{
"description": "before the maximum date is valid",
"data": {
"finalDate": "2014-12-03"
},
"valid": true
},
{
"description": "after the maximum date is still invalid",
"data": {
"finalDate": "2015-11-09",
"maxIsExclusive": true
},
"valid": false
},
{
"description": "boundary point is invalid",
"data": {
"finalDate": "2015-08-17",
"maxIsExclusive": true
},
"valid": false
},
{
"description": "before the maximum date is still valid",
"data": {
"finalDate": "2014-12-03",
"maxIsExclusive": true
},
"valid": true
},
{
"description": "fails if value of exclusiveFormatMaximum is not boolean",
"data": {
"finalDate": "2014-12-03",
"maxIsExclusive": "false"
},
"valid": false
}
]
},
{
"description": "formatMaximum and exclusiveFormatMaximum in the properties",
"schema": {
"properties": {
"finalDate": {
"format": "date",
"formatMaximum": { "$data": "1/beforeThan" },
"exclusiveFormatMaximum": { "$data": "1/maxIsExclusive" }
},
"beforeThan": {},
"maxIsExclusive": {}
}
},
"tests": [
{
"description": "after the maximum date is invalid",
"data": {
"finalDate": "2015-11-09",
"beforeThan": "2015-08-17",
"maxIsExclusive": false
},
"valid": false
},
{
"description": "boundary point is valid",
"data": {
"finalDate": "2015-08-17",
"beforeThan": "2015-08-17"
},
"valid": true
},
{
"description": "before the maximum date is valid",
"data": {
"finalDate": "2014-12-03",
"beforeThan": "2015-08-17"
},
"valid": true
},
{
"description": "after the maximum date is still invalid",
"data": {
"finalDate": "2015-11-09",
"beforeThan": "2015-08-17",
"maxIsExclusive": true
},
"valid": false
},
{
"description": "boundary point is invalid",
"data": {
"finalDate": "2015-08-17",
"beforeThan": "2015-08-17",
"maxIsExclusive": true
},
"valid": false
},
{
"description": "before the maximum date is still valid",
"data": {
"finalDate": "2014-12-03",
"beforeThan": "2015-08-17",
"maxIsExclusive": true
},
"valid": true
},
{
"description": "fails if value of exclusiveFormatMaximum is not boolean",
"data": {
"finalDate": "2014-12-03",
"beforeThan": "2015-08-17",
"maxIsExclusive": "false"
},
"valid": false
},
{
"description": "fails if value of formatMaximum is not string",
"data": {
"finalDate": "2014-12-03",
"beforeThan": 2015,
"maxIsExclusive": false
},
"valid": false
}
]
},
{
"description": "formatMaximum with format and exclusiveFormatMaximum in the properties",
"schema": {
"properties": {
"when": {
"format": { "$data": "1/whenFormat" },
"formatMaximum": "2015-08-17",
"exclusiveFormatMaximum": { "$data": "1/maxIsExclusive" }
},
"whenFormat": {},
"maxIsExclusive": {}
}
},
"tests": [
{
"description": "after the maximum date is invalid",
"data": {
"when": "2015-11-09",
"whenFormat": "date",
"maxIsExclusive": false
},
"valid": false
},
{
"description": "boundary point is valid",
"data": {
"when": "2015-08-17",
"whenFormat": "date"
},
"valid": true
},
{
"description": "before the maximum date is valid",
"data": {
"when": "2014-12-03",
"whenFormat": "date"
},
"valid": true
},
{
"description": "after the maximum date is still invalid",
"data": {
"when": "2015-11-09",
"whenFormat": "date",
"maxIsExclusive": true
},
"valid": false
},
{
"description": "boundary point is invalid",
"data": {
"when": "2015-08-17",
"whenFormat": "date",
"maxIsExclusive": true
},
"valid": false
},
{
"description": "before the maximum date is still valid",
"data": {
"when": "2014-12-03",
"whenFormat": "date",
"maxIsExclusive": true
},
"valid": true
},
{
"description": "fails if value of exclusiveFormatMaximum is not boolean",
"data": {
"when": "2014-12-03",
"whenFormat": "date",
"maxIsExclusive": "false"
},
"valid": false
}
]
},
{
"description": "formatMaximum, format and exclusiveFormatMaximum in the properties",
"schema": {
"properties": {
"when": {
"format": { "$data": "1/whenFormat" },
"formatMaximum": { "$data": "1/beforeThan" },
"exclusiveFormatMaximum": { "$data": "1/maxIsExclusive" }
},
"beforeThan": {},
"whenFormat": {},
"maxIsExclusive": {}
}
},
"tests": [
{
"description": "after the maximum date is invalid",
"data": {
"when": "2015-11-09",
"whenFormat": "date",
"beforeThan": "2015-08-17",
"maxIsExclusive": false
},
"valid": false
},
{
"description": "boundary point is valid",
"data": {
"when": "2015-08-17",
"whenFormat": "date",
"beforeThan": "2015-08-17"
},
"valid": true
},
{
"description": "before the maximum date is valid",
"data": {
"when": "2014-12-03",
"whenFormat": "date",
"beforeThan": "2015-08-17"
},
"valid": true
},
{
"description": "after the maximum date is still invalid",
"data": {
"when": "2015-11-09",
"whenFormat": "date",
"beforeThan": "2015-08-17",
"maxIsExclusive": true
},
"valid": false
},
{
"description": "boundary point is invalid",
"data": {
"when": "2015-08-17",
"whenFormat": "date",
"beforeThan": "2015-08-17",
"maxIsExclusive": true
},
"valid": false
},
{
"description": "before the maximum date is still valid",
"data": {
"when": "2014-12-03",
"whenFormat": "date",
"beforeThan": "2015-08-17",
"maxIsExclusive": true
},
"valid": true
},
{
"description": "fails if value of exclusiveFormatMaximum is not boolean",
"data": {
"when": "2014-12-03",
"whenFormat": "date",
"beforeThan": "2015-08-17",
"maxIsExclusive": "false"
},
"valid": false
}
]
}
]

View File

@ -0,0 +1,588 @@
[
{
"description": "formatMinimum in the property",
"schema": {
"properties": {
"finalDate": {
"format": "date",
"formatMinimum": { "$data": "1/laterThan" }
},
"laterThan": {}
}
},
"tests": [
{
"description": "before the minimum date is invalid",
"data": {
"finalDate": "2014-12-03",
"laterThan": "2015-08-17"
},
"valid": false
},
{
"description": "boundary point is valid",
"data": {
"finalDate": "2015-08-17",
"laterThan": "2015-08-17"
},
"valid": true
},
{
"description": "after the minimum date is valid",
"data": {
"finalDate": "2015-11-09",
"laterThan": "2015-08-17"
},
"valid": true
},
{
"description": "ignores non-strings",
"data": {
"finalDate": 2015,
"laterThan": "2015-08-17"
},
"valid": true
},
{
"description": "fails if value of formatMinimum is not string",
"data": {
"finalDate": "2016-11-09",
"laterThan": 2015
},
"valid": false
}
]
},
{
"description": "formatMinimum in the property with exclusiveFormatMinimum",
"schema": {
"properties": {
"finalDate": {
"format": "date",
"formatMinimum": { "$data": "1/laterThan" },
"exclusiveFormatMinimum": true
},
"laterThan": {}
}
},
"tests": [
{
"description": "before the minimum date is still invalid",
"data": {
"finalDate": "2014-12-03",
"laterThan": "2015-08-17"
},
"valid": false
},
{
"description": "boundary point is invalid",
"data": {
"finalDate": "2015-08-17",
"laterThan": "2015-08-17"
},
"valid": false
},
{
"description": "after the minimum date is still valid",
"data": {
"finalDate": "2015-11-09",
"laterThan": "2015-08-17"
},
"valid": true
}
]
},
{
"description": "formatMinimum with format in the property",
"schema": {
"properties": {
"when": {
"format": { "$data": "1/whenFormat" },
"formatMinimum": "2015-08-17"
},
"whenFormat": {}
}
},
"tests": [
{
"description": "before the minimum date is invalid",
"data": {
"when": "2014-12-03",
"whenFormat": "date"
},
"valid": false
},
{
"description": "boundary point is valid",
"data": {
"when": "2015-08-17",
"whenFormat": "date"
},
"valid": true
},
{
"description": "after the minimum date is valid",
"data": {
"when": "2015-11-09",
"whenFormat": "date"
},
"valid": true
},
{
"description": "ignores non-strings",
"data": {
"when": 2015,
"whenFormat": "date"
},
"valid": true
}
]
},
{
"description": "formatMinimum with format in the property and with exclusiveFormatMinimum",
"schema": {
"properties": {
"when": {
"format": { "$data": "1/whenFormat" },
"formatMinimum": "2015-08-17",
"exclusiveFormatMinimum": true
},
"whenFormat": {}
}
},
"tests": [
{
"description": "before the minimum date is still invalid",
"data": {
"when": "2014-12-03",
"whenFormat": "date"
},
"valid": false
},
{
"description": "boundary point is invalid",
"data": {
"when": "2015-08-17",
"whenFormat": "date"
},
"valid": false
},
{
"description": "after the minimum date is still valid",
"data": {
"when": "2015-11-09",
"whenFormat": "date"
},
"valid": true
}
]
},
{
"description": "formatMinimum and format in the properties",
"schema": {
"properties": {
"when": {
"format": { "$data": "1/whenFormat" },
"formatMinimum": { "$data": "1/laterThan" }
},
"whenFormat": {},
"laterThan": {}
}
},
"tests": [
{
"description": "before the minimum date is invalid",
"data": {
"when": "2014-12-03",
"whenFormat": "date",
"laterThan": "2015-08-17"
},
"valid": false
},
{
"description": "boundary point is valid",
"data": {
"when": "2015-08-17",
"whenFormat": "date",
"laterThan": "2015-08-17"
},
"valid": true
},
{
"description": "after the minimum date is valid",
"data": {
"when": "2015-11-09",
"whenFormat": "date",
"laterThan": "2015-08-17"
},
"valid": true
}
]
},
{
"description": "formatMinimum and format in the properties with exclusiveFormatMinimum",
"schema": {
"properties": {
"when": {
"format": { "$data": "1/whenFormat" },
"formatMinimum": { "$data": "1/laterThan" },
"exclusiveFormatMinimum": true
},
"whenFormat": {},
"laterThan": {}
}
},
"tests": [
{
"description": "before the minimum date is still invalid",
"data": {
"when": "2014-12-03",
"whenFormat": "date",
"laterThan": "2015-08-17"
},
"valid": false
},
{
"description": "boundary point is invalid",
"data": {
"when": "2015-08-17",
"whenFormat": "date",
"laterThan": "2015-08-17"
},
"valid": false
},
{
"description": "after the minimum date is still valid",
"data": {
"when": "2015-11-09",
"whenFormat": "date",
"laterThan": "2015-08-17"
},
"valid": true
}
]
},
{
"description": "exclusiveFormatMinimum in the property",
"schema": {
"properties": {
"finalDate": {
"format": "date",
"formatMinimum": "2015-08-17",
"exclusiveFormatMinimum": { "$data": "1/minIsExclusive" }
},
"minIsExclusive": {}
}
},
"tests": [
{
"description": "before the minimum date is invalid",
"data": {
"finalDate": "2014-12-03",
"minIsExclusive": false
},
"valid": false
},
{
"description": "boundary point is valid",
"data": {
"finalDate": "2015-08-17"
},
"valid": true
},
{
"description": "after the minimum date is valid",
"data": {
"finalDate": "2015-11-09"
},
"valid": true
},
{
"description": "before the minimum date is still invalid",
"data": {
"finalDate": "2014-12-03",
"minIsExclusive": true
},
"valid": false
},
{
"description": "boundary point is invalid",
"data": {
"finalDate": "2015-08-17",
"minIsExclusive": true
},
"valid": false
},
{
"description": "after the minimum date is still valid",
"data": {
"finalDate": "2015-11-09",
"minIsExclusive": true
},
"valid": true
},
{
"description": "fails if value of exclusiveFormatMinimum is not boolean",
"data": {
"finalDate": "2015-11-09",
"minIsExclusive": "false"
},
"valid": false
}
]
},
{
"description": "formatMinimum and exclusiveFormatMinimum in the properties",
"schema": {
"properties": {
"finalDate": {
"format": "date",
"formatMinimum": { "$data": "1/laterThan" },
"exclusiveFormatMinimum": { "$data": "1/minIsExclusive" }
},
"laterThan": {},
"minIsExclusive": {}
}
},
"tests": [
{
"description": "before the minimum date is invalid",
"data": {
"finalDate": "2014-12-03",
"laterThan": "2015-08-17",
"minIsExclusive": false
},
"valid": false
},
{
"description": "boundary point is valid",
"data": {
"finalDate": "2015-08-17",
"laterThan": "2015-08-17"
},
"valid": true
},
{
"description": "after the minimum date is valid",
"data": {
"finalDate": "2015-11-09",
"laterThan": "2015-08-17"
},
"valid": true
},
{
"description": "before the minimum date is still invalid",
"data": {
"finalDate": "2014-12-03",
"laterThan": "2015-08-17",
"minIsExclusive": true
},
"valid": false
},
{
"description": "boundary point is invalid",
"data": {
"finalDate": "2015-08-17",
"laterThan": "2015-08-17",
"minIsExclusive": true
},
"valid": false
},
{
"description": "after the minimum date is still valid",
"data": {
"finalDate": "2015-11-09",
"laterThan": "2015-08-17",
"minIsExclusive": true
},
"valid": true
},
{
"description": "fails if value of exclusiveFormatMinimum is not boolean",
"data": {
"finalDate": "2015-11-09",
"laterThan": "2015-08-17",
"minIsExclusive": "false"
},
"valid": false
},
{
"description": "fails if value of formatMinimum is not string",
"data": {
"finalDate": "2016-11-09",
"laterThan": 2015,
"minIsExclusive": false
},
"valid": false
}
]
},
{
"description": "formatMinimum with format and exclusiveFormatMinimum in the properties",
"schema": {
"properties": {
"when": {
"format": { "$data": "1/whenFormat" },
"formatMinimum": "2015-08-17",
"exclusiveFormatMinimum": { "$data": "1/minIsExclusive" }
},
"whenFormat": {},
"minIsExclusive": {}
}
},
"tests": [
{
"description": "before the minimum date is invalid",
"data": {
"when": "2014-12-03",
"whenFormat": "date",
"minIsExclusive": false
},
"valid": false
},
{
"description": "boundary point is valid",
"data": {
"when": "2015-08-17",
"whenFormat": "date"
},
"valid": true
},
{
"description": "after the minimum date is valid",
"data": {
"when": "2015-11-09",
"whenFormat": "date"
},
"valid": true
},
{
"description": "before the minimum date is still invalid",
"data": {
"when": "2014-12-03",
"whenFormat": "date",
"minIsExclusive": true
},
"valid": false
},
{
"description": "boundary point is invalid",
"data": {
"when": "2015-08-17",
"whenFormat": "date",
"minIsExclusive": true
},
"valid": false
},
{
"description": "after the minimum date is still valid",
"data": {
"when": "2015-11-09",
"whenFormat": "date",
"minIsExclusive": true
},
"valid": true
},
{
"description": "fails if value of exclusiveFormatMinimum is not boolean",
"data": {
"when": "2015-11-09",
"whenFormat": "date",
"minIsExclusive": "false"
},
"valid": false
}
]
},
{
"description": "formatMinimum, format and exclusiveFormatMinimum in the properties",
"schema": {
"properties": {
"when": {
"format": { "$data": "1/whenFormat" },
"formatMinimum": { "$data": "1/laterThan" },
"exclusiveFormatMinimum": { "$data": "1/minIsExclusive" }
},
"laterThan": {},
"whenFormat": {},
"minIsExclusive": {}
}
},
"tests": [
{
"description": "before the minimum date is invalid",
"data": {
"when": "2014-12-03",
"whenFormat": "date",
"laterThan": "2015-08-17",
"minIsExclusive": false
},
"valid": false
},
{
"description": "boundary point is valid",
"data": {
"when": "2015-08-17",
"whenFormat": "date",
"laterThan": "2015-08-17"
},
"valid": true
},
{
"description": "after the minimum date is valid",
"data": {
"when": "2015-11-09",
"whenFormat": "date",
"laterThan": "2015-08-17"
},
"valid": true
},
{
"description": "before the minimum date is still invalid",
"data": {
"when": "2014-12-03",
"whenFormat": "date",
"laterThan": "2015-08-17",
"minIsExclusive": true
},
"valid": false
},
{
"description": "boundary point is invalid",
"data": {
"when": "2015-08-17",
"whenFormat": "date",
"laterThan": "2015-08-17",
"minIsExclusive": true
},
"valid": false
},
{
"description": "after the minimum date is still valid",
"data": {
"when": "2015-11-09",
"whenFormat": "date",
"laterThan": "2015-08-17",
"minIsExclusive": true
},
"valid": true
},
{
"description": "fails if value of exclusiveFormatMinimum is not boolean",
"data": {
"when": "2015-11-09",
"whenFormat": "date",
"laterThan": "2015-08-17",
"minIsExclusive": "false"
},
"valid": false
}
]
}
]

View File

@ -202,5 +202,19 @@
"valid": true
}
]
},
{
"description": "formatMaximum is valid with unknown format",
"schema": {
"format": "unknown",
"formatMaximum": "2015"
},
"tests": [
{
"description": "always valid",
"data": "2016",
"valid": true
}
]
}
]