Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix: Metadata of function symbol is included now.

  • Loading branch information...
commit 490442464bf585952d1f3b368857c5b554c934dd 1 parent c2f6765
@guv authored
Showing with 8 additions and 4 deletions.
  1. +5 −3 src/clojure/options.clj
  2. +3 −1 test/clojure/options_tests.clj
View
8 src/clojure/options.clj
@@ -28,7 +28,7 @@
Returns the map {:meta-map metadata, :body-list func-body} with the meta data of the function
and the list of function bodies.
"
- [func-decl]
+ [fname, func-decl]
(let [
; extract doc string (if present) and create metadata map
meta-map (if (string? (first func-decl))
@@ -57,7 +57,9 @@
; remove metadata at the end if present
func-decl (if (map? (last func-decl))
(butlast func-decl)
- func-decl)
+ func-decl),
+ ; merge metadata of the function name symbol with the collected metadata
+ meta-map (merge (meta fname) meta-map)
]
{:meta-map meta-map, :body-list func-decl}))
@@ -385,7 +387,7 @@
(defmacro defn+opts
"Define a function with defn-like syntax and option support."
[fname & fdecl]
- (let [{:keys [meta-map body-list]} (process-defn-decl fdecl)]
+ (let [{:keys [meta-map body-list]} (process-defn-decl fname, fdecl)]
(assert-args defn+opts
(= 1 (count body-list)) "that only one body is specified")
(let [[params & body] (first body-list),
View
4 test/clojure/options_tests.clj
@@ -105,10 +105,11 @@
(g 10 :call-f true :delta 5) => 16)
-(defn+opts int->str
+(defn+opts ^{:awesome true} int->str
"Converts a given positive integer into a string.
<base>The base to use for string encoding (<= 10).</base>
"
+ {:used-meta-map true}
[x | {base 10}]
(loop [x x, digits (list)]
(if (pos? x)
@@ -118,6 +119,7 @@
(facts "'int->str meta"
(resolve 'int->str) => truthy
(meta #'int->str) => (contains {:clojure.options/defn+opts true, :options anything, :mandatory-parameters ['x]})
+ (meta #'int->str) => (contains {:awesome true, :used-meta-map true}),
(-> #'int->str meta :options) => (contains {:mine (just {'base {:name 'base, :default 10, :doc "The base to use for string encoding (<= 10)."}})})
(-> #'int->str meta :doc) => (and #"Converts a given positive integer into a string\." #":base" #"The base to use for string encoding \(<= 10\)\.")
(-> #'int->str meta :doc) =not=> (or #"<base>" #"</base>"))
Please sign in to comment.
Something went wrong with that request. Please try again.