diff --git a/GTG/core/tasks.py b/GTG/core/tasks.py index 2c960239a..f867639a6 100644 --- a/GTG/core/tasks.py +++ b/GTG/core/tasks.py @@ -43,7 +43,7 @@ # REGEXES # ------------------------------------------------------------------------------ -TAG_REGEX = re.compile(r'^\B\@\w+(\-\w+)*\,*') +TAG_LINE_REGEX = re.compile(r'^\B\@\w+(\-\w+)*\,*.*') SUB_REGEX = re.compile(r'\{\!.+\!\}') @@ -307,16 +307,19 @@ def title(self, value) -> None: @GObject.Property(type=str) def excerpt(self) -> str: - if not self.content: - return '' - # Strip tags - txt = TAG_REGEX.sub('', self.content) + txt = TAG_LINE_REGEX.sub('', self.content) # Strip subtasks txt = SUB_REGEX.sub('', txt) - return f'{txt.strip()[:80]}…' + # Strip whitespace + txt = txt.strip() + + if not txt: + return '' + + return f'{txt[:80]}…' def add_tag(self, tag: Tag) -> None: diff --git a/tests/core/test_task.py b/tests/core/test_task.py index d33fe53aa..86e43ce48 100644 --- a/tests/core/test_task.py +++ b/tests/core/test_task.py @@ -35,7 +35,7 @@ def test_title(self): self.assertEqual(task.title, 'My Title') - def test_excerpt(self): + def test_excerpt_normal(self): task = Task(id=uuid4(), title='A Task') self.assertEqual(task.excerpt, '') @@ -51,6 +51,38 @@ def test_excerpt(self): self.assertEqual(task.excerpt, expected) + def test_excerpt_empty_task(self): + task = Task(id=uuid4(), title='A Task') + + self.assertEqual(task.excerpt, '') + + task.content = '' + + self.assertEqual(task.excerpt, '') + + + def test_excerpt_only_tags(self): + task = Task(id=uuid4(), title='A Task') + + self.assertEqual(task.excerpt, '') + + task.content = '@sometag, @someother' + + self.assertEqual(task.excerpt, '') + + + def test_excerpt_only_whitespace(self): + task = Task(id=uuid4(), title='A Task') + + self.assertEqual(task.excerpt, '') + + task.content = (' ' + '' + ' ') + + self.assertEqual(task.excerpt, '') + + def test_toggle_active_single(self): task = Task(id=uuid4(), title='A Task')