Skip to content

Commit

Permalink
Merge commit 'd1b69fc7c69fca9f04cfdd3ee3b1f156fc97a5f1'
Browse files Browse the repository at this point in the history
* commit 'd1b69fc7c69fca9f04cfdd3ee3b1f156fc97a5f1':
  Squashed 'json/' changes from e524505b..83e866b4
  • Loading branch information
Julian committed Feb 19, 2025
2 parents 850befe + d1b69fc commit dd1cd33
Show file tree
Hide file tree
Showing 10 changed files with 449 additions and 9 deletions.
33 changes: 29 additions & 4 deletions json/bin/annotate-specification-links
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ def line_number_of(path: Path, case: dict[str, Any]) -> int:
1,
)

def extract_kind_and_spec(key: str) -> (str, str):
"""
Extracts specification number and kind from the defined key
"""
can_have_spec = ["rfc", "iso"]
if not any(key.startswith(el) for el in can_have_spec):
return key, ""
number = re.search(r"\d+", key)
spec = "" if number is None else number.group(0)
kind = key.removesuffix(spec)
return kind, spec


def main():
# Clear annotations which may have been emitted by a previous run.
Expand All @@ -82,20 +94,33 @@ def main():
line=error.lineno,
col=error.pos + 1,
title=str(error),
message=f"cannot load {path}"
)
sys.stdout.write(error)
continue

for test_case in contents:
specifications = test_case.get("specification")
if specifications is not None:
for each in specifications:
quote = each.pop("quote", "")
(kind, section), = each.items()
(key, section), = each.items()

number = re.search(r"\d+", kind)
spec = "" if number is None else number.group(0)
(kind, spec) = extract_kind_and_spec(key)

url_template = version_urls[kind]
if url_template is None:
error = annotation(
level="error",
path=path,
line=line_number_of(path, test_case),
title=f"unsupported template '{kind}'",
message=f"cannot find a URL template for '{kind}'"
)
sys.stdout.write(error)
continue

url = version_urls[kind].expand(
url = url_template.expand(
spec=spec,
section=section,
)
Expand Down
2 changes: 1 addition & 1 deletion json/bin/specification_urls.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"external": {
"ecma262": "https://262.ecma-international.org/{section}",
"perl5": "https://perldoc.perl.org/perlre#{section}",
"rfc": "https://www.rfc-editor.org/rfc/{spec}.txt#{section}",
"rfc": "https://www.rfc-editor.org/rfc/rfc{spec}.html#section-{section}",
"iso": "https://www.iso.org/obp/ui"
}
}
49 changes: 48 additions & 1 deletion json/tests/draft-next/optional/format/idn-hostname.json
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,58 @@
"description": "empty string",
"data": "",
"valid": false
},
}
]
},
{
"description": "validation of separators in internationalized host names",
"specification": [
{"rfc3490": "3.1", "quote": "Whenever dots are used as label separators, the following characters MUST be recognized as dots: U+002E (full stop), U+3002 (ideographic full stop), U+FF0E (fullwidth full stop), U+FF61(halfwidth ideographic full stop)"}
],
"schema": {
"$schema": "https://json-schema.org/draft/next/schema",
"format": "idn-hostname"
},
"tests": [
{
"description": "single dot",
"data": ".",
"valid": false
},
{
"description": "single ideographic full stop",
"data": "\u3002",
"valid": false
},
{
"description": "single fullwidth full stop",
"data": "\uff0e",
"valid": false
},
{
"description": "single halfwidth ideographic full stop",
"data": "\uff61",
"valid": false
},
{
"description": "dot as label separator",
"data": "a.b",
"valid": true
},
{
"description": "ideographic full stop as label separator",
"data": "a\u3002b",
"valid": true
},
{
"description": "fullwidth full stop as label separator",
"data": "a\uff0eb",
"valid": true
},
{
"description": "halfwidth ideographic full stop as label separator",
"data": "a\uff61b",
"valid": true
}
]
}
Expand Down
49 changes: 48 additions & 1 deletion json/tests/draft2019-09/optional/format/idn-hostname.json
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,58 @@
"description": "empty string",
"data": "",
"valid": false
},
}
]
},
{
"description": "validation of separators in internationalized host names",
"specification": [
{"rfc3490": "3.1", "quote": "Whenever dots are used as label separators, the following characters MUST be recognized as dots: U+002E (full stop), U+3002 (ideographic full stop), U+FF0E (fullwidth full stop), U+FF61(halfwidth ideographic full stop)"}
],
"schema": {
"$schema": "https://json-schema.org/draft/2019-09/schema",
"format": "idn-hostname"
},
"tests": [
{
"description": "single dot",
"data": ".",
"valid": false
},
{
"description": "single ideographic full stop",
"data": "\u3002",
"valid": false
},
{
"description": "single fullwidth full stop",
"data": "\uff0e",
"valid": false
},
{
"description": "single halfwidth ideographic full stop",
"data": "\uff61",
"valid": false
},
{
"description": "dot as label separator",
"data": "a.b",
"valid": true
},
{
"description": "ideographic full stop as label separator",
"data": "a\u3002b",
"valid": true
},
{
"description": "fullwidth full stop as label separator",
"data": "a\uff0eb",
"valid": true
},
{
"description": "halfwidth ideographic full stop as label separator",
"data": "a\uff61b",
"valid": true
}
]
}
Expand Down
53 changes: 53 additions & 0 deletions json/tests/draft2019-09/propertyNames.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,58 @@
"valid": true
}
]
},
{
"description": "propertyNames with const",
"schema": {
"$schema": "https://json-schema.org/draft/2019-09/schema",
"propertyNames": {"const": "foo"}
},
"tests": [
{
"description": "object with property foo is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "object with any other property is invalid",
"data": {"bar": 1},
"valid": false
},
{
"description": "empty object is valid",
"data": {},
"valid": true
}
]
},
{
"description": "propertyNames with enum",
"schema": {
"$schema": "https://json-schema.org/draft/2019-09/schema",
"propertyNames": {"enum": ["foo", "bar"]}
},
"tests": [
{
"description": "object with property foo is valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "object with property foo and bar is valid",
"data": {"foo": 1, "bar": 1},
"valid": true
},
{
"description": "object with any other property is invalid",
"data": {"baz": 1},
"valid": false
},
{
"description": "empty object is valid",
"data": {},
"valid": true
}
]
}
]
49 changes: 48 additions & 1 deletion json/tests/draft2020-12/optional/format/idn-hostname.json
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,58 @@
"description": "empty string",
"data": "",
"valid": false
},
}
]
},
{
"description": "validation of separators in internationalized host names",
"specification": [
{"rfc3490": "3.1", "quote": "Whenever dots are used as label separators, the following characters MUST be recognized as dots: U+002E (full stop), U+3002 (ideographic full stop), U+FF0E (fullwidth full stop), U+FF61(halfwidth ideographic full stop)"}
],
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"format": "idn-hostname"
},
"tests": [
{
"description": "single dot",
"data": ".",
"valid": false
},
{
"description": "single ideographic full stop",
"data": "\u3002",
"valid": false
},
{
"description": "single fullwidth full stop",
"data": "\uff0e",
"valid": false
},
{
"description": "single halfwidth ideographic full stop",
"data": "\uff61",
"valid": false
},
{
"description": "dot as label separator",
"data": "a.b",
"valid": true
},
{
"description": "ideographic full stop as label separator",
"data": "a\u3002b",
"valid": true
},
{
"description": "fullwidth full stop as label separator",
"data": "a\uff0eb",
"valid": true
},
{
"description": "halfwidth ideographic full stop as label separator",
"data": "a\uff61b",
"valid": true
}
]
}
Expand Down
Loading

0 comments on commit dd1cd33

Please sign in to comment.