mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Some tests for the search template stuff
This commit is contained in:
parent
bfbccea138
commit
3a9435e537
@ -639,7 +639,7 @@ class Parser(SearchQueryParser): # {{{
|
|||||||
if DEBUG:
|
if DEBUG:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
raise ParseException(_('template: missing or invalid separator (#@[tdnb]?#)'))
|
raise ParseException(_('template: missing or invalid separator (#@[tdnb]#:)'))
|
||||||
matchkind, query = _matchkind(query, case_sensitive=case_sensitive)
|
matchkind, query = _matchkind(query, case_sensitive=case_sensitive)
|
||||||
matches = set()
|
matches = set()
|
||||||
error_string = '*@*TEMPLATE_ERROR*@*'
|
error_string = '*@*TEMPLATE_ERROR*@*'
|
||||||
|
@ -360,6 +360,22 @@ class ReadingTest(BaseTest):
|
|||||||
self.assertEqual(cache.search('#rating:>4'), {3})
|
self.assertEqual(cache.search('#rating:>4'), {3})
|
||||||
self.assertEqual(cache.search('#rating:2'), {2})
|
self.assertEqual(cache.search('#rating:2'), {2})
|
||||||
|
|
||||||
|
# template searches
|
||||||
|
# Test text search
|
||||||
|
self.assertEqual(cache.search('template:"{#formats}#@t#:fmt1"'), {1,2})
|
||||||
|
self.assertEqual(cache.search('template:"{authors}#@t#:=Author One"'), {2})
|
||||||
|
cache.set_field('pubdate', {1:p('2001-02-06'), 2:p('2001-10-06'), 3:p('2001-06-06')})
|
||||||
|
cache.set_field('timestamp', {1:p('2002-02-06'), 2:p('2000-10-06'), 3:p('2001-06-06')})
|
||||||
|
# Test numeric compare search
|
||||||
|
self.assertEqual(cache.search("template:\"program: "
|
||||||
|
"floor(days_between(field(\'pubdate\'), "
|
||||||
|
"field(\'timestamp\')))#@n#:>0\""), {2,3})
|
||||||
|
# Test date search
|
||||||
|
self.assertEqual(cache.search('template:{pubdate}#@d#:<2001-09-01"'), {1,3})
|
||||||
|
# Test boolean search
|
||||||
|
self.assertEqual(cache.search('template:{series}#@b#:true'), {1,2})
|
||||||
|
self.assertEqual(cache.search('template:{series}#@b#:false'), {3})
|
||||||
|
|
||||||
# Note that the old db searched uuid for un-prefixed searches, the new
|
# Note that the old db searched uuid for un-prefixed searches, the new
|
||||||
# db does not, for performance
|
# db does not, for performance
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user