Skip to content

Break out iterator tests from cljs.core-test #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions src/test/cljs/cljs/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -408,43 +408,6 @@
(halt-when :anomaly #(assoc %2 :partial-results %1))
[1 2 {:anomaly :oh-no!} 3 4]))))

(defn seq-iter-match
[coll]
(let [i (-iterator coll)]
(loop [s (seq coll)
n 0]
(if (seq s)
(do
(when-not (.hasNext i)
(throw
(js/Error.
(str "Iterator exhausted before seq at(" n ")" ))))
(let [iv (.next i)
sv (first s)]
(when-not (= iv sv)
(throw
(js/Error.
(str "Iterator value " iv " and seq value " sv " did not match at ( " n ")")))))
(recur (rest s) (inc n)))
(if (.hasNext i)
(throw
(js/Error.
(str "Seq exhausted before iterator at (" n ")")))
true)))))

(defrecord TestIterRec [a b])

(deftest coll-iter-seq-match
(testing "Direct iterators match sequences"
(let [test-map (apply hash-map (range 200))
test-set (apply hash-set (range 200))
test-queue (into cljs.core.PersistentQueue.EMPTY (vec (range 100)))
test-record (into (TestIterRec. 1 2) {:c 3 :d 4})]
(is (= true (seq-iter-match test-map)))
(is (= true (seq-iter-match test-set)))
(is (= true (seq-iter-match test-queue)))
(is (= true (seq-iter-match test-record))))))

(deftest test-reader-literals
(testing "Testing reader literals"
(is (= #queue [1] (into cljs.core.PersistentQueue.EMPTY [1])))
Expand Down
47 changes: 47 additions & 0 deletions src/test/cljs/cljs/iterator_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.

(ns cljs.iterator-test
(:require [cljs.test :refer-macros [deftest testing is are run-tests]]))

(defn seq-iter-match
[coll]
(let [i (-iterator coll)]
(loop [s (seq coll)
n 0]
(if (seq s)
(do
(when-not (.hasNext i)
(throw
(js/Error.
(str "Iterator exhausted before seq at(" n ")" ))))
(let [iv (.next i)
sv (first s)]
(when-not (= iv sv)
(throw
(js/Error.
(str "Iterator value " iv " and seq value " sv " did not match at ( " n ")")))))
(recur (rest s) (inc n)))
(if (.hasNext i)
(throw
(js/Error.
(str "Seq exhausted before iterator at (" n ")")))
true)))))

(defrecord TestIterRec [a b])

(deftest coll-iter-seq-match
(testing "Direct iterators match sequences"
(let [test-map (apply hash-map (range 200))
test-set (apply hash-set (range 200))
test-queue (into cljs.core.PersistentQueue.EMPTY (vec (range 100)))
test-record (into (TestIterRec. 1 2) {:c 3 :d 4})]
(is (= true (seq-iter-match test-map)))
(is (= true (seq-iter-match test-set)))
(is (= true (seq-iter-match test-queue)))
(is (= true (seq-iter-match test-record))))))
2 changes: 2 additions & 0 deletions src/test/cljs/test_runner.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
[cljs.core-test :as core-test]
[cljs.chunked-seq]
[cljs.interop-test]
[cljs.iterator-test]
[cljs.reader-test]
[cljs.binding-test]
[cljs.parse-test]
Expand Down Expand Up @@ -81,6 +82,7 @@
'cljs.core-test
'cljs.chunked-seq
'cljs.interop-test
'cljs.iterator-test
'cljs.reader-test
'cljs.parse-test
'clojure.set-test
Expand Down