Skip to content

Commit 2e131b3

Browse files
committed
- break out iterator tests
1 parent 0277a75 commit 2e131b3

File tree

3 files changed

+49
-37
lines changed

3 files changed

+49
-37
lines changed

src/test/cljs/cljs/core_test.cljs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -408,43 +408,6 @@
408408
(halt-when :anomaly #(assoc %2 :partial-results %1))
409409
[1 2 {:anomaly :oh-no!} 3 4]))))
410410

411-
(defn seq-iter-match
412-
[coll]
413-
(let [i (-iterator coll)]
414-
(loop [s (seq coll)
415-
n 0]
416-
(if (seq s)
417-
(do
418-
(when-not (.hasNext i)
419-
(throw
420-
(js/Error.
421-
(str "Iterator exhausted before seq at(" n ")" ))))
422-
(let [iv (.next i)
423-
sv (first s)]
424-
(when-not (= iv sv)
425-
(throw
426-
(js/Error.
427-
(str "Iterator value " iv " and seq value " sv " did not match at ( " n ")")))))
428-
(recur (rest s) (inc n)))
429-
(if (.hasNext i)
430-
(throw
431-
(js/Error.
432-
(str "Seq exhausted before iterator at (" n ")")))
433-
true)))))
434-
435-
(defrecord TestIterRec [a b])
436-
437-
(deftest coll-iter-seq-match
438-
(testing "Direct iterators match sequences"
439-
(let [test-map (apply hash-map (range 200))
440-
test-set (apply hash-set (range 200))
441-
test-queue (into cljs.core.PersistentQueue.EMPTY (vec (range 100)))
442-
test-record (into (TestIterRec. 1 2) {:c 3 :d 4})]
443-
(is (= true (seq-iter-match test-map)))
444-
(is (= true (seq-iter-match test-set)))
445-
(is (= true (seq-iter-match test-queue)))
446-
(is (= true (seq-iter-match test-record))))))
447-
448411
(deftest test-reader-literals
449412
(testing "Testing reader literals"
450413
(is (= #queue [1] (into cljs.core.PersistentQueue.EMPTY [1])))

src/test/cljs/cljs/iterator_test.cljs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
; Copyright (c) Rich Hickey. All rights reserved.
2+
; The use and distribution terms for this software are covered by the
3+
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4+
; which can be found in the file epl-v10.html at the root of this distribution.
5+
; By using this software in any fashion, you are agreeing to be bound by
6+
; the terms of this license.
7+
; You must not remove this notice, or any other, from this software.
8+
9+
(ns cljs.iterator-test
10+
(:require [cljs.test :refer-macros [deftest testing is are run-tests]]))
11+
12+
(defn seq-iter-match
13+
[coll]
14+
(let [i (-iterator coll)]
15+
(loop [s (seq coll)
16+
n 0]
17+
(if (seq s)
18+
(do
19+
(when-not (.hasNext i)
20+
(throw
21+
(js/Error.
22+
(str "Iterator exhausted before seq at(" n ")" ))))
23+
(let [iv (.next i)
24+
sv (first s)]
25+
(when-not (= iv sv)
26+
(throw
27+
(js/Error.
28+
(str "Iterator value " iv " and seq value " sv " did not match at ( " n ")")))))
29+
(recur (rest s) (inc n)))
30+
(if (.hasNext i)
31+
(throw
32+
(js/Error.
33+
(str "Seq exhausted before iterator at (" n ")")))
34+
true)))))
35+
36+
(defrecord TestIterRec [a b])
37+
38+
(deftest coll-iter-seq-match
39+
(testing "Direct iterators match sequences"
40+
(let [test-map (apply hash-map (range 200))
41+
test-set (apply hash-set (range 200))
42+
test-queue (into cljs.core.PersistentQueue.EMPTY (vec (range 100)))
43+
test-record (into (TestIterRec. 1 2) {:c 3 :d 4})]
44+
(is (= true (seq-iter-match test-map)))
45+
(is (= true (seq-iter-match test-set)))
46+
(is (= true (seq-iter-match test-queue)))
47+
(is (= true (seq-iter-match test-record))))))

src/test/cljs/test_runner.cljs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
[cljs.core-test :as core-test]
2020
[cljs.chunked-seq]
2121
[cljs.interop-test]
22+
[cljs.iterator-test]
2223
[cljs.reader-test]
2324
[cljs.binding-test]
2425
[cljs.parse-test]
@@ -81,6 +82,7 @@
8182
'cljs.core-test
8283
'cljs.chunked-seq
8384
'cljs.interop-test
85+
'cljs.iterator-test
8486
'cljs.reader-test
8587
'cljs.parse-test
8688
'clojure.set-test

0 commit comments

Comments
 (0)