Beispiel #1
0
 def test_make_expr_filter (self):
     self.assertEquals (Filter, type(make_expr_filter ('type="Context"', True))) 
     
     self.assertEquals("expecting a Boolean got a String: field:name", catch_exception(lambda: make_expr_filter ('name', True)))
     self.assertEquals("expecting a Boolean got a Date: field:date_due", catch_exception(lambda: make_expr_filter ('due', True)))
     self.assertEquals("expecting a Date got a String: field:name", catch_exception(lambda: make_expr_filter ('due = name', True)))
     self.assertEquals('found "name" not: [\'AND\', \'OR\', \'EQ\', \'NE\', \'CB\']', catch_exception(lambda: make_expr_filter ('not name', True)))
Beispiel #2
0
    def test_make_expr_filter(self):
        self.assertEquals(Filter,
                          type(make_expr_filter('type="Context"', True)))

        self.assertEquals(
            "expecting a Boolean got a String: field:name",
            catch_exception(lambda: make_expr_filter('name', True)))
        self.assertEquals(
            "expecting a Boolean got a Date: field:date_due",
            catch_exception(lambda: make_expr_filter('due', True)))
        self.assertEquals(
            "expecting a Date got a String: field:name",
            catch_exception(lambda: make_expr_filter('due = name', True)))
        self.assertEquals(
            'found "name" not: [\'AND\', \'OR\', \'EQ\', \'NE\', \'CB\']',
            catch_exception(lambda: make_expr_filter('not name', True)))
Beispiel #3
0
    def test_make_command_filter(self):
        self.assertEquals(None, make_command_filter("nonsense"))
        self.assertEquals(Sort, type(make_command_filter("sort Task name")))
        self.assertEquals(Flatten,
                          type(make_command_filter("flatten Project")))
        self.assertEquals(Prune, type(make_command_filter("prune Folder")))

        self.assertEquals(
            "prune takes one node type argument, got: prune x y",
            catch_exception(lambda: make_command_filter("prune x y")))
        self.assertEquals(
            "no such node type in prune: Floder",
            catch_exception(lambda: make_command_filter("prune Floder")))
        self.assertEquals(
            "flatten takes one node type argument, got: flatten x y",
            catch_exception(lambda: make_command_filter("flatten x y")))
        self.assertEquals(
            "no such node type in flatten: Floder",
            catch_exception(lambda: make_command_filter("flatten Floder")))
        self.assertEquals(
            "no such node type in sort: Kangaroo",
            catch_exception(lambda: make_command_filter("sort Kangaroo ")))
        self.assertEquals(
            "sort takes two arguments, node type and field, got: sort x y z",
            catch_exception(lambda: make_command_filter("sort x y z")))
        self.assertEquals(
            "no such sortable field:weight",
            catch_exception(lambda: make_command_filter("sort Task weight")))
Beispiel #4
0
 def test_tokenisation(self):
     self.assertEquals('aa,OB,bb,CB,cc', pretty_tokens(tokenise ('aa(bb)cc')))
     self.assertEquals('aa,"bb",cc,EQ', pretty_tokens(tokenise ('aa"bb"cc=')))
     self.assertEquals('aa,"bb",cc,EQ', pretty_tokens(tokenise ("aa'bb'cc=")))
     self.assertEquals('a,NE,b', pretty_tokens(tokenise ("a != b")))
     self.assertEquals('a,AND,b', pretty_tokens(tokenise ("a and b")))
     self.assertEquals('a,OR,b', pretty_tokens(tokenise ("a or b")))
     self.assertEquals('a,CB,OR,OB,b', pretty_tokens(tokenise ("a)or(b")))
     self.assertEquals('NOT,a', pretty_tokens(tokenise ("! a")))
     self.assertEquals('ab,BS,cd', pretty_tokens(tokenise ("ab\\cd")))
     self.assertEquals('work', pretty_tokens(tokenise ('work'))) # Contains an or
     
     self.assertEquals("unclosed quote", catch_exception(lambda: tokenise ('a"b')))
Beispiel #5
0
    def test_tokenisation(self):
        self.assertEquals('aa,OB,bb,CB,cc',
                          pretty_tokens(tokenise('aa(bb)cc')))
        self.assertEquals('aa,"bb",cc,EQ',
                          pretty_tokens(tokenise('aa"bb"cc=')))
        self.assertEquals('aa,"bb",cc,EQ',
                          pretty_tokens(tokenise("aa'bb'cc=")))
        self.assertEquals('a,NE,b', pretty_tokens(tokenise("a != b")))
        self.assertEquals('a,AND,b', pretty_tokens(tokenise("a and b")))
        self.assertEquals('a,OR,b', pretty_tokens(tokenise("a or b")))
        self.assertEquals('a,CB,OR,OB,b', pretty_tokens(tokenise("a)or(b")))
        self.assertEquals('NOT,a', pretty_tokens(tokenise("! a")))
        self.assertEquals('ab,BS,cd', pretty_tokens(tokenise("ab\\cd")))
        self.assertEquals('work',
                          pretty_tokens(tokenise('work')))  # Contains an or

        self.assertEquals("unclosed quote",
                          catch_exception(lambda: tokenise('a"b')))
Beispiel #6
0
 def test_make_command_filter (self):
     self.assertEquals (None, make_command_filter ("nonsense"))
     self.assertEquals (Sort, type(make_command_filter ("sort Task name")))
     self.assertEquals (Flatten, type(make_command_filter ("flatten Project")))
     self.assertEquals (Prune, type(make_command_filter ("prune Folder")))
     
     self.assertEquals("prune takes one node type argument, got: prune x y", catch_exception(lambda: make_command_filter ("prune x y")))
     self.assertEquals("no such node type in prune: Floder", catch_exception(lambda: make_command_filter ("prune Floder")))
     self.assertEquals("flatten takes one node type argument, got: flatten x y", catch_exception(lambda: make_command_filter ("flatten x y")))
     self.assertEquals("no such node type in flatten: Floder", catch_exception(lambda: make_command_filter ("flatten Floder")))
     self.assertEquals("no such node type in sort: Kangaroo", catch_exception(lambda: make_command_filter ("sort Kangaroo ")))
     self.assertEquals("sort takes two arguments, node type and field, got: sort x y z", catch_exception(lambda: make_command_filter ("sort x y z")))
     self.assertEquals("no such sortable field:weight", catch_exception(lambda: make_command_filter ("sort Task weight")))