Skip to content

Commit

Permalink
testing whether JSON schema patterns work in SHACL
Browse files Browse the repository at this point in the history
  • Loading branch information
mristin committed Aug 27, 2024
1 parent a7025ba commit 92bcf9e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 56 deletions.
6 changes: 3 additions & 3 deletions aas_core_codegen/jsonschema/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _define_type(
)


def _fix_pattern_for_utf16(pattern: str) -> str:
def fix_pattern_for_utf16(pattern: str) -> str:
"""Fix the pattern for UTF-16-only regex engines."""
regex, error = parse_retree.parse([pattern])
if error is not None:
Expand Down Expand Up @@ -195,7 +195,7 @@ def _define_constraints_for_primitive_type(
and len(pattern_constraints) > 0
):
if len(pattern_constraints) == 1:
definition["pattern"] = _fix_pattern_for_utf16(
definition["pattern"] = fix_pattern_for_utf16(
pattern_constraints[0].pattern
)
else:
Expand All @@ -207,7 +207,7 @@ def _define_constraints_for_primitive_type(
[
(
"pattern",
_fix_pattern_for_utf16(pattern_constraint.pattern),
fix_pattern_for_utf16(pattern_constraint.pattern),
)
]
)
Expand Down
19 changes: 7 additions & 12 deletions aas_core_codegen/rdf_shacl/shacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
common as rdf_shacl_common,
)
from aas_core_codegen.rdf_shacl.common import INDENT as I, INDENT2 as II, INDENT3 as III
from aas_core_codegen.java import verification as java_verification
from aas_core_codegen.jsonschema import main as jsonschema_main


@require(lambda prop, cls: id(prop) in cls.property_id_set)
Expand Down Expand Up @@ -235,19 +235,14 @@ def _define_property_shape(
assert regex is not None

# NOTE (mristin):
# We render the pattern exactly as the Java would render it since most
# SHACL validators in the wild run on Java.
rendered_pattern = parse_retree.render(
regex=regex, renderer=java_verification.REGEX_RENDERER
# We render the pattern exactly as we do for JSON Schema since most
# SHACL validators in the wild run regex engines which understand the patterns
# for JSON Schema and work in UTF-16.
rendered_pattern = jsonschema_main.fix_pattern_for_utf16(
pattern_constraint.pattern
)

assert len(rendered_pattern) == 1 and isinstance(rendered_pattern[0], str), (
"Expected strictly only a string output from rendering "
f"a string pattern (*e.g.*, no FormattedValues), "
f"but got: {rendered_pattern}"
)

pattern_literal = rdf_shacl_common.string_literal(rendered_pattern[0])
pattern_literal = rdf_shacl_common.string_literal(rendered_pattern)

stmts.append(Stripped(f"sh:pattern {pattern_literal} ;"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ aas:AbstractLangStringShape a sh:NodeShape ;
sh:minCount 1 ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
.

Expand All @@ -60,7 +60,7 @@ aas:AdministrativeInformationShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 4 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
sh:pattern "^(0|[1-9][0-9]*)$" ;
] ;
sh:property [
Expand All @@ -71,7 +71,7 @@ aas:AdministrativeInformationShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 4 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
sh:pattern "^(0|[1-9][0-9]*)$" ;
] ;
sh:property [
Expand All @@ -89,7 +89,7 @@ aas:AdministrativeInformationShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 2000 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
.

Expand Down Expand Up @@ -147,7 +147,7 @@ aas:AssetInformationShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 2000 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand All @@ -163,7 +163,7 @@ aas:AssetInformationShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 2000 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand Down Expand Up @@ -206,7 +206,7 @@ aas:BasicEventElementShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 255 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand Down Expand Up @@ -259,8 +259,8 @@ aas:BlobShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 100 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+/([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+([ \\t]*;[ \\t]*([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+=(([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+|\"(([\\t !#-\\[\\]-~]|[\\x{80}-\\x{ff}])|\\\\([\\t !-~]|[\\x{80}-\\x{ff}]))*\"))*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
sh:pattern "^([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+/([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+([ \\t]*;[ \\t]*([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+=(([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+|\"(([\\t !#-\\[\\]-~]|[\\x80-\\xff])|\\\\([\\t !-~]|[\\x80-\\xff]))*\"))*$" ;
] ;
.

Expand Down Expand Up @@ -336,7 +336,7 @@ aas:DataSpecificationIec61360Shape a sh:NodeShape ;
sh:minCount 0 ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand All @@ -352,7 +352,7 @@ aas:DataSpecificationIec61360Shape a sh:NodeShape ;
sh:minCount 0 ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand All @@ -361,7 +361,7 @@ aas:DataSpecificationIec61360Shape a sh:NodeShape ;
sh:minCount 0 ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand All @@ -383,7 +383,7 @@ aas:DataSpecificationIec61360Shape a sh:NodeShape ;
sh:minCount 0 ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand All @@ -400,7 +400,7 @@ aas:DataSpecificationIec61360Shape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 2000 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand Down Expand Up @@ -453,7 +453,7 @@ aas:EntityShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 2000 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand Down Expand Up @@ -540,7 +540,7 @@ aas:EventPayloadShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 255 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand Down Expand Up @@ -577,7 +577,7 @@ aas:ExtensionShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 128 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand Down Expand Up @@ -612,7 +612,7 @@ aas:FileShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 2000 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand All @@ -622,8 +622,8 @@ aas:FileShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 100 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+/([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+([ \\t]*;[ \\t]*([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+=(([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+|\"(([\\t !#-\\[\\]-~]|[\\x{80}-\\x{ff}])|\\\\([\\t !-~]|[\\x{80}-\\x{ff}]))*\"))*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
sh:pattern "^([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+/([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+([ \\t]*;[ \\t]*([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+=(([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+|\"(([\\t !#-\\[\\]-~]|[\\x80-\\xff])|\\\\([\\t !-~]|[\\x80-\\xff]))*\"))*$" ;
] ;
.

Expand Down Expand Up @@ -753,7 +753,7 @@ aas:IdentifiableShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 2000 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
.

Expand All @@ -774,7 +774,7 @@ aas:KeyShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 2000 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
.

Expand Down Expand Up @@ -993,7 +993,7 @@ aas:QualifierShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 128 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand Down Expand Up @@ -1067,7 +1067,7 @@ aas:ReferableShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 128 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand All @@ -1077,7 +1077,7 @@ aas:ReferableShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 128 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
sh:pattern "^[a-zA-Z][a-zA-Z0-9_]*$" ;
] ;
sh:property [
Expand Down Expand Up @@ -1159,7 +1159,7 @@ aas:ResourceShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 2000 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand All @@ -1169,8 +1169,8 @@ aas:ResourceShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 100 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+/([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+([ \\t]*;[ \\t]*([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+=(([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+|\"(([\\t !#-\\[\\]-~]|[\\x{80}-\\x{ff}])|\\\\([\\t !-~]|[\\x{80}-\\x{ff}]))*\"))*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
sh:pattern "^([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+/([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+([ \\t]*;[ \\t]*([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+=(([!#$%&'*+\\-.^_`|~0-9a-zA-Z])+|\"(([\\t !#-\\[\\]-~]|[\\x80-\\xff])|\\\\([\\t !-~]|[\\x80-\\xff]))*\"))*$" ;
] ;
.

Expand All @@ -1185,7 +1185,7 @@ aas:SpecificAssetIdShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 64 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand All @@ -1195,7 +1195,7 @@ aas:SpecificAssetIdShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 2000 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand Down Expand Up @@ -1311,7 +1311,7 @@ aas:ValueReferencePairShape a sh:NodeShape ;
sh:maxCount 1 ;
sh:minLength 1 ;
sh:maxLength 2000 ;
sh:pattern "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$" ;
sh:pattern "^([\\x09\\x0a\\x0d\\x20-\\ud7ff\\ue000-\\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$" ;
] ;
sh:property [
a sh:PropertyShape ;
Expand Down
20 changes: 10 additions & 10 deletions tests/our_jsonschema/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,33 +157,33 @@ def test_on_examples(self) -> None:

class Test_pattern_transpilation(unittest.TestCase):
def test_unescaped_above_ascii_character_in_bmp(self) -> None:
pattern = aas_core_codegen.jsonschema.main._fix_pattern_for_utf16("\ud7ff")
pattern = aas_core_codegen.jsonschema.main.fix_pattern_for_utf16("\ud7ff")
self.assertEqual("\ud7ff", pattern)

def test_escaped_above_ascii_character_in_bmp(self) -> None:
pattern = aas_core_codegen.jsonschema.main._fix_pattern_for_utf16("\\ud7ff")
pattern = aas_core_codegen.jsonschema.main.fix_pattern_for_utf16("\\ud7ff")
self.assertEqual("\\ud7ff", pattern)

def test_unescaped_range_in_bmp(self) -> None:
pattern = aas_core_codegen.jsonschema.main._fix_pattern_for_utf16(
pattern = aas_core_codegen.jsonschema.main.fix_pattern_for_utf16(
"[\x20-\uD7FF]"
)
self.assertEqual("[\x20-\uD7FF]", pattern)

def test_escaped_range_in_bmp(self) -> None:
pattern = aas_core_codegen.jsonschema.main._fix_pattern_for_utf16(
pattern = aas_core_codegen.jsonschema.main.fix_pattern_for_utf16(
"[\\x20-\\ud7ff]"
)
self.assertEqual("[\\x20-\\ud7ff]", pattern)

def test_escaped_range_in_bmp_always_lowercase(self) -> None:
pattern = aas_core_codegen.jsonschema.main._fix_pattern_for_utf16(
pattern = aas_core_codegen.jsonschema.main.fix_pattern_for_utf16(
"[\\x20-\\uD7FF]"
)
self.assertEqual("[\\x20-\\ud7ff]", pattern)

def test_unescaped_above_bmp(self) -> None:
pattern = aas_core_codegen.jsonschema.main._fix_pattern_for_utf16(
pattern = aas_core_codegen.jsonschema.main.fix_pattern_for_utf16(
"[\U00010000-\U0010FFFF]"
)
self.assertEqual(
Expand All @@ -193,7 +193,7 @@ def test_unescaped_above_bmp(self) -> None:
)

def test_escaped_above_bmp(self) -> None:
pattern = aas_core_codegen.jsonschema.main._fix_pattern_for_utf16(
pattern = aas_core_codegen.jsonschema.main.fix_pattern_for_utf16(
"[\\U00010000-\\U0010FFFF]"
)
self.assertEqual(
Expand All @@ -203,15 +203,15 @@ def test_escaped_above_bmp(self) -> None:
)

def test_unescaped_special_ascii_characters(self) -> None:
pattern = aas_core_codegen.jsonschema.main._fix_pattern_for_utf16("[\t\n\r]")
pattern = aas_core_codegen.jsonschema.main.fix_pattern_for_utf16("[\t\n\r]")
self.assertEqual("[\\t\\n\\r]", pattern)

def test_escaped_special_ascii_characters(self) -> None:
pattern = aas_core_codegen.jsonschema.main._fix_pattern_for_utf16("[\\t\\n\\r]")
pattern = aas_core_codegen.jsonschema.main.fix_pattern_for_utf16("[\\t\\n\\r]")
self.assertEqual("[\\t\\n\\r]", pattern)

def test_on_XML_string_pattern(self) -> None:
pattern = aas_core_codegen.jsonschema.main._fix_pattern_for_utf16(
pattern = aas_core_codegen.jsonschema.main.fix_pattern_for_utf16(
r"^[\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\U00010000-\U0010FFFF]*$"
)
self.assertEqual(
Expand Down

0 comments on commit 92bcf9e

Please sign in to comment.