From 03288b1df6da35d72b525e0087b849fa53b844d0 Mon Sep 17 00:00:00 2001 From: ederag Date: Sat, 16 Nov 2019 13:24:34 +0100 Subject: [PATCH] accept activities starting with '#' --- src/hamster/lib/__init__.py | 10 ++++++++-- tests/stuff_test.py | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/hamster/lib/__init__.py b/src/hamster/lib/__init__.py index cbe8172b5..2b044a25b 100644 --- a/src/hamster/lib/__init__.py +++ b/src/hamster/lib/__init__.py @@ -337,15 +337,21 @@ def parse_fact(text, phase=None, res=None, date=None): if not m: break tag = m.group(1) - tags.append(tag) # strip the matched string (including #) + backup_text = remaining_text remaining_text = remaining_text[:m.start()] + # empty remaining text means that activity is starting with a '#' + if remaining_text: + tags.append(tag) + else: + remaining_text = backup_text + break # put tags back in input order res["tags"] = list(reversed(tags)) return parse_fact(remaining_text, "activity", res, date) if "activity" in phases: - activity = re.split("[@|#|,]", text, 1)[0] + activity = re.split("[@|,]", text, 1)[0] if looks_like_time(activity): # want meaningful activities return res diff --git a/tests/stuff_test.py b/tests/stuff_test.py index 6bd0de113..13bb70a0e 100644 --- a/tests/stuff_test.py +++ b/tests/stuff_test.py @@ -82,8 +82,8 @@ def test_description(self): def test_tags(self): # plain activity name - activity = Fact.parse("case, with added #de description #and, #some #tägs") - self.assertEqual(activity.activity, "case") + activity = Fact.parse("#case, with added #de description #and, #some #tägs") + self.assertEqual(activity.activity, "#case") self.assertEqual(activity.description, "with added #de description") self.assertEqual(set(activity.tags), set(["and", "some", "tägs"])) assert not activity.category