Skip to content

Commit 75b0e87

Browse files
Merge branch 'master' of [email protected]:relevance/clojurescript
2 parents c31fcc4 + 456fe28 commit 75b0e87

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/cljs/cljs/reader.cljs

+26
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,29 @@ nil if the end of stream has been reached")
338338
(if (= res reader)
339339
(recur reader eof-is-error sentinel is-recursive)
340340
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+

0 commit comments

Comments
 (0)