mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-01 09:33:23 +02:00
Some tests for the search template stuff
This commit is contained in:
parent
bfbccea138
commit
3a9435e537
2 changed files with 17 additions and 1 deletions
|
|
@ -639,7 +639,7 @@ def fi(default_value=None):
|
|||
if DEBUG:
|
||||
import traceback
|
||||
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)
|
||||
matches = set()
|
||||
error_string = '*@*TEMPLATE_ERROR*@*'
|
||||
|
|
|
|||
|
|
@ -360,6 +360,22 @@ def test_searching(self): # {{{
|
|||
self.assertEqual(cache.search('#rating:>4'), {3})
|
||||
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
|
||||
# db does not, for performance
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue