home · contact · privacy
For testing, properly start parsing at first line, rather than jumping it.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 30 Sep 2025 23:04:06 +0000 (01:04 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 30 Sep 2025 23:04:06 +0000 (01:04 +0200)
src/ircplom/testing.py
src/tests/pingpong.txt

index 48f98d6ba1afccec446cbf93a98fda45fd259aba..8efc742098b039d6749fee89d182a8191832b99b 100644 (file)
@@ -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))
 
index ac3d0cd635908273984e1ff01e6588c346238003..f0e27fac32fc71c062ae6d537b0fb048b660bd3f 100644 (file)
@@ -1,4 +1,3 @@
-#
 > /connect foo.bar.baz foo:bar baz:foobarbazquux
 1 .$ isupport cleared
 1 .$ isupport:CHANTYPES set to: [#&]