Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
vemv committed Jun 23, 2023
1 parent 569530b commit 3d9457d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
3 changes: 2 additions & 1 deletion cider-eldoc.el
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ It can be a function or var now."
("special-form" 'special-form)
("macro" 'macro)
("method" 'method)
("variable" 'var)))
("variable" 'var)
(or 'fn)))

(defun cider-eldoc-info-at-point ()
"Return eldoc info at point.
Expand Down
60 changes: 34 additions & 26 deletions test/cider-eldoc-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@
(expect (cider--eldoc-format-class-names class-names)
:to-equal "(String StringBuffer CharSequence & 1 more)")))))

;; NOTE: more cases could be added. Correct behavior is TBD, see https://github.com/clojure-emacs/orchard/issues/99
(describe "cider-eldoc-thing-type"
(it "Identifies special forms correctly"
(let ((eldoc-info '("type" "special-form")))
(expect (cider-eldoc-thing-type eldoc-info) :to-equal 'special-form)))
(it "Identifies functions correctly"
(let ((eldoc-info '("type" "function")))
(expect (cider-eldoc-thing-type eldoc-info) :to-equal 'fn)))
(it "Defaults to 'fn"
(let ((eldoc-info '("type" "made-up-123")))
(expect (cider-eldoc-thing-type eldoc-info) :to-equal 'fn))))

(describe "cider-eldoc-format-special-form"
Expand All @@ -89,16 +93,13 @@
(cider-eldoc-format-special-form 'if 0 eldoc-info)
(expect 'cider-eldoc-format-arglist :to-have-been-called-with '(("test" "then" "else?")) 0)))
(it "Should not remove duplicates from special-form arglists that do not have duplicates"
(let ((eldoc-info '("ns" nil
"symbol" "."
"arglists" ((".instanceMember" "instance" "args*") (".instanceMember" "Classname" "args*") ("Classname/staticMethod" "args*") ("Classname/staticField"))
"type" "special-form")))
(let* ((arglists ((".instanceMember" "instance" "args*") (".instanceMember" "Classname" "args*") ("Classname/staticMethod" "args*") ("Classname/staticField")))
(eldoc-info `("ns" nil
"symbol" "."
"arglists" ,arglists
"type" "special-form")))
(cider-eldoc-format-special-form 'if 0 eldoc-info)
(expect 'cider-eldoc-format-arglist :to-have-been-called-with '((".instanceMember" "instance" "args*")
(".instanceMember" "Classname" "args*")
("Classname/staticMethod" "args*")
("Classname/staticField"))
0))))
(expect 'cider-eldoc-format-arglist :to-have-been-called-with arglists))))

(describe "cider-eldoc-format-thing"
:var (class-names)
Expand Down Expand Up @@ -274,25 +275,32 @@
(spy-on 'cider-connected-p :and-return-value t)
(spy-on 'cider-eldoc--edn-file-p :and-return-value nil))
(it "Should call cider-eldoc-format-variable for vars"
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value '("thing" "foo" "pos" 0 "eldoc-info" ("ns" "clojure.core" "symbol" "foo" "type" "variable" "docstring" "test docstring")))
(spy-on 'cider-eldoc-format-variable)
(cider-eldoc)
(expect 'cider-eldoc-format-variable :to-have-been-called-with "foo" '("ns" "clojure.core" "symbol" "foo" "type" "variable" "docstring" "test docstring")))
(let* ((info '("ns" "clojure.core" "symbol" "foo" "type" "variable" "docstring" "test docstring")))
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value `("thing" "foo" "pos" 0 "eldoc-info" ,info))
(spy-on 'cider-eldoc-format-variable)
(cider-eldoc)
(expect 'cider-eldoc-format-variable :to-have-been-called-with "foo" info)))

(it "Should call cider-eldoc-format-special-form for special forms"
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value '("thing" "if" "pos" 0 "eldoc-info" ("ns" "clojure.core" "symbol" "if" "type" "special-form" "arglists" ("special form arglist"))))
(spy-on 'cider-eldoc-format-special-form)
(cider-eldoc)
(expect 'cider-eldoc-format-special-form :to-have-been-called-with "if" 0 '("ns" "clojure.core" "symbol" "if" "type" "special-form" "arglists" ("special form arglist"))))
(let* ((info '("ns" "clojure.core" "symbol" "if" "type" "special-form" "arglists" ("special form arglist"))))
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value `("thing" "if" "pos" 0 "eldoc-info" ,info))
(spy-on 'cider-eldoc-format-special-form)
(cider-eldoc)
(expect 'cider-eldoc-format-special-form :to-have-been-called-with "if" 0 info)))

(it "Should call cider-eldoc-format-function for functions"
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value '("thing" "a-fn" "pos" 0 "eldoc-info" ("ns" "foo.bar" "symbol" "a-fn" "type" "function" "arglists" ("function arglist"))))
(spy-on 'cider-eldoc-format-function)
(cider-eldoc)
(expect 'cider-eldoc-format-function :to-have-been-called-with "a-fn" 0 '("ns" "foo.bar" "symbol" "a-fn" "type" "function" "arglists" ("function arglist"))))
(let* ((info '("ns" "foo.bar" "symbol" "a-fn" "type" "function" "arglists" ("function arglist"))))
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value `("thing" "a-fn" "pos" 0 "eldoc-info" ,info))
(spy-on 'cider-eldoc-format-function)
(cider-eldoc)
(expect 'cider-eldoc-format-function :to-have-been-called-with "a-fn" 0 info)))

(it "Should call cider-eldoc-format-function for macros"
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value '("thing" "a-macro" "pos" 0 "eldoc-info" ("ns" "clojure.core" "symbol" "a-macro" "type" "macro" "arglists" ("macro arglist"))))
(spy-on 'cider-eldoc-format-function)
(cider-eldoc)
(expect 'cider-eldoc-format-function :to-have-been-called-with "a-macro" 0 '("ns" "clojure.core" "symbol" "a-macro" "type" "macro" "arglists" ("macro arglist")))))
(let* ((info '("ns" "clojure.core" "symbol" "a-macro" "type" "macro" "arglists" ("macro arglist"))))
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value `("thing" "a-macro" "pos" 0 "eldoc-info" ,info))
(spy-on 'cider-eldoc-format-function)
(cider-eldoc)
(expect 'cider-eldoc-format-function :to-have-been-called-with "a-macro" 0 info))))

(describe "cider-eldoc-format-sym-doc"
:var (eldoc-echo-area-use-multiline-p)
Expand Down Expand Up @@ -364,6 +372,6 @@
(it "adds the datomic query inputs of the query at point to the arglist"
(spy-on 'cider-second-sexp-in-list :and-return-value t)
(spy-on 'cider-sync-request:eldoc-datomic-query
:and-return-value '(dict "inputs" (("$" "?first-name"))))
:and-return-value '(dict "inputs" (("$" "?first-name"))))
(expect (cider--eldoc-add-datomic-query-inputs-to-arglists '(("query" "&" "inputs")))
:to-equal '(("query" "$" "?first-name")))))

0 comments on commit 3d9457d

Please sign in to comment.