Permalink
Browse files

add a test for laziness

  • Loading branch information...
1 parent 9ad0722 commit d65790e6e831de89986d24dfa0bc4056fb34123b @joegallo committed Nov 12, 2011
Showing with 22 additions and 0 deletions.
  1. +22 −0 test/doric/test/core.clj
View
@@ -83,3 +83,25 @@
(is (.contains rendered "| 1 | 2 |"))
(is (.contains rendered "| 3 | 4 |"))
(is (.contains rendered "|---+---|"))))
+
+(deftest test-table*-laziness
+ (let [calls (atom 0)
+ inc #(do (swap! calls inc) %)]
+ (testing "formats are not lazy"
+ (let [seq (table* [{:name :1 :format inc}
+ {:name :2 :format inc}]
+ [{:1 3 :2 4}])]
+ (is (= 2 @calls))))
+ (reset! calls 0)
+ (testing "unless you provide widths"
+ (let [seq (table* [{:name :1 :format inc :width 10}
+ {:name :2 :format inc :width 10}]
+ [{:1 3 :2 4}])]
+ (is (= 0 @calls))))
+ (reset! calls 0)
+ (testing "even for formats that should be automatically lazy, like csv"
+ (let [seq (table* ^{:format csv}
+ [{:name :1 :format inc :width 0}
+ {:name :2 :format inc :width 0}]
+ [{:1 3 :2 4}])]
+ (is (= 0 @calls))))))

0 comments on commit d65790e

Please sign in to comment.