goto module definition tested

This commit is contained in:
XeroOl 2024-07-09 20:37:11 -05:00
parent 11c4af5ae1
commit 07e8239216
4 changed files with 48 additions and 37 deletions

View File

@ -56,7 +56,6 @@ identifiers are declared / referenced in which places."
position (utils.pos->position file.text line byte server.position-encoding)] position (utils.pos->position file.text line byte server.position-encoding)]
{:start position :end position})) {:start position :end position}))
(λ compile [{:configuration {: macro-path} :root-uri ?root-uri &as server} file] (λ compile [{:configuration {: macro-path} :root-uri ?root-uri &as server} file]
"Compile the file, and record all the useful information from the compiler into the file object" "Compile the file, and record all the useful information from the compiler into the file object"
;; The useful information being recorded: ;; The useful information being recorded:

View File

@ -14,7 +14,7 @@
;; "|" is the cursor ;; "|" is the cursor
;; "==" is the definition that should be found ;; "==" is the definition that should be found
(fn test-basics [] (fn test-local []
(check "(fn ==x== []) x|") (check "(fn ==x== []) x|")
(check "(local ==x== 10) (check "(local ==x== 10)
@ -77,7 +77,7 @@
(check "==(fn foo| [] nil)==") (check "==(fn foo| [] nil)==")
nil) nil)
(fn test-indirection [] (fn test-fields []
(check "(fn ==target== [] nil) (check "(fn ==target== [] nil)
(local obstacle {: target}) (local obstacle {: target})
(obstacle.tar|get)") (obstacle.tar|get)")
@ -131,6 +131,19 @@
(local (a b) (values {:x y : y} {: x : y})) (local (a b) (values {:x y : y} {: x : y}))
(print b.x| a)") (print b.x| a)")
(check "(local a {:b {:c =={:d #\"hi\"}==}})
(a.b.|c.d)")
(check "(local a {:b {:c =={:d #\"hi\"}==}})
(a.b.c|.d)")
;; finds fn declarations
(check "(local M {})
(fn ==M.my-function== [] nil)
(M.my-function|)")
nil)
(fn test-thru-require []
(check (check
{:foo.fnl "(fn ==target== [] {:foo.fnl "(fn ==target== []
nil) nil)
@ -175,23 +188,22 @@
; :main.fnl "(local {: target} (require :f|oo)) ; :main.fnl "(local {: target} (require :f|oo))
; (target)"})) ; (target)"}))
(check "(local a {:b {:c =={:d #\"hi\"}==}})
(a.b.|c.d)")
(check "(local a {:b {:c =={:d #\"hi\"}==}})
(a.b.c|.d)")
nil) nil)
; (fn test-macro []
; (check "(macro ==my-macro== [] `nil)
; (my-mac|ro)")
; (check {:m.fnl ";; fennel-ls: macro-file
; (fn ==my-macro== [] `nil)
; {: my-macro}"
; :main.fnl "(import-macros m :m)
; (m.my-macro|)"}))
(fn test-no-crash [] (fn test-no-crash []
(check "(macro cool [a b] `(let [,b 10] ,a))\n(cool |x ==x==)") (check "(macro cool [a b] `(let [,b 10] ,a))\n(cool |x ==x==)")
(check "(macro cool [a b] `(let [,b 10] ,a))\n(cool x x|)") (check "(macro cool [a b] `(let [,b 10] ,a))\n(cool x x|)")
(check "|#$...")
(check "|#$...")) nil)
; ;; (it "can go to a destructured function argument") ; ;; (it "can go to a destructured function argument")
; ;; (it "can go through more than one file") ; ;; (it "can go through more than one file")
@ -202,13 +214,13 @@
; ;; (it "can follow import-macros (namespaced)") ; ;; (it "can follow import-macros (namespaced)")
; ;; (it "can go to the definition in a lua file") ; ;; (it "can go to the definition in a lua file")
; ;; (it "finds (set a.b) definitions") ; ;; (it "finds (set a.b) definitions")
; (it "finds (fn a.b [] ...) declarations"
; ;; (it "finds (tset a :b) definitions") ; ;; (it "finds (tset a :b) definitions")
; ;; (it "finds (setmetatable a {:__index {:b def}) definitions") ; ;; (it "finds (setmetatable a {:__index {:b def}) definitions")
; ;; (it "finds definitions into a function (fn foo [] (local x 10) {: x}) (let [result (foo)] (print result.x)) finds result.x") ; ;; (it "finds definitions into a function (fn foo [] (local x 10) {: x}) (let [result (foo)] (print result.x)) finds result.x")
; ;; (it "finds definitions through a function (fn foo [{: y}] {:x y}) (let [result (foo {:y {}})] (print result.x)) finds result.x") ; ;; (it "finds definitions through a function (fn foo [{: y}] {:x y}) (let [result (foo {:y {}})] (print result.x)) finds result.x")
; ;; (it "finds through setmetatable with an :__index function") ; ;; (it "finds through setmetatable with an :__index function")
{: test-basics {: test-local
: test-indirection : test-fields
: test-thru-require
: test-no-crash} : test-no-crash}

View File

@ -1,6 +1,10 @@
(local faith (require :faith)) (local faith (require :faith))
(local fennel (require :fennel))
(faith.run (case (os.getenv "FAITH_TEST")
target (let [(module function) (target:match "([^ ]+) ([^ ]+)")]
(xpcall (. (require module) function) #(print ($:tostring target))))
_ (faith.run
[:test.json-rpc [:test.json-rpc
:test.string-processing :test.string-processing
:test.capabilities :test.capabilities
@ -14,4 +18,4 @@
:test.code-action :test.code-action
:test.rename :test.rename
:test.misc :test.misc
:test.check]) :test.check]))

View File

@ -1,11 +1,7 @@
(local dispatch (require :fennel-ls.dispatch)) (local dispatch (require :fennel-ls.dispatch))
(local message (require :fennel-ls.message)) (local message (require :fennel-ls.message))
(local ROOT-PATH (local ROOT-PATH "/path/to/test/project")
(-> (io.popen "pwd")
(: :read :*a)
(: :sub 1 -2) ;; take off newline
(.. "/test/test-project")))
(local ROOT-URI (local ROOT-URI
(.. "file://" ROOT-PATH)) (.. "file://" ROOT-PATH))