tests: speedup koptinterface tests

This commit is contained in:
Benoit Pierre
2024-12-25 15:46:15 +01:00
committed by Frans de Jonge
parent 77ef1ea1a2
commit cc5ef2dbce

View File

@@ -1,31 +1,22 @@
describe("Koptinterface module", function()
local DocCache, DocumentRegistry, Koptinterface
local DocumentRegistry, Koptinterface
setup(function()
require("commonrequire")
DocCache = require("document/doccache")
DocumentRegistry = require("document/documentregistry")
Koptinterface = require("document/koptinterface")
end)
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
describe("should", function()
before_each(function()
doc = DocumentRegistry:openDocument(tall_pdf)
complex_doc = DocumentRegistry:openDocument(complex_pdf)
paper_doc = DocumentRegistry:openDocument(paper_pdf)
local doc
setup(function()
doc = DocumentRegistry:openDocument("spec/front/unit/data/tall.pdf")
doc.configurable.text_wrap = 0
complex_doc.configurable.text_wrap = 0
paper_doc.configurable.text_wrap = 0
DocCache:clear()
end)
after_each(function()
teardown(function()
doc:close()
complex_doc:close()
paper_doc:close()
end)
it("should get auto bbox", function()
@@ -78,15 +69,13 @@ describe("Koptinterface module", function()
it("should get native text boxes", function()
Koptinterface:getCachedContext(doc, 1)
local boxes = Koptinterface:getNativeTextBoxes(doc, 1)
local lines_in_native_page = #boxes
assert.truthy(lines_in_native_page == 60)
assert.equal(60, #boxes)
end)
it("should get native text boxes from scratch", function()
Koptinterface:getCachedContext(doc, 1)
local boxes = Koptinterface:getNativeTextBoxesFromScratch(doc, 1)
local lines_in_native_page = #boxes
assert.truthy(lines_in_native_page == 60)
assert.equal(60, #boxes)
end)
it("should get reflow text boxes", function()
@@ -105,6 +94,21 @@ describe("Koptinterface module", function()
assert.truthy(lines_in_reflowed_page > 60)
end)
end)
describe("should", function()
local complex_doc
setup(function()
complex_doc = DocumentRegistry:openDocument("spec/front/unit/data/sample.pdf")
complex_doc.configurable.text_wrap = 0
end)
teardown(function()
complex_doc:close()
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
@@ -130,6 +134,21 @@ describe("Koptinterface module", function()
assert.is.same("time,", word_boxes.word)
end)
end)
describe("should", function()
local paper_doc
setup(function()
paper_doc = DocumentRegistry:openDocument("spec/front/unit/data/paper.pdf")
paper_doc.configurable.text_wrap = 0
end)
teardown(function()
paper_doc:close()
end)
it("should get link from native position", function()
local link = Koptinterface:getLinkFromPosition(paper_doc, 1, {
x = 140, y = 560,
@@ -147,4 +166,7 @@ describe("Koptinterface module", function()
assert.truthy(link)
assert.is.same(20, link.page)
end)
end)
end)