Skip to content

Commit 5a73a7a

Browse files
authored
Merge pull request #26 from angusiguess/seq-tests
Add tests for seq
2 parents a25aa0c + f582358 commit 5a73a7a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/clojure/core_test/seq.cljc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
(ns clojure.core-test.seq
2+
(:require [clojure.test :as t :refer [deftest testing is are]]))
3+
4+
(deftest test-seq
5+
;; Sourced via canSeq https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L581
6+
(are [in expected] (= expected (seq in))
7+
"test" '(\t \e \s \t)
8+
[1 2 3 4] '(1 2 3 4)
9+
'(:a :b :c :d) '(:a :b :c :d)
10+
'() nil
11+
nil nil
12+
(sorted-set 3.0 1.0 -2.5 4.0) '(-2.5 1.0 3.0 4.0)
13+
(range 5 10) '(5 6 7 8 9)
14+
(int-array 3) '(0 0 0))
15+
(testing "sets and maps"
16+
(let [input #{440M 55000M 80000}
17+
input-hash (into (hash-set) input)
18+
input-map {:a {:b "4"}
19+
:c 800
20+
nil 40}
21+
input-sorted-map (into (sorted-map) input-map)
22+
input-hash-map (into (hash-map) input-map)]
23+
(is (= input (into #{} (seq input))))
24+
(is (= input-hash (into (hash-set) (seq input))))
25+
(is (= input-sorted-map (into (sorted-map) (seq input-sorted-map))))
26+
(is (= input-hash-map (into (hash-map) (seq input-hash-map))))
27+
(is (= input-map (into {} (seq input-map))))))
28+
(testing "nonseqables"
29+
(is (thrown? IllegalArgumentException (seq 1)))
30+
(is (thrown? IllegalArgumentException (seq (fn [])))))
31+
(testing "infinite sequences are produced by seq"
32+
(let [infinite-seq (seq (range))]
33+
(is (seq? infinite-seq))
34+
(is (= (range 10000) (take 10000 infinite-seq))))))

0 commit comments

Comments
 (0)