diff options
Diffstat (limited to 'spec/unit/persist_spec.lua')
-rw-r--r-- | spec/unit/persist_spec.lua | 76 |
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 @@ | |||
1 | local test_env = require("spec.util.test_env") | ||
2 | local testing_paths = test_env.testing_paths | ||
3 | |||
4 | test_env.unload_luarocks() | ||
5 | local persist = require("luarocks.persist") | ||
6 | |||
7 | describe("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([[ | ||
23 | bar = 1234 | ||
24 | foo = "string" | ||
25 | ]], persist.save_from_table_to_string({foo = "string", bar = 1234})) | ||
26 | end) | ||
27 | |||
28 | it("nested tables", function() | ||
29 | assert.are.same([[ | ||
30 | bar = { | ||
31 | baz = "string" | ||
32 | } | ||
33 | foo = { | ||
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([[ | ||
41 | bar = { | ||
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([[ | ||
49 | bar = "a \\backslash?" | ||
50 | foo = "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([===[ | ||
56 | bar = [==[ | ||
57 | ]] | ||
58 | ]=]]==] | ||
59 | foo = [[ | ||
60 | First line | ||
61 | Second 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([===[ | ||
67 | bar = [==[ | ||
68 | ]] | ||
69 | ]=]==] | ||
70 | foo = [=[ | ||
71 | First line | ||
72 | Second line [1]]=] | ||
73 | ]===], persist.save_from_table_to_string({foo = "First line\nSecond line [1]", bar = "]]\n]="})) | ||
74 | end) | ||
75 | end) | ||
76 | end) | ||