# Path: chopsticks/pencode.py
# def pencode(obj):
#     """Encode the given Python primitive structure, returning a byte string."""
#     p = Pencoder()
#     p._pencode(obj, p.backrefs, p.out)
#     return p.getvalue()
# 
# def pdecode(buf):
#     """Decode a pencoded byte string to a structure."""
#     return PDecoder().decode(buf)


import math
import pytest
from hypothesis import example, given, strategies
from chopsticks.pencode import pencode, pdecode
def test_roundtrip_unicode(s):
    """We can round-trip a unicode string."""
    assert_roundtrip(s)


@given(ascii_binary)
def test_roundtrip_bytes(s):
    """We can round-trip Bytes."""
    assert_roundtrip(s)


@given(strategies.lists(mutables | immutables))
def test_roundtrip_list(l):
    """We can round-trip a list."""
    assert_roundtrip(l)


def test_roundtrip_self_referential():
    """We can round-trip a self-referential structure."""
    a = []
    a.append(a)
    assert_roundtrip(a)


def test_roundtrip_backref():
    """References to the same object are preserved."""
    foo = 'foo'
    obj = [foo, foo]
    buf = pencode(obj)
    assert isinstance(buf, bytes)

# Path: chopsticks/pencode.py
# def pencode(obj):
#     """Encode the given Python primitive structure, returning a byte string."""
#     p = Pencoder()
#     p._pencode(obj, p.backrefs, p.out)
#     return p.getvalue()
# 
# def pdecode(buf):
#     """Decode a pencoded byte string to a structure."""
#     return PDecoder().decode(buf)


# Path: tests/test_pencode.py
import math
import pytest
from hypothesis import example, given, strategies
from chopsticks.pencode import pencode, pdecode

def test_roundtrip_unicode(s):
    """We can round-trip a unicode string."""
    assert_roundtrip(s)


@given(ascii_binary)
def test_roundtrip_bytes(s):
    """We can round-trip Bytes."""
    assert_roundtrip(s)


@given(strategies.lists(mutables | immutables))
def test_roundtrip_list(l):
    """We can round-trip a list."""
    assert_roundtrip(l)


def test_roundtrip_self_referential():
    """We can round-trip a self-referential structure."""
    a = []
    a.append(a)
    assert_roundtrip(a)


def test_roundtrip_backref():
    """References to the same object are preserved."""
    foo = 'foo'
    obj = [foo, foo]
    buf = pencode(obj)
    assert isinstance(buf, bytes)

    a, b = pdecode(buf)