A semantic search engine for source code https://bitshift.benkurtovic.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 10 години
преди 10 години
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from __future__ import unicode_literals
  2. import unittest
  3. from bitshift.query import parse_query
  4. TESTS = [
  5. # Text
  6. ("test", "Tree(Text(String(u'test')))"),
  7. ("re:test", "Tree(Text(Regex(u'test')))"),
  8. # Language
  9. ("language:python", "Tree(Language(Python))"),
  10. ("language:py", "Tree(Language(Python))"),
  11. ("l:r:r..y", "Tree(Language(Ruby))"),
  12. ("lang:re:py|c", "Tree(BinaryOp(Language(C), OR, Language(Python)))"),
  13. # Author
  14. ('"author:Ben Kurtovic"', "Tree(Author(String(u'Ben Kurtovic')))"),
  15. (r"'a:re:b.*?\sk.*?'", r"Tree(Author(Regex(u'b.*?\\sk.*?')))"),
  16. # Date
  17. ("'create:before:Jan 1, 2014'",
  18. "Tree(Date(CREATE, BEFORE, 2014-01-01 00:00:00))"),
  19. ("'modify:after:2010-05-09 10:11:12'",
  20. "Tree(Date(MODIFY, AFTER, 2010-05-09 10:11:12))"),
  21. # Symbol
  22. ("sym:foobar", "Tree(Symbol(ALL, String(u'foobar')))"),
  23. ("func:foo_bar", "Tree(Symbol(FUNCTION, String(u'foo_bar')))"),
  24. ("func:foo_bar()", "Tree(Symbol(FUNCTION, String(u'foo_bar')))"),
  25. ("class:FooBar", "Tree(Symbol(CLASS, String(u'FooBar')))"),
  26. ("var:foobar", "Tree(Symbol(VARIABLE, String(u'foobar')))"),
  27. ("var:r:foobar", "Tree(Symbol(VARIABLE, Regex(u'foobar')))"),
  28. ]
  29. class TestQueryParser(unittest.TestCase):
  30. """Unit tests for the query parser in :py:mod:`bitshift.query`."""
  31. def test_parse(self):
  32. """test full query parsing"""
  33. for test, expected in TESTS:
  34. self.assertEqual(expected, parse_query(test).serialize())
  35. if __name__ == "__main__":
  36. unittest.main(verbosity=2)