-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
308 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
local bibtex_data | ||
local bibtex_parser | ||
local bibtex2csl | ||
local json_encode | ||
local json_decode | ||
local latex_parser | ||
local util | ||
if kpse then | ||
kpse.set_program_name("luatex") | ||
local kpse_searcher = package.searchers[2] | ||
---@diagnostic disable-next-line: duplicate-set-field | ||
package.searchers[2] = function (pkg_name) | ||
local pkg_file = package.searchpath(pkg_name, package.path) | ||
if pkg_file then | ||
return loadfile(pkg_file) | ||
end | ||
return kpse_searcher(pkg_name) | ||
end | ||
bibtex_data = require("citeproc-bibtex-data") | ||
bibtex_parser = require("citeproc-bibtex-parser") | ||
bibtex2csl = require("citeproc-bibtex2csl") | ||
require("lualibs") | ||
json_encode = utilities.json.tojson | ||
json_decode = utilities.json.tolua | ||
latex_parser = require("citeproc-latex-parser") | ||
util = require("citeproc-util") | ||
else | ||
bibtex_data = require("citeproc.bibtex-data") | ||
bibtex_parser = require("citeproc.bibtex-parser") | ||
bibtex2csl = require("citeproc.bibtex2csl") | ||
json_decode = require("dkjson").encode | ||
json_decode = require("dkjson").decode | ||
latex_parser = require("citeproc.latex-parser") | ||
util = require("citeproc.util") | ||
end | ||
|
||
|
||
local function listdir(path) | ||
local files = {} | ||
for file in lfs.dir(path) do | ||
if not string.match(file, "^%.") then | ||
table.insert(files, file) | ||
end | ||
end | ||
table.sort(files) | ||
return files | ||
end | ||
|
||
|
||
local function test_bib_json(bib_contents, sentence_case_title, check_sentence_case, case_protection, baseline_path) | ||
local bib_data, exceptions = bibtex_parser.parse(bib_contents, {}) | ||
if bib_data then | ||
bib_data = { | ||
entries = bib_data.entries | ||
} | ||
else | ||
bib_data = { | ||
entries = {}, | ||
} | ||
end | ||
|
||
local baseline_content = util.read_file(baseline_path) | ||
local baseline = json_decode(baseline_content) | ||
|
||
for i, entry in ipairs(bib_data.entries) do | ||
|
||
describe("#" .. entry.key, function () | ||
|
||
for field, value in pairs(entry.fields) do | ||
|
||
local field_type = nil | ||
if bibtex_data.fields[field] then | ||
field_type = bibtex_data.fields[field].type | ||
end | ||
|
||
if field_type == "name" then | ||
-- value = latex_parser.latex_to_pseudo_html(value) | ||
|
||
elseif field_type == "date" then | ||
-- value = latex_parser.latex_to_pseudo_html(value) | ||
|
||
elseif sentence_case_title and entry.type ~= "jurisdiction" and (field == "title" | ||
or field == "subtitle" | ||
or field == "shorttitle" | ||
or field == "booktitle" | ||
or field == "booksubtitle" | ||
or field == "issuetitle" | ||
or field == "issuesubtitle" | ||
or field == "maintitle" | ||
or field == "mainsubtitle" | ||
or field == "eventtitle" | ||
or field == "origtitle" | ||
or field == "series" | ||
or field == "type" | ||
) then | ||
|
||
it("#" .. field, function () | ||
value = latex_parser.latex_to_sentence_case_pseudo_html(value, true, case_protection, check_sentence_case) | ||
assert.equal(baseline.entries[i].fields[field], value) | ||
end) | ||
|
||
else | ||
-- value = latex_parser.latex_to_pseudo_html(value, true, false) | ||
end | ||
|
||
value = string.gsub(value, '</span>([%d%p%s]*)<span class="nocase">', "%1") | ||
entry.fields[field] = value | ||
end | ||
|
||
end) | ||
|
||
end | ||
|
||
end | ||
|
||
|
||
local function main() | ||
local bib_dir = "./tests/bbt/bib" | ||
for _, file in ipairs(listdir(bib_dir)) do | ||
if string.match(file, "%.bib$") then | ||
|
||
describe(file, function () | ||
local bib_path = bib_dir .. "/" .. file | ||
local bib_contents = util.read_file(bib_path) | ||
if not bib_contents then | ||
error(string.format('File not found: "%s"', bib_path)) | ||
end | ||
|
||
local sentence_case_options = {"on+guess", "on", "off"} | ||
local case_protection_options = {"as-needed", "strict", "off"} | ||
|
||
for _, sentence_case in ipairs(sentence_case_options) do | ||
for _, caseprotection in ipairs(case_protection_options) do | ||
-- print(sentence_case, caseprotection) | ||
local config = string.format("sentencecase=%s^caseprotection=%s", sentence_case, caseprotection) | ||
local sentence_case_title = (sentence_case ~= "off") | ||
local case_protection = (caseprotection ~= "off") | ||
local check_sentence_case = (sentence_case == "on+guess") | ||
|
||
local json_path = string.format("./tests/bbt/converted/%s/%s", config, file:gsub("%.bib$", ".json")) | ||
local baseline_path = string.format("./tests/bbt/baseline/%s/%s", config, file:gsub("%.bib$", ".json")) | ||
|
||
describe(config, function () | ||
-- print(json_path) | ||
test_bib_json(bib_contents, sentence_case_title, check_sentence_case, case_protection, baseline_path) | ||
end) | ||
|
||
end | ||
end | ||
end) | ||
end | ||
end | ||
end | ||
|
||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.