1+ (ns special.eagerize-test
2+ (:require [clojure.test :refer [deftest is testing]]
3+ [special.eagerize :refer [eagerize]]))
4+
5+ (defn- make-nested-lazy-list
6+ " Returns a lazy-sequece of e.
7+ Defaults to random-ints when called with no args."
8+ ([]
9+ (make-nested-lazy-list #(rand-int 42 )))
10+ ([e]
11+ (repeatedly 10 (constantly e))))
12+
13+ (defrecord TestRecord [s])
14+ (deftype TestType [s])
15+
16+ (deftest eagerize-test
17+ (testing " Can eagerize deep nested Clojure IPersistentList."
18+ (is (realized?
19+ (let [ls (list (make-nested-lazy-list ))]
20+ (eagerize ls)
21+ (first ls)))))
22+
23+ (testing " Can eagerize deep nested Clojure IMapEntry."
24+ (is (realized?
25+ (let [ls (first {:e (make-nested-lazy-list )})]
26+ (eagerize ls)
27+ (val ls)))))
28+
29+ (testing " Can eagerize deep nested Clojure ISeq."
30+ (is (realized?
31+ (let [ls (make-nested-lazy-list (make-nested-lazy-list ))]
32+ (eagerize ls)
33+ (first ls)))))
34+
35+ (testing " Can eagerize deep nested Clojure IRecord."
36+ (is (realized?
37+ (let [ls (->TestRecord (make-nested-lazy-list ))]
38+ (eagerize ls)
39+ (:s ls)))))
40+
41+ (testing " Can eagerize deep nested Clojure IType."
42+ (is (realized?
43+ (let [ls (TestType. (make-nested-lazy-list ))]
44+ (eagerize ls)
45+ (.-s ls)))))
46+
47+ (testing " Can eagerize deep nested Clojure Delay."
48+ (is (realized?
49+ (let [ls (delay (make-nested-lazy-list ))]
50+ (eagerize ls)
51+ @ls))))
52+
53+ (testing " Can eagerize deep nested Java Iterable."
54+ (is (realized?
55+ (let [ls (doto (java.util.LinkedList. )
56+ (.add (make-nested-lazy-list )))]
57+ (eagerize ls)
58+ (first ls)))))
59+
60+ (testing " Can eagerize deep nested Java AbstractMap."
61+ (is (realized?
62+ (let [ls (doto (java.util.HashMap. )
63+ (.put " a" (make-nested-lazy-list )))]
64+ (eagerize ls)
65+ (.get ls " a" )))))
66+
67+ (testing " Can eagerize deep nested Java Stack."
68+ (is (realized?
69+ (let [ls (doto (java.util.Stack. )
70+ (.push (make-nested-lazy-list )))]
71+ (eagerize ls)
72+ (.pop ls)))))
73+
74+ (testing " Can eagerize deep nested Java Arrays."
75+ (is (realized?
76+ (let [ls (doto (make-array clojure.lang.ISeq 2 )
77+ (aset 0 (make-nested-lazy-list )))]
78+ (eagerize ls)
79+ (aget ls 0 ))))))
0 commit comments