Permalink
Browse files

CLJ-960: tests for :line and :column metadata as provided by LineNumb…

…eringPushbackReader

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information...
1 parent a76c4b8 commit 2f0c86eb6aae27a8e517f5d84ff4973dd6ce6742 @cemerick cemerick committed with stuarthalloway Oct 19, 2012
Showing with 36 additions and 0 deletions.
  1. +36 −0 test/clojure/test_clojure/reader.clj
@@ -21,6 +21,7 @@
(:use [clojure.instant :only [read-instant-date
read-instant-calendar
read-instant-timestamp]])
+ (:require clojure.walk)
(:import [clojure.lang BigInt Ratio]
java.io.File
java.util.TimeZone))
@@ -395,6 +396,41 @@
;; Metadata (^ or #^ (deprecated))
+(deftest t-line-column-numbers
+ (let [code "(ns reader-metadata-test
+ (:require [clojure.java.io
+ :refer (resource reader)]))
+
+(let [a 5]
+ ^:added-metadata
+ (defn add-5
+ [x]
+ (reduce + x (range a))))"
+ stream (clojure.lang.LineNumberingPushbackReader.
+ (java.io.StringReader. code))
+ top-levels (take-while identity (repeatedly #(read stream false nil)))
+ expected-metadata '{ns {:line 1, :column 1}
+ :require {:line 2, :column 3}
+ resource {:line 3, :column 21}
+ let {:line 5, :column 1}
+ defn {:line 6, :column 3 :added-metadata true}
+ reduce {:line 9, :column 5}
+ range {:line 9, :column 17}}
+ verified-forms (atom 0)]
+ (doseq [form top-levels]
+ (clojure.walk/postwalk
+ #(when (list? %)
+ (is (= (expected-metadata (first %))
+ (meta %)))
+ (is (->> (meta %)
+ vals
+ (filter number?)
+ (every? (partial instance? Integer))))
+ (swap! verified-forms inc))
+ form))
+ ;; sanity check against e.g. reading returning ()
+ (is (= (count expected-metadata) @verified-forms))))
+
(deftest t-Metadata
(is (= (meta '^:static ^:awesome ^{:static false :bar :baz} sym) {:awesome true, :bar :baz, :static true})))

0 comments on commit 2f0c86e

Please sign in to comment.