|
| 1 | +local t = require("html-entities") |
| 2 | + |
| 3 | +-- see if the file exists |
| 4 | +function file_exists(file) |
| 5 | + local f = io.open(file, "rb") |
| 6 | + if f then f:close() end |
| 7 | + return f ~= nil |
| 8 | +end |
| 9 | + |
| 10 | +-- get all lines from a file, returns an empty |
| 11 | +-- list/table if the file does not exist |
| 12 | +function lines_from(file) |
| 13 | + if not file_exists(file) then return {} end |
| 14 | + local lines = {} |
| 15 | + for line in io.lines(file) do |
| 16 | + lines[#lines + 1] = line |
| 17 | + end |
| 18 | + return lines |
| 19 | +end |
| 20 | + |
| 21 | + |
| 22 | +describe("testenconde", function() |
| 23 | + it("do setup", function() |
| 24 | + assert.has_no.errors(t.setup) |
| 25 | + end) |
| 26 | + it("runs Encode", function() |
| 27 | + vim.api.nvim_command('edit tests/dec_ref.txt') |
| 28 | + vim.api.nvim_command("HtmlEncode") |
| 29 | + vim.api.nvim_command('write! tests/enc_test.txt') |
| 30 | + local encoded = lines_from('tests/enc_test.txt') |
| 31 | + local ref = lines_from('tests/enc_ref.txt') |
| 32 | + assert.equals(vim.deep_equal(encoded, ref), true) |
| 33 | + end) |
| 34 | + |
| 35 | +end) |
| 36 | + |
| 37 | +describe("testdecode", function() |
| 38 | + it("do setup", function() |
| 39 | + assert.has_no.errors(t.setup) |
| 40 | + end) |
| 41 | + it("runs Decode", function() |
| 42 | + vim.api.nvim_command('edit tests/enc_ref.txt') |
| 43 | + vim.api.nvim_command("HtmlDecode") |
| 44 | + vim.api.nvim_command('write! tests/dec_test.txt') |
| 45 | + local encoded = lines_from('tests/dec_test.txt') |
| 46 | + local ref = lines_from('tests/dec_ref.txt') |
| 47 | + assert.equals(vim.deep_equal(encoded, ref), true) |
| 48 | + end) |
| 49 | + |
| 50 | +end) |
0 commit comments