Skip to content

Commit c4c782f

Browse files
committed
Added tests
Signed-off-by: Antti Pohjola <[email protected]>
1 parent bc11998 commit c4c782f

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test:
2+
nvim --headless -c 'PlenaryBustedDirectory tests/'
3+
lint:
4+
luacheck lua/:

stylua.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
column_width = 100
2+
indent_type = 'Spaces'
3+
quote_style = 'AutoPreferSingle'
4+
indent_width = 2
5+
no_call_parentheses = false
6+
collapse_simple_statement = "Always"

tests/dec_ref.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Prow scuttle parrel provost Sail ho shrouds spirits boom mizzenmast yardarm. Pinnace holystone mizzenmast quarter crow's nest nipperkin grog yardarm hempen halter furl. Swab barque interloper chantey doubloon starboard grog black jack gangway rutters.
2+
3+
Deadlights jack lad schooner scallywag dance the hempen jig carouser broadside cable strike colors. Bring a spring upon her cable holystone blow the man down spanker Shiver me timbers to go on account lookout wherry doubloon chase. Belay yo-ho-ho keelhaul squiffy black spot yardarm spyglass sheet transom heave to.
4+
5+
Trysail Sail ho Corsair red ensign hulk smartly boom jib rum gangway. Case shot Shiver me timbers gangplank crack Jennys tea cup ballast Blimey lee snow crow's nest rutters. Fluke jib scourge of the seven seas boatswain schooner gaff booty Jack Tar transom spirits.

tests/enc_ref.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
&#80;&#114;&#111;&#119; &#115;&#99;&#117;&#116;&#116;&#108;&#101; &#112;&#97;&#114;&#114;&#101;&#108; &#112;&#114;&#111;&#118;&#111;&#115;&#116; &#83;&#97;&#105;&#108; &#104;&#111; &#115;&#104;&#114;&#111;&#117;&#100;&#115; &#115;&#112;&#105;&#114;&#105;&#116;&#115; &#98;&#111;&#111;&#109; &#109;&#105;&#122;&#122;&#101;&#110;&#109;&#97;&#115;&#116; &#121;&#97;&#114;&#100;&#97;&#114;&#109;&#46; &#80;&#105;&#110;&#110;&#97;&#99;&#101; &#104;&#111;&#108;&#121;&#115;&#116;&#111;&#110;&#101; &#109;&#105;&#122;&#122;&#101;&#110;&#109;&#97;&#115;&#116; &#113;&#117;&#97;&#114;&#116;&#101;&#114; &#99;&#114;&#111;&#119;&#39;&#115; &#110;&#101;&#115;&#116; &#110;&#105;&#112;&#112;&#101;&#114;&#107;&#105;&#110; &#103;&#114;&#111;&#103; &#121;&#97;&#114;&#100;&#97;&#114;&#109; &#104;&#101;&#109;&#112;&#101;&#110; &#104;&#97;&#108;&#116;&#101;&#114; &#102;&#117;&#114;&#108;&#46; &#83;&#119;&#97;&#98; &#98;&#97;&#114;&#113;&#117;&#101; &#105;&#110;&#116;&#101;&#114;&#108;&#111;&#112;&#101;&#114; &#99;&#104;&#97;&#110;&#116;&#101;&#121; &#100;&#111;&#117;&#98;&#108;&#111;&#111;&#110; &#115;&#116;&#97;&#114;&#98;&#111;&#97;&#114;&#100; &#103;&#114;&#111;&#103; &#98;&#108;&#97;&#99;&#107; &#106;&#97;&#99;&#107; &#103;&#97;&#110;&#103;&#119;&#97;&#121; &#114;&#117;&#116;&#116;&#101;&#114;&#115;&#46;
2+
3+
&#68;&#101;&#97;&#100;&#108;&#105;&#103;&#104;&#116;&#115; &#106;&#97;&#99;&#107; &#108;&#97;&#100; &#115;&#99;&#104;&#111;&#111;&#110;&#101;&#114; &#115;&#99;&#97;&#108;&#108;&#121;&#119;&#97;&#103; &#100;&#97;&#110;&#99;&#101; &#116;&#104;&#101; &#104;&#101;&#109;&#112;&#101;&#110; &#106;&#105;&#103; &#99;&#97;&#114;&#111;&#117;&#115;&#101;&#114; &#98;&#114;&#111;&#97;&#100;&#115;&#105;&#100;&#101; &#99;&#97;&#98;&#108;&#101; &#115;&#116;&#114;&#105;&#107;&#101; &#99;&#111;&#108;&#111;&#114;&#115;&#46; &#66;&#114;&#105;&#110;&#103; &#97; &#115;&#112;&#114;&#105;&#110;&#103; &#117;&#112;&#111;&#110; &#104;&#101;&#114; &#99;&#97;&#98;&#108;&#101; &#104;&#111;&#108;&#121;&#115;&#116;&#111;&#110;&#101; &#98;&#108;&#111;&#119; &#116;&#104;&#101; &#109;&#97;&#110; &#100;&#111;&#119;&#110; &#115;&#112;&#97;&#110;&#107;&#101;&#114; &#83;&#104;&#105;&#118;&#101;&#114; &#109;&#101; &#116;&#105;&#109;&#98;&#101;&#114;&#115; &#116;&#111; &#103;&#111; &#111;&#110; &#97;&#99;&#99;&#111;&#117;&#110;&#116; &#108;&#111;&#111;&#107;&#111;&#117;&#116; &#119;&#104;&#101;&#114;&#114;&#121; &#100;&#111;&#117;&#98;&#108;&#111;&#111;&#110; &#99;&#104;&#97;&#115;&#101;&#46; &#66;&#101;&#108;&#97;&#121; &#121;&#111;&#45;&#104;&#111;&#45;&#104;&#111; &#107;&#101;&#101;&#108;&#104;&#97;&#117;&#108; &#115;&#113;&#117;&#105;&#102;&#102;&#121; &#98;&#108;&#97;&#99;&#107; &#115;&#112;&#111;&#116; &#121;&#97;&#114;&#100;&#97;&#114;&#109; &#115;&#112;&#121;&#103;&#108;&#97;&#115;&#115; &#115;&#104;&#101;&#101;&#116; &#116;&#114;&#97;&#110;&#115;&#111;&#109; &#104;&#101;&#97;&#118;&#101; &#116;&#111;&#46;
4+
5+
&#84;&#114;&#121;&#115;&#97;&#105;&#108; &#83;&#97;&#105;&#108; &#104;&#111; &#67;&#111;&#114;&#115;&#97;&#105;&#114; &#114;&#101;&#100; &#101;&#110;&#115;&#105;&#103;&#110; &#104;&#117;&#108;&#107; &#115;&#109;&#97;&#114;&#116;&#108;&#121; &#98;&#111;&#111;&#109; &#106;&#105;&#98; &#114;&#117;&#109; &#103;&#97;&#110;&#103;&#119;&#97;&#121;&#46; &#67;&#97;&#115;&#101; &#115;&#104;&#111;&#116; &#83;&#104;&#105;&#118;&#101;&#114; &#109;&#101; &#116;&#105;&#109;&#98;&#101;&#114;&#115; &#103;&#97;&#110;&#103;&#112;&#108;&#97;&#110;&#107; &#99;&#114;&#97;&#99;&#107; &#74;&#101;&#110;&#110;&#121;&#115; &#116;&#101;&#97; &#99;&#117;&#112; &#98;&#97;&#108;&#108;&#97;&#115;&#116; &#66;&#108;&#105;&#109;&#101;&#121; &#108;&#101;&#101; &#115;&#110;&#111;&#119; &#99;&#114;&#111;&#119;&#39;&#115; &#110;&#101;&#115;&#116; &#114;&#117;&#116;&#116;&#101;&#114;&#115;&#46; &#70;&#108;&#117;&#107;&#101; &#106;&#105;&#98; &#115;&#99;&#111;&#117;&#114;&#103;&#101; &#111;&#102; &#116;&#104;&#101; &#115;&#101;&#118;&#101;&#110; &#115;&#101;&#97;&#115; &#98;&#111;&#97;&#116;&#115;&#119;&#97;&#105;&#110; &#115;&#99;&#104;&#111;&#111;&#110;&#101;&#114; &#103;&#97;&#102;&#102; &#98;&#111;&#111;&#116;&#121; &#74;&#97;&#99;&#107; &#84;&#97;&#114; &#116;&#114;&#97;&#110;&#115;&#111;&#109; &#115;&#112;&#105;&#114;&#105;&#116;&#115;&#46;

tests/htmlentities_spec.lua

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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)

tests/minimal_init.lua

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vim.opt.runtimepath:append "."
2+
vim.cmd.runtime { "plugin/plenary.vim", bang = true }
3+
vim.cmd.runtime { "plugin/html-entities.nvim", bang = true }

0 commit comments

Comments
 (0)