Skip to content

Commit

Permalink
test_switch_issue_913 tests added, Issue #913
Browse files Browse the repository at this point in the history
  • Loading branch information
arekbulski committed Mar 26, 2021
1 parent ce54a16 commit e1233f5
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2177,4 +2177,40 @@ def test_struct_copy():

common(d, b"\x00\x01\x02", Container(a=1,b=2), 3)
common(d_copy, b"\x00\x01\x02", Container(a=1,b=2), 3)


def test_switch_issue_913():
enum = Enum(Byte, Zero=0, One=1, Two=2)
mapping = {
enum.Zero: Pass,
enum.One: Int8ul,
enum.Two: Int16ul,
}

d = Switch(keyfunc = this.x, cases = mapping)
common2(d, b"", None, 0, x="Zero")
common2(d, b"\xab", 171, 1, x="One")
common2(d, b"\x09\x00", 9, 2, x="Two")

def test_switch_issue_913_without_enum():
mapping = {
"Zero": Pass,
"One": Int8ul,
"Two": Int16ul,
}

d = Switch(keyfunc = this.x, cases = mapping)
common2(d, b"", None, 0, x="Zero")
common2(d, b"\xab", 171, 1, x="One")
common2(d, b"\x09\x00", 9, 2, x="Two")

def test_switch_issue_913_on_integers():
mapping = {
0: Pass,
1: Int8ul,
2: Int16ul,
}

d = Switch(keyfunc = this.x, cases = mapping)
common2(d, b"", None, 0, x=0)
common2(d, b"\xab", 171, 1, x=1)
common2(d, b"\x09\x00", 9, 2, x=2)

0 comments on commit e1233f5

Please sign in to comment.