Skip to content

Commit c68c9a4

Browse files
committed
sizeof enum
1 parent b2e37ed commit c68c9a4

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

cstruct/cenum.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22

33

44
class CEnum(AbstractCEnum):
5-
...
5+
@classmethod
6+
def sizeof(cls) -> int:
7+
"Type size (in bytes)"
8+
return cls.__size__

tests/test_cenum.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class HtmlFont(CEnum):
2121
__def__ = """
2222
#define NONE 0
2323
24-
enum htmlfont {
24+
enum HtmlFont {
2525
HTMLFONT_NONE = NONE,
2626
HTMLFONT_BOLD,
2727
HTMLFONT_ITALIC,
@@ -87,4 +87,14 @@ def test_struct_with_enum():
8787
s1 = StructWithEnum()
8888
s1.unpack(packed)
8989
assert s1.font == HtmlFont.HTMLFONT_NONE
90-
assert s1.font_size == 20
90+
91+
92+
def test_sizeof():
93+
assert cstruct.sizeof("enum Dummy") == 4
94+
assert cstruct.sizeof("enum HtmlFont") == 2
95+
96+
97+
# def test_type():
98+
# color = cstruct.parse("enum Color : short { red, green, blue };")
99+
# assert color.__size__ == 2
100+
# assert cstruct.sizeof("enum Color") == 2

0 commit comments

Comments
 (0)