main
Matthew Butterick 6 years ago
parent f5d2309164
commit e7e2038d4d

@ -10,6 +10,11 @@
[(input-port? arg) arg]
[else (raise-argument-error '->input-port "byte string or input port" arg)]))
(define (dict-ref* d . keys)
(for/fold ([d d])
([k (in-list keys)])
(dict-ref d k)))
(define private-keys '(parent _startOffset _currentOffset _length))
(define (dict->mutable-hash x)
(define h (make-hasheq))

@ -72,13 +72,13 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
"size should add to parent pointerSize"
(let ([parent (mhash 'parent (mhash 'pointerSize 0))])
(check-equal? (size (+xpointer #:relative-to 'parent) 10 #:parent parent) 1)
(check-equal? (dict-ref (dict-ref parent 'parent) 'pointerSize) 1)))
(check-equal? (dict-ref* parent 'parent 'pointerSize) 1)))
(test-case
"size should add to global pointerSize"
(let ([parent (mhash 'parent (mhash 'parent (mhash 'parent (mhash 'pointerSize 0))))])
(check-equal? (size (+xpointer #:relative-to 'global) 10 #:parent parent) 1)
(check-equal? (dict-ref (dict-ref (dict-ref (dict-ref parent 'parent) 'parent) 'parent) 'pointerSize) 1)))
(check-equal? (dict-ref* parent 'parent 'parent 'parent 'pointerSize) 1)))
(test-case
"size should handle void pointers"
@ -142,8 +142,8 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
'pointerOffset 5
'pointers null)))
(encode (+xpointer #:relative-to 'parent) 10 #:parent parent)
(check-equal? (dict-ref (dict-ref parent 'parent) 'pointerOffset) 6)
(check-equal? (dict-ref (dict-ref parent 'parent) 'pointers) (list (mhasheq 'type uint8
(check-equal? (dict-ref* parent 'parent 'pointerOffset) 6)
(check-equal? (dict-ref* parent 'parent 'pointers) (list (mhasheq 'type uint8
'val 10
'parent parent)))
(check-equal? (get-output-bytes (current-output-port)) (bytes 2))))
@ -158,8 +158,8 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
'pointerOffset 5
'pointers null)))))
(encode (+xpointer #:relative-to 'global) 10 #:parent parent)
(check-equal? (dict-ref (dict-ref (dict-ref (dict-ref parent 'parent) 'parent) 'parent) 'pointerOffset) 6)
(check-equal? (dict-ref (dict-ref (dict-ref (dict-ref parent 'parent) 'parent) 'parent) 'pointers)
(check-equal? (dict-ref* parent 'parent 'parent 'parent 'pointerOffset) 6)
(check-equal? (dict-ref* parent 'parent 'parent 'parent 'pointers)
(list (mhasheq 'type uint8
'val 10
'parent parent)))
@ -172,11 +172,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
'startOffset 0
'pointerOffset 1
'pointers null))
(encode (+xpointer uint8 'void) (+xvoid-pointer uint8 55) #:parent parent)
(encode (+xpointer uint8 'void) (+xvoid-pointer uint8 55) #:parent parent)
(check-equal? (dict-ref parent 'pointerOffset) 2)
(check-equal? (dict-ref parent 'pointers) (list (mhasheq 'type uint8
'val 55
'parent parent)))
(check-equal? (dict-ref parent 'pointers) (list (mhasheq 'type uint8 'val 55 'parent parent)))
(check-equal? (get-output-bytes (current-output-port)) (bytes 1))))
(test-case

Loading…
Cancel
Save