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):
self.assertEqual(self.output, "")
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):
command = ListCommand(["help"], self.todolist, self.out, self.error)
command.execute()
......
......@@ -54,17 +54,20 @@ class ExpressionCommand(Command):
args = self.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):
argfilter = Filter.OrdinalTagFilter(arg)
elif re.match(Filter.PRIORITY_MATCH, 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:
argfilter = Filter.GrepFilter(arg)
if is_negated:
argfilter = Filter.NegationFilter(argfilter)
result.append(argfilter)
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