Skip to content

Commit

Permalink
restrict description barrier to double comma
Browse files Browse the repository at this point in the history
This is breaking: starting a description with a single comma
does not work any longer. A double coma is required instead.
  • Loading branch information
ederag committed Nov 23, 2019
1 parent 9cce2d7 commit 42d3c05
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
18 changes: 4 additions & 14 deletions src/hamster/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,11 @@ def serialized_name(self):
if self.category:
res += "@%s" % self.category

force_tag_barrier = False
if ',' in self.activity:
if self.description:
res += ',, '
# otherwise the description double comma
# might be swallowed as a tag barrier
force_tag_barrier = True
elif self.description:
res += ', '
res += self.description

if (force_tag_barrier
or '#' in self.activity
res += self.description

if ('#' in self.activity
or '#' in self.category
or '#' in self.description
):
Expand Down Expand Up @@ -386,9 +379,6 @@ def parse_fact(text, phase=None, res=None, date=None):
if "description" in phases:
# first look for double comma (description hard left boundary)
head, sep, description = text.partition(",,")
if not sep:
# hard boundary not found, try legacy soft boundary
head, sep, description = text.partition(",")
res["description"] = description.strip()
return parse_fact(head, "activity", res, date)

Expand Down
14 changes: 7 additions & 7 deletions tests/stuff_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_category(self):

def test_description(self):
# plain activity name
activity = Fact.parse("case, with added descriptiön")
activity = Fact.parse("case,, with added descriptiön")
self.assertEqual(activity.activity, "case")
self.assertEqual(activity.description, "with added descriptiön")
assert not activity.category
Expand All @@ -82,7 +82,7 @@ def test_description(self):

def test_tags(self):
# plain activity name
activity = Fact.parse("#case, description with #hash,, #and, #some #tägs")
activity = Fact.parse("#case,, description with #hash,, #and, #some #tägs")
self.assertEqual(activity.activity, "#case")
self.assertEqual(activity.description, "description with #hash")
self.assertEqual(set(activity.tags), set(["and", "some", "tägs"]))
Expand All @@ -92,7 +92,7 @@ def test_tags(self):

def test_full(self):
# plain activity name
activity = Fact.parse("1225-1325 case@cat, description #ta non-tag,, #tag #bäg")
activity = Fact.parse("1225-1325 case@cat,, description #ta non-tag,, #tag #bäg")
self.assertEqual(activity.start_time.strftime("%H:%M"), "12:25")
self.assertEqual(activity.end_time.strftime("%H:%M"), "13:25")
self.assertEqual(activity.activity, "case")
Expand All @@ -101,7 +101,7 @@ def test_full(self):
self.assertEqual(set(activity.tags), set(["bäg", "tag"]))

def test_copy(self):
fact1 = Fact.parse("12:25-13:25 case@cat, description #tag #bäg")
fact1 = Fact.parse("12:25-13:25 case@cat,, description #tag #bäg")
fact2 = fact1.copy()
self.assertEqual(fact1.start_time, fact2.start_time)
self.assertEqual(fact1.end_time, fact2.end_time)
Expand All @@ -119,7 +119,7 @@ def test_copy(self):
self.assertEqual(fact3.tags, ["changed"])

def test_comparison(self):
fact1 = Fact.parse("12:25-13:25 case@cat, description #tag #bäg")
fact1 = Fact.parse("12:25-13:25 case@cat,, description #tag #bäg")
fact2 = fact1.copy()
self.assertEqual(fact1, fact2)
fact2 = fact1.copy()
Expand Down Expand Up @@ -149,12 +149,12 @@ def test_comparison(self):

def test_decimal_in_activity(self):
# cf. issue #270
fact = Fact.parse("12:25-13:25 10.0@ABC, Two Words #tag #bäg")
fact = Fact.parse("12:25-13:25 10.0@ABC,, Two Words #tag #bäg")
self.assertEqual(fact.activity, "10.0")
self.assertEqual(fact.category, "ABC")
self.assertEqual(fact.description, "Two Words")
# should not pick up a time here
fact = Fact.parse("10.00@ABC, Two Words #tag #bäg")
fact = Fact.parse("10.00@ABC,, Two Words #tag #bäg")
self.assertEqual(fact.activity, "10.00")
self.assertEqual(fact.category, "ABC")
self.assertEqual(fact.description, "Two Words")
Expand Down

0 comments on commit 42d3c05

Please sign in to comment.