Fix bug in new array reader
authorDaniel Llorens <lloda@sarc.name>
Wed, 3 Mar 2021 17:40:39 +0000 (18:40 +0100)
committerDaniel Llorens <lloda@sarc.name>
Wed, 3 Mar 2021 17:40:39 +0000 (18:40 +0100)
* module/ice-9/read.scm (read-array): Return pair for dimension when len
  is given; single number is lbnd for list->typed-array.
* test-suite/tests/arrays.test: More test cases for the reader.

module/ice-9/read.scm
test-suite/tests/arrays.test

index 7f79bf9f948de989e28eaf94dc61fb625d5949c0..9e3346c5a1b7bbcb2619dc1ae7b2e14558de0792 100644 (file)
           (error "unexpected end of input while reading array"))
         (values ch
                 (if len
-                    (if (zero? lbnd)
-                        len
-                        (list lbnd (+ lbnd (1- len))))
-                    lbnd))))
+                  (list lbnd (+ lbnd (1- len)))
+                  lbnd))))
     (define (read-shape ch alt)
       (if (memv ch '(#\@ #\:))
           (let*-values (((ch head) (read-dimension ch))
index c8eed39d3b74b3850a31c68ea1d9b9d42399cf53..c2716ed176e3a42b88cfa54b96e6084e7fd281fb 100644 (file)
 ;;; printing arrays
 ;;;
 
-(with-test-prefix/c&e "printing and reading arrays"
+(with-test-prefix/c&e "printing arrays"
   (pass-if-equal "writing 1D arrays that aren't vectors"
     "#1(b c)"
     (format #f "~a" (make-shared-array #(a b c)
       "#3@1@-1@1(((1)) ((1)) ((1)))"
       (format #f "~a" (make-array 1 '(1 3) '(-1 -1) '(1 1)))))
 
+;;;
+;;; reading arrays
+;;;
+
+(with-test-prefix/c&e "reading arrays"
+  
+  (pass-if "empty 3-array with first nonempty dim I"
+    (array-equal? (make-array 1 1 0 0)
+                  (call-with-input-string "#3(())" read)))
+  (pass-if "empty 3-array with first nonempty dim II"
+    (array-equal? (make-array 1 1 0 0)
+                  #3(())))
+  
+  (pass-if "empty 3-array with middle nonempty dim I"
+    (array-equal? (make-array 1 0 1 0)
+                  (call-with-input-string "#3:0:1:0()" read)))
+  (pass-if "empty 3-array with middle nonempty dim II"
+    (array-equal? (make-array 1 0 1 0)
+                  #3:0:1:0()))
+
+  (pass-if "empty typed 3-array with middle nonempty dim I"
+    (array-equal? (make-typed-array 'f64 1 0 1 0)
+                  (call-with-input-string "#3f64:0:1:0()" read)))
+  (pass-if "empty typed 3-array with middle nonempty dim II"
+    (array-equal? (make-typed-array 'f64 1 0 1 0)
+                  #3f64:0:1:0()))
+
+  (pass-if "array with specified size I"
+    (array-equal? #f64(1 2 3)
+                  (call-with-input-string "#f64:3(1 2 3)" read)))
+  (pass-if "array with specified size II"
+    (array-equal? #f64(1 2 3)
+                  #f64:3(1 2 3))))
+