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
|
local test_env = require("test/test_environment")
test_env.unload_luarocks()
local persist = require("luarocks.persist")
describe("Luarocks persist test #whitebox #w_persist", function()
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("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)
|