add diagnostic test for unknown module field

This commit is contained in:
XeroOl 2024-03-01 17:32:51 -06:00
parent 0dd9c0ff65
commit be997dc7fb

View File

@ -1,9 +1,6 @@
(local faith (require :faith)) (local faith (require :faith))
(local {: view} (require :fennel)) (local {: view} (require :fennel))
(local {: ROOT-URI (local {: create-client-with-files} (require :test.utils))
: create-client} (require :test.utils.client))
(local filename (.. ROOT-URI "/imaginary.fnl"))
(fn find [diagnostics e] (fn find [diagnostics e]
"returns the index of the diagnostic " "returns the index of the diagnostic "
@ -24,9 +21,7 @@
i))) i)))
(fn check [file-contents expected unexpected] (fn check [file-contents expected unexpected]
(let [self (create-client) (let [{: diagnostics} (create-client-with-files file-contents)]
[{:params {: diagnostics}}] (self:open-file! filename file-contents)]
(each [_ e (ipairs unexpected)] (each [_ e (ipairs unexpected)]
(let [i (find diagnostics e)] (let [i (find diagnostics e)]
(faith.= nil i (.. "Lint matching " (view e) "\n" (faith.= nil i (.. "Lint matching " (view e) "\n"
@ -116,15 +111,16 @@
(check "(fn [a b] (set a.x 10) (fn b.f []))" [] [{}]) (check "(fn [a b] (set a.x 10) (fn b.f []))" [] [{}])
nil) nil)
; (fn test-unknown-module-field [] (fn test-unknown-module-field []
; (check {:the-guy-they-tell-you-not-to-worry-about.fnl (check {:the-guy-they-tell-you-not-to-worry-about.fnl
; "(local M {:a 1}) "(local M {:a 1})
; (fn M.b [] 2) (fn M.b [] 2)
; M" M"
; :main.fnl :main.fnl
; "(local {: a : c &as guy} (require :the-guy-they-tell-you-not-to-worry-about)) "(local {: a : c &as guy} (require :the-guy-they-tell-you-not-to-worry-about))
; (print guy.b guy.d)"} (print guy.b guy.d)"}
; [{:code 302}] [{:code 302 :message "unknown module field: a"}])) [{:code 302}] [{:code 302 :message "unknown module field: a"}
{:code 302 :message "unknown module field: b"}]))
(fn test-unnecessary-colon [] (fn test-unnecessary-colon []
(check "(let [x :haha] (: x :find :a))" (check "(let [x :haha] (: x :find :a))"