Clarify behaviour of funny characters and pattern matching on numbers

This commit is contained in:
Dion Moult
2022-09-14 09:56:51 +10:00
parent 68e2bb1fa7
commit 227b1391bd
2 changed files with 12 additions and 4 deletions
+2
View File
@@ -745,6 +745,8 @@ class Restriction:
if other not in [cast_to_value(v, other) for v in value]:
return False
elif constraint == "pattern":
if not isinstance(other, str):
return False
value = value if isinstance(value, list) else [value]
for pattern in value:
if re.compile(identities.translate_pattern(pattern)).fullmatch(other) is None:
+10 -4
View File
@@ -376,11 +376,11 @@ class TestAttribute:
)
ifc = ifcopenshell.file()
facet = Attribute(name="Name", value="")
facet = Attribute(name="Name", value="Don'tÄrgerhôtelЊет")
run(
"Non-ascii characters are treated without encoding",
facet=facet,
inst=ifc.createIfcWall(Name=""),
inst=ifc.createIfcWall(Name="Don'tÄrgerhôtelЊет"),
expected=True,
)
@@ -911,8 +911,8 @@ class TestProperty:
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "Baz"})
run("Specifying a value fails against different values", facet=facet, inst=element, expected=False)
facet = Property(propertySet="Foo_Bar", name="Foo", value="", measure="IfcLabel")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": ""})
facet = Property(propertySet="Foo_Bar", name="Foo", value="Don'tÄrgerhôtelЊет", measure="IfcLabel")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "Don'tÄrgerhôtelЊет"})
run("Non-ascii characters are treated without encoding", facet=facet, inst=element, expected=True)
identifier = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345"
@@ -1595,6 +1595,12 @@ class TestRestriction:
element.Name = "A5"
run("Regex patterns can be used 3/3", facet=facet, inst=element, expected=False)
ifc = ifcopenshell.file()
restriction = Restriction(options={"pattern": ".*"})
element = ifc.createIfcSurfaceStyleRefraction(RefractionIndex=42)
facet = Attribute(name="RefractionIndex", value=restriction)
run("Patterns only work on strings and nothing else", facet=facet, inst=element, expected=False)
ifc = ifcopenshell.file()
restriction = Restriction(options={"length": 2})
facet = Attribute(name="Name", value=restriction)