diff options
| author | Albert Krewinkel <[email protected]> | 2024-01-17 12:19:20 +0100 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-04-16 10:23:08 -0700 |
| commit | 5f937eae617d72f5f01e24f5a72bafc5b04fde15 (patch) | |
| tree | 99a21e079e428b93561e12a45ecc6a0961cc5f09 /pandoc-lua-engine/test/lua | |
| parent | 9a09c89636e78edaed52276a2b3e00fb7368631b (diff) | |
Lua: add new module `pandoc.image`
The module provides basic querying functions for image properties.
Diffstat (limited to 'pandoc-lua-engine/test/lua')
| -rw-r--r-- | pandoc-lua-engine/test/lua/module/pandoc-image.lua | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/pandoc-lua-engine/test/lua/module/pandoc-image.lua b/pandoc-lua-engine/test/lua/module/pandoc-image.lua new file mode 100644 index 000000000..72f261449 --- /dev/null +++ b/pandoc-lua-engine/test/lua/module/pandoc-image.lua @@ -0,0 +1,68 @@ +-- +-- Tests for the system module +-- +local image = require 'pandoc.image' +local tasty = require 'tasty' + +local group = tasty.test_group +local test = tasty.test_case +local assert = tasty.assert + +local svg_image = [==[<?xml version="1.0"?> +<svg xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + height="70" width="70" + viewBox="-35 -35 70 70"> + <title>test</title> + <!-- document shape --> + <polygon points="-10,-31.53 -10,-3.25 0,0 10,-3.25 10,-23.53 2,-31.53" /> +</svg> +]==] + +return { + -- Check existence of static fields + group 'static fields' { + }, + + group 'size' { + test('returns a table', function () + local imgsize = { + width = 70, + height = 70, + dpi_horz = 96, + dpi_vert = 96, + } + assert.are_same(image.size(svg_image), imgsize) + end), + test('fails on faulty eps', function () + assert.error_matches( + function () image.size('%!PS EPSF') end, + 'could not determine EPS size' + ) + end), + test('fails if input is not an image', function () + assert.error_matches( + function () image.size('not an image') end, + 'could not determine image type' + ) + end), + test('respects the dpi setting', function () + local imgsize = { + width = 70, + height = 70, + dpi_horz = 300, + dpi_vert = 300, + } + assert.are_same(image.size(svg_image, {dpi=300}), imgsize) + end), + }, + + group 'format' { + test('SVG', function () + assert.are_equal(image.format(svg_image), 'svg') + end), + test('returns nil if input is not an image', function () + assert.is_nil(image.format('not an image')) + end), + }, +} |
