From 11bb8627677fb8b49af92d7c55aec07c69f95843 Mon Sep 17 00:00:00 2001
From: Albert Krewinkel <albert@zeitkraut.de>
Date: Wed, 12 Jun 2019 18:58:38 +0200
Subject: Lua: add a `clone()` method to all AST elements (#5572)

Closes: #5568
---
 test/lua/module/pandoc.lua | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

(limited to 'test/lua/module')

diff --git a/test/lua/module/pandoc.lua b/test/lua/module/pandoc.lua
index 1c02c8720..ca2168805 100644
--- a/test/lua/module/pandoc.lua
+++ b/test/lua/module/pandoc.lua
@@ -87,6 +87,44 @@ return {
       end)
     },
   },
+
+  group 'clone' {
+    test('clones Attr', function ()
+      local attr = pandoc.Attr('test', {'my-class'}, {foo = 'bar'})
+      local cloned = attr:clone()
+      attr.identifier = ''
+      attr.classes = {}
+      attr.attributes = {}
+      assert.are_same(cloned.identifier, 'test')
+      assert.are_same(cloned.classes, {'my-class'})
+      assert.are_same(cloned.attributes.foo, 'bar')
+    end),
+    test('clones ListAttributes', function ()
+      local la = pandoc.ListAttributes(2, pandoc.DefaultStyle, pandoc.Period)
+      local cloned = la:clone()
+      la.start = 9
+      assert.are_same(cloned.start, 2)
+    end),
+    test('clones Para', function ()
+      local para = pandoc.Para {pandoc.Str 'Hello'}
+      local cloned = para:clone()
+      para.content[1].text = 'bye'
+      assert.are_same(cloned, pandoc.Para {pandoc.Str 'Hello'})
+    end),
+    test('clones Str', function ()
+      local str = pandoc.Str 'Hello'
+      local cloned = str:clone()
+      str.text = 'bye'
+      assert.are_same(cloned.text, 'Hello')
+    end),
+    test('clones Citation', function ()
+      local cite = pandoc.Citation('leibniz', pandoc.AuthorInText)
+      local cloned = cite:clone()
+      cite.id = 'newton'
+      assert.are_same(cloned.id, 'leibniz')
+    end),
+  },
+
   group 'pipe' {
     test('external string processing', function ()
       if os_is_windows() then
-- 
cgit v1.2.3