aboutsummaryrefslogtreecommitdiff
path: root/test/lua/module/pandoc-template.lua
blob: c288b2016176b72e0bc60e372ed2355228f0f65b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
local tasty = require 'tasty'
local template = require 'pandoc.template'

local assert = tasty.assert
local test = tasty.test_case
local group = tasty.test_group

return {
  test('is table', function ()
    assert.are_equal(type(template), 'table')
  end),
  group 'default' {
    test('is function', function ()
      assert.are_equal(type(template.default), 'function')
    end),
    test('returns a string for known format', function ()
      assert.are_equal(
        pandoc.utils.type(template.default 'json'),
        'string'
      )
      assert.are_equal(
        pandoc.utils.type(template.default 'markdown'),
        'string'
      )
    end),
    test('fails on unknown format', function ()
      local success, msg = pcall(function ()
          return pandoc.utils.type(template.default 'nosuchformat')
      end)
      assert.is_falsy(success)
    end),
  },
  group 'compile' {
    test('is function', function ()
      assert.are_equal(type(template.compile), 'function')
    end),
    test('returns a Template', function ()
      assert.are_equal(
        pandoc.utils.type(template.compile('$title$')),
        'pandoc Template'
      )
    end),
    test('returns a Template', function ()
      local templ_path = pandoc.path.join{'lua', 'module', 'default.test'}
      assert.are_equal(
        pandoc.utils.type(template.compile('${ partial() }', templ_path)),
        'pandoc Template'
      )
    end),
    test('fails if template has non-existing partial', function ()
      assert.error_matches(
        function () return template.compile('${ nosuchpartial() }') end,
        'PandocCouldNotFindDataFileError'
      )
    end),
    test('works with default template that uses partials', function ()
      local jats_template = template.default 'jats'
      assert.are_equal(type(jats_template), 'string')
      assert.are_equal(
        pandoc.utils.type(template.compile(jats_template)),
        'pandoc Template'
      )
    end),
  },
}