diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2019-05-30 08:44:40 +0200 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2019-05-30 08:44:40 +0200 |
commit | f7222370afd50f6ea65f199fd8e4f03101ec8ff4 (patch) | |
tree | 2f52001b5775326e0a39df368c475569af85b354 /test | |
parent | 5a82ecaaa19176afc24576fd80b91c9a529c2dcb (diff) | |
download | pandoc-f7222370afd50f6ea65f199fd8e4f03101ec8ff4.tar.gz |
Lua modules: test pandoc.mediabag
Diffstat (limited to 'test')
-rw-r--r-- | test/Tests/Lua/Module.hs | 11 | ||||
-rw-r--r-- | test/lua/module/pandoc-mediabag.lua | 72 |
2 files changed, 80 insertions, 3 deletions
diff --git a/test/Tests/Lua/Module.hs b/test/Tests/Lua/Module.hs index 324acce04..baa81f4f0 100644 --- a/test/Tests/Lua/Module.hs +++ b/test/Tests/Lua/Module.hs @@ -19,9 +19,14 @@ import Tests.Lua (runLuaTest) tests :: [TestTree] tests = - [ testPandocLua "pandoc" ("lua" </> "module" </> "pandoc.lua") - , testPandocLua "pandoc.types" ("lua" </> "module" </> "pandoc-types.lua") - , testPandocLua "pandoc.util" ("lua" </> "module" </> "pandoc-utils.lua") + [ testPandocLua "pandoc" + ("lua" </> "module" </> "pandoc.lua") + , testPandocLua "pandoc.mediabag" + ("lua" </> "module" </> "pandoc-mediabag.lua") + , testPandocLua "pandoc.types" + ("lua" </> "module" </> "pandoc-types.lua") + , testPandocLua "pandoc.util" + ("lua" </> "module" </> "pandoc-utils.lua") ] testPandocLua :: TestName -> FilePath -> TestTree diff --git a/test/lua/module/pandoc-mediabag.lua b/test/lua/module/pandoc-mediabag.lua new file mode 100644 index 000000000..5ff65ee44 --- /dev/null +++ b/test/lua/module/pandoc-mediabag.lua @@ -0,0 +1,72 @@ +local tasty = require 'tasty' + +local test = tasty.test_case +local group = tasty.test_group +local assert = tasty.assert + +local mediabag = require 'pandoc.mediabag' + +return { + group 'insert' { + test('insert adds an item to the mediabag', function () + local fp = "media/hello.txt" + local mt = "text/plain" + local contents = "Hello, World!" + assert.are_same(mediabag.list(), {}) + mediabag.insert(fp, mt, contents) + assert.are_same( + mediabag.list(), + {{['path'] = fp, ['type'] = mt, ['length'] = 13}} + ) + mediabag.empty() -- clean up + end), + test('is idempotent', function () + local fp = "media/hello.txt" + local mt = "text/plain" + local contents = "Hello, World!" + mediabag.insert(fp, mt, contents) + mediabag.insert(fp, mt, contents) + assert.are_same( + mediabag.list(), + {{['path'] = fp, ['type'] = mt, ['length'] = 13}} + ) + mediabag.empty() -- clean up + end), + }, + + group 'delete' { + test('removes an item', function () + assert.are_same(mediabag.list(), {}) + mediabag.insert('test.html', 'text/html', '<aside>Who cares?</aside>') + mediabag.insert('test.css', 'text/plain', 'aside { color: red; }') + assert.are_equal(#mediabag.list(), 2) + mediabag.delete('test.html') + assert.are_same( + mediabag.list(), + {{['path'] = 'test.css', ['type'] = 'text/plain', ['length'] = 21}} + ) + mediabag.empty() -- clean up + end), + }, + + group 'items' { + test('iterates over all items', function () + local input_items = { + ['test.html'] = {'text/html', '<aside>Really?</aside>'}, + ['test.css'] = {'text/plain', 'aside { color: red; }'}, + ['test.js'] = {'application/javascript', 'alert("HI MOM!")'} + } + -- fill mediabag + for name, v in pairs(input_items) do + mediabag.insert(name, v[1], v[2]) + end + + local seen_items = {} + for fp, mt, c in mediabag.items() do + seen_items[fp] = {mt, c} + end + assert.are_same(seen_items, input_items) + mediabag.empty() -- clean up + end) + } +} |