hotfix issue with path join
Not sure why I didn't test these changes, but the path-join function didn't actually work fully as expected. Now, various edge cases have been ironed out: "/path" + "/foo/bar" -> "/foo/bar", instead of "/path/foo/bar" "" + "code.fnl" -> "code.fnl", instead of "/code.fnl"
This commit is contained in:
parent
552b03b983
commit
cb9f09ba84
@ -198,15 +198,14 @@ WARNING: this is only used in the test code, not in the real language server"
|
||||
(= (path:sub 1 1) "/")))
|
||||
|
||||
(λ path-join [path suffix]
|
||||
(-> (.. path path-sep suffix)
|
||||
;; delete duplicate
|
||||
;; windows
|
||||
(: :gsub "^%.\\" "")
|
||||
(: :gsub "\\+" "\\")
|
||||
;; modern society
|
||||
(: :gsub "^%./" "")
|
||||
(: :gsub "/+" "/")
|
||||
(->> (pick-values 1))))
|
||||
(if (absolute-path? suffix) suffix
|
||||
(= path "") suffix
|
||||
(let [clean-path (path:gsub "[\\/]?$" path-sep) ; ensure trailing slash
|
||||
clean-suffix (if (or (= (suffix:sub 1 2) "./")
|
||||
(= (suffix:sub 1 2) ".\\"))
|
||||
(suffix:sub 3)
|
||||
suffix)]
|
||||
(.. clean-path clean-suffix))))
|
||||
|
||||
(fn find [t x ?k]
|
||||
(match (next t ?k) (k x) k (k y_) (find t x k)))
|
||||
|
||||
@ -43,6 +43,28 @@
|
||||
(create-client "(let [map {}] (set (. map (tostring :a)) :b))")
|
||||
nil)
|
||||
|
||||
(fn test-path-join []
|
||||
;; Basic path joining
|
||||
(faith.= "path/file" (utils.path-join "path/" "file"))
|
||||
(faith.= "path/file" (utils.path-join "path" "file"))
|
||||
(faith.= "path/file" (utils.path-join "path" "./file"))
|
||||
|
||||
; Empty path - return suffix as-is
|
||||
(faith.= "file" (utils.path-join "" "file"))
|
||||
(faith.= "main.fnl" (utils.path-join "" "main.fnl"))
|
||||
(faith.= "path/" (utils.path-join "path" ""))
|
||||
|
||||
; Absolute suffix should override base path
|
||||
(faith.= "/usr/share/awesome/lib" (utils.path-join "/home/myusername/.config/awesome/" "/usr/share/awesome/lib"))
|
||||
|
||||
; Leading ./ in suffix should be stripped
|
||||
(faith.= "/home/myusername/my-project/main.fnl" (utils.path-join "/home/myusername/my-project" "./main.fnl"))
|
||||
|
||||
; Nested relative paths
|
||||
(faith.= "a/b/c/d" (utils.path-join "a/b" "c/d"))
|
||||
nil)
|
||||
|
||||
{: test-multi-sym-split
|
||||
: test-find-symbol
|
||||
: test-failure}
|
||||
: test-failure
|
||||
: test-path-join}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user