@@ -124,49 +124,27 @@ Usage: *hello*
124124 " 'foo"
125125)
126126
127- (simple-tests code-block-tests
128- (with-out-str
129- (with-pprint-dispatch code-dispatch
130- (pprint
131- '(defn cl-format
132- " An implementation of a Common Lisp compatible format function"
133- [stream format-in & args]
134- (let [compiled-format (if (string? format-in) (compile-format format-in) format-in)
135- navigator (init-navigator args)]
136- (execute-format stream compiled-format navigator))))))
137- " (defn cl-format
127+ (defmacro code-block
128+ " Read a string then print it with code-dispatch and succeed if it comes out the same"
129+ [test-name & blocks]
130+ `(simple-tests ~test-name
131+ ~@(apply concat
132+ (for [block blocks]
133+ `[(with-out-str
134+ (with-pprint-dispatch code-dispatch
135+ (pprint (read-string ~block))))
136+ (str ~block " \n " )]))))
137+
138+ (code-block code-block-tests
139+ " (defn cl-format
138140 \" An implementation of a Common Lisp compatible format function\"
139141 [stream format-in & args]
140142 (let [compiled-format (if (string? format-in)
141143 (compile-format format-in)
142144 format-in)
143145 navigator (init-navigator args)]
144- (execute-format stream compiled-format navigator)))
145- "
146-
147- (with-out-str
148- (with-pprint-dispatch code-dispatch
149- (pprint
150- '(defn pprint-defn [writer alis]
151- (if (next alis)
152- (let [[defn-sym defn-name & stuff] alis
153- [doc-str stuff] (if (string? (first stuff))
154- [(first stuff) (next stuff)]
155- [nil stuff])
156- [attr-map stuff] (if (map? (first stuff))
157- [(first stuff) (next stuff)]
158- [nil stuff])]
159- (pprint-logical-block writer :prefix " (" :suffix " )"
160- (cl-format true " ~w ~1I~@_~w" defn-sym defn-name )
161- (if doc-str
162- (cl-format true " ~_~w" doc-str))
163- (if attr-map
164- (cl-format true " ~_~w" attr-map))
165- ; ; Note: the multi-defn case will work OK for malformed defns too
166- (cond
167- (vector? (first stuff)) (single-defn stuff (or doc-str attr-map))
168- :else (multi-defn stuff (or doc-str attr-map)))))
169- (pprint-simple-code-list writer alis))))))
146+ (execute-format stream compiled-format navigator)))"
147+
170148 " (defn pprint-defn [writer alis]
171149 (if (next alis)
172150 (let [[defn-sym defn-name & stuff] alis
@@ -190,9 +168,41 @@ Usage: *hello*
190168 stuff
191169 (or doc-str attr-map))
192170 :else (multi-defn stuff (or doc-str attr-map)))))
193- (pprint-simple-code-list writer alis)))
194- " )
195-
171+ (pprint-simple-code-list writer alis)))" )
172+
173+ (code-block ns-macro-test
174+ " (ns slam.hound.stitch
175+ (:use [slam.hound.prettify :only [prettify]]))"
176+
177+ " (ns slam.hound.prettify
178+ \" Format a namespace declaration using pretty print with custom dispatch.\"
179+ (:use [clojure.pprint :only [cl-format code-dispatch formatter-out
180+ pprint pprint-logical-block
181+ pprint-newline with-pprint-dispatch
182+ write-out]]))"
183+
184+ " (ns autodoc.build-html
185+ \" This is the namespace that builds the HTML pages themselves.
186+ It is implemented with a number of custom enlive templates.\"
187+ {:skip-wiki true, :author \" Tom Faulhaber\" }
188+ (:refer-clojure :exclude [empty complement])
189+ (:import [java.util.jar JarFile]
190+ [java.io File FileWriter BufferedWriter StringReader
191+ BufferedInputStream BufferedOutputStream
192+ ByteArrayOutputStream FileReader FileInputStream]
193+ [java.util.regex Pattern])
194+ (:require [clojure.string :as str])
195+ (:use [net.cgrand.enlive-html :exclude (deftemplate)]
196+ [clojure.java.io :only (as-file file writer)]
197+ [clojure.java.shell :only (sh)]
198+ [clojure.pprint :only (pprint cl-format pprint-ident
199+ pprint-logical-block set-pprint-dispatch
200+ get-pretty-writer fresh-line)]
201+ [clojure.data.json :only (pprint-json)]
202+ [autodoc.collect-info :only (contrib-info)]
203+ [autodoc.params :only (params expand-classpath)])
204+ (:use clojure.set clojure.java.io clojure.data clojure.java.browse
205+ clojure.inspector clojure.zip clojure.stacktrace))" )
196206
197207(defn tst-pprint
198208 " A helper function to pprint to a string with a restricted right margin"
0 commit comments