Permalink
Browse files

putting everything back into a semi-working state

  • Loading branch information...
1 parent ee7a658 commit a850ba198f79b11d4e0ab92929135579ab098bc4 @ztellman committed Dec 9, 2011
Showing with 27 additions and 10 deletions.
  1. +6 −7 src/potemkin/namespace.clj
  2. +12 −3 test/potemkin/test/namespace.clj
  3. +9 −0 test/potemkin/test/protocol.clj
View
@@ -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
@@ -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))
@@ -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)))
@@ -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)))
+ )
@@ -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.