From 389313ea8d89de8be9991ab84f7564b8caf0a067 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Fri, 26 Sep 2025 17:43:37 +0200 Subject: [PATCH] To testing "repeat" command, add optional replacement context. --- src/ircplom/testing.py | 34 ++++++++++++++++++++-------------- src/tests/test.txt | 34 ++++++++-------------------------- 2 files changed, 28 insertions(+), 40 deletions(-) diff --git a/src/ircplom/testing.py b/src/ircplom/testing.py index 22977a7..7bd422b 100644 --- a/src/ircplom/testing.py +++ b/src/ircplom/testing.py @@ -101,27 +101,33 @@ class TestingClientTui(ClientTui): assert isinstance(self._term, TestTerminal) self._q_keypresses = self._term._q_keypresses with self._path_test.open('r', encoding='utf8') as f: - self._playbook = tuple(line.rstrip() for line in f.readlines()) + self._playbook = [line.rstrip() for line in f.readlines()] self._playbook_anchors: dict[str, int] = {} while True: + inserts: list[str] = [] 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 (t := self.split_active_line(line)) and t[0] == 'repeat': - found_repeat = True - start_key, end_key = t[1].split(' ', maxsplit=1) - 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 + split = self.split_active_line(line) + if (not split) or split[0] != 'repeat': + continue + range_data = split[1].split(' ', maxsplit=2) + start_key, end_key = range_data[:2] + start = self._playbook_anchors[start_key] + 1 + end = self._playbook_anchors[end_key] + inserts = self._playbook[int(start):int(end)] + if len(range_data) == 3: + for jdx, insert in enumerate(inserts): + if (res := self.split_active_line(insert)): + inserts[jdx] = ' '.join([range_data[2]] + [res[1]]) + self._playbook = (self._playbook[:idx] + + inserts + + self._playbook[idx + 1:]) + break + if not inserts: + break self._playbook_idx = -1 self._play_till_next_log() diff --git a/src/tests/test.txt b/src/tests/test.txt index 7462aa0..acc8d08 100644 --- a/src/tests/test.txt +++ b/src/tests/test.txt @@ -2,6 +2,7 @@ # on /connect init databases, log in new windows > /connect foo.bar.baz foo:bar baz:foobarbazquux +|standard-clears-in |isupport-clear-in 1 $ isupport cleared 1 $ isupport:CHANTYPES set to: [#&] @@ -11,6 +12,7 @@ 1 $ caps cleared 1 $ users cleared 1 $ channels cleared +|standard-clears-out , $ DISCONNECTED # connect with values set by /connect, init CAP negotation @@ -345,13 +347,7 @@ repeat isupport-clear-in isupport-clear-out # test setting up second client, but 432 irrecoverably > /connect baz.bar.foo ?foo foo:foo -8 $ isupport cleared -8 $ isupport:CHANTYPES set to: [#&] -8 $ isupport:PREFIX set to: [(ov)@+] -8 $ isupport:USERLEN set to: [10] -8 $ caps cleared -8 $ users cleared -8 $ channels cleared +repeat standard-clears-in standard-clears-out 8 , $ DISCONNECTED 8 $ hostname set to: [baz.bar.foo] 8 $ port set to: [-1] @@ -359,30 +355,20 @@ repeat isupport-clear-in isupport-clear-out 8 $ user_wanted set to: [foo] 8 $ realname set to: [foo] 8 $ port set to: [6697] -8 $ connection_state set to: [connecting] -8 $ connection_state set to: [connected] +repeat conn0 conn1 8 , $ CONNECTED 1:8 > CAP LS :302 1:8 > USER foo 0 * :foo 1:8 > NICK :?foo 1:8 < :*.?.net 432 * ?foo :Erroneous nickname -8 $ isupport cleared -8 $ isupport:CHANTYPES set to: [#&] -8 $ isupport:PREFIX set to: [(ov)@+] -8 $ isupport:USERLEN set to: [10] +repeat isupport-clear-in isupport-clear-out 8 8 $ connection_state set to: [] , $ DISCONNECTED 8 !$ nickname refused for bad format, giving up # test failing third connection > /connect baz.baz.baz baz baz:baz -9 $ isupport cleared -9 $ isupport:CHANTYPES set to: [#&] -9 $ isupport:PREFIX set to: [(ov)@+] -9 $ isupport:USERLEN set to: [10] -9 $ caps cleared -9 $ users cleared -9 $ channels cleared +repeat standard-clears-in standard-clears-out 9 , $ DISCONNECTED 9 $ hostname set to: [baz.baz.baz] 9 $ port set to: [-1] @@ -390,18 +376,14 @@ repeat isupport-clear-in isupport-clear-out 9 $ user_wanted set to: [baz] 9 $ realname set to: [baz] 9 $ port set to: [6697] -9 $ connection_state set to: [connecting] -9 $ connection_state set to: [connected] +repeat conn0 conn1 9 , $ CONNECTED 2:9 > CAP LS :302 2:9 > USER baz 0 * :baz 2:9 > NICK :baz 2: < FAKE_IRC_CONN_ABORT_EXCEPTION 9 $ connection_state set to: [broken: FAKE_IRC_CONN_ABORT_EXCEPTION] -9 $ isupport cleared -9 $ isupport:CHANTYPES set to: [#&] -9 $ isupport:PREFIX set to: [(ov)@+] -9 $ isupport:USERLEN set to: [10] +repeat isupport-clear-in isupport-clear-out 9 9 $ connection_state set to: [] , $ DISCONNECTED -- 2.30.2