Commit 46f10988 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Only remove one (key,value) pair from tag list when setting a new value.

This fixes a problem where a todo had multiple occurrences of a tag,
or where the same value occurred in other tags than the tag to be set.

Only one instance of the tag should be set to the new value.
parent 55585430
......@@ -79,7 +79,7 @@ class TodoBase(object):
if not p_force_add and value:
# remove old value from the tags
self.fields['tags'] = [t for t in self.fields['tags'] \
if t[0] != p_key and t[1] != value]
if not (t[0] == p_key and t[1] == value)]
self.src = re.sub(
r'\b' + p_key + ':' + value + r'\b',
......
......@@ -44,6 +44,22 @@ class TodoBaseTester(unittest.TestCase):
self.assertTrue(re.search(r'\bfoo:baz\b', todo.src))
self.assertFalse(re.search(r'\bfoo:bar\b', todo.src))
def test_set_tag_double_value(self):
todo = TodoBase.TodoBase("(C) Foo foo:bar baz:bar")
todo.set_tag('foo', 'blah');
self.assertTrue(todo.has_tag('foo'))
self.assertTrue(todo.tag_value('foo'), 'blah')
self.assertTrue(todo.has_tag('baz'))
self.assertTrue(todo.tag_value('baz'), 'bar')
def test_set_tag_double_tag(self):
todo = TodoBase.TodoBase("(C) Foo foo:bar foo:baz")
todo.set_tag('foo', 'blah')
self.assertTrue(todo.has_tag('foo', 'blah'))
self.assertTrue(todo.has_tag('foo', 'bar') or todo.has_tag('foo', 'baz'))
def test_set_tag_empty_value(self):
todo = TodoBase.TodoBase("(C) Foo foo:bar foo:baz")
todo.set_tag('foo')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment