Skip to content

Commit 0c1a702

Browse files
committed
add more anchor validation tests
1 parent bf0360f commit 0c1a702

File tree

2 files changed

+99
-4
lines changed

2 files changed

+99
-4
lines changed

tests/draft2019-09/anchor.json

+52-2
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,68 @@
118118
]
119119
},
120120
{
121-
"description": "invalid anchors",
121+
"description": "anchor validity",
122122
"comment": "Section 8.2.3",
123123
"schema": {
124124
"$schema": "https://json-schema.org/draft/2019-09/schema",
125125
"$ref": "https://json-schema.org/draft/2019-09/schema"
126126
},
127127
"tests": [
128128
{
129-
"description": "MUST start with a letter (and not #)",
129+
"description": "MUST NOT start with #",
130130
"data": { "$anchor" : "#foo" },
131131
"valid": false
132132
},
133+
{
134+
"description": "MUST NOT start with number",
135+
"data": { "$anchor" : "0number" },
136+
"valid": false
137+
},
138+
{
139+
"description": "MUST NOT start with period",
140+
"data": { "$anchor" : ".period" },
141+
"valid": false
142+
},
143+
{
144+
"description": "MUST NOT start with hyphen",
145+
"data": { "$anchor" : "-hyphen" },
146+
"valid": false
147+
},
148+
{
149+
"description": "MUST NOT start with underscore",
150+
"data": { "$anchor" : "_underscore" },
151+
"valid": false
152+
},
153+
{
154+
"description": "MUST NOT start with colon",
155+
"data": { "$anchor" : ":colon" },
156+
"valid": false
157+
},
158+
{
159+
"description": "MAY contain colon",
160+
"data": { "$anchor" : "inner:colon" },
161+
"valid": true
162+
},
163+
{
164+
"description": "MAY contain underscore",
165+
"data": { "$anchor" : "under_score" },
166+
"valid": true
167+
},
168+
{
169+
"description": "MAY contain hyphen",
170+
"data": { "$anchor" : "inner-hyphen" },
171+
"valid": true
172+
},
173+
{
174+
"description": "MAY contain period",
175+
"data": { "$anchor" : "inner.period" },
176+
"valid": true
177+
},
178+
{
179+
"description": "MAY contain numbers",
180+
"data": { "$anchor" : "start0123456789end" },
181+
"valid": true
182+
},
133183
{
134184
"description": "JSON pointers are not valid",
135185
"data": { "$anchor" : "/a/b" },

tests/draft2020-12/anchor.json

+47-2
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,63 @@
118118
]
119119
},
120120
{
121-
"description": "invalid anchors",
121+
"description": "anchor validity",
122122
"comment": "Section 8.2.2",
123123
"schema": {
124124
"$schema": "https://json-schema.org/draft/2020-12/schema",
125125
"$ref": "https://json-schema.org/draft/2020-12/schema"
126126
},
127127
"tests": [
128128
{
129-
"description": "MUST start with a letter (and not #)",
129+
"description": "MUST NOT start with #",
130130
"data": { "$anchor" : "#foo" },
131131
"valid": false
132132
},
133+
{
134+
"description": "MUST NOT start with number",
135+
"data": { "$anchor" : "0number" },
136+
"valid": false
137+
},
138+
{
139+
"description": "MUST NOT start with period",
140+
"data": { "$anchor" : ".period" },
141+
"valid": false
142+
},
143+
{
144+
"description": "MUST NOT start with hyphen",
145+
"data": { "$anchor" : "-hyphen" },
146+
"valid": false
147+
},
148+
{
149+
"description": "MAY start with underscore",
150+
"data": { "$anchor" : "_underscore" },
151+
"valid": true
152+
},
153+
{
154+
"description": "MUST NOT contain colon",
155+
"data": { "$anchor" : "inner:colon" },
156+
"valid": false
157+
},
158+
{
159+
"description": "MAY contain underscore",
160+
"data": { "$anchor" : "under_score" },
161+
"valid": true
162+
},
163+
{
164+
"description": "MAY contain hyphen",
165+
"data": { "$anchor" : "inner-hyphen" },
166+
"valid": true
167+
},
168+
{
169+
"description": "MAY contain period",
170+
"data": { "$anchor" : "inner.period" },
171+
"valid": true
172+
},
173+
{
174+
"description": "MAY contain numbers",
175+
"data": { "$anchor" : "start0123456789end" },
176+
"valid": true
177+
},
133178
{
134179
"description": "JSON pointers are not valid",
135180
"data": { "$anchor" : "/a/b" },

0 commit comments

Comments
 (0)