diff --git a/tests/test_commands.py b/tests/test_commands.py index 9a609b9..e1f3600 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -536,3 +536,41 @@ async def test_look_no_here_line_when_alone(player, test_zone): output = "".join(c[0][0] for c in player.writer.write.call_args_list) assert "Here:" not in output + + +@pytest.mark.asyncio +async def test_quit_removes_player_from_zone(monkeypatch): + """Quitting removes player from zone contents.""" + from mudlib.commands import quit as quit_mod + from mudlib.player import players + + monkeypatch.setattr(quit_mod, "save_player", lambda p: None) + + terrain = [["." for _ in range(10)] for _ in range(10)] + zone = Zone( + name="qz", + width=10, + height=10, + toroidal=True, + terrain=terrain, + impassable=set(), + ) + writer = MagicMock() + writer.write = MagicMock() + writer.drain = AsyncMock() + writer.close = MagicMock() + p = Player( + name="quitter", + location=zone, + x=5, + y=5, + reader=MagicMock(), + writer=writer, + ) + players.clear() + players["quitter"] = p + + assert p in zone._contents + await quit_mod.cmd_quit(p, "") + assert p not in zone._contents + assert "quitter" not in players