Revamp ToC ticks handling (#6716)

Replace the level `0` `getTocTicks` heuristic with a simple sorted, deduped flat listing of *every* ToC node (via `getTocTicksFlattened`).
This commit is contained in:
NiLuJe
2020-09-27 22:25:16 +02:00
committed by GitHub
parent 25d5e9322c
commit 1ac5846eff
5 changed files with 133 additions and 144 deletions

View File

@@ -31,12 +31,6 @@ describe("Readertoc module", function()
assert.is.equal("SCENE I. Friar Laurence's cell.", title)
end)
describe("getTocTicks API", 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(28, #ticks_level_0)
end)
local ticks_level_1 = nil
it("should get ticks of level 1", function()
ticks_level_1 = toc:getTocTicks(1)
@@ -57,26 +51,31 @@ describe("Readertoc module", function()
assert.are.same(ticks_level_2, ticks_level_m1)
end
end)
local ticks_level_flat = nil
it("should get all ticks (flattened)", function()
ticks_level_flat = toc:getTocTicksFlattened()
assert.are.same(28, #ticks_level_flat)
end)
end)
it("should get page of next chapter", function()
assert.truthy(toc:getNextChapter(10, 0) > 10)
assert.truthy(toc:getNextChapter(100, 0) > 100)
assert.are.same(nil, toc:getNextChapter(290, 0))
assert.truthy(toc:getNextChapter(10) > 10)
assert.truthy(toc:getNextChapter(100) > 100)
assert.are.same(nil, toc:getNextChapter(290))
end)
it("should get page of previous chapter", function()
assert.truthy(toc:getPreviousChapter(10, 0) < 10)
assert.truthy(toc:getPreviousChapter(100, 0) < 100)
assert.truthy(toc:getPreviousChapter(200, 0) < 200)
assert.truthy(toc:getPreviousChapter(10) < 10)
assert.truthy(toc:getPreviousChapter(100) < 100)
assert.truthy(toc:getPreviousChapter(200) < 200)
end)
it("should get page left of chapter", function()
assert.truthy(toc:getChapterPagesLeft(10, 0) > 10)
assert.truthy(toc:getChapterPagesLeft(95, 0) > 10)
assert.are.same(nil, toc:getChapterPagesLeft(290, 0))
assert.truthy(toc:getChapterPagesLeft(10) > 10)
assert.truthy(toc:getChapterPagesLeft(95) > 10)
assert.are.same(nil, toc:getChapterPagesLeft(290))
end)
it("should get page done of chapter", function()
assert.truthy(toc:getChapterPagesDone(11, 0) < 5)
assert.truthy(toc:getChapterPagesDone(88, 0) < 5)
assert.truthy(toc:getChapterPagesDone(290, 0) > 10)
assert.truthy(toc:getChapterPagesDone(11) < 5)
assert.truthy(toc:getChapterPagesDone(88) < 5)
assert.truthy(toc:getChapterPagesDone(290) > 10)
end)
describe("collasible TOC", function()
it("should collapse the secondary toc nodes by default", function()