aboutsummaryrefslogtreecommitdiff
path: root/test/lua
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2019-08-15 22:53:02 +0200
committerAlbert Krewinkel <albert@zeitkraut.de>2019-08-16 20:52:15 +0200
commit2712d3e869b8a371e1fa261f05fbd5d76561e3a0 (patch)
treeafcfdaeec4729ab65ffa2538d32214a3db723dab /test/lua
parent813e1fc7e0705f11ff374ffd525e8868edd0045a (diff)
downloadpandoc-2712d3e869b8a371e1fa261f05fbd5d76561e3a0.tar.gz
Lua: traverse nested blocks and inlines in correct order
Traversal methods are updated to use the new Walk module such that sequences with nested Inline (or Block) elements are traversed in the order in which they appear in the linearized document. Fixes: #5667
Diffstat (limited to 'test/lua')
-rw-r--r--test/lua/module/pandoc.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/lua/module/pandoc.lua b/test/lua/module/pandoc.lua
index ca2168805..1725d275b 100644
--- a/test/lua/module/pandoc.lua
+++ b/test/lua/module/pandoc.lua
@@ -171,4 +171,42 @@ return {
)
end)
},
+
+ group 'walk_block' {
+ test('block walking order', function ()
+ local acc = {}
+ local nested_nums = pandoc.Div {
+ pandoc.Para{pandoc.Str'1'},
+ pandoc.Div{
+ pandoc.Para{pandoc.Str'2'},
+ pandoc.Para{pandoc.Str'3'}
+ },
+ pandoc.Para{pandoc.Str'4'}
+ }
+ pandoc.walk_block(
+ nested_nums,
+ {Para = function (p) table.insert(acc, p.content[1].text) end}
+ )
+ assert.are_equal('1234', table.concat(acc))
+ end)
+ },
+
+ group 'walk_inline' {
+ test('inline walking order', function ()
+ local acc = {}
+ local nested_nums = pandoc.Span {
+ pandoc.Str'1',
+ pandoc.Emph {
+ pandoc.Str'2',
+ pandoc.Str'3'
+ },
+ pandoc.Str'4'
+ }
+ pandoc.walk_inline(
+ nested_nums,
+ {Str = function (s) table.insert(acc, s.text) end}
+ )
+ assert.are_equal('1234', table.concat(acc))
+ end)
+ }
}