Skip to content

Commit 8ccbfdc

Browse files
Merge pull request #412 from json-schema-org/ether/more-format-duration-2
some more tests for the "duration" format
2 parents 1d5c3c0 + 1329dab commit 8ccbfdc

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

tests/draft2019-09/format.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,5 +646,41 @@
646646
"valid": true
647647
}
648648
]
649+
},
650+
{
651+
"description": "validation of durations",
652+
"schema": { "format": "duration" },
653+
"tests": [
654+
{
655+
"description": "ignores integers",
656+
"data": 12,
657+
"valid": true
658+
},
659+
{
660+
"description": "ignores floats",
661+
"data": 13.7,
662+
"valid": true
663+
},
664+
{
665+
"description": "ignores objects",
666+
"data": {},
667+
"valid": true
668+
},
669+
{
670+
"description": "ignores arrays",
671+
"data": [],
672+
"valid": true
673+
},
674+
{
675+
"description": "ignores booleans",
676+
"data": false,
677+
"valid": true
678+
},
679+
{
680+
"description": "ignores null",
681+
"data": null,
682+
"valid": true
683+
}
684+
]
649685
}
650686
]

tests/draft2019-09/optional/format/duration.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,86 @@
1212
"description": "an invalid duration string",
1313
"data": "PT1D",
1414
"valid": false
15+
},
16+
{
17+
"description": "no elements present",
18+
"data": "P",
19+
"valid": false
20+
},
21+
{
22+
"description": "no time elements present",
23+
"data": "P1YT",
24+
"valid": false
25+
},
26+
{
27+
"description": "no date or time elements present",
28+
"data": "PT",
29+
"valid": false
30+
},
31+
{
32+
"description": "elements out of order",
33+
"data": "P2D1Y",
34+
"valid": false
35+
},
36+
{
37+
"description": "missing time separator",
38+
"data": "P1D2H",
39+
"valid": false
40+
},
41+
{
42+
"description": "time element in the date position",
43+
"data": "P2S",
44+
"valid": false
45+
},
46+
{
47+
"description": "four years duration",
48+
"data": "P4Y",
49+
"valid": true
50+
},
51+
{
52+
"description": "zero time, in seconds",
53+
"data": "PT0S",
54+
"valid": true
55+
},
56+
{
57+
"description": "zero time, in days",
58+
"data": "P0D",
59+
"valid": true
60+
},
61+
{
62+
"description": "one month duration",
63+
"data": "P1M",
64+
"valid": true
65+
},
66+
{
67+
"description": "one minute duration",
68+
"data": "PT1M",
69+
"valid": true
70+
},
71+
{
72+
"description": "elements may be omitted if their value is zero",
73+
"data": "PT1H1S",
74+
"valid": true
75+
},
76+
{
77+
"description": "one and a half days, in hours",
78+
"data": "PT36H",
79+
"valid": true
80+
},
81+
{
82+
"description": "one and a half days, in days and hours",
83+
"data": "P1DT12H",
84+
"valid": true
85+
},
86+
{
87+
"description": "two weeks",
88+
"data": "P2W",
89+
"valid": true
90+
},
91+
{
92+
"description": "weeks cannot be combined with other units",
93+
"data": "P1Y2W",
94+
"valid": false
1595
}
1696
]
1797
}

0 commit comments

Comments
 (0)