aboutsummaryrefslogtreecommitdiff
path: root/spec/unit/persist_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/persist_spec.lua')
-rw-r--r--spec/unit/persist_spec.lua76
1 files changed, 76 insertions, 0 deletions
diff --git a/spec/unit/persist_spec.lua b/spec/unit/persist_spec.lua
new file mode 100644
index 00000000..f426fd83
--- /dev/null
+++ b/spec/unit/persist_spec.lua
@@ -0,0 +1,76 @@
1local test_env = require("spec.util.test_env")
2local testing_paths = test_env.testing_paths
3
4test_env.unload_luarocks()
5local persist = require("luarocks.persist")
6
7describe("luarocks.persist #unit", function()
8 local runner
9
10 setup(function()
11 runner = require("luacov.runner")
12 runner.init(testing_paths.testrun_dir .. "/luacov.config")
13 runner.tick = true
14 end)
15
16 teardown(function()
17 runner.shutdown()
18 end)
19
20 describe("persist.save_from_table_to_string", function()
21 it("simple table", function()
22 assert.are.same([[
23bar = 1234
24foo = "string"
25]], persist.save_from_table_to_string({foo = "string", bar = 1234}))
26 end)
27
28 it("nested tables", function()
29 assert.are.same([[
30bar = {
31 baz = "string"
32}
33foo = {
34 1, 2, 3, 4
35}
36]], persist.save_from_table_to_string({foo = {1, 2, 3, 4}, bar = {baz = "string"}}))
37 end)
38
39 it("table with a keyword key (#947)", function()
40 assert.are.same([[
41bar = {
42 ["function"] = "foo"
43}
44]], persist.save_from_table_to_string({bar = {["function"] = "foo"}}))
45 end)
46
47 it("strings with quotes", function()
48 assert.are.same([[
49bar = "a \\backslash?"
50foo = "a \"quote\"?"
51]], persist.save_from_table_to_string({foo = 'a "quote"?', bar = 'a \\backslash?'}))
52 end)
53
54 it("multiline strings", function()
55 assert.are.same([===[
56bar = [==[
57]]
58]=]]==]
59foo = [[
60First line
61Second line]]
62]===], persist.save_from_table_to_string({foo = "First line\nSecond line", bar = "]]\n]=]"}))
63 end)
64
65 it("multiline strings ending with brackets", function()
66 assert.are.same([===[
67bar = [==[
68]]
69]=]==]
70foo = [=[
71First line
72Second line [1]]=]
73]===], persist.save_from_table_to_string({foo = "First line\nSecond line [1]", bar = "]]\n]="}))
74 end)
75 end)
76end)