diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 61f66e4..b04c638 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -4,16 +4,17 @@ on: [ push ] jobs: test: - runs-on: ubuntu-latest strategy: matrix: neovim-version: [ "v0.9.0", "v0.9.1", "stable", "nightly" ] - + os: [ windows-latest, ubuntu-latest ] + runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: MunifTanjim/setup-neovim-action@v1 + - uses: actions/checkout@v4 + - uses: rhysd/action-setup-vim@v1 with: - tag: ${{ matrix.neovim-version }} + neovim: true + version: ${{ matrix.neovim-version }} - name: Install Neovim plugins run: | ./script/setup-test-deps diff --git a/.gitignore b/.gitignore index ce2296b..2c83a2b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.clj-kondo/ /.test-config/ +/.test-state/ diff --git a/fnl/nfnl/compile.fnl b/fnl/nfnl/compile.fnl index 046b059..7e6c17b 100644 --- a/fnl/nfnl/compile.fnl +++ b/fnl/nfnl/compile.fnl @@ -10,7 +10,8 @@ (local header-marker "[nfnl]") (fn with-header [file src] - (.. "-- " header-marker " Compiled from " file " by https://github.com/Olical/nfnl, do not edit.\n" src)) + (let [file (fs.standardize-path file)] ;; Normalize the path for Windows + (.. "-- " header-marker " Compiled from " file " by https://github.com/Olical/nfnl, do not edit.\n" src))) (fn safe-target? [path] "Reads the given file and checks if it contains our header marker on the diff --git a/fnl/nfnl/core.fnl b/fnl/nfnl/core.fnl index 3c227b5..c4525c8 100644 --- a/fnl/nfnl/core.fnl +++ b/fnl/nfnl/core.fnl @@ -408,6 +408,12 @@ (tset t k nil))) nil) +(fn dbg [x] + "Prints each of the arguments using vim.inspect and returns them. + Great for debugging some confusing code without changing the behavior" + (print (vim.inspect x)) + x) + {: rand : nil? : number? @@ -458,4 +464,5 @@ : constantly : distinct : sort - : clear-table!} + : clear-table! + : dbg} diff --git a/fnl/nfnl/fs.fnl b/fnl/nfnl/fs.fnl index 87ec065..436d6ce 100644 --- a/fnl/nfnl/fs.fnl +++ b/fnl/nfnl/fs.fnl @@ -93,6 +93,15 @@ (replace-extension "lua") (replace-dirs "fnl" "lua"))) +(fn standardize-path [path] + "Replaces all non standard path separators with the standard forward slash" + (str.replace path "\\" "/")) + +(fn correct-separators [path] + "Replaces all path separators with the ones appropriate for this system" + (str.replace path "\\" (path-sep)) + (str.replace path "/" (path-sep))) + {: basename : filename : file-name-root @@ -108,4 +117,6 @@ : join-path : read-first-line : replace-dirs - : fnl-path->lua-path} + : fnl-path->lua-path + : standardize-path + : correct-separators} diff --git a/fnl/nfnl/string.fnl b/fnl/nfnl/string.fnl index dbda7a4..b01758b 100644 --- a/fnl/nfnl/string.fnl +++ b/fnl/nfnl/string.fnl @@ -66,10 +66,15 @@ (= suffix (string.sub s (- s-len suffix-len -1))) false))) +(fn replace [s from to] + "Replace all occurrences of from with to in the string." + (string.gsub s from to)) + {: join : split : blank? : triml : trimr : trim - : ends-with?} + : ends-with? + : replace} diff --git a/fnl/spec/nfnl/config_spec.fnl b/fnl/spec/nfnl/config_spec.fnl index 8110ecd..e374263 100644 --- a/fnl/spec/nfnl/config_spec.fnl +++ b/fnl/spec/nfnl/config_spec.fnl @@ -1,4 +1,5 @@ (local {: describe : it} (require :plenary.busted)) +(local core (autoload :nfnl.core)) (local assert (require :luassert.assert)) (local config (require :nfnl.config)) (local fs (require :nfnl.fs)) @@ -32,9 +33,24 @@ (assert.is_true (config.config-file-path? ".nfnl.fnl")) (assert.is_false (config.config-file-path? ".fnl.fnl")))))) +(describe + "find" + (fn [] + (it "finds the nearest .nfnl file to the given path" + (fn [] + (assert.equals + (fs.join-path (fs.full-path ".") ".nfnl.fnl") + (fs.join-path ".nfnl.fnl" (config.find "."))))))) + (describe "find-and-load" (fn [] + ; (it "can read found path securely" + ; (fn [] + ; (let [config-file-path (config.find ".") + ; config-source (vim.secure.read (core.dbg (fs.standardize-path config-file-path)))] + ; (assert.equals "{:verbose true}" config-source)))) + (it "loads the repo config file" (fn [] (let [{: cfg : root-dir : config} @@ -45,7 +61,7 @@ (it "returns an empty table if a config file isn't found" (fn [] - (assert.are.same {} (config.find-and-load "/some/made/up/dir")))))) + (assert.are.same {} (config.find-and-load (fs.correct-separators "/some/made/up/dir"))))))) (fn sorted [xs] (table.sort xs) diff --git a/fnl/spec/nfnl/fs_spec.fnl b/fnl/spec/nfnl/fs_spec.fnl index 85eb70d..4b0b29c 100644 --- a/fnl/spec/nfnl/fs_spec.fnl +++ b/fnl/spec/nfnl/fs_spec.fnl @@ -2,13 +2,15 @@ (local assert (require :luassert.assert)) (local fs (require :nfnl.fs)) +(fn windows? [] (= jit.os "Windows")) + (describe "basename" (fn [] (it "removes the last segment of a path" (fn [] - (assert.equals "foo" (fs.basename "foo/bar.fnl")) - (assert.equals "foo/bar" (fs.basename "foo/bar/baz.fnl")) + (assert.equals "foo" (fs.basename (fs.join-path ["foo" "bar.fnl"]))) + (assert.equals (fs.join-path ["foo" "bar"]) (fs.basename (fs.join-path ["foo" "bar" "baz.fnl"]))) (assert.equals "." (fs.basename "baz.fnl")))) (it "happily lets nils flow back out" @@ -18,9 +20,11 @@ (describe "path-sep" (fn [] - (it "returns the OS path separator (test assumes Linux)" + (it "returns the OS path separator" (fn [] - (assert.equals "/" (fs.path-sep)))))) + (if (windows?) + (assert.equals "\\" (fs.path-sep)) + (assert.equals "/" (fs.path-sep))))))) (describe "replace-extension" @@ -34,22 +38,41 @@ (fn [] (it "splits a path into parts" (fn [] - (assert.are.same ["foo" "bar" "baz"] (fs.split-path "foo/bar/baz")) - (assert.are.same ["" "foo" "bar" "baz"] (fs.split-path "/foo/bar/baz")))))) + (assert.are.same ["foo" "bar" "baz"] (fs.split-path (fs.correct-separators "foo/bar/baz"))z) + (assert.are.same ["" "foo" "bar" "baz"] (fs.split-path (fs.correct-separators "/foo/bar/baz"))))))) (describe "join-path" (fn [] (it "joins a path together" (fn [] - (assert.equals "foo/bar/baz" (fs.join-path ["foo" "bar" "baz"])) - (assert.equals "/foo/bar/baz" (fs.join-path ["" "foo" "bar" "baz"])))))) + (assert.equals "foo/bar/baz" (fs.standardize-path (fs.join-path ["foo" "bar" "baz"]))) + (assert.equals "/foo/bar/baz" (fs.standardize-path (fs.join-path ["" "foo" "bar" "baz"]))))))) (describe "replace-dirs" (fn [] (it "replaces directories in a path that match a string with another string" (fn [] - (assert.equals "foo/lua/bar" (fs.replace-dirs "foo/fnl/bar" "fnl" "lua")) - (assert.equals "/foo/lua/bar" (fs.replace-dirs "/foo/fnl/bar" "fnl" "lua")) - (assert.equals "/foo/nfnl/bar" (fs.replace-dirs "/foo/nfnl/bar" "fnl" "lua")))))) + (assert.equals "foo/lua/bar" (fs.standardize-path (fs.replace-dirs (fs.correct-separators "foo/fnl/bar") "fnl" "lua"))) + (assert.equals "/foo/lua/bar" (fs.standardize-path (fs.replace-dirs (fs.correct-separators "/foo/fnl/bar") "fnl" "lua"))) + (assert.equals "/foo/nfnl/bar" (fs.standardize-path (fs.replace-dirs "/foo/nfnl/bar" "fnl" "lua"))))))) + +(describe + "standardize-path" + (fn [] + (it "replaces all path separators with forward slash" + (fn [] + (assert.equals "foo/bar/baz.fnl" (fs.standardize-path "foo\\bar\\baz.fnl")) + (assert.equals "foo/bar/baz.fnl" (fs.standardize-path "foo/bar/baz.fnl")))))) + +(describe + "correct-separators" + (fn [] + (it "" + (fn [] + (if (windows?) + (do (assert.equals "foo\\bar\\baz.fnl" (fs.correct-separators "foo/bar/baz.fnl")) + (assert.equals "foo\\bar\\baz.fnl" (fs.correct-separators "foo\\bar\\baz.fnl"))) + (do (assert.equals "foo/bar/baz.fnl" (fs.correct-separators "foo/bar/baz.fnl")) + (assert.equals "foo/bar/baz.fnl" (fs.correct-separators "foo\\bar\\baz.fnl")))))))) diff --git a/lua/nfnl/compile.lua b/lua/nfnl/compile.lua index 63fdbb3..c34a536 100644 --- a/lua/nfnl/compile.lua +++ b/lua/nfnl/compile.lua @@ -1,4 +1,4 @@ --- [nfnl] Compiled from fnl/nfnl/compile.fnl by https://github.com/Olical/nfnl, do not edit. +-- [nfnl] Compiled from fnl\nfnl\compile.fnl by https://github.com/Olical/nfnl, do not edit. local _local_1_ = require("nfnl.module") local autoload = _local_1_["autoload"] local core = autoload("nfnl.core") @@ -9,7 +9,8 @@ local config = autoload("nfnl.config") local mod = {} local header_marker = "[nfnl]" local function with_header(file, src) - return ("-- " .. header_marker .. " Compiled from " .. file .. " by https://github.com/Olical/nfnl, do not edit.\n" .. src) + local file0 = fs["standardize-path"](file) + return ("-- " .. header_marker .. " Compiled from " .. file0 .. " by https://github.com/Olical/nfnl, do not edit.\n" .. src) end local function safe_target_3f(path) local header = fs["read-first-line"](path) diff --git a/lua/nfnl/config.lua b/lua/nfnl/config.lua index 1eac1e2..bbb765a 100644 --- a/lua/nfnl/config.lua +++ b/lua/nfnl/config.lua @@ -1,4 +1,4 @@ --- [nfnl] Compiled from fnl/nfnl/config.fnl by https://github.com/Olical/nfnl, do not edit. +-- [nfnl] Compiled from fnl\nfnl\config.fnl by https://github.com/Olical/nfnl, do not edit. local _local_1_ = require("nfnl.module") local autoload = _local_1_["autoload"] local core = autoload("nfnl.core") diff --git a/lua/nfnl/core.lua b/lua/nfnl/core.lua index 1aff3f5..9696790 100644 --- a/lua/nfnl/core.lua +++ b/lua/nfnl/core.lua @@ -1,4 +1,4 @@ --- [nfnl] Compiled from fnl/nfnl/core.fnl by https://github.com/Olical/nfnl, do not edit. +-- [nfnl] Compiled from fnl\nfnl\core.fnl by https://github.com/Olical/nfnl, do not edit. local _local_1_ = require("nfnl.module") local autoload = _local_1_["autoload"] local fennel = autoload("nfnl.fennel") @@ -443,4 +443,8 @@ local function clear_table_21(t) end return nil end -return {rand = rand, ["nil?"] = nil_3f, ["number?"] = number_3f, ["boolean?"] = boolean_3f, ["string?"] = string_3f, ["table?"] = table_3f, ["function?"] = function_3f, keys = keys, count = count, ["empty?"] = empty_3f, first = first, second = second, last = last, inc = inc, dec = dec, ["even?"] = even_3f, ["odd?"] = odd_3f, vals = vals, ["kv-pairs"] = kv_pairs, ["run!"] = run_21, complement = complement, filter = filter, remove = remove, map = map, ["map-indexed"] = map_indexed, identity = identity, reduce = reduce, some = some, butlast = butlast, rest = rest, concat = concat, mapcat = mapcat, ["pr-str"] = pr_str, str = str, println = println, pr = pr, slurp = slurp, spit = spit, ["merge!"] = merge_21, merge = merge, ["select-keys"] = select_keys, get = get, ["get-in"] = get_in, assoc = assoc, ["assoc-in"] = assoc_in, update = update, ["update-in"] = update_in, constantly = constantly, distinct = distinct, sort = sort, ["clear-table!"] = clear_table_21} +local function dbg(x) + print(vim.inspect(x)) + return x +end +return {rand = rand, ["nil?"] = nil_3f, ["number?"] = number_3f, ["boolean?"] = boolean_3f, ["string?"] = string_3f, ["table?"] = table_3f, ["function?"] = function_3f, keys = keys, count = count, ["empty?"] = empty_3f, first = first, second = second, last = last, inc = inc, dec = dec, ["even?"] = even_3f, ["odd?"] = odd_3f, vals = vals, ["kv-pairs"] = kv_pairs, ["run!"] = run_21, complement = complement, filter = filter, remove = remove, map = map, ["map-indexed"] = map_indexed, identity = identity, reduce = reduce, some = some, butlast = butlast, rest = rest, concat = concat, mapcat = mapcat, ["pr-str"] = pr_str, str = str, println = println, pr = pr, slurp = slurp, spit = spit, ["merge!"] = merge_21, merge = merge, ["select-keys"] = select_keys, get = get, ["get-in"] = get_in, assoc = assoc, ["assoc-in"] = assoc_in, update = update, ["update-in"] = update_in, constantly = constantly, distinct = distinct, sort = sort, ["clear-table!"] = clear_table_21, dbg = dbg} diff --git a/lua/nfnl/fs.lua b/lua/nfnl/fs.lua index 526aad1..2459038 100644 --- a/lua/nfnl/fs.lua +++ b/lua/nfnl/fs.lua @@ -1,4 +1,4 @@ --- [nfnl] Compiled from fnl/nfnl/fs.fnl by https://github.com/Olical/nfnl, do not edit. +-- [nfnl] Compiled from fnl\nfnl\fs.fnl by https://github.com/Olical/nfnl, do not edit. local _local_1_ = require("nfnl.module") local autoload = _local_1_["autoload"] local core = autoload("nfnl.core") @@ -110,4 +110,11 @@ end local function fnl_path__3elua_path(fnl_path) return replace_dirs(replace_extension(fnl_path, "lua"), "fnl", "lua") end -return {basename = basename, filename = filename, ["file-name-root"] = file_name_root, ["full-path"] = full_path, mkdirp = mkdirp, ["replace-extension"] = replace_extension, absglob = absglob, relglob = relglob, ["glob-dir-newer?"] = glob_dir_newer_3f, ["path-sep"] = path_sep, findfile = findfile, ["split-path"] = split_path, ["join-path"] = join_path, ["read-first-line"] = read_first_line, ["replace-dirs"] = replace_dirs, ["fnl-path->lua-path"] = fnl_path__3elua_path} +local function standardize_path(path) + return str.replace(path, "\\", "/") +end +local function correct_separators(path) + str.replace(path, "\\", path_sep()) + return str.replace(path, "/", path_sep()) +end +return {basename = basename, filename = filename, ["file-name-root"] = file_name_root, ["full-path"] = full_path, mkdirp = mkdirp, ["replace-extension"] = replace_extension, absglob = absglob, relglob = relglob, ["glob-dir-newer?"] = glob_dir_newer_3f, ["path-sep"] = path_sep, findfile = findfile, ["split-path"] = split_path, ["join-path"] = join_path, ["read-first-line"] = read_first_line, ["replace-dirs"] = replace_dirs, ["fnl-path->lua-path"] = fnl_path__3elua_path, ["standardize-path"] = standardize_path, ["correct-separators"] = correct_separators} diff --git a/lua/nfnl/string.lua b/lua/nfnl/string.lua index c0de95a..f0ca292 100644 --- a/lua/nfnl/string.lua +++ b/lua/nfnl/string.lua @@ -1,4 +1,4 @@ --- [nfnl] Compiled from fnl/nfnl/string.fnl by https://github.com/Olical/nfnl, do not edit. +-- [nfnl] Compiled from fnl\nfnl\string.fnl by https://github.com/Olical/nfnl, do not edit. local _local_1_ = require("nfnl.module") local autoload = _local_1_["autoload"] local core = autoload("nfnl.core") @@ -73,4 +73,7 @@ local function ends_with_3f(s, suffix) return false end end -return {join = join, split = split, ["blank?"] = blank_3f, triml = triml, trimr = trimr, trim = trim, ["ends-with?"] = ends_with_3f} +local function replace(s, from, to) + return string.gsub(s, from, to) +end +return {join = join, split = split, ["blank?"] = blank_3f, triml = triml, trimr = trimr, trim = trim, ["ends-with?"] = ends_with_3f, replace = replace} diff --git a/lua/spec/nfnl/config_spec.lua b/lua/spec/nfnl/config_spec.lua index 289b3f0..584d466 100644 --- a/lua/spec/nfnl/config_spec.lua +++ b/lua/spec/nfnl/config_spec.lua @@ -1,7 +1,8 @@ --- [nfnl] Compiled from fnl/spec/nfnl/config_spec.fnl by https://github.com/Olical/nfnl, do not edit. +-- [nfnl] Compiled from fnl\spec\nfnl\config_spec.fnl by https://github.com/Olical/nfnl, do not edit. local _local_1_ = require("plenary.busted") local describe = _local_1_["describe"] local it = _local_1_["it"] +local core = autoload("nfnl.core") local assert = require("luassert.assert") local config = require("nfnl.config") local fs = require("nfnl.fs") @@ -36,30 +37,37 @@ end describe("config-file-path?", _6_) local function _8_() local function _9_() - local _let_10_ = config["find-and-load"](".") - local cfg = _let_10_["cfg"] - local root_dir = _let_10_["root-dir"] - local config0 = _let_10_["config"] + return assert.equals(fs["join-path"](fs["full-path"]("."), ".nfnl.fnl"), fs["join-path"](".nfnl.fnl", config.find("."))) + end + return it("finds the nearest .nfnl file to the given path", _9_) +end +describe("find", _8_) +local function _10_() + local function _11_() + local _let_12_ = config["find-and-load"](".") + local cfg = _let_12_["cfg"] + local root_dir = _let_12_["root-dir"] + local config0 = _let_12_["config"] assert.are.same({verbose = true}, config0) assert.equals(vim.fn.getcwd(), root_dir) return assert.equals("function", type(cfg)) end - it("loads the repo config file", _9_) - local function _11_() - return assert.are.same({}, config["find-and-load"]("/some/made/up/dir")) + it("loads the repo config file", _11_) + local function _13_() + return assert.are.same({}, config["find-and-load"](fs["correct-separators"]("/some/made/up/dir"))) end - return it("returns an empty table if a config file isn't found", _11_) + return it("returns an empty table if a config file isn't found", _13_) end -describe("find-and-load", _8_) +describe("find-and-load", _10_) local function sorted(xs) table.sort(xs) return xs end -local function _12_() - local function _13_() +local function _14_() + local function _15_() assert.are.same({"/foo/bar/nfnl", "/foo/baz/my-proj"}, sorted(config["path-dirs"]({runtimepath = "/foo/bar/nfnl,/foo/bar/other-thing", ["rtp-patterns"] = {(fs["path-sep"]() .. "nfnl$")}, ["base-dirs"] = {"/foo/baz/my-proj"}}))) return assert.are.same({"/foo/bar/nfnl", "/foo/baz/my-proj"}, sorted(config["path-dirs"]({runtimepath = "/foo/bar/nfnl,/foo/bar/other-thing", ["rtp-patterns"] = {(fs["path-sep"]() .. "nfnl$")}, ["base-dirs"] = {"/foo/baz/my-proj", "/foo/bar/nfnl"}}))) end - return it("builds path dirs from runtimepath, deduplicates the base-dirs", _13_) + return it("builds path dirs from runtimepath, deduplicates the base-dirs", _15_) end -return describe("path-dirs", _12_) +return describe("path-dirs", _14_) diff --git a/lua/spec/nfnl/fs_spec.lua b/lua/spec/nfnl/fs_spec.lua index 215998e..1fce54a 100644 --- a/lua/spec/nfnl/fs_spec.lua +++ b/lua/spec/nfnl/fs_spec.lua @@ -1,13 +1,16 @@ --- [nfnl] Compiled from fnl/spec/nfnl/fs_spec.fnl by https://github.com/Olical/nfnl, do not edit. +-- [nfnl] Compiled from fnl\spec\nfnl\fs_spec.fnl by https://github.com/Olical/nfnl, do not edit. local _local_1_ = require("plenary.busted") local describe = _local_1_["describe"] local it = _local_1_["it"] local assert = require("luassert.assert") local fs = require("nfnl.fs") +local function windows_3f() + return (jit.os == "Windows") +end local function _2_() local function _3_() - assert.equals("foo", fs.basename("foo/bar.fnl")) - assert.equals("foo/bar", fs.basename("foo/bar/baz.fnl")) + assert.equals("foo", fs.basename(fs["join-path"]({"foo", "bar.fnl"}))) + assert.equals(fs["join-path"]({"foo", "bar"}), fs.basename(fs["join-path"]({"foo", "bar", "baz.fnl"}))) return assert.equals(".", fs.basename("baz.fnl")) end it("removes the last segment of a path", _3_) @@ -19,40 +22,65 @@ end describe("basename", _2_) local function _5_() local function _6_() - return assert.equals("/", fs["path-sep"]()) + if windows_3f() then + return assert.equals("\\", fs["path-sep"]()) + else + return assert.equals("/", fs["path-sep"]()) + end end - return it("returns the OS path separator (test assumes Linux)", _6_) + return it("returns the OS path separator", _6_) end describe("path-sep", _5_) -local function _7_() - local function _8_() +local function _8_() + local function _9_() return assert.equals("foo.lua", fs["replace-extension"]("foo.fnl", "lua")) end - return it("replaces extensions", _8_) + return it("replaces extensions", _9_) +end +describe("replace-extension", _8_) +local function _10_() + local function _11_() + assert.are.same({"foo", "bar", "baz"}, fs["split-path"](fs["correct-separators"]("foo/bar/baz")), z) + return assert.are.same({"", "foo", "bar", "baz"}, fs["split-path"](fs["correct-separators"]("/foo/bar/baz"))) + end + return it("splits a path into parts", _11_) +end +describe("split-path", _10_) +local function _12_() + local function _13_() + assert.equals("foo/bar/baz", fs["standardize-path"](fs["join-path"]({"foo", "bar", "baz"}))) + return assert.equals("/foo/bar/baz", fs["standardize-path"](fs["join-path"]({"", "foo", "bar", "baz"}))) + end + return it("joins a path together", _13_) end -describe("replace-extension", _7_) -local function _9_() - local function _10_() - assert.are.same({"foo", "bar", "baz"}, fs["split-path"]("foo/bar/baz")) - return assert.are.same({"", "foo", "bar", "baz"}, fs["split-path"]("/foo/bar/baz")) +describe("join-path", _12_) +local function _14_() + local function _15_() + assert.equals("foo/lua/bar", fs["standardize-path"](fs["replace-dirs"](fs["correct-separators"]("foo/fnl/bar"), "fnl", "lua"))) + assert.equals("/foo/lua/bar", fs["standardize-path"](fs["replace-dirs"](fs["correct-separators"]("/foo/fnl/bar"), "fnl", "lua"))) + return assert.equals("/foo/nfnl/bar", fs["standardize-path"](fs["replace-dirs"]("/foo/nfnl/bar", "fnl", "lua"))) end - return it("splits a path into parts", _10_) + return it("replaces directories in a path that match a string with another string", _15_) end -describe("split-path", _9_) -local function _11_() - local function _12_() - assert.equals("foo/bar/baz", fs["join-path"]({"foo", "bar", "baz"})) - return assert.equals("/foo/bar/baz", fs["join-path"]({"", "foo", "bar", "baz"})) +describe("replace-dirs", _14_) +local function _16_() + local function _17_() + assert.equals("foo/bar/baz.fnl", fs["standardize-path"]("foo\\bar\\baz.fnl")) + return assert.equals("foo/bar/baz.fnl", fs["standardize-path"]("foo/bar/baz.fnl")) end - return it("joins a path together", _12_) + return it("replaces all path separators with forward slash", _17_) end -describe("join-path", _11_) -local function _13_() - local function _14_() - assert.equals("foo/lua/bar", fs["replace-dirs"]("foo/fnl/bar", "fnl", "lua")) - assert.equals("/foo/lua/bar", fs["replace-dirs"]("/foo/fnl/bar", "fnl", "lua")) - return assert.equals("/foo/nfnl/bar", fs["replace-dirs"]("/foo/nfnl/bar", "fnl", "lua")) +describe("standardize-path", _16_) +local function _18_() + local function _19_() + if windows_3f() then + assert.equals("foo\\bar\\baz.fnl", fs["correct-separators"]("foo/bar/baz.fnl")) + return assert.equals("foo\\bar\\baz.fnl", fs["correct-separators"]("foo\\bar\\baz.fnl")) + else + assert.equals("foo/bar/baz.fnl", fs["correct-separators"]("foo/bar/baz.fnl")) + return assert.equals("foo/bar/baz.fnl", fs["correct-separators"]("foo\\bar\\baz.fnl")) + end end - return it("replaces directories in a path that match a string with another string", _14_) + return it("", _19_) end -return describe("replace-dirs", _13_) +return describe("correct-separators", _18_) diff --git a/script/setup-test-deps.ps1 b/script/setup-test-deps.ps1 new file mode 100644 index 0000000..4a23b82 --- /dev/null +++ b/script/setup-test-deps.ps1 @@ -0,0 +1,10 @@ + +$PACK_DIR = "./.test-config/nvim/pack/nfnl-tests/start" + +mkdir $PACK_DIR -erroraction 'silentlycontinue' +git clone https://github.com/nvim-lua/plenary.nvim.git $PACK_DIR/plenary.nvim +git clone https://github.com/nvim-lua/plenary.nvim.git $PACK_DIR/fennel.vim + +$LINK_TARGET = $GITHUB_WORKSPACE ?? $PWD +echo $LINK_TARGET +new-item -path $PACK_DIR/nfnl -itemtype Junction -value $LINK_TARGET -force diff --git a/script/test.ps1 b/script/test.ps1 new file mode 100644 index 0000000..1ac1e21 --- /dev/null +++ b/script/test.ps1 @@ -0,0 +1,7 @@ +$env:XDG_CONFIG_HOME = "$PWD/.test-config" +$env:XDG_STATE_HOME = "$PWD/.test-state" + +rm -for -rec $env:XDG_STATE_HOME -erroraction 'silentlycontinue' + +nvim --headless -c 'edit .nfnl.fnl' -c trust -c qa +nvim --headless -c 'PlenaryBustedDirectory lua\\spec'