Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #23 from ryantm/master

add doc-from-ns-form to bultitude.core
  • Loading branch information...
commit eb89b62b6662d62c1a0a144cdd835699cd3a63dc 2 parents 628dd0e + 2691432
Anthony Grimes authored
Showing with 38 additions and 0 deletions.
  1. +5 −0 src/bultitude/core.clj
  2. +33 −0 test/bultitude/core_test.clj
5 src/bultitude/core.clj
View
@@ -123,3 +123,8 @@
(.replace \- \_)
(.replace \. \/))
".clj"))
+
+(defn doc-from-ns-form
+ "Extract the docstring from a given ns form without evaluating the form. The docstring returned should be the return value of (:doc (meta namespace-symbol)) if the ns-form were to be evaluated."
+ [ns-form]
+ (:doc (meta (second (second (second (macroexpand ns-form)))))))
33 test/bultitude/core_test.clj
View
@@ -22,3 +22,36 @@
(is (=
#{'bulti-tude.test}
(set (namespaces-on-classpath :prefix "bulti-tude"))))))
+
+(defn test-doc-from-ns-form-helper
+ [docstring ns-form]
+ (eval ns-form)
+ (is (= docstring
+ (:doc (meta *ns*))
+ (doc-from-ns-form ns-form))))
+
+(deftest doc-from-ns-form-test
+ (testing "doc-from-ns-form"
+ (let [callee-ns-name (ns-name *ns*)]
+ (test-doc-from-ns-form-helper
+ nil
+ '(ns no-doc-namespace-name))
+ (test-doc-from-ns-form-helper
+ "Docstring"
+ '(ns regular-doc-namespace-name "Docstring"))
+ (test-doc-from-ns-form-helper
+ "Attribute-Docstring"
+ '(ns attribute-doc-namepsace-name {:doc "Attribute-Docstring"}))
+ (test-doc-from-ns-form-helper
+ "Meta-Docstring"
+ '(ns ^{:doc "Meta-Docstring"} meta-doc-namespace-name))
+ (test-doc-from-ns-form-helper
+ "Docstring"
+ '(ns ^{:doc "Meta-Docstring"} meta-and-reg-doc-namespace-name "Docstring"))
+ (test-doc-from-ns-form-helper
+ "Attribute-Docstring"
+ '(ns reg-and-attribute-doc-namespace-name "Docstring" {:doc "Attribute-Docstring"}))
+ (test-doc-from-ns-form-helper
+ "Attribute-Docstring"
+ '(ns ^{:doc "Meta-Docstring"} all-doc-namespace-name "Docstring" {:doc "Attribute-Docstring"}))
+ (in-ns callee-ns-name))))
Please sign in to comment.
Something went wrong with that request. Please try again.