From fce45aff34dea1959b0640d9a02374c6bb5897de Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 17 Oct 2020 19:00:16 +0200 Subject: util.paths: Add some tests --- spec/util_paths_spec.lua | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 spec/util_paths_spec.lua (limited to 'spec/util_paths_spec.lua') diff --git a/spec/util_paths_spec.lua b/spec/util_paths_spec.lua new file mode 100644 index 00000000..243b35fb --- /dev/null +++ b/spec/util_paths_spec.lua @@ -0,0 +1,39 @@ +local sep = package.config:match("(.)\n"); +describe("util.paths", function () + local paths = require "util.paths"; + describe("#join()", function () + it("returns single component as-is", function () + assert.equal("foo", paths.join("foo")); + end); + it("joins paths", function () + assert.equal("foo"..sep.."bar", paths.join("foo", "bar")) + end); + it("joins longer paths", function () + assert.equal("foo"..sep.."bar"..sep.."baz", paths.join("foo", "bar", "baz")) + end); + it("joins even longer paths", function () + assert.equal("foo"..sep.."bar"..sep.."baz"..sep.."moo", paths.join("foo", "bar", "baz", "moo")) + end); + end) + + describe("#glob_to_pattern()", function () + it("works", function () + assert.equal("^thing.%..*$", paths.glob_to_pattern("thing?.*")) + end); + + end) + describe("#resolve_relative_path()", function () + it("returns absolute paths as-is", function () + if sep == "/" then + assert.equal("/tmp/path", paths.resolve_relative_path("/run", "/tmp/path")); + elseif sep == "\\" then + assert.equal("C:\\Program Files", paths.resolve_relative_path("A:\\", "C:\\Program Files")); + end + end); + it("resolves relative paths", function () + if sep == "/" then + assert.equal("/run/path", paths.resolve_relative_path("/run", "path")); + end + end); + end) +end) -- cgit v1.2.3 From c812a980682ce678045ee8031b8b0da9237458f0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 17 Oct 2020 19:24:44 +0200 Subject: util_paths_spec: Trim trailing white space And add spacing between describe() blocks --- spec/util_paths_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/util_paths_spec.lua') diff --git a/spec/util_paths_spec.lua b/spec/util_paths_spec.lua index 243b35fb..2e8a0c08 100644 --- a/spec/util_paths_spec.lua +++ b/spec/util_paths_spec.lua @@ -20,8 +20,8 @@ describe("util.paths", function () it("works", function () assert.equal("^thing.%..*$", paths.glob_to_pattern("thing?.*")) end); - end) + describe("#resolve_relative_path()", function () it("returns absolute paths as-is", function () if sep == "/" then -- cgit v1.2.3