aboutsummaryrefslogtreecommitdiff
path: root/pandoc-lua-engine/test/lua/module/pandoc.lua
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2026-01-02 13:30:47 +0100
committerJohn MacFarlane <[email protected]>2026-01-02 11:10:09 -0500
commit8f8ea44d02b6a3ca0c3e80eaf78e926889f29c9b (patch)
treed5c93a91e98838bcb916f24b8ca8b97fbc09d699 /pandoc-lua-engine/test/lua/module/pandoc.lua
parente8d140f41feb0ad023c0b7f22355fec96207dfee (diff)
Lua: add function `pandoc.with_state`
The function allows to run a callback with a modified pandoc state. This provides the ability to temporarily modify the resource path, the user data directory, and the HTTP request headers. Closes: #10859
Diffstat (limited to 'pandoc-lua-engine/test/lua/module/pandoc.lua')
-rw-r--r--pandoc-lua-engine/test/lua/module/pandoc.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/pandoc-lua-engine/test/lua/module/pandoc.lua b/pandoc-lua-engine/test/lua/module/pandoc.lua
index 3d745b428..1bb364f54 100644
--- a/pandoc-lua-engine/test/lua/module/pandoc.lua
+++ b/pandoc-lua-engine/test/lua/module/pandoc.lua
@@ -463,6 +463,43 @@ return {
end),
},
+ group 'with_state' {
+ test('request_headers can be modified', function ()
+ local headers = {
+ {"Authorization", "Basic my-secret"}
+ }
+ pandoc.with_state({request_headers = headers}, function ()
+ assert.are_same(PANDOC_STATE.request_headers, headers)
+ end)
+ end),
+ test('resource_path can be modified', function ()
+ local paths = {'.', '/test/resource/path' }
+ pandoc.with_state({resource_path = paths}, function ()
+ assert.are_same(PANDOC_STATE.resource_path, paths)
+ end)
+ end),
+ test('user_data_dir can be modified', function ()
+ local opts = {user_data_dir = '/my/test/path'}
+ pandoc.with_state(opts, function ()
+ assert.are_equal(PANDOC_STATE.user_data_dir, '/my/test/path')
+ end)
+ end),
+ test('original value is restored afterwards', function ()
+ local orig_user_data_dir = PANDOC_STATE.user_data_dir
+ local opts = {user_data_dir = '/my/test/path'}
+ pandoc.with_state(opts, function () end)
+ assert.are_equal(PANDOC_STATE.user_data_dir, orig_user_data_dir)
+ end),
+ test('unsupported options are ignored', function ()
+ local orig_log = PANDOC_STATE.log
+ local opts = {log = 'nonsense'}
+ pandoc.with_state(opts, function ()
+ assert.are_same(PANDOC_STATE.log, orig_log)
+ end)
+ assert.are_same(PANDOC_STATE.log, orig_log)
+ end),
+ },
+
group 'Marshal' {
group 'Inlines' {
test('Strings are broken into words', function ()