Commit ef7a1150 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Fix negation of ordinal tag filters

When an ordinal tag filter is negated (i.e. -id:1), then this isn't seen
as a negation but as an ordinal tag filter with tag -id and value 1.
Which isn't likely to exist, resulting in every todo item to be excluded
from the result.
parent 2f8b1da0
...@@ -314,6 +314,14 @@ class ListCommandTest(CommandTest): ...@@ -314,6 +314,14 @@ class ListCommandTest(CommandTest):
self.assertEqual(self.output, "") self.assertEqual(self.output, "")
self.assertEqual(self.errors, "option -z not recognized\n") self.assertEqual(self.errors, "option -z not recognized\n")
def test_list42(self):
command = ListCommand(["-x", "+Project1", "-id:1"], self.todolist, self.out,
self.error)
command.execute()
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n")
self.assertEqual(self.errors, "")
def test_help(self): def test_help(self):
command = ListCommand(["help"], self.todolist, self.out, self.error) command = ListCommand(["help"], self.todolist, self.out, self.error)
command.execute() command.execute()
......
...@@ -54,17 +54,20 @@ class ExpressionCommand(Command): ...@@ -54,17 +54,20 @@ class ExpressionCommand(Command):
args = self.args args = self.args
for arg in args: for arg in args:
# when a word starts with -, it should be negated
is_negated = len(arg) > 1 and arg[0] == '-'
arg = arg[1:] if is_negated else arg
if re.match(Filter.ORDINAL_TAG_MATCH, arg): if re.match(Filter.ORDINAL_TAG_MATCH, arg):
argfilter = Filter.OrdinalTagFilter(arg) argfilter = Filter.OrdinalTagFilter(arg)
elif re.match(Filter.PRIORITY_MATCH, arg): elif re.match(Filter.PRIORITY_MATCH, arg):
argfilter = Filter.PriorityFilter(arg) argfilter = Filter.PriorityFilter(arg)
elif len(arg) > 1 and arg[0] == '-':
# when a word starts with -, exclude it
argfilter = Filter.GrepFilter(arg[1:])
argfilter = Filter.NegationFilter(argfilter)
else: else:
argfilter = Filter.GrepFilter(arg) argfilter = Filter.GrepFilter(arg)
if is_negated:
argfilter = Filter.NegationFilter(argfilter)
result.append(argfilter) result.append(argfilter)
return result return result
......
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