-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils_spec.lua
More file actions
43 lines (37 loc) · 1.63 KB
/
utils_spec.lua
File metadata and controls
43 lines (37 loc) · 1.63 KB
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
---@diagnostic disable: param-type-mismatch, discard-returns
local utils = require("mods.utils")
describe("mods.utils", function()
local tests
-------------
--- quote ---
-------------
-- stylua: ignore
tests = {
--------------input--------------|--------------expected---------------
{ "foo" , '"foo"' },
{ "" , '""' },
{ "" , '""' },
{ '"' , [['"']] },
{ "'" , [["'"]] },
{ "it's ok" , [["it's ok"]] },
{ [[a "b" c]] , [['a "b" c']] },
{ "a 'b' c" , [["a 'b' c"]] },
{ "bar_baz" , '"bar_baz"' },
{ [[he said "hi"]] , [['he said "hi"']] },
{ "hello world" , '"hello world"' },
{ [[back\slash]] , [["back\slash"]] },
{ [['mix "quotes" and 'single']] , [["'mix \"quotes\" and 'single'"]] },
}
for i = 1, #tests do
local input, expected = unpack(tests[i], 1, 2)
local label = ("%q"):format(input)
it(("quote(%s)"):format(label), function()
assert.are_equal(expected, utils.quote(input))
end)
end
it("errors on non-string input", function()
assert.has_error(function()
utils.quote(false)
end)
end)
end)