Skip to content

Commit 989f7e7

Browse files
committed
test(duration): expand RFC 3339 ABNF grammar coverage for duration format
Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
1 parent 601aa70 commit 989f7e7

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[
22
{
33
"description": "validation of duration strings",
4+
"comment": "RFC 3339 Appendix A defines the ABNF grammar for ISO-8601 durations used by JSON Schema format 'duration'. These tests enforce only the syntax defined by that grammar.",
45
"schema": {
56
"$schema": "https://json-schema.org/draft/2019-09/schema",
67
"format": "duration"
@@ -135,6 +136,51 @@
135136
"description": "element without unit",
136137
"data": "P1",
137138
"valid": false
139+
},
140+
{
141+
"description": "all date and time components",
142+
"data": "P1Y2M3DT4H5M6S",
143+
"valid": true
144+
},
145+
{
146+
"description": "date components only",
147+
"data": "P1Y2M3D",
148+
"valid": true
149+
},
150+
{
151+
"description": "time components only",
152+
"data": "PT1H2M3S",
153+
"valid": true
154+
},
155+
{
156+
"description": "month and day",
157+
"data": "P1M2D",
158+
"valid": true
159+
},
160+
{
161+
"description": "hour and minute",
162+
"data": "PT1H30M",
163+
"valid": true
164+
},
165+
{
166+
"description": "multi-digit values in all components",
167+
"data": "P10Y10M10DT10H10M10S",
168+
"valid": true
169+
},
170+
{
171+
"description": "leading whitespace is invalid",
172+
"data": " P1D",
173+
"valid": false
174+
},
175+
{
176+
"description": "trailing whitespace is invalid",
177+
"data": "P1D ",
178+
"valid": false
179+
},
180+
{
181+
"description": "empty string is invalid",
182+
"data": "",
183+
"valid": false
138184
}
139185
]
140186
}

tests/draft2020-12/optional/format/duration.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[
22
{
33
"description": "validation of duration strings",
4+
"comment": "RFC 3339 Appendix A defines the ABNF grammar for ISO-8601 durations used by JSON Schema format 'duration'. These tests enforce only the syntax defined by that grammar.",
45
"schema": {
56
"$schema": "https://json-schema.org/draft/2020-12/schema",
67
"format": "duration"
@@ -135,6 +136,51 @@
135136
"description": "element without unit",
136137
"data": "P1",
137138
"valid": false
139+
},
140+
{
141+
"description": "all date and time components",
142+
"data": "P1Y2M3DT4H5M6S",
143+
"valid": true
144+
},
145+
{
146+
"description": "date components only",
147+
"data": "P1Y2M3D",
148+
"valid": true
149+
},
150+
{
151+
"description": "time components only",
152+
"data": "PT1H2M3S",
153+
"valid": true
154+
},
155+
{
156+
"description": "month and day",
157+
"data": "P1M2D",
158+
"valid": true
159+
},
160+
{
161+
"description": "hour and minute",
162+
"data": "PT1H30M",
163+
"valid": true
164+
},
165+
{
166+
"description": "multi-digit values in all components",
167+
"data": "P10Y10M10DT10H10M10S",
168+
"valid": true
169+
},
170+
{
171+
"description": "leading whitespace is invalid",
172+
"data": " P1D",
173+
"valid": false
174+
},
175+
{
176+
"description": "trailing whitespace is invalid",
177+
"data": "P1D ",
178+
"valid": false
179+
},
180+
{
181+
"description": "empty string is invalid",
182+
"data": "",
183+
"valid": false
138184
}
139185
]
140186
}

tests/v1/format/duration.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[
22
{
33
"description": "validation of duration strings",
4+
"comment": "RFC 3339 Appendix A defines the ABNF grammar for ISO-8601 durations used by JSON Schema format 'duration'. These tests enforce only the syntax defined by that grammar.",
45
"schema": {
56
"$schema": "https://json-schema.org/v1",
67
"format": "duration"
@@ -135,6 +136,51 @@
135136
"description": "element without unit",
136137
"data": "P1",
137138
"valid": false
139+
},
140+
{
141+
"description": "all date and time components",
142+
"data": "P1Y2M3DT4H5M6S",
143+
"valid": true
144+
},
145+
{
146+
"description": "date components only",
147+
"data": "P1Y2M3D",
148+
"valid": true
149+
},
150+
{
151+
"description": "time components only",
152+
"data": "PT1H2M3S",
153+
"valid": true
154+
},
155+
{
156+
"description": "month and day",
157+
"data": "P1M2D",
158+
"valid": true
159+
},
160+
{
161+
"description": "hour and minute",
162+
"data": "PT1H30M",
163+
"valid": true
164+
},
165+
{
166+
"description": "multi-digit values in all components",
167+
"data": "P10Y10M10DT10H10M10S",
168+
"valid": true
169+
},
170+
{
171+
"description": "leading whitespace is invalid",
172+
"data": " P1D",
173+
"valid": false
174+
},
175+
{
176+
"description": "trailing whitespace is invalid",
177+
"data": "P1D ",
178+
"valid": false
179+
},
180+
{
181+
"description": "empty string is invalid",
182+
"data": "",
183+
"valid": false
138184
}
139185
]
140186
}

0 commit comments

Comments
 (0)