Skip to content

Commit

Permalink
Correct property value check in remove_gds_property() (#276)
Browse files Browse the repository at this point in the history
* Test GDS property deletion

* Fix property value check
  • Loading branch information
jatoben authored Nov 7, 2024
1 parent 9e6616e commit 1fd3f4a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ bool remove_gds_property(Property*& properties, uint16_t attribute) {
}
Property* property = properties;
while (property->next &&
(!is_gds_property(property->next) || property->value->unsigned_integer != attribute))
(!is_gds_property(property->next) || property->next->value->unsigned_integer != attribute))
property = property->next;
if (property->next) {
Property* rem = property->next;
Expand Down
69 changes: 69 additions & 0 deletions tests/property_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,72 @@ def test_properties():
["TWO", -2.3e-4, b"two"],
["Three", b"\xFF\xEE", 0],
]


def test_delete_gds_property():
def create_props(obj) -> gdstk.Reference:
obj.set_gds_property(100, "bar")
obj.set_gds_property(101, "baz")
obj.set_gds_property(102, "quux")

assert obj.properties == [
["S_GDS_PROPERTY", 102, b"quux\x00"],
["S_GDS_PROPERTY", 101, b"baz\x00"],
["S_GDS_PROPERTY", 100, b"bar\x00"],
]

return obj

for obj in (
gdstk.FlexPath(0j, 2),
gdstk.Label("foo", (0, 0)),
gdstk.rectangle((0, 0), (1, 1)),
gdstk.Reference("foo"),
gdstk.RobustPath((0.5, 50), 0),
):
create_props(obj)
obj.delete_gds_property(102)

assert obj.get_gds_property(100) == "bar"
assert obj.get_gds_property(101) == "baz"
assert obj.get_gds_property(102) is None
assert obj.properties == [
["S_GDS_PROPERTY", 101, b"baz\x00"],
["S_GDS_PROPERTY", 100, b"bar\x00"],
]

for obj in (
gdstk.FlexPath(0j, 2),
gdstk.Label("foo", (0, 0)),
gdstk.rectangle((0, 0), (1, 1)),
gdstk.Reference("foo"),
gdstk.RobustPath((0.5, 50), 0),
):
create_props(obj)
obj.delete_gds_property(101)

assert obj.get_gds_property(100) == "bar"
assert obj.get_gds_property(101) is None
assert obj.get_gds_property(102) == "quux"
assert obj.properties == [
["S_GDS_PROPERTY", 102, b"quux\x00"],
["S_GDS_PROPERTY", 100, b"bar\x00"],
]

for obj in (
gdstk.FlexPath(0j, 2),
gdstk.Label("foo", (0, 0)),
gdstk.rectangle((0, 0), (1, 1)),
gdstk.Reference("foo"),
gdstk.RobustPath((0.5, 50), 0),
):
create_props(obj)
obj.delete_gds_property(100)

assert obj.get_gds_property(100) is None
assert obj.get_gds_property(101) == "baz"
assert obj.get_gds_property(102) == "quux"
assert obj.properties == [
["S_GDS_PROPERTY", 102, b"quux\x00"],
["S_GDS_PROPERTY", 101, b"baz\x00"],
]

0 comments on commit 1fd3f4a

Please sign in to comment.