From a4f380dea17a97fac5f6839390af9ef9eaf0f9e8 Mon Sep 17 00:00:00 2001 From: Omikhleia Date: Mon, 16 Sep 2024 12:04:33 +0200 Subject: [PATCH] test(core): Add busted test for the CSL engine --- csl/spec/csl_spec.lua | 68 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 csl/spec/csl_spec.lua diff --git a/csl/spec/csl_spec.lua b/csl/spec/csl_spec.lua new file mode 100644 index 000000000..d056b3af2 --- /dev/null +++ b/csl/spec/csl_spec.lua @@ -0,0 +1,68 @@ +SILE = require("core.sile") + +local CslLocale = require("csl.core.locale").CslLocale +local CslStyle = require("csl.core.style").CslStyle +local CslEngine = require("csl.core.engine").CslEngine + +describe("CSL engine", function () + local locale, err1 = CslLocale.read("csl/locales/locales-en-US.xml") + local style, err2 = CslStyle.read("csl/styles/chicago-author-date.csl") + + local cslentryJungle = { + type = "paper-conference", + ["citation-key"] = "jungle2024", + ["citation-number"] = 1, + author = { + { + family = "Smith", + ["family-short"] = "S", + given = "George", + ["given-short"] = "G", + } + }, + title = "Article title", + page = "10-20", + issued = { + year = "2024" + }, + publisher = "Publisher", + ["publisher-place"] = "Place", + volume = "10", + editor = { + { + family = "Doe", + ["family-short"] = "D", + given = "Jane", + ["given-short"] = "J", + } + }, + locator = { + label = "page", + value = "30-35" + }, + ["collection-number"] = "3", + ["collection-title"] = "Series", + ["container-title"] = "Book Title", + } + + it("should parse locale and style", function () + assert.is.falsy(err1) + assert.is.falsy(err2) + assert.is.truthy(locale) + assert.is.truthy(style) + end) + + it("should render a citation", function () + local engine = CslEngine(style, locale) + local citation = engine:cite(cslentryJungle) + assert.is.equal("(Smith 2024, 30–35)", citation) + end) + + it ("should render a reference", function () + local engine = CslEngine(style, locale) + local reference = engine:reference(cslentryJungle) + assert.is.equal( + "Smith, George. 2024. “Article title.” In Book Title, edited by Jane Doe, 10:10–20. Series 3. Place: Publisher.", + reference) + end) +end)