mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
add isChapterBegin/End API for readertoc
and add missing test epub
This commit is contained in:
@@ -153,15 +153,41 @@ function ReaderToc:getPreviousChapter(cur_pageno, level)
|
||||
return previous_chapter
|
||||
end
|
||||
|
||||
function ReaderToc:isChapterBegin(cur_pageno, level)
|
||||
local ticks = self:getTocTicks(level)
|
||||
local _begin = false
|
||||
for i = 1, #ticks do
|
||||
if ticks[i] == cur_pageno then
|
||||
_begin = true
|
||||
break
|
||||
end
|
||||
end
|
||||
return _begin
|
||||
end
|
||||
|
||||
function ReaderToc:isChapterEnd(cur_pageno, level)
|
||||
local ticks = self:getTocTicks(level)
|
||||
local _end= false
|
||||
for i = 1, #ticks do
|
||||
if ticks[i] - 1 == cur_pageno then
|
||||
_end = true
|
||||
break
|
||||
end
|
||||
end
|
||||
return _end
|
||||
end
|
||||
|
||||
function ReaderToc:getChapterPagesLeft(pageno, level)
|
||||
--if self:isChapterEnd(pageno, level) then return 0 end
|
||||
local next_chapter = self:getNextChapter(pageno, level)
|
||||
if next_chapter then
|
||||
next_chapter = next_chapter - pageno
|
||||
next_chapter = next_chapter - pageno - 1
|
||||
end
|
||||
return next_chapter
|
||||
end
|
||||
|
||||
function ReaderToc:getChapterPagesDone(pageno, level)
|
||||
if self:isChapterBegin(pageno, level) then return 0 end
|
||||
local previous_chapter = self:getPreviousChapter(pageno, level)
|
||||
if previous_chapter then
|
||||
previous_chapter = pageno - previous_chapter
|
||||
|
||||
@@ -24,6 +24,7 @@ describe("Readertoc module", function()
|
||||
local ticks_level_0 = nil
|
||||
it("should get ticks of level 0", function()
|
||||
ticks_level_0 = toc:getTocTicks(0)
|
||||
DEBUG("ticks", ticks_level_0)
|
||||
assert.are.same(26, #ticks_level_0)
|
||||
end)
|
||||
local ticks_level_1 = nil
|
||||
@@ -53,8 +54,13 @@ describe("Readertoc module", function()
|
||||
assert.are.same(190, toc:getPreviousChapter(200, 0))
|
||||
end)
|
||||
it("should get page left of chapter", function()
|
||||
assert.are.same(15, toc:getChapterPagesLeft(10, 0))
|
||||
assert.are.same(3, toc:getChapterPagesLeft(100, 0))
|
||||
assert.are.same(14, toc:getChapterPagesLeft(10, 0))
|
||||
assert.are.same(2, toc:getChapterPagesLeft(100, 0))
|
||||
assert.are.same(nil, toc:getChapterPagesLeft(200, 0))
|
||||
end)
|
||||
it("should get page done of chapter", function()
|
||||
assert.are.same(1, toc:getChapterPagesDone(10, 0))
|
||||
assert.are.same(0, toc:getChapterPagesDone(100, 0))
|
||||
assert.are.same(10, toc:getChapterPagesDone(200, 0))
|
||||
end)
|
||||
end)
|
||||
|
||||
BIN
test/juliet.epub
Normal file
BIN
test/juliet.epub
Normal file
Binary file not shown.
Reference in New Issue
Block a user