From: Christian Heller Date: Tue, 30 Sep 2025 23:04:06 +0000 (+0200) Subject: For testing, properly start parsing at first line, rather than jumping it. X-Git-Url: https://plomlompom.com/repos/?a=commitdiff_plain;h=cfb583576fabb9393d144740fb21a8e3bc6bf897;p=ircplom For testing, properly start parsing at first line, rather than jumping it. --- diff --git a/src/ircplom/testing.py b/src/ircplom/testing.py index 48f98d6..8efc742 100644 --- a/src/ircplom/testing.py +++ b/src/ircplom/testing.py @@ -158,7 +158,8 @@ class _Playbook: anchors[line[1:]] = idx if not expand_parsed(_TOK_REPEAT, repeat, anchors=anchors): break - self._lines = [ln for ln in self._lines if ln[:1] != _CHAR_ANCHOR] + self._lines = [ln for ln in self._lines + if ln and ln[:1] not in {_CHAR_ANCHOR, _CHAR_COMMENT}] self._idx = 0 @property @@ -168,7 +169,7 @@ class _Playbook: def ensure_has_started(self) -> None: 'Check if still at beginning, and if so, play till at next log line.' if self._idx == 0: - self._play_till_next_log() + self._play_till_log() def next_log(self) -> tuple[int, tuple[int, ...], str]: 'Return index, win IDs, and context of next expected log line.' @@ -178,12 +179,12 @@ class _Playbook: expected_win_ids = tuple( int(idx) for idx in context.split(_CHAR_WIN_ID_SEP) if idx) used_idx = self._idx - self._play_till_next_log() + self._idx += 1 + self._play_till_log() return used_idx, expected_win_ids, msg - def _play_till_next_log(self) -> None: + def _play_till_log(self) -> None: while True: - self._idx += 1 if (result := self._split_active_line(self._current_line)): context, msg = result if context == _CHAR_PROMPT: @@ -197,11 +198,12 @@ class _Playbook: client.conn.put_server_msg(msg) else: break + self._idx += 1 @staticmethod def _split_active_line(line: str) -> Optional[tuple[str, ...]]: 'Return 2-items tuple of split line, or None if empty/comment/anchor.' - if line[:1] == _CHAR_COMMENT or _CHAR_CONTEXT_SEP not in line: + if _CHAR_CONTEXT_SEP not in line: return None return tuple(line.split(_CHAR_CONTEXT_SEP, maxsplit=1)) diff --git a/src/tests/pingpong.txt b/src/tests/pingpong.txt index ac3d0cd..f0e27fa 100644 --- a/src/tests/pingpong.txt +++ b/src/tests/pingpong.txt @@ -1,4 +1,3 @@ -# > /connect foo.bar.baz foo:bar baz:foobarbazquux 1 .$ isupport cleared 1 .$ isupport:CHANTYPES set to: [#&]