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
66
67
68
69
70
71
72
73
74
75
76
|
local test_env = require("spec.util.test_env")
local testing_paths = test_env.testing_paths
test_env.unload_luarocks()
local persist = require("luarocks.persist")
describe("Luarocks persist test #unit", function()
local runner
setup(function()
runner = require("luacov.runner")
runner.init(testing_paths.testrun_dir .. "/luacov.config")
runner.tick = true
end)
teardown(function()
runner.shutdown()
end)
describe("persist.save_from_table_to_string", function()
it("simple table", function()
assert.are.same([[
bar = 1234
foo = "string"
]], persist.save_from_table_to_string({foo = "string", bar = 1234}))
end)
it("nested tables", function()
assert.are.same([[
bar = {
baz = "string"
}
foo = {
1, 2, 3, 4
}
]], persist.save_from_table_to_string({foo = {1, 2, 3, 4}, bar = {baz = "string"}}))
end)
it("table with a keyword key (#947)", function()
assert.are.same([[
bar = {
["function"] = "foo"
}
]], persist.save_from_table_to_string({bar = {["function"] = "foo"}}))
end)
it("strings with quotes", function()
assert.are.same([[
bar = "a \\backslash?"
foo = "a \"quote\"?"
]], persist.save_from_table_to_string({foo = 'a "quote"?', bar = 'a \\backslash?'}))
end)
it("multiline strings", function()
assert.are.same([===[
bar = [==[
]]
]=]]==]
foo = [[
First line
Second line]]
]===], persist.save_from_table_to_string({foo = "First line\nSecond line", bar = "]]\n]=]"}))
end)
it("multiline strings ending with brackets", function()
assert.are.same([===[
bar = [==[
]]
]=]==]
foo = [=[
First line
Second line [1]]=]
]===], persist.save_from_table_to_string({foo = "First line\nSecond line [1]", bar = "]]\n]="}))
end)
end)
end)
|