Skip to content

Commit

Permalink
putting everything back into a semi-working state
Browse files Browse the repository at this point in the history
  • Loading branch information
ztellman committed Dec 9, 2011
1 parent ee7a658 commit a850ba1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
13 changes: 6 additions & 7 deletions src/potemkin/namespace.clj
Expand Up @@ -17,15 +17,15 @@
n (:name m)
arglists (:arglists m)
doc (:doc m)]
`(do
(def ~n
~(eval sym))
#_`(do
(def ~n ~(ns-resolve (:ns m) (:name m)))
(alter-meta! ~(list 'var n) assoc
:doc ~doc
:arglists '~arglists
:arglists ~(list 'quote arglists)
:file ~(:file m)
:line ~(:line m))
~(list 'var n))))
~(list 'var n))
(list `def (with-meta n {:doc doc :arglists (list 'quote arglists) :file (:file m) :line (:line m)}) (eval sym))))

(defmacro import-macro
"Given a macro in another namespace, defines a macro with the same name in the
Expand All @@ -39,11 +39,10 @@
doc (:doc m)
args-sym (gensym "args")]
`(do
(defmacro ~n
(defmacro ~(with-meta n {:arglists arglists})
[~'& ~args-sym]
(list* ~sym ~args-sym))
(alter-meta! ~(list 'var n) assoc
:arglists '~arglists
:doc ~doc
:file ~(:file m)
:line ~(:line m))
Expand Down
15 changes: 12 additions & 3 deletions test/potemkin/test/namespace.clj
Expand Up @@ -12,11 +12,14 @@
clojure.test)
(:require
[clojure.repl :as repl]
[clojure.string :as str]))
[clojure.string :as str]
[potemkin.test.protocol :as p]))

(import-macro #'repl/source)
(import-macro #'repl/doc)
(import-fn #'repl/find-doc)
(import-fn #'p/multi-arity)
(import-fn #'p/protocol-function)

(defn drop-lines [n s]
(->> s str/split-lines (drop n) (interpose "\n") (apply str)))
Expand All @@ -25,14 +28,20 @@
`(= ~@(map (fn [x] `(with-out-str ~x)) args)))

(defmacro rest-out= [& args]
`(= ~@(map (fn [x] `(drop-lines 2 (with-out-str ~x))) args)))
`(do
;;(do ~@(map (fn [x] `(println (with-out-str ~x))) args))
(= ~@(map (fn [x] `(drop-lines 2 (with-out-str ~x))) args))))

(deftest test-import-macro
(is (out= (source repl/source) (source source)))
(is (rest-out= (doc repl/doc) (doc doc))))

(deftest test-import-fn
(is (out= (source repl/find-doc) (source find-doc)))
(is (rest-out= (doc repl/find-doc) (doc find-doc))))
(is (rest-out= (doc repl/find-doc) (doc find-doc)))
(is (out= (source p/multi-arity) (source multi-arity)))
(is (rest-out= (doc p/multi-arity) (doc multi-arity)))
(is (rest-out= (doc p/protocol-function) (doc protocol-function)))
)


9 changes: 9 additions & 0 deletions test/potemkin/test/protocol.clj
@@ -0,0 +1,9 @@
(ns potemkin.test.protocol)

(defn multi-arity
"Here is a doc-string."
([x])
([x y]))

(defprotocol TestProtocol
(protocol-function [x a b c] "This is a protocol function."))

0 comments on commit a850ba1

Please sign in to comment.