summaryrefslogtreecommitdiff
path: root/spec/unit/persist_spec.lua
diff options
context:
space:
mode:
authorMike Vink <mike@pionative.com>2025-02-03 21:29:42 +0100
committerMike Vink <mike@pionative.com>2025-02-03 21:29:42 +0100
commit5155816b7b925dec5d5feb1568b1d7ceb00938b9 (patch)
treedeca28ea15e79f6f804c3d90d2ba757881638af5 /spec/unit/persist_spec.lua
fetch tarballHEADmaster
Diffstat (limited to 'spec/unit/persist_spec.lua')
-rw-r--r--spec/unit/persist_spec.lua74
1 files changed, 74 insertions, 0 deletions
diff --git a/spec/unit/persist_spec.lua b/spec/unit/persist_spec.lua
new file mode 100644
index 0000000..ed78345
--- /dev/null
+++ b/spec/unit/persist_spec.lua
@@ -0,0 +1,74 @@
+local test_env = require("spec.util.test_env")
+local testing_paths = test_env.testing_paths
+
+local persist = require("luarocks.persist")
+
+describe("luarocks.persist #unit", function()
+ local runner
+
+ lazy_setup(function()
+ runner = require("luacov.runner")
+ runner.init(testing_paths.testrun_dir .. "/luacov.config")
+ end)
+
+ lazy_teardown(function()
+ runner.save_stats()
+ 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)