Skip to content

Commit

Permalink
Fixed problem comparing enums to enums.
Browse files Browse the repository at this point in the history
Fixes #113
  • Loading branch information
d0c-s4vage committed Jan 8, 2020
1 parent bdada9f commit 38015f4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[![PyPI Statistics](https://img.shields.io/pypi/dm/pfp)](https://pypistats.org/packages/pfp)
[![Latest Release](https://img.shields.io/pypi/v/pfp)](https://pypi.python.org/pypi/pfp/)
[![Documentation Status](https://readthedocs.org/projects/pfp/badge/?version=latest)](https://pfp.readthedocs.io/en/latest/)
[![Coverage Status](https://coveralls.io/repos/github/d0c-s4vage/pfp/badge.svg?branch=master)](https://coveralls.io/github/d0c-s4vage/pfp?branch=master)

# pfp

Expand Down
4 changes: 2 additions & 2 deletions pfp/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -1983,13 +1983,13 @@ def __init__(
bitfield_left_right=bitfield_left_right,
)

def _pfp__parse(self, stream, save_offset=False):
def _pfp__parse(self, stream, save_offset=False, set_val=True):
"""Parse the IO stream for this enum
:stream: An IO stream that can be read from
:returns: The number of bytes parsed
"""
res = super(Enum, self)._pfp__parse(stream, save_offset)
res = super(Enum, self)._pfp__parse(stream, save_offset, set_val=set_val)

if self._pfp__value in self.enum_vals:
self.enum_name = self.enum_vals[self._pfp__value]
Expand Down
16 changes: 16 additions & 0 deletions tests/test_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,22 @@ def test_enum_with_bitfield_inline(self):
self.assertEqual(dom.test2, 1)
self.assertEqual(dom.test2.enum_name, "BLAH2")

def test_enum_compared_to_enum(self):
dom = self._test_parse_build(
"\x00\x00\x00\x01",
"""
BigEndian();
enum <uchar> TEST_ENUM {
BLAH1,
};
do {
TEST_ENUM test = BLAH1;
} while (test == BLAH1);
""",
)
self.assertEqual(len(dom.test), 4)


if __name__ == "__main__":
unittest.main()

0 comments on commit 38015f4

Please sign in to comment.