Skip to content

Commit 7650ab2

Browse files
authored
fix: add gobytes test - round-tripped & re-encoded (#396)
1 parent ce2b31b commit 7650ab2

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

_examples/gobytes/test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@
2222
assert empty_bytes == b"", "expected b'', got %r" % (empty_bytes,)
2323
print("Go empty bytes to Python: ", empty_bytes)
2424

25+
# Regression test for issue #359 (reverse direction): converting a 0-length
26+
# Python bytes to a Go []byte, then back, must not crash either.
27+
empty_from_bytes = go.Slice_byte.from_bytes(b"")
28+
print("Python empty bytes to Go: ", empty_from_bytes)
29+
roundtrip_bytes = bytes(empty_from_bytes)
30+
assert roundtrip_bytes == b"", "expected b'', got %r" % (roundtrip_bytes,)
31+
print("Go empty bytes round-trip: ", roundtrip_bytes)
32+
2533
print("OK")

main_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ Python bytes to Go: go.Slice_byte len: 4 handle: 3 [0, 1, 2, 3]
284284
Go bytes to Python: b'\x03\x04\x05'
285285
Go empty slice: go.Slice_byte len: 0 handle: 5 []
286286
Go empty bytes to Python: b''
287+
Python empty bytes to Go: go.Slice_byte len: 0 handle: 6 []
288+
Go empty bytes round-trip: b''
287289
OK
288290
`),
289291
})

0 commit comments

Comments
 (0)