1.0.23.17: new function: SIMPLE-ARRAY-VECTOR
[sbcl.git] / tests / array.pure.lisp
index fe9c4f0..0994d49 100644 (file)
                            'bit-vector)
           do (assert (bit-vector-equal r1 r2)))))
 
-;;; CLHS, ADJUST-ARRAY: An error of type error is signaled if
-;;; fill-pointer is supplied and non-nil but array has no fill pointer.
-(assert (eq :good
-            (handler-case
-                (let ((array (make-array 12)))
-                  (assert (not (array-has-fill-pointer-p array)))
-                  (adjust-array array 12 :fill-pointer t)
-                  array)
-              (type-error ()
-                :good))))
-
-;;; SIMPLE-VECTOR-COMPARE-AND-SWAP
-
-(let ((v (vector 1)))
-  ;; basics
-  (assert (eql 1 (sb-kernel:simple-vector-compare-and-swap v 0 1 2)))
-  (assert (eql 2 (sb-kernel:simple-vector-compare-and-swap v 0 1 3)))
-  (assert (eql 2 (svref v 0)))
-  ;; bounds
-  (multiple-value-bind (res err)
-      (ignore-errors (sb-kernel:simple-vector-compare-and-swap v -1 1 2))
-    (assert (not res))
-    (assert (typep err 'type-error)))
-  (multiple-value-bind (res err)
-      (ignore-errors (sb-kernel:simple-vector-compare-and-swap v 1 1 2))
-    (assert (not res))
-    (assert (typep err 'type-error))))
-
-;; type of the first argument
-(multiple-value-bind (res err)
-    (ignore-errors (sb-kernel:simple-vector-compare-and-swap "foo" 1 1 2))
-    (assert (not res))
-    (assert (typep err 'type-error)))
+(with-test (:name (adjust-array fill-pointer))
+  ;; CLHS, ADJUST-ARRAY: An error of type error is signaled if
+  ;; fill-pointer is supplied and non-nil but array has no fill pointer.
+  (assert (eq :good
+              (handler-case
+                  (let ((array (make-array 12)))
+                    (assert (not (array-has-fill-pointer-p array)))
+                    (adjust-array array 12 :fill-pointer t)
+                    array)
+                (type-error ()
+                  :good)))))
+
+(with-test (:name (adjust-array multidimensional))
+  (let ((ary (make-array '(2 2))))
+    ;; SBCL used to give multidimensional arrays a bogus fill-pointer
+    (assert (not (array-has-fill-pointer-p (adjust-array ary '(2 2)))))))
+
+(with-test (:name %set-fill-pointer/error)
+  (let ((v (make-array 3 :fill-pointer 0)))
+    (handler-case
+        (progn
+          (setf (fill-pointer v) 12)
+          (error "WTF"))
+      (error (e)
+        (assert (eql 12 (type-error-datum e)))
+        (assert (equal '(integer 0 3) (type-error-expected-type e)))))))
+
+(with-test (:name simple-array-vector)
+  (let ((vec (vector 1 2 3)))
+    (assert (eq vec (sb-ext:simple-array-vector vec)))
+    (assert (equalp (vector 1 2 3 4)
+                    (sb-ext:simple-array-vector
+                     (make-array '(2 2) :initial-contents '((1 2) (3 4))))))
+    (assert (eq 'fixnum (array-element-type
+                         (sb-ext:simple-array-vector (make-array '(3 4 5)
+                                                                 :element-type 'fixnum)))))))