You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.5 KiB
Racket
48 lines
1.5 KiB
Racket
#lang racket/base
|
|
(require rackunit
|
|
racket/class
|
|
"../number.rkt"
|
|
"../helper.rkt"
|
|
"../reserved.rkt"
|
|
"../generic.rkt")
|
|
|
|
#|
|
|
approximates
|
|
https://github.com/mbutterick/restructure/blob/master/test/Reserved.coffee
|
|
|#
|
|
|
|
(test-case
|
|
"reserved: size should have a default count of 1"
|
|
(check-equal? (size (+xreserved uint8)) 1))
|
|
|
|
(test-case
|
|
"reserved: size should allow custom counts and types"
|
|
(check-equal? (size (+xreserved uint16be 10)) 20))
|
|
|
|
(test-case
|
|
"reserved: should decode"
|
|
(parameterize ([current-input-port (open-input-bytes (bytes 0 0))])
|
|
(define reserved (+xreserved uint16be))
|
|
(check-equal? (decode reserved) (void))
|
|
(check-equal? (pos (current-input-port)) 2)))
|
|
|
|
(test-case
|
|
"reserved: should decode with post-decode"
|
|
(parameterize ([current-input-port (open-input-bytes (bytes 0 0))])
|
|
(define reserved (+xreserved uint16be #:post-decode (λ (val) 42)))
|
|
(check-equal? (decode reserved) 42)
|
|
(check-equal? (pos (current-input-port)) 2)))
|
|
|
|
(test-case
|
|
"reserved: should encode"
|
|
(parameterize ([current-output-port (open-output-bytes)])
|
|
(define reserved (+xreserved uint16be))
|
|
(encode reserved #f)
|
|
(check-equal? (get-output-bytes (current-output-port)) (bytes 0 0))))
|
|
|
|
(test-case
|
|
"reserved: should encode with pre-encode"
|
|
(parameterize ([current-output-port (open-output-bytes)])
|
|
(define reserved (+xreserved uint32be #:pre-encode (λ (val) 42)))
|
|
(encode reserved #f)
|
|
(check-equal? (get-output-bytes (current-output-port)) (bytes 0 0 0 0)))) |