File tree 1 file changed +26
-0
lines changed
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -338,3 +338,29 @@ nil if the end of stream has been reached")
338
338
(if (= res reader)
339
339
(recur reader eof-is-error sentinel is-recursive)
340
340
res)))))
341
+
342
+ (defn read-string
343
+ " Reads one object from the string s"
344
+ [s]
345
+ (let [r (push-back-reader s)]
346
+ (read r true nil false )))
347
+
348
+ ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Tests ;;;;;;;;;;;;;;;;
349
+
350
+ (defn test-reader
351
+ []
352
+ (assert (= 1 (read-string " 1" )))
353
+ (assert (= 2 (read-string " #_nope 2" )))
354
+ (assert (= [3 4 ] (read-string " [3 4]" )))
355
+ (assert (= " foo" (read-string " \" foo\" " )))
356
+ (assert (= :hello (read-string " :hello" )))
357
+ (assert (= 'goodbye (read-string " goodbye" )))
358
+ (assert (= #{1 2 3 } (read-string " #{1 2 3}" )))
359
+ (assert (= '(7 8 9 ) (read-string " (7 8 9)" )))
360
+ (assert (= '(deref foo) (read-string " @foo" )))
361
+ (assert (= '(quote bar) (read-string " 'bar" )))
362
+ (assert (= \a (read-string " \\ a" )))
363
+ (assert (= {:tag 'String} (meta (read-string " ^String {:a 1}" ))))
364
+ (assert (= [:a 'b #{'c {:d [:e :f :g ]}}]
365
+ (read-string " [:a b #{c {:d [:e :f :g]}}]" ))))
366
+
You can’t perform that action at this time.
0 commit comments