| 1 |
# vim:fileencoding=utf-8 |
| 2 |
# License: GPL v3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net> |
| 3 |
from __python__ import bound_methods, hash_literals |
| 4 |
|
| 5 |
from read_book.annotations import merge_annot_lists |
| 6 |
from testing import assert_equal, test, assert_true |
| 7 |
|
| 8 |
|
| 9 |
def bm(title, bmid, year=20, first_cfi_number=1): |
| 10 |
return { |
| 11 |
'title': title, 'id': bmid, 'timestamp': f'20{year}-06-29T03:21:48.895323+00:00', |
| 12 |
'pos_type': 'epubcfi', 'pos': str.format('epubcfi(/{}/4/8)', first_cfi_number) |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
def hl(uuid, hlid, year=20, first_cfi_number=1): |
| 17 |
return { |
| 18 |
'uuid': uuid, 'id': hlid, 'timestamp': f'20{year}-06-29T03:21:48.895323+00:00', |
| 19 |
'start_cfi': '/4/8', 'spine_index': first_cfi_number |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
@test |
| 24 |
def merging_annotations(): |
| 25 |
for atype in 'bookmark highlight'.split(' '): |
| 26 |
f = bm if atype == 'bookmark' else hl |
| 27 |
a = [f('one', 1, 20, 2), f('two', 2, 20, 4), f('a', 3, 20, 16),] |
| 28 |
b = [f('one', 10, 30, 2), f('two', 20, 10, 4), f('b', 30, 20, 8),] |
| 29 |
changed, c = merge_annot_lists(a, b, atype) |
| 30 |
assert_true(changed) |
| 31 |
|
| 32 |
def get_id(x): |
| 33 |
return x.id |
| 34 |
|
| 35 |
assert_equal(list(map(get_id, c)), [10, 2, 30, 3]) |