|
|
|
@ -14,7 +14,7 @@ https://github.com/mbutterick/restructure/blob/master/test/LazyArray.coffee
|
|
|
|
|
|#
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"lazy-array: decode should decode items lazily"
|
|
|
|
|
"stream: decode should decode items lazily"
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))])
|
|
|
|
|
(define xla (x:stream uint8 4))
|
|
|
|
|
(define arr (decode xla))
|
|
|
|
@ -26,7 +26,7 @@ https://github.com/mbutterick/restructure/blob/master/test/LazyArray.coffee
|
|
|
|
|
(check-equal? (stream-ref arr 3) 4)))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"lazy-array: decode should decode items lazily with post-decode"
|
|
|
|
|
"stream: decode should decode items lazily with post-decode"
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))])
|
|
|
|
|
(define xla (x:stream uint8 4 #:post-decode (λ (str) (stream-map (λ (i) (* 2 i)) str))))
|
|
|
|
|
(define arr (decode xla))
|
|
|
|
@ -39,35 +39,35 @@ https://github.com/mbutterick/restructure/blob/master/test/LazyArray.coffee
|
|
|
|
|
(check-equal? (stream-ref arr 3) 8)))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"lazy-array: should be able to convert to an array"
|
|
|
|
|
"stream: should be able to convert to an array"
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))])
|
|
|
|
|
(define xla (x:stream uint8 4))
|
|
|
|
|
(define arr (decode xla))
|
|
|
|
|
(check-equal? (stream->list arr) '(1 2 3 4))))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"lazy-array: decode should decode length as number before array"
|
|
|
|
|
"stream: decode should decode length as number before array"
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes (bytes 4 1 2 3 4 5))])
|
|
|
|
|
(define xla (x:stream uint8 uint8))
|
|
|
|
|
(define arr (decode xla))
|
|
|
|
|
(check-equal? (stream->list arr) '(1 2 3 4))))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"lazy-array: size should work with xlazy-arrays"
|
|
|
|
|
"stream: size should work with xlazy-arrays"
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))])
|
|
|
|
|
(define xla (x:stream uint8 4))
|
|
|
|
|
(define arr (decode xla))
|
|
|
|
|
(check-equal? (send xla x:size arr) 4)))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"lazy-array: encode should work with xlazy-arrays"
|
|
|
|
|
"stream: encode should work with xlazy-arrays"
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))])
|
|
|
|
|
(define xla (x:stream uint8 4))
|
|
|
|
|
(define arr (decode xla))
|
|
|
|
|
(check-equal? (encode xla arr #f) (bytes 1 2 3 4))))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"lazy-array: encode should work with xlazy-arrays with pre-encode"
|
|
|
|
|
"stream: encode should work with xlazy-arrays with pre-encode"
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))])
|
|
|
|
|
(define xla (x:stream uint8 4 #:pre-encode (λ (str) (stream-map (λ (val) (* 2 val)) str))))
|
|
|
|
|
(define arr (decode xla))
|
|
|
|
|