Example #1
0
 def test__comparison_parsing(self):
     from minisparql import _expression_parser
     p = _expression_parser()
     toks = p.parseString('(?a < 10)')
     self.assertTrue(toks is not None)
     self.assertEqual(1, len(toks))
     e = toks[0]
     self.assertTrue(e.resolve(dict(a=1)))
     self.assertTrue(e.resolve(dict(a=9)))
     self.assertFalse(e.resolve(dict(a=10)))
Example #2
0
 def test__function_parsing(self):
     from minisparql import _expression_parser
     p = _expression_parser()
     for expr, a, expected in [('bound(?a)', None, False),
                               ('bound(?a)', 'h', True),
                               ('isBlank(?a)', '', True),
                               ('isBlank(?a)', 'f', False)]:
         toks = p.parseString(expr)
         self.assertTrue(toks is not None)
         self.assertEqual(1, len(toks))
         e = toks[0]
         self.assertEqual(expected, e.resolve(dict(a=a)))
Example #3
0
 def test__arithmetic_parsing(self):
     from minisparql import _expression_parser
     p = _expression_parser()
     toks = p.parseString('(?a + ?b * 2)')
     self.assertTrue(toks is not None)
     self.assertEqual(1, len(toks))
     e = toks[0]
     self.assertEqual(1, e.resolve(dict(a=1, b=0)))
     self.assertEqual(2, e.resolve(dict(a=2, b=0)))
     self.assertEqual(2, e.resolve(dict(a=0, b=1)))
     self.assertEqual(4, e.resolve(dict(a=0, b=2)))
     self.assertEqual(5, e.resolve(dict(a=1, b=2)))
     self.assertEqual(10, e.resolve(dict(a=2, b=4)))
Example #4
0
 def test__boolean_expression_parsing(self):
     from minisparql import _expression_parser
     p = _expression_parser()
     for expr, a, expected in [('(2 * ?a < 10)', 4, True),
                               ('(2 * ?a < 10)', 5, False),
                               ('(2 * ?a < 10 && ?a > 3)', 3, False),
                               ('(2 * ?a < 10 || ?a > 3)', 3, True),
                               ('(!(2 * ?a < 10))', 4, False)]: 
         toks = p.parseString(expr)
         self.assertTrue(toks is not None)
         self.assertEqual(1, len(toks))
         e = toks[0]
         self.assertEqual(expected, e.resolve(dict(a=a)))
Example #5
0
 def test__regex_parsing(self):
     from minisparql import _expression_parser
     p = _expression_parser()
     for expr, a, expected in [('regex(?a, "yes")', "yes", True),
                               ('regex(?a, "no")', "yes", False),
                               ('regex(?a, "^start")', "starting", True),
                               ('regex(?a, "^start")', "not starting", False),
                               ('regex(?a, "end$")', "does end", True),
                               ('regex(?a, "end$")', "neverending", False),
                               ('regex(?a, "UPPER", "i")', "upper", True)]:
         toks = p.parseString(expr)
         self.assertTrue(toks is not None)
         self.assertEqual(1, len(toks))
         e = toks[0]
         self.assertEqual(expected, e.resolve(dict(a=a)))