Skip to content
Snippets Groups Projects
Unverified Commit f95817bf authored by Bryan Maass's avatar Bryan Maass Committed by GitHub
Browse files

mu/defn fix: no return schema docstring generation (#28121)

* handle nil return schemas for docstring gen

* adds more mu/defn docstring generation tests
parent 7f70a68b
No related branches found
No related tags found
No related merge requests found
......@@ -70,7 +70,7 @@ explain-fn-fail!
(str "Inputs: " (if single
(pr-str (first (mapv :raw-arglist parglists)))
(str "(" (str/join "\n " (map (comp pr-str :raw-arglist) parglists)) ")"))
"\n Return: " (str/replace (u/pprint-to-str (:schema return))
"\n Return: " (str/replace (u/pprint-to-str (:schema return :any))
"\n"
(str "\n "))
(when (not-empty doc) (str "\n\n " doc))))
......
......@@ -35,6 +35,55 @@
(is (str/ends-with? (:doc (meta #'boo)) "something very important to remember goes here"))
(ns-unmap *ns* 'boo))
(testing "no schemas given should work"
(mu/defn qux [])
(is (= "Inputs: []\n Return: :any"
(:doc (meta #'qux))))
(ns-unmap *ns* 'qux)
(mu/defn qux "Original docstring." [])
(is (= (str/join "\n"
[ "Inputs: []"
" Return: :any"
" "
""
" Original docstring."])
(:doc (meta #'qux))))
(ns-unmap *ns* 'qux))
(testing "no return schemas given should work"
(mu/defn qux [x :- :int])
(is (= "Inputs: [x :- :int]\n Return: :any"
(:doc (meta #'qux))))
(ns-unmap *ns* 'qux)
(mu/defn qux "Original docstring." [x :- :int])
(is (= (str/join "\n"
[ "Inputs: [x :- :int]"
" Return: :any"
" "
""
" Original docstring."])
(:doc (meta #'qux))))
(ns-unmap *ns* 'qux))
(testing "no input schemas given should work"
(mu/defn qux :- :int [])
(is (= "Inputs: []\n Return: :int"
(:doc (meta #'qux))))
(ns-unmap *ns* 'qux)
(mu/defn qux :- :int
"Original docstring."
[x :- :int])
(is (= (str/join "\n"
[ "Inputs: [x :- :int]"
" Return: :int"
" "
""
" Original docstring."])
(:doc (meta #'qux))))
(ns-unmap *ns* 'qux))
(testing "multi-arity, and varargs doc strings should work"
(mu/defn ^:private foo :- [:multi {:dispatch :type}
[:sized [:map [:type [:= :sized]]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment