main
Matthew Butterick 6 years ago
parent 964ced9cdf
commit a5476dfd49

@ -31,12 +31,12 @@ https://github.com/mbutterick/restructure/blob/master/test/Array.coffee
(test-case
"array: decode length from parent key"
(parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))])
(check-equal? (send (+xarray #:type uint8 #:length 'len) xxdecode (current-input-port) (mhash 'len 4)) '(1 2 3 4))))
(check-equal? (decode (+xarray #:type uint8 #:length 'len) (current-input-port) #:parent (mhash 'len 4)) '(1 2 3 4))))
(test-case
"array: decode byte count from parent key"
(parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))])
(check-equal? (send (+xarray #:type uint16be #:length 'len #:count-bytes #t) xxdecode (current-input-port) (mhash 'len 4)) '(258 772))))
(check-equal? (decode (+xarray #:type uint16be #:length 'len #:count-bytes #t) (current-input-port) #:parent (mhash 'len 4)) '(258 772))))
(test-case
"array: decode length as number before array"
@ -61,12 +61,12 @@ https://github.com/mbutterick/restructure/blob/master/test/Array.coffee
(test-case
"array: decode to the end of parent if no length given"
(parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))])
(check-equal? (send (+xarray #:type uint8) xxdecode (current-input-port) (mhash '_length 4 '_startOffset 0)) '(1 2 3 4))))
(check-equal? (decode (+xarray #:type uint8) (current-input-port) #:parent (mhash '_length 4 '_startOffset 0)) '(1 2 3 4))))
(test-case
"array: decode to the end of the stream if parent exists, but its length is 0"
(parameterize ([current-input-port (open-input-bytes (bytes 1 2 3 4 5))])
(check-equal? (send (+xarray #:type uint8) xxdecode (current-input-port) (mhash '_length 0 '_startOffset 0)) '(1 2 3 4 5))))
(check-equal? (decode (+xarray #:type uint8) (current-input-port) #:parent (mhash '_length 0 '_startOffset 0)) '(1 2 3 4 5))))
(test-case
"array: decode to the end of the stream if no parent and length is given"

@ -26,12 +26,12 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee
(test-case
"string: decode length from parent key"
(parameterize ([current-input-port (open-input-bytes #"testing")])
(check-equal? (send (+xstring 'len) xxdecode (current-input-port) (mhash 'len 7)) "testing")))
(check-equal? (decode (+xstring 'len) (current-input-port) #:parent (mhash 'len 7)) "testing")))
(test-case
"string: decode length as number before string"
(parameterize ([current-input-port (open-input-bytes #"\x07testing")])
(check-equal? (send (+xstring uint8) xxdecode (current-input-port) (mhash 'len 7)) "testing")))
(check-equal? (decode (+xstring uint8) (current-input-port) #:parent (mhash 'len 7)) "testing")))
(test-case
"string: decode utf8"

Loading…
Cancel
Save