diff --git a/tests/tests.el b/tests/tests.el index a6dda41a..a36e9c6c 100644 --- a/tests/tests.el +++ b/tests/tests.el @@ -25,8 +25,6 @@ (require 'subr-x) (require 'package) (require 'compat) -(require 'seq) -(require 'stream) (require 'map) (require 'ert) (require 'generator) @@ -234,164 +232,6 @@ SYMS-STR are the string names of symbols from `loopy-iter-bare-commands'." collect (format "(%s . %s)" true iter)) "\n"))))) - -;;; Custom sequence for testing - -(cl-defstruct loopy--test-custom-seq - "Custom sequence for testing generic sequences." - (value) - (next)) - -(cl-defmethod seqp ((_seq loopy--test-custom-seq)) - t) - -(ert-deftest custom-seq-seqp () - (should (seqp (make-loopy--test-custom-seq :value 0 :next nil)))) - -;; For some reason, this _does_ affect streams. -;; -(cl-defmethod seq-do (func (seq loopy--test-custom-seq)) - (cl-assert (loopy--test-custom-seq-p seq) - "Non-custom-seq passed to `seq-do' for custom seqs") - (while seq - (funcall func (loopy--test-custom-seq-value seq)) - (setq seq (loopy--test-custom-seq-next seq)))) - -(ert-deftest custom-seq-do () - (should (equal '(2 1 0) - (let ((res)) - (seq-do (lambda (x) (push x res)) - (make-loopy--test-custom-seq - :value 0 - :next (make-loopy--test-custom-seq - :value 1 - :next (make-loopy--test-custom-seq - :value 2 - :next nil)))) - res)))) - -(ert-deftest custom-seq-do-not-affect-streams () - "We're seeing some odd behavior in the `substream' tests after -writing a `seq-do' method for the custom seq." - (should (equal '(2 1 0) - (let ((res)) - (seq-do (lambda (x) (push x res)) - (stream (vector 0 1 2))) - res)))) - -(cl-defmethod seq-into-sequence ((seq loopy--test-custom-seq)) - (let ((res nil)) - (seq-do (lambda (elt) (push elt res)) - seq) - (nreverse res))) - -(ert-deftest custom-seq-into-sequence () - (should (equal '(0 1 2) - (seq-into-sequence (make-loopy--test-custom-seq - :value 0 - :next (make-loopy--test-custom-seq - :value 1 - :next (make-loopy--test-custom-seq - :value 2 - :next nil))))))) - -(cl-defmethod seq-into (seq (_type (eql loopy--test-custom-seq))) - (let ((res) - (this)) - (seq-doseq (elt seq) - (if (not res) - (setq res (make-loopy--test-custom-seq :value elt :next nil) - this res) - (let ((new (make-loopy--test-custom-seq :value elt :next nil))) - (setf (loopy--test-custom-seq-next this) new - this new)))) - res)) - -(ert-deftest custom-seq-into () - (should (equal (seq-into '(0 1 2) 'loopy--test-custom-seq) - (make-loopy--test-custom-seq - :value 0 - :next (make-loopy--test-custom-seq - :value 1 - :next (make-loopy--test-custom-seq - :value 2 - :next nil)))))) - -(cl-defmethod seq-elt ((seq loopy--test-custom-seq) idx) - (cl-block loopy--test-custom-seq-elt - (seq-do-indexed (lambda (elt idx2) - (when (= idx idx2) - (cl-return-from loopy--test-custom-seq-elt elt))) - seq) - (signal 'args-out-of-range (list seq idx)))) - -(ert-deftest custom-seq-elt () - (should (= 1 (seq-elt (seq-into '(0 1 2 3 4) 'loopy--test-custom-seq) 1)))) - -(cl-defmethod seq-length ((seq loopy--test-custom-seq)) - (let ((res 0)) - (seq-do (lambda (_) (setq res (1+ res))) - seq) - res)) - -(ert-deftest custom-seq-length () - (should (= 5 (seq-length (seq-into '(0 1 2 3 4) 'loopy--test-custom-seq))))) - -(cl-defmethod seq-copy ((seq loopy--test-custom-seq)) - (seq-into seq 'loopy--test-custom-seq)) - -(ert-deftest custom-seq-copy () - (should-not (let* ((seq1 (make-loopy--test-custom-seq :value 1 :next nil)) - (seq2 (seq-copy seq1))) - (setf (loopy--test-custom-seq-value seq1) 99) - (equal seq1 seq2)))) - -(cl-defmethod seq-subseq ((seq loopy--test-custom-seq) start &optional end) - "Inefficient but good enough for testing." - (seq-into (seq-subseq (seq-into-sequence seq) - start end) - 'loopy--test-custom-seq)) - -(ert-deftest custom-seq-subseq () - (should (equal (make-loopy--test-custom-seq - :value 0 - :next (make-loopy--test-custom-seq - :value 1 - :next (make-loopy--test-custom-seq - :value 2 - :next nil))) - (seq-subseq (seq-into '(10 12 0 1 2 3 4) 'loopy--test-custom-seq) - 2 5)))) - -(cl-defmethod (setf seq-elt) (store (sequence loopy--test-custom-seq) n) - (let ((idx2 0)) - (while (/= n idx2) - (let ((next (loopy--test-custom-seq-next sequence))) - (if (null next) - (signal 'args-out-of-range (list sequence n)) - (setq sequence next) - (cl-incf idx2)))) - (setf (loopy--test-custom-seq-value sequence) store)) - store) - -(ert-deftest custom-seq-setf-seq-elt () - (should (equal (make-loopy--test-custom-seq - :value 0 - :next (make-loopy--test-custom-seq - :value 99 - :next (make-loopy--test-custom-seq - :value 2 - :next nil))) - (let ((seq (make-loopy--test-custom-seq - :value 0 - :next (make-loopy--test-custom-seq - :value 1 - :next (make-loopy--test-custom-seq - :value 2 - :next nil))))) - (setf (seq-elt seq 1) 99) - seq)))) - ;;; Macro arguments ;;;; Named (loop Name) @@ -2450,8 +2290,8 @@ Using numbers directly will use less variables and more efficient code." :doc "Check that `sequence' does not correctly work on `seq'. If it does, we confused them somewhere in the setup code. Custom types are records, which are sequences, so they still work in that way." - :result '(loopy--test-custom-seq 1 nil) - :body ((with (my-seq (seq-into '(1) 'loopy--test-custom-seq))) + :result '(--stream-fresh--) + :body ((with (my-seq (stream '(1) ))) (sequence i my-seq) (collect i)) :loopy t @@ -2703,8 +2543,7 @@ are records, which are sequences, so they still work in that way." :body ((_cmd l '(97 98 99 100 101)) (_cmd a [97 98 99 100 101]) (_cmd s "abcde") - (_cmd c (seq-into '(97 98 99 100 101) - 'loopy--test-custom-seq)) + (_cmd c (stream '(97 98 99 100 101))) (if (not (and (/= l a) (/= a s) (/= s c))) @@ -2724,7 +2563,7 @@ are records, which are sequences, so they still work in that way." :body [((seq (a . b) [(97 . 98)]) (finally-return a b)) ((seq [a b] '([97 98])) (finally-return a b)) ((seq [a b] ["ab"]) (finally-return a b)) - ((seq [a b] (seq-into '("ab") 'loopy--test-custom-seq)) (finally-return a b))] + ((seq [a b] (stream '("ab") )) (finally-return a b))] :loopy t :iter-keyword (seq) :iter-bare ((seq . seqing))) @@ -2736,7 +2575,7 @@ are records, which are sequences, so they still work in that way." (collect i)) ((seq i [0 1 2 3 4 5 6 7 8 9 10] :by 2) (collect i)) - ((seq i (seq-into [0 1 2 3 4 5 6 7 8 9 10] 'loopy--test-custom-seq) :by 2) + ((seq i (stream [0 1 2 3 4 5 6 7 8 9 10] ) :by 2) (collect i))] :loopy t :iter-keyword (seq collect) @@ -2762,7 +2601,7 @@ are records, which are sequences, so they still work in that way." (collect i)) ((with (times 0)) - (seq i (seq-into (list 1 2 3 4 5 6) 'loopy--test-custom-seq) + (seq i (stream (list 1 2 3 4 5 6) ) :by (progn (cl-assert (= times 0)) (cl-incf times) @@ -2778,7 +2617,7 @@ are records, which are sequences, so they still work in that way." :result '(0 1 2) :multi-body t :body [((with (times 0)) - (seq i (seq-into (vector 0 1 2 3 4 5 6) 'loopy--test-custom-seq) + (seq i (stream (vector 0 1 2 3 4 5 6) ) :to (progn (cl-assert (= times 0)) (cl-incf times) @@ -2786,7 +2625,7 @@ are records, which are sequences, so they still work in that way." (collect i)) ((with (times 0)) - (seq i (seq-into (vector 0 1 2 3 4 5 6) 'loopy--test-custom-seq) + (seq i (stream (vector 0 1 2 3 4 5 6) ) :upto (progn (cl-assert (= times 0)) (cl-incf times) @@ -2794,7 +2633,7 @@ are records, which are sequences, so they still work in that way." (collect i)) ((with (times 0)) - (seq i (seq-into (vector 2 1 0) 'loopy--test-custom-seq) + (seq i (stream (vector 2 1 0) ) :downto (progn (cl-assert (= times 0)) (cl-incf times) @@ -2802,7 +2641,7 @@ are records, which are sequences, so they still work in that way." (collect i)) ((with (times 0)) - (seq i (seq-into (vector 0 1 2 3 4 5 6) 'loopy--test-custom-seq) + (seq i (stream (vector 0 1 2 3 4 5 6) ) :below (progn (cl-assert (= times 0)) (cl-incf times) @@ -2810,7 +2649,7 @@ are records, which are sequences, so they still work in that way." (collect i)) ((with (times 0)) - (seq i (seq-into (vector 2 1 0) 'loopy--test-custom-seq) + (seq i (stream (vector 2 1 0) ) :above (progn (cl-assert (= times 0)) (cl-incf times) @@ -2828,7 +2667,7 @@ are records, which are sequences, so they still work in that way." (collect (cons cat i))) ((seq i (list 4 3 2 1 0) :index cat) (collect (cons cat i))) - ((seq i (seq-into (list 4 3 2 1 0) 'loopy--test-custom-seq) + ((seq i (stream (list 4 3 2 1 0) ) :index cat) (collect (cons cat i)))] :loopy t @@ -2838,7 +2677,7 @@ are records, which are sequences, so they still work in that way." (loopy-deftest seq-:from-:downto-:by :result '(8 6 4 2) - :body ((seq i (seq-into [0 1 2 3 4 5 6 7 8 9 10] 'loopy--test-custom-seq) + :body ((seq i (stream [0 1 2 3 4 5 6 7 8 9 10] ) :from 8 :downto 1 :by 2) (collect i)) :loopy t @@ -2848,7 +2687,7 @@ are records, which are sequences, so they still work in that way." (loopy-deftest seq-:upto :result '(0 1 2 3 4 5 6 7) - :body ((seq i (seq-into [0 1 2 3 4 5 6 7 8 9 10] 'loopy--test-custom-seq) :upto 7) + :body ((seq i (stream [0 1 2 3 4 5 6 7 8 9 10] ) :upto 7) (collect i)) :loopy t :iter-keyword (seq collect) @@ -2857,7 +2696,7 @@ are records, which are sequences, so they still work in that way." (loopy-deftest seq-:to :result '(0 1 2 3 4 5 6 7) - :body ((seq i (seq-into [0 1 2 3 4 5 6 7 8 9 10] 'loopy--test-custom-seq) :to 7) + :body ((seq i (stream [0 1 2 3 4 5 6 7 8 9 10] ) :to 7) (collect i)) :loopy t :iter-keyword (seq collect) @@ -2866,7 +2705,7 @@ are records, which are sequences, so they still work in that way." (loopy-deftest seq-:downto :result '(10 9 8 7 6 5 4 3) - :body ((seq i (seq-into [0 1 2 3 4 5 6 7 8 9 10] 'loopy--test-custom-seq) :downto 3) + :body ((seq i (stream [0 1 2 3 4 5 6 7 8 9 10] ) :downto 3) (collect i)) :loopy t :iter-keyword (seq collect) @@ -2875,7 +2714,7 @@ are records, which are sequences, so they still work in that way." (loopy-deftest seq-:above :result '(10 9 8) - :body ((seq i (seq-into [0 1 2 3 4 5 6 7 8 9 10] 'loopy--test-custom-seq) :above 7) + :body ((seq i (stream [0 1 2 3 4 5 6 7 8 9 10] ) :above 7) (collect i)) :loopy t :iter-keyword (seq collect) @@ -2884,7 +2723,7 @@ are records, which are sequences, so they still work in that way." (loopy-deftest seq-:below :result '(0 1 2) - :body ((seq i (seq-into [0 1 2 3 4 5 6 7 8 9 10] 'loopy--test-custom-seq) :below 3) + :body ((seq i (stream [0 1 2 3 4 5 6 7 8 9 10] ) :below 3) (collect i)) :loopy t :iter-keyword (seq collect) @@ -2893,7 +2732,7 @@ are records, which are sequences, so they still work in that way." (loopy-deftest seq-:downfrom :result '(5 4 3 2 1 0) - :body ((seq i (seq-into [0 1 2 3 4 5] 'loopy--test-custom-seq) :downfrom 5) + :body ((seq i (stream [0 1 2 3 4 5] ) :downfrom 5) (collect i)) :loopy t :iter-keyword (seq collect) @@ -2902,7 +2741,7 @@ are records, which are sequences, so they still work in that way." (loopy-deftest seq-:upfrom :result '(2 3 4 5) - :body ((seq i (seq-into [0 1 2 3 4 5] 'loopy--test-custom-seq) :upfrom 2) + :body ((seq i (stream [0 1 2 3 4 5] ) :upfrom 2) (collect i)) :loopy t :iter-keyword (seq collect) @@ -2911,7 +2750,7 @@ are records, which are sequences, so they still work in that way." (loopy-deftest seq-multi-seq :result '((1 3) (1 4) (2 3) (2 4)) - :body ((seq i [1 2] (seq-into '(3 4) 'loopy--test-custom-seq)) + :body ((seq i [1 2] (stream '(3 4) )) (collect i)) :loopy t :iter-keyword (seq collect) @@ -2920,7 +2759,7 @@ are records, which are sequences, so they still work in that way." (loopy-deftest seq-multi-seq-:by :result '((1 3) (2 3)) - :body ((seq i [1 2] (seq-into '(3 4) 'loopy--test-custom-seq) :by 2) + :body ((seq i [1 2] (stream '(3 4) ) :by 2) (collect i)) :loopy t :iter-keyword (seq collect) @@ -2940,7 +2779,7 @@ are records, which are sequences, so they still work in that way." ((with (start 8) (end 2) (step -2)) - (seq i (seq-into [0 1 2 3 4 5 6 7 8 9 10] 'loopy--test-custom-seq) + (seq i (stream [0 1 2 3 4 5 6 7 8 9 10] ) :from start :to end :by step :test #'>=) (collect i)) @@ -2978,7 +2817,7 @@ are records, which are sequences, so they still work in that way." (collect i)) ((with (times 0)) - (seq i (seq-into '(0 1 2 3 4 5 6 7 8 9 10) 'loopy--test-custom-seq) + (seq i (stream '(0 1 2 3 4 5 6 7 8 9 10) ) :from 2 :to 8 :by 2 :test (progn (cl-assert (= times 0)) @@ -3216,7 +3055,7 @@ are records, which are sequences, so they still work in that way." If it does, we confused them somewhere in the setup code. Custom types are records, which are sequences, so they still work in that way." :result (record 7 7 7) - :body ((with (my-seq (seq-into '(1 2 3 4) 'loopy--test-custom-seq))) + :body ((with (my-seq (stream '(1 2 3 4) ))) (sequence-ref i my-seq) (do (setf i 7)) (finally-return my-seq)) @@ -3414,8 +3253,8 @@ are records, which are sequences, so they still work in that way." ;;;;; Seq Ref (loopy-deftest seq-ref - :result (seq-into '(7 7 7 7) 'loopy--test-custom-seq) - :body ((with (my-seq (seq-into '(1 2 3 4) 'loopy--test-custom-seq))) + :result (stream '(7 7 7 7) ) + :body ((with (my-seq (stream '(1 2 3 4) ))) (_cmd i my-seq) (do (setf i 7)) (finally-return my-seq)) @@ -3448,22 +3287,9 @@ are records, which are sequences, so they still work in that way." :iter-bare ((seq-ref . seqing-ref) (do . ignore))) -(loopy-deftest seq-ref-:by-custom-seq - :result (seq-into '(99 1 99 3 99 5 99 7 99 9 99) - 'loopy--test-custom-seq) - :body ((with (my-list (seq-into (list 0 1 2 3 4 5 6 7 8 9 10) - 'loopy--test-custom-seq))) - (seq-ref i my-list :by 2) - (do (setf i 99)) - (finally-return my-list)) - :loopy t - :iter-keyword (seq-ref do) - :iter-bare ((seq-ref . seqing-ref) - (do . ignore))) - (loopy-deftest seq-ref-:by-just-once - :result (seq-into "a1a3a5a7a9" 'loopy--test-custom-seq) - :body ((with (my-str (seq-into "0123456789" 'loopy--test-custom-seq)) + :result (stream "a1a3a5a7a9" ) + :body ((with (my-str (stream "0123456789" )) (times 0)) (seq-ref i my-str :by (progn (cl-assert (= times 0)) @@ -3477,8 +3303,8 @@ are records, which are sequences, so they still work in that way." (do . ignore))) (loopy-deftest seq-ref-:by-:index - :result (seq-into "a1a3a5a7a9" 'loopy--test-custom-seq) - :body ((with (my-str (seq-into "0123456789" 'loopy--test-custom-seq))) + :result (stream "a1a3a5a7a9" ) + :body ((with (my-str (stream "0123456789" ))) (seq-ref i my-str :by 2 :index cat) (do (setf i ?a)) (finally-return my-str)) @@ -3488,10 +3314,8 @@ are records, which are sequences, so they still work in that way." (do . ignore))) (loopy-deftest seq-ref-:from-:by - :result (seq-into '(0 cat 2 cat 4 cat 6 cat 8 cat) - 'loopy--test-custom-seq) - :body ((with (my-list (seq-into (list 0 1 2 3 4 5 6 7 8 9) - 'loopy--test-custom-seq))) + :result (seq-into '(0 cat 2 cat 4 cat 6 cat 8 cat) 'loopy--test-custom-seq) + :body ((with (my-list (seq-into (list 0 1 2 3 4 5 6 7 8 9) 'loopy--test-custom-seq))) (seq-ref i my-list :from 1 :by 2 ) (do (setf i 'cat)) (finally-return my-list)) @@ -3501,8 +3325,8 @@ are records, which are sequences, so they still work in that way." (do . ignore))) (loopy-deftest seq-ref-:downto-:by - :result (seq-into "0123456a8a" 'loopy--test-custom-seq) - :body ((with (my-str (seq-into "0123456789" 'loopy--test-custom-seq))) + :result (stream "0123456a8a" ) + :body ((with (my-str (stream "0123456789" ))) (seq-ref i my-str :downto 6 :by 2 ) (do (setf i ?a)) (finally-return my-str)) @@ -3512,8 +3336,8 @@ are records, which are sequences, so they still work in that way." (do . ignore))) (loopy-deftest seq-ref-:below - :result (seq-into "aaaaa56789" 'loopy--test-custom-seq) - :body ((with (my-str (seq-into "0123456789" 'loopy--test-custom-seq))) + :result (stream "aaaaa56789" ) + :body ((with (my-str (stream "0123456789" ))) (seq-ref i my-str :below 5) (do (setf i ?a)) (finally-return my-str)) @@ -3523,8 +3347,8 @@ are records, which are sequences, so they still work in that way." (do . ignore))) (loopy-deftest seq-ref-:above - :result (seq-into "012345aaaa" 'loopy--test-custom-seq) - :body ((with (my-str (seq-into "0123456789" 'loopy--test-custom-seq))) + :result (stream "012345aaaa" ) + :body ((with (my-str (stream "0123456789" ))) (seq-ref i my-str :above 5) (do (setf i ?a)) (finally-return my-str)) @@ -3534,9 +3358,8 @@ are records, which are sequences, so they still work in that way." (do . ignore))) (loopy-deftest seq-ref-:above-list - :result (seq-into '(0 1 2 3 4 5 cat cat cat cat) 'loopy--test-custom-seq) - :body ((with (my-list (seq-into (list 0 1 2 3 4 5 6 7 8 9) - 'loopy--test-custom-seq))) + :result (stream '(0 1 2 3 4 5 cat cat cat cat) ) + :body ((with (my-list (seq-into (list 0 1 2 3 4 5 6 7 8 9) 'loopy--test-custom-seq))) (seq-ref i my-list :above 5) (do (setf i 'cat)) (finally-return my-list)) @@ -3546,8 +3369,8 @@ are records, which are sequences, so they still work in that way." (do . ignore))) (loopy-deftest seq-ref-:upto - :result (seq-into "aaaaaa6789" 'loopy--test-custom-seq) - :body ((with (my-str (seq-into "0123456789" 'loopy--test-custom-seq))) + :result (stream "aaaaaa6789" ) + :body ((with (my-str (stream "0123456789" ))) (seq-ref i my-str :upto 5) (do (setf i ?a)) (finally-return my-str)) @@ -3557,8 +3380,8 @@ are records, which are sequences, so they still work in that way." (do . ignore))) (loopy-deftest seq-ref-:upfrom-:by - :result (seq-into "0a2a4a6a8a" 'loopy--test-custom-seq) - :body ((with (my-str (seq-into "0123456789" 'loopy--test-custom-seq))) + :result (stream "0a2a4a6a8a" ) + :body ((with (my-str (stream "0123456789" ))) (seq-ref i my-str :upfrom 1 :by 2 ) (do (setf i ?a)) (finally-return my-str)) @@ -3568,10 +3391,8 @@ are records, which are sequences, so they still work in that way." (do . ignore))) (loopy-deftest seq-ref-:upfrom-:by-string - :result (seq-into '(0 cat 2 cat 4 cat 6 cat 8 cat) - 'loopy--test-custom-seq) - :body ((with (my-list (seq-into (list 0 1 2 3 4 5 6 7 8 9) - 'loopy--test-custom-seq))) + :result (seq-into '(0 cat 2 cat 4 cat 6 cat 8 cat) 'loopy--test-custom-seq) + :body ((with (my-list (seq-into (list 0 1 2 3 4 5 6 7 8 9) 'loopy--test-custom-seq))) (seq-ref i my-list :upfrom 1 :by 2) (do (setf i 'cat)) (finally-return my-list)) @@ -3581,10 +3402,8 @@ are records, which are sequences, so they still work in that way." (do . ignore))) (loopy-deftest seq-ref-:downfrom - :result (seq-into '(0 cat 2 cat 4 cat 6 7 8 9) - 'loopy--test-custom-seq) - :body ((with (my-list (seq-into (list 0 1 2 3 4 5 6 7 8 9) - 'loopy--test-custom-seq))) + :result (seq-into '(0 cat 2 cat 4 cat 6 7 8 9) 'loopy--test-custom-seq) + :body ((with (my-list (seq-into (list 0 1 2 3 4 5 6 7 8 9) 'loopy--test-custom-seq))) (seq-ref i my-list :downfrom 5 :by 2) (do (setf i 'cat)) (finally-return my-list)) @@ -3608,9 +3427,9 @@ are records, which are sequences, so they still work in that way." (loopy-deftest seq-ref-:by-variable :doc "`seq-ref' can use literal `:by' directly." - :result (seq-into [0 1 22 3 22 5 22 7 22 9 10] 'loopy--test-custom-seq) + :result (stream [0 1 22 3 22 5 22 7 22 9 10] ) :body ((with (start 2) (end 8) (step 2) - (arr (seq-into (number-sequence 0 10) 'loopy--test-custom-seq))) + (arr (stream (number-sequence 0 10) ))) (seq-ref i arr :from start :to end :by step) (do (setf i 22)) (finally-return arr)) @@ -3621,8 +3440,8 @@ are records, which are sequences, so they still work in that way." (loopy-deftest seq-ref-destructuring :doc "Check that `seq-ref' implements destructuring. Not destructuring itself." - :result (seq-into [(7 8 9) (7 8 9)] 'loopy--test-custom-seq) - :body ((with (my-seq (seq-into [(1 2 3) (4 5 6)] 'loopy--test-custom-seq))) + :result (stream [(7 8 9) (7 8 9)] ) + :body ((with (my-seq (stream [(1 2 3) (4 5 6)] ))) (seq-ref (i j k) my-seq) (do (setf i 7) (setf j 8)