From d4d0c1a19f5fc5df0f082df1fb7323141175a310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=A4fer?= Date: Sun, 10 May 2020 11:08:05 +0200 Subject: Add function to calculate unique prefix of two strings --- test/test_common.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/test_common.py b/test/test_common.py index d7bc2b8b..b6560fc9 100644 --- a/test/test_common.py +++ b/test/test_common.py @@ -11,7 +11,7 @@ from poezio.common import (_datetime_tuple as datetime_tuple, get_utc_time, get_local_time, shell_split, _find_argument_quoted as find_argument_quoted, _find_argument_unquoted as find_argument_unquoted, parse_str_to_secs, - parse_secs_to_str, safeJID) + parse_secs_to_str, safeJID, unique_prefix_of) def test_utc_time(): delta = timedelta(seconds=-3600) @@ -63,3 +63,22 @@ def test_parse_secs_to_str(): def test_safeJID(): assert safeJID('toto@titi/tata') == JID('toto@titi/tata') assert safeJID('toto@…') == JID('') + +def test_unique_prefix_of__no_shared_prefix(): + assert unique_prefix_of("a", "b") == "a" + assert unique_prefix_of("foo", "bar") == "f" + assert unique_prefix_of("foo", "") == "f" + +def test_unique_prefix_of__equal(): + assert unique_prefix_of("foo", "foo") == "foo" + +def test_unique_prefix_of__a_prefix(): + assert unique_prefix_of("foo", "foobar") == "foo" + +def test_unique_prefix_of__b_prefix(): + assert unique_prefix_of("foobar", "foo") == "foob" + +def test_unique_prefix_of__normal_shared_prefix(): + assert unique_prefix_of("foobar", "foobaz") == "foobar" + assert unique_prefix_of("fnord", "funky") == "fn" + assert unique_prefix_of("asbestos", "aspergers") == "asb" -- cgit v1.2.3 From c1863addfd33d3d3f3f03bcb036a0966097914cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=A4fer?= Date: Sun, 10 May 2020 14:38:43 +0200 Subject: Add function to find a tab by unique prefix --- test/test_tabs.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test') diff --git a/test/test_tabs.py b/test/test_tabs.py index 0a6930d4..6989bd67 100644 --- a/test/test_tabs.py +++ b/test/test_tabs.py @@ -183,3 +183,25 @@ def test_slice(): tabs.append(dummy3) assert tabs[1:2][0] is dummy2 + +def test_find_by_unique_prefix(): + DummyTab.reset() + tabs = Tabs(h) + t1 = DummyTab() + t2 = DummyTab() + t3 = DummyTab() + tabs.append(t1) + tabs.append(t2) + tabs.append(t3) + + t1.name = "foo" + t2.name = "bar" + t3.name = "fnord" + + assert tabs.find_by_unique_prefix("f") == (True, None) + assert tabs.find_by_unique_prefix("b") == (True, t2) + assert tabs.find_by_unique_prefix("fo") == (True, t1) + assert tabs.find_by_unique_prefix("fn") == (True, t3) + assert tabs.find_by_unique_prefix("fx") == (False, None) + assert tabs.find_by_unique_prefix("x") == (False, None) + assert tabs.find_by_unique_prefix("") == (True, None) -- cgit v1.2.3