home · contact · privacy
For testing, allow nesting of repeat ranges.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 26 Sep 2025 12:31:12 +0000 (14:31 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 26 Sep 2025 12:31:12 +0000 (14:31 +0200)
src/ircplom/testing.py

index 23062e540243109bed8bf5d865f74669809adc27..b97e09f6b42d4d707cfab7932eb80c1e38403e37 100644 (file)
@@ -103,9 +103,28 @@ class TestingClientTui(ClientTui):
         with self._path_test.open('r', encoding='utf8') as f:
             self._playbook = tuple(line[:-1] for line in f.readlines())
         self._playbook_anchors: dict[str, int] = {}
-        for idx, line in enumerate(self._playbook):
-            if line[:1] == '|':
-                self._playbook_anchors[line[1:]] = idx + 1
+        while True:
+            self._playbook_anchors.clear()
+            for idx, line in enumerate(self._playbook):
+                if line[:1] == '|':
+                    self._playbook_anchors[line[1:]] = idx
+            found_repeat = False
+            for idx, line in enumerate(self._playbook):
+                if line[:1] in '#|' or not line.strip():
+                    continue
+                context, msg = line.split(' ', maxsplit=1)
+                if context == 'repeat':
+                    found_repeat = True
+                    start_key, end_key = msg.split(' ')
+                    start = self._playbook_anchors[start_key] + 1
+                    end = self._playbook_anchors[end_key]
+                    self._playbook = (self._playbook[:idx]
+                                      + self._playbook[int(start):int(end)]
+                                      + self._playbook[idx + 1:])
+                    break
+            if found_repeat:
+                continue
+            break
         self._playbook_idx = -1
         self._play_till_next_log()
 
@@ -147,14 +166,6 @@ class TestingClientTui(ClientTui):
             if line[:1] in '#|' or not line.strip():
                 continue
             context, msg = line.split(' ', maxsplit=1)
-            if context == 'repeat':
-                start_key, end_key = msg.split(' ')
-                start = self._playbook_anchors[start_key]
-                end = self._playbook_anchors[end_key]
-                self._playbook = (self._playbook[:self._playbook_idx + 1]
-                                  + self._playbook[int(start):int(end)]
-                                  + self._playbook[self._playbook_idx + 1:])
-                continue
             if context == '>':
                 for c in msg:
                     self._q_keypresses.put(c)