-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.lisp
43 lines (38 loc) · 1.09 KB
/
test.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(defpackage #:com.clearly-useful.iterator-protocol.test
(:use #:cl
#:com.clearly-useful.generic-collection-interface
#:com.clearly-useful.iterator-protocol))
(in-package #:com.clearly-useful.iterator-protocol.test)
(defun test-builtin-iterator (seq)
"confirm that it works as is, and after seq."
(assert (typep seq 'seqable))
(let ((it (iterator seq)))
(doseq (o seq)
(multiple-value-bind (val continue) (iterator-next! it)
(assert (equalp o val))
(assert continue)))
(iterator-next! it)
(iterator-finish! it)
(assert (null (nth-value 1 (iterator-next! it)))))
(let ((s seq))
(do-iterator (x seq)
(assert (equalp x (head s)))
(setf s (tail s))))
(unless (typep seq 'seq)
(test-builtin-iterator (seq seq))))
(assert (com.clearly-useful.iterator-protocol::%seq-iterator-p
(iterator '(a b c))))
(assert (com.clearly-useful.iterator-protocol::%vector-iterator-p
(iterator #(a b c))))
(mapcar #'test-builtin-iterator
'(;;cons
(a b c)
;;vector
"abc"
;;vector again
#(a b c)
;;array
#2A((a b) (c d))
;;mixed
(a . #(b c))
))