various test/coverage optimization

This commit is contained in:
chrox
2016-08-15 00:32:23 +08:00
parent 7e4dc7a3fe
commit 001433e6bc
6 changed files with 79 additions and 14 deletions

View File

@@ -7,16 +7,25 @@ describe("Koptinterface module", function()
Cache = require("cache")
end)
local sample_pdf = "spec/front/unit/data/tall.pdf"
local doc
local tall_pdf = "spec/front/unit/data/tall.pdf"
local complex_pdf = "spec/front/unit/data/sample.pdf"
local paper_pdf = "spec/front/unit/data/paper.pdf"
local doc, complex_doc, paper_doc
before_each(function()
doc = DocumentRegistry:openDocument(sample_pdf)
doc = DocumentRegistry:openDocument(tall_pdf)
complex_doc = DocumentRegistry:openDocument(complex_pdf)
paper_doc = DocumentRegistry:openDocument(paper_pdf)
doc.configurable.text_wrap = 0
complex_doc.configurable.text_wrap = 0
paper_doc.configurable.text_wrap = 0
Cache:clear()
end)
after_each(function()
doc:close()
complex_doc:close()
paper_doc:close()
end)
it("should get auto bbox", function()
@@ -56,7 +65,6 @@ describe("Koptinterface module", function()
doc.configurable.text_wrap = 1
local kc = Koptinterface:getCachedContext(doc, 1)
assert.truthy(kc)
doc.configurable.text_wrap = 0
end)
it("should hint reflowed page in background", function()
@@ -65,7 +73,6 @@ describe("Koptinterface module", function()
-- and wait for reflowing to complete
local kc = Koptinterface:getCachedContext(doc, 1)
assert.truthy(kc)
doc.configurable.text_wrap = 0
end)
it("should get native text boxes", function()
@@ -75,12 +82,69 @@ describe("Koptinterface module", function()
assert.truthy(lines_in_native_page == 60)
end)
it("should get native text boxes from scratch", function()
local kc = Koptinterface:getCachedContext(doc, 1)
local boxes = Koptinterface:getNativeTextBoxesFromScratch(doc, 1)
local lines_in_native_page = #boxes
assert.truthy(lines_in_native_page == 60)
end)
it("should get reflow text boxes", function()
doc.configurable.text_wrap = 1
local kc = Koptinterface:getCachedContext(doc, 1)
local boxes = Koptinterface:getReflowedTextBoxes(doc, 1)
local lines_in_reflowed_page = #boxes
assert.truthy(lines_in_reflowed_page > 60)
doc.configurable.text_wrap = 0
end)
it("should get reflow text boxes from scratch", function()
doc.configurable.text_wrap = 1
local kc = Koptinterface:getCachedContext(doc, 1)
local boxes = Koptinterface:getReflowedTextBoxesFromScratch(doc, 1)
local lines_in_reflowed_page = #boxes
assert.truthy(lines_in_reflowed_page > 60)
end)
it("should get page block of a two-column page", function()
for i = 0.3, 0.6, 0.3 do
for j = 0.3, 0.6, 0.3 do
local block = Koptinterface:getPageBlock(complex_doc, 34, i, j)
assert.truthy(block.x1 - block.x0 < 0.5)
end
end
end)
it("should get word from native position", function()
local word_boxes = Koptinterface:getWordFromPosition(complex_doc, {
page = 19, x = 400, y = 530,
})
assert.is.same("previous", word_boxes.word)
end)
it("should get word from reflow position", function()
complex_doc.configurable.text_wrap = 1
local kc = Koptinterface:getCachedContext(complex_doc, 19)
local word_boxes = Koptinterface:getWordFromPosition(complex_doc, {
page = 19, x = 320, y = 730,
})
assert.is.same("examples", word_boxes.word)
end)
it("should get link from native position", function()
local link = Koptinterface:getLinkFromPosition(paper_doc, 1, {
x = 140, y = 560,
})
assert.truthy(link)
assert.is.same(20, link.page)
require("dbg"):v("link", link)
end)
it("should get link from reflow position", function()
paper_doc.configurable.text_wrap = 1
local link = Koptinterface:getLinkFromPosition(paper_doc, 1, {
x = 500, y = 480,
})
assert.truthy(link)
assert.is.same(20, link.page)
end)
end)