;;;; absolutely no warranty. See the COPYING and CREDITS files for
;;;; more information.
+(in-package :cl-user)
+
;;; As reported by Paul Dietz from his ansi-test suite for gcl, REMOVE
;;; malfunctioned when given :START, :END and :FROM-END arguments.
;;; Make sure it doesn't happen again.
(multiple-value-bind (seq err) (ignore-errors (copy-seq '(1 2 3 . 4)))
(assert (not seq))
(assert (typep err 'type-error))))
+
+;;; UBX-BASH-COPY transform had an inconsistent return type
+(let ((sb-c::*check-consistency* t))
+ (handler-bind ((warning #'error))
+ (compile nil
+ '(lambda (l)
+ (declare (type fixnum l))
+ (let* ((bsize 128)
+ (b1 (make-array bsize :element-type '(unsigned-byte 8)))
+ (b2 (make-array l :element-type '(unsigned-byte 8))))
+ (replace b1 b2 :start2 0 :end2 l))))))
+
+(with-test (:name :bug-452008)
+ ;; FIND & POSITION on lists should check bounds and (in safe code) detect
+ ;; circular and dotted lists.
+ (macrolet ((test (type lambda)
+ `(let ((got (handler-case
+ (funcall (compile nil ',lambda))
+ (,type () :error)
+ (:no-error (res)
+ (list :no-error res)))))
+ (let ((*print-circle* t))
+ (format t "test: ~S~%" ',lambda))
+ (unless (eq :error got)
+ (error "wanted an error, got ~S for~% ~S"
+ (second got) ',lambda)))))
+ (test sb-kernel:bounding-indices-bad-error
+ (lambda ()
+ (find :foo '(1 2 3 :foo) :start 1 :end 5 :from-end t)))
+ (test sb-kernel:bounding-indices-bad-error
+ (lambda ()
+ (position :foo '(1 2 3 :foo) :start 1 :end 5 :from-end t)))
+ (test sb-kernel:bounding-indices-bad-error
+ (lambda ()
+ (find :foo '(1 2 3 :foo) :start 3 :end 0 :from-end t)))
+ (test sb-kernel:bounding-indices-bad-error
+ (lambda ()
+ (position :foo '(1 2 3 :foo) :start 3 :end 0 :from-end t)))
+ (test type-error
+ (lambda ()
+ (let ((list (list 1 2 3 :foo)))
+ (find :bar (nconc list list)))))
+ (test type-error
+ (lambda ()
+ (let ((list (list 1 2 3 :foo)))
+ (position :bar (nconc list list)))))))
+
+(with-test (:name :bug-554385)
+ ;; FIND-IF shouldn't look through the entire list.
+ (assert (= 2 (find-if #'evenp '(1 2 1 1 1 1 1 1 1 1 1 1 :foo))))
+ ;; Even though the end bounds are incorrect, the
+ ;; element is found before that's an issue.
+ (assert (eq :foo (find :foo '(1 2 3 :foo) :start 1 :end 5)))
+ (assert (= 3 (position :foo '(1 2 3 :foo) :start 1 :end 5))))
+
+(with-test (:name (:search :empty-seq))
+ (assert (eql 0
+ (funcall (compile nil
+ `(lambda (x)
+ (declare (optimize (speed 3)) (simple-vector x))
+ (search x #())))
+ #())))
+ (assert (eql 0
+ (funcall (compile nil
+ `(lambda (x)
+ (declare (optimize (speed 3)) (simple-vector x))
+ (search x #(t t t))))
+ #())))
+ (assert (eql 0
+ (funcall (compile nil
+ `(lambda (x)
+ (declare (optimize (speed 3)) (simple-vector x))
+ (search x #(t t t) :end1 0)))
+ #(t t t))))
+ (assert (eql 0
+ (funcall (compile nil
+ `(lambda (x)
+ (declare (optimize (speed 3)) (simple-vector x))
+ (search x #(t t t) :key nil)))
+ #())))
+ (assert (eql 0
+ (funcall (compile nil
+ `(lambda (x k)
+ (declare (optimize (speed 3)) (simple-vector x))
+ (search x #(t t t) :key k)))
+ #() nil)))
+ (assert (eq :ok
+ (handler-case
+ (funcall (compile nil
+ `(lambda (x)
+ (declare (optimize (speed 3)) (simple-vector x))
+ (search x #(t t t) :start2 1 :end2 0 :end1 0)))
+ #(t t t))
+ (sb-kernel:bounding-indices-bad-error ()
+ :ok))))
+ (assert (eql 1
+ (funcall (lambda ()
+ (declare (optimize speed))
+ (search #() #(1 1) :start2 1 :end2 1)))))
+ (assert (eql 2
+ (funcall (lambda ()
+ (declare (optimize speed))
+ (search #(1) #(1 1) :start1 1 :start2 2))))))