Files
PeakRDL-BusDecoder/tests/body/test_body.py
Arnav Sacheti b1f1bf983a Refactor tests (better grouping + cocotb support) (#15)
* initial refactor

* fix cocotb tests

* fix typecheck

* install verilator
2025-10-26 17:56:35 -07:00

51 lines
1.4 KiB
Python

from peakrdl_busdecoder.body import Body
class TestBody:
"""Test the base Body class."""
def test_empty_body(self) -> None:
"""Test empty body returns empty string."""
body = Body()
assert str(body) == ""
assert not body # Should be falsy when empty
def test_add_single_line(self) -> None:
"""Test adding a single line to body."""
body = Body()
body += "line1"
assert str(body) == "line1"
assert body # Should be truthy when not empty
def test_add_multiple_lines(self) -> None:
"""Test adding multiple lines to body."""
body = Body()
body += "line1"
body += "line2"
body += "line3"
expected = "line1\nline2\nline3"
assert str(body) == expected
def test_add_returns_self(self) -> None:
"""Test that add operation returns self for chaining."""
body = Body()
body += "line1"
body += "line2"
# Chaining works because += returns self
assert len(body.lines) == 2
def test_add_nested_body(self) -> None:
"""Test adding another body as a line."""
outer = Body()
inner = Body()
inner += "inner1"
inner += "inner2"
outer += "outer1"
outer += inner
outer += "outer2"
expected = "outer1\ninner1\ninner2\nouter2"
assert str(outer) == expected