diff options
| author | Albert Krewinkel <[email protected]> | 2024-06-01 20:56:11 +0200 |
|---|---|---|
| committer | Albert Krewinkel <[email protected]> | 2024-06-01 21:10:29 +0200 |
| commit | 83de55bb357f66984edaf1cd699402dbe4cde5c0 (patch) | |
| tree | ace4cb05a91d2b5cb9b75c1eabee68f97923f2bc /pandoc-lua-engine/test/lua/module | |
| parent | 075ed1052f1739a96317b692b5aa61c03e6ac833 (diff) | |
Lua: Set `pandoc.List` as default metatable for JSON lists
Lists created by `pandoc.json.decode` now behave like lists generated
via `pandoc.List`. This also ensures that `pandoc.List` tables are
encoded as JSON arrays when passed to `pandoc.json.encode`.
Fixes: #9834
Diffstat (limited to 'pandoc-lua-engine/test/lua/module')
| -rw-r--r-- | pandoc-lua-engine/test/lua/module/pandoc-json.lua | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/pandoc-lua-engine/test/lua/module/pandoc-json.lua b/pandoc-lua-engine/test/lua/module/pandoc-json.lua index 46400d572..2b0adadca 100644 --- a/pandoc-lua-engine/test/lua/module/pandoc-json.lua +++ b/pandoc-lua-engine/test/lua/module/pandoc-json.lua @@ -1,6 +1,7 @@ -- -- Tests for the system module -- +local pandoc = require 'pandoc' local json = require 'pandoc.json' local tasty = require 'tasty' @@ -33,19 +34,26 @@ return { local obj = setmetatable( {title = 23}, { - __tojson = function (obj) + __tojson = function (_) return '"Nichts ist so wie es scheint"' end } ) assert.are_same(json.encode(obj), [["Nichts ist so wie es scheint"]]) end), - test('Inline (Space)', function () + test('pandoc.List', function () + local list = pandoc.List {'foo', 'bar', 'baz'} assert.are_equal( - json.encode(pandoc.Space()), - '{"t":"Space"}' + json.encode(list), + '["foo","bar","baz"]' ) end), + test('Inline (Space)', function () + assert.are_equal( + json.encode(pandoc.Space()), + '{"t":"Space"}' + ) + end), test('Block (HorizontalRule)', function () assert.are_equal( json.encode(pandoc.HorizontalRule()), @@ -85,6 +93,9 @@ return { test('object', function () assert.are_same(json.decode '{"a":5}', {a = 5}) end), + test('list of strings', function () + assert.are_equal(json.decode '["foo", "bar"]', pandoc.List{"foo", "bar"}) + end), test('Inline (Space)', function () assert.are_equal(json.decode '{"t":"Space"}', pandoc.Space()) end), |
