Skip to content

Commit 06481b1

Browse files
Shristibotkumari-Shristijdesrosiers
authored
test: add unicode pattern and patternProperties tests for draft2020-12 (#837)
* test: add unicode pattern and patternProperties tests for draft2020-12 * Remove unintended snyk instructions file * test: add required Unicode property escape tests for draft2020-12 Add tests using \p{Letter} pattern which requires the ECMA-262 u flag: - pattern.json: verify Unicode-mode regex with ASCII letters, non-ASCII letters, and digits - patternProperties.json: verify Unicode-mode pattern matching for property names * Added tests for v1 * Shorten test description to satisfy sanity check * Revert whitespace changes in patternProperties.json * Cleanup whitespace --------- Co-authored-by: Shristibot <sshristi233@gmail.com> Co-authored-by: Jason Desrosiers <jdesrosi@gmail.com>
1 parent 601aa70 commit 06481b1

4 files changed

Lines changed: 105 additions & 0 deletions

File tree

tests/draft2020-12/pattern.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,30 @@
6161
"valid": true
6262
}
6363
]
64+
},
65+
{
66+
"description": "pattern with Unicode property escape requires unicode mode",
67+
"schema": {
68+
"$schema": "https://json-schema.org/draft/2020-12/schema",
69+
"type": "string",
70+
"pattern": "^\\p{Letter}+$"
71+
},
72+
"tests": [
73+
{
74+
"description": "ASCII letters match",
75+
"data": "Hello",
76+
"valid": true
77+
},
78+
{
79+
"description": "Non-ASCII letters match",
80+
"data": "π",
81+
"valid": true
82+
},
83+
{
84+
"description": "Digits do not match",
85+
"data": "123",
86+
"valid": false
87+
}
88+
]
6489
}
6590
]

tests/draft2020-12/patternProperties.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,33 @@
172172
"valid": true
173173
}
174174
]
175+
},
176+
{
177+
"description": "patternProperties with Unicode property escape",
178+
"schema": {
179+
"$schema": "https://json-schema.org/draft/2020-12/schema",
180+
"type": "object",
181+
"patternProperties": {
182+
"^\\p{Letter}+$": {
183+
"type": "number"
184+
}
185+
}
186+
},
187+
"tests": [
188+
{
189+
"description": "Unicode letter property name matches",
190+
"data": {
191+
"π": 1
192+
},
193+
"valid": true
194+
},
195+
{
196+
"description": "Non-letter property name does not match pattern",
197+
"data": {
198+
"123": 1
199+
},
200+
"valid": true
201+
}
202+
]
175203
}
176204
]

tests/v1/pattern.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,30 @@
6161
"valid": true
6262
}
6363
]
64+
},
65+
{
66+
"description": "pattern with Unicode property escape",
67+
"schema": {
68+
"$schema": "https://json-schema.org/v1",
69+
"type": "string",
70+
"pattern": "^\\p{Letter}+$"
71+
},
72+
"tests": [
73+
{
74+
"description": "a valid case with a Unicode letter",
75+
"data": "π",
76+
"valid": true
77+
},
78+
{
79+
"description": "another valid case with multiple Unicode letters",
80+
"data": "πλ",
81+
"valid": true
82+
},
83+
{
84+
"description": "an invalid case where the string contains digits",
85+
"data": "123",
86+
"valid": false
87+
}
88+
]
6489
}
6590
]

tests/v1/patternProperties.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,32 @@
172172
"valid": true
173173
}
174174
]
175+
},
176+
{
177+
"description": "patternProperties with Unicode property escape",
178+
"schema": {
179+
"$schema": "https://json-schema.org/v1",
180+
"type": "object",
181+
"patternProperties": {
182+
"^\\p{Letter}+$": {"type": "number"}
183+
}
184+
},
185+
"tests": [
186+
{
187+
"description": "Unicode letter property name matches",
188+
"data": {"π": 1},
189+
"valid": true
190+
},
191+
{
192+
"description": "Unicode letter property name matches but value type is incorrect",
193+
"data": {"π": "1"},
194+
"valid": false
195+
},
196+
{
197+
"description": "Non-letter property name does not match pattern",
198+
"data": {"123": 1},
199+
"valid": true
200+
}
201+
]
175202
}
176203
]

0 commit comments

Comments
 (0)