diff options
author | Daniel Llorens <daniel.llorens@bluewin.ch> | 2017-02-21 12:23:35 +0100 |
---|---|---|
committer | Daniel Llorens <daniel.llorens@bluewin.ch> | 2017-10-31 13:23:44 +0100 |
commit | e0bcda4ad940c4e15679cc2b229838b33acdd36c (patch) | |
tree | dd80936c215d1e4bf0ade19c8080707a8b0539c0 /test-suite | |
parent | f52fc0566feabe4f1d3ba630287a418606ac30f9 (diff) |
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.
Diffstat (limited to 'test-suite')
-rw-r--r-- | test-suite/tests/arrays.test | 55 | ||||
-rw-r--r-- | test-suite/tests/print.test | 58 |
2 files changed, 104 insertions, 9 deletions
diff --git a/test-suite/tests/arrays.test b/test-suite/tests/arrays.test index 1df77b1ba..e913e30a2 100644 --- a/test-suite/tests/arrays.test +++ b/test-suite/tests/arrays.test @@ -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))))) + diff --git a/test-suite/tests/print.test b/test-suite/tests/print.test index 82cc77603..f2e31451c 100644 --- a/test-suite/tests/print.test +++ b/test-suite/tests/print.test @@ -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 + + (let ((testa (make-typed-array 's32 0 20 20))) + (pass-if-equal "#2s32(…)" + (tprint testa 8 "UTF-8")) + + (pass-if-equal "#2s32(# …)" + (tprint testa 10 "UTF-8")) - (pass-if-equal "#2s32(# …)" - (tprint (make-typed-array 's32 0 20 20) 10 "UTF-8")) + (pass-if-equal "#2s32((…) …)" + (tprint testa 12 "UTF-8")) - (pass-if-equal "#2s32((…) …)" - (tprint (make-typed-array 's32 0 20 20) 12 "UTF-8")) + (pass-if-equal "#2s32((0 …) …)" + (tprint testa 14 "UTF-8"))) - (pass-if-equal "#2s32((0 …) …)" - (tprint (make-typed-array 's32 0 20 20) 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")) |