1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-19 10:10:23 +02:00

Fix bitvectors and non-zero lower bound arrays in truncated-print

* module/ice-9/arrays.scm (array-print-prefix): New private function.
* libguile/arrays.c (scm_i_print_array): Reuse (array-print-prefix) from
  (ice-9 arrays). Make sure to release the array handle.
* module/ice-9/pretty-print.scm (truncated-print): Support
  bitvectors.
  Don't try to guess the array prefix but call array-print-prefix from
  (ice-9 arrays) instead.
  Fix call to print-sequence to support non-zero lower bound arrays.
* test-suite/tests/arrays.test: Test that arrays print properly.
* test-suite/tests/print.test: Test truncated-print with bitvectors,
  non-zero lower bound arrays.
This commit is contained in:
Daniel Llorens 2017-02-21 12:23:35 +01:00
parent f52fc0566f
commit e0bcda4ad9
5 changed files with 169 additions and 56 deletions

View file

@ -999,4 +999,57 @@
"#1(b c)"
(format #f "~a" (make-shared-array #(a b c)
(lambda (i) (list (+ i 1)))
2))))
2)))
(pass-if-equal "0-array"
"#0(9)"
(format #f "~a" (make-array 9)))
(pass-if-equal "2-array"
"#2f64((0.0 1.0) (2.0 3.0))"
(format #f "~a" #2f64((0 1) (2 3))))
(pass-if-equal "empty 3-array"
"#3()"
(format #f "~a" (make-array 1 0 0 0)))
(pass-if-equal "empty 3-array with last nonempty dim."
"#3:0:0:1()"
(format #f "~a" (make-array 1 0 0 1)))
(pass-if-equal "empty 3-array with middle nonempty dim."
"#3:0:1:0()"
(format #f "~a" (make-array 1 0 1 0)))
(pass-if-equal "empty 3-array with first nonempty dim."
"#3(())"
(format #f "~a" (make-array 1 1 0 0)))
(pass-if-equal "3-array with non-zero lower bounds"
"#3@1@0@1(((1 1 1) (1 1 1)) ((1 1 1) (1 1 1)))"
(format #f "~a" (make-array 1 '(1 2) '(0 1) '(1 3))))
(pass-if-equal "3-array with non-zero-lower bounds and last nonempty dim."
"#3@0:0@0:0@1:3()"
(format #f "~a" (make-array 1 0 0 '(1 3))))
(pass-if-equal "3-array with non-zero-lower bounds and middle nonempty dim."
"#3@0:0@1:3@0:0()"
(format #f "~a" (make-array 1 0 '(1 3) 0)))
(pass-if-equal "3-array with non-zero-lower bounds and first nonempty dim."
"#3@1@0@0(() () ())"
(format #f "~a" (make-array 1 '(1 3) 0 0)))
(pass-if-equal "3-array with singleton dim case I"
"#3@1@1@-1(((1 1 1)))"
(format #f "~a" (make-array 1 '(1 1) '(1 1) '(-1 1))))
(pass-if-equal "3-array with singleton dim case II"
"#3@-1@1@1(((1) (1) (1)))"
(format #f "~a" (make-array 1 '(-1 -1) '(1 3) '(1 1))))
(pass-if-equal "3-array with singleton dim case III"
"#3@1@-1@1(((1)) ((1)) ((1)))"
(format #f "~a" (make-array 1 '(1 3) '(-1 -1) '(1 1)))))

View file

@ -147,6 +147,35 @@
(pass-if-equal "#<directory (test-…>"
(tprint (current-module) 20 "UTF-8"))
;; bitvectors
(let ((testv (bitvector #t #f #f #t #t #f #t #t)))
(pass-if-equal "#*10011011"
(tprint testv 11 "UTF-8"))
(pass-if-equal "#*10011011"
(tprint testv 11 "ISO-8859-1"))
(pass-if-equal "#*10011…"
(tprint testv 8 "UTF-8"))
(pass-if-equal "#*100..."
(tprint testv 8 "ISO-8859-1"))
(pass-if-equal "#*10…"
(tprint testv 5 "UTF-8"))
(pass-if-equal "#*..."
(tprint testv 5 "ISO-8859-1"))
(pass-if-equal "#*1…"
(tprint testv 4 "UTF-8"))
(pass-if-equal "#"
(tprint testv 4 "ISO-8859-1")))
;; rank 0 arrays
(pass-if-equal "#0(#)"
(tprint (make-typed-array #t 9.0) 6 "UTF-8"))
@ -162,18 +191,31 @@
(pass-if-equal "#"
(tprint (make-typed-array 's32 0 20 20) 7 "UTF-8"))
(pass-if-equal "#2s32(…)"
(tprint (make-typed-array 's32 0 20 20) 8 "UTF-8"))
;; higher dimensional arrays
(pass-if-equal "#2s32(# …)"
(tprint (make-typed-array 's32 0 20 20) 10 "UTF-8"))
(let ((testa (make-typed-array 's32 0 20 20)))
(pass-if-equal "#2s32(…)"
(tprint testa 8 "UTF-8"))
(pass-if-equal "#2s32((…) …)"
(tprint (make-typed-array 's32 0 20 20) 12 "UTF-8"))
(pass-if-equal "#2s32(# …)"
(tprint testa 10 "UTF-8"))
(pass-if-equal "#2s32((0 …) …)"
(tprint (make-typed-array 's32 0 20 20) 14 "UTF-8"))
(pass-if-equal "#2s32((…) …)"
(tprint testa 12 "UTF-8"))
(pass-if-equal "#2s32((0 …) …)"
(tprint testa 14 "UTF-8")))
;; check that bounds are printed correctly
(pass-if-equal "#2@-1@0((foo foo foo foo …) …)"
(tprint (make-array 'foo '(-1 3) 5) 30 "UTF-8"))
(pass-if-equal "#3@-1:5@0:0@0:5(() () () # #)"
(tprint (make-array 'foo '(-1 3) 0 5) 30 "UTF-8"))
;; nested objects including arrays
(pass-if-equal "#2((#(9 9) #(9 9)) (#(9 9) #(9 9)))"
(tprint (make-typed-array #t (make-typed-array #t 9 2) 2 2) 40 "UTF-8"))