|
|
|
@ -26,30 +26,23 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
|
|
|
|
|
(test-case
|
|
|
|
|
"decode should support immediate offsets"
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes (bytes 1 53))])
|
|
|
|
|
(check-equal? (decode (+xpointer #:style 'immediate)) 53)))
|
|
|
|
|
(check-equal? (decode (+xpointer #:relative-to 'immediate)) 53)))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"decode should support offsets relative to the parent"
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes (bytes 0 0 1 53))])
|
|
|
|
|
(pos (current-input-port) 2)
|
|
|
|
|
(check-equal? (decode (+xpointer #:style 'parent)
|
|
|
|
|
(check-equal? (decode (+xpointer #:relative-to 'parent)
|
|
|
|
|
#:parent (mhash 'parent (mhash '_startOffset 2))) 53)))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"decode should support global offsets"
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes (bytes 1 2 4 0 0 0 53))])
|
|
|
|
|
(pos (current-input-port) 2)
|
|
|
|
|
(check-equal? (decode (+xpointer #:style 'global)
|
|
|
|
|
(check-equal? (decode (+xpointer #:relative-to 'global)
|
|
|
|
|
#:parent (mhash 'parent (mhash 'parent (mhash '_startOffset 2))))
|
|
|
|
|
53)))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"decode should support offsets relative to a property on the parent"
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes (bytes 1 0 0 0 0 53))])
|
|
|
|
|
(check-equal? (decode (+xpointer #:relative-to (λ (parent) (dict-ref (dict-ref parent 'parent) 'ptr)))
|
|
|
|
|
#:parent (mhash '_startOffset 0 'parent (mhash 'ptr 4)))
|
|
|
|
|
53)))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"decode should support returning pointer if there is no decode type"
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes (bytes 4))])
|
|
|
|
@ -72,19 +65,19 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
|
|
|
|
|
(test-case
|
|
|
|
|
"size should add to immediate pointerSize"
|
|
|
|
|
(let ([parent (mhash 'pointerSize 0)])
|
|
|
|
|
(check-equal? (size (+xpointer #:style 'immediate) 10 #:parent parent) 1)
|
|
|
|
|
(check-equal? (size (+xpointer #:relative-to 'immediate) 10 #:parent parent) 1)
|
|
|
|
|
(check-equal? (dict-ref parent 'pointerSize) 1)))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"size should add to parent pointerSize"
|
|
|
|
|
(let ([parent (mhash 'parent (mhash 'pointerSize 0))])
|
|
|
|
|
(check-equal? (size (+xpointer #:style 'parent) 10 #:parent parent) 1)
|
|
|
|
|
(check-equal? (size (+xpointer #:relative-to 'parent) 10 #:parent parent) 1)
|
|
|
|
|
(check-equal? (dict-ref (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 #:style 'global) 10 #:parent parent) 1)
|
|
|
|
|
(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)))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
@ -134,7 +127,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
|
|
|
|
|
'startOffset 0
|
|
|
|
|
'pointerOffset 1
|
|
|
|
|
'pointers null))
|
|
|
|
|
(encode (+xpointer #:style 'immediate) 10 #:parent parent)
|
|
|
|
|
(encode (+xpointer #:relative-to 'immediate) 10 #:parent parent)
|
|
|
|
|
(check-equal? (dict-ref parent 'pointerOffset) 2)
|
|
|
|
|
(check-equal? (dict-ref parent 'pointers) (list (mhasheq 'type uint8
|
|
|
|
|
'val 10
|
|
|
|
@ -148,7 +141,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
|
|
|
|
|
'startOffset 3
|
|
|
|
|
'pointerOffset 5
|
|
|
|
|
'pointers null)))
|
|
|
|
|
(encode (+xpointer #:style 'parent) 10 #:parent parent)
|
|
|
|
|
(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
|
|
|
|
|
'val 10
|
|
|
|
@ -164,7 +157,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
|
|
|
|
|
'startOffset 3
|
|
|
|
|
'pointerOffset 5
|
|
|
|
|
'pointers null)))))
|
|
|
|
|
(encode (+xpointer #:style 'global) 10 #:parent parent)
|
|
|
|
|
(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)
|
|
|
|
|
(list (mhasheq 'type uint8
|
|
|
|
@ -172,21 +165,6 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
|
|
|
|
|
'parent parent)))
|
|
|
|
|
(check-equal? (dump (current-output-port)) (bytes 5))))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"encode should support offsets relative to a property on the parent"
|
|
|
|
|
(parameterize ([current-output-port (open-output-bytes)])
|
|
|
|
|
(define parent (mhash 'pointerSize 0
|
|
|
|
|
'startOffset 0
|
|
|
|
|
'pointerOffset 10
|
|
|
|
|
'pointers null
|
|
|
|
|
'val (mhash 'ptr 4)))
|
|
|
|
|
(encode (+xpointer #:relative-to (λ (parent) (dict-ref parent 'ptr))) 10 #:parent parent)
|
|
|
|
|
(check-equal? (dict-ref parent 'pointerOffset) 11)
|
|
|
|
|
(check-equal? (dict-ref parent 'pointers) (list (mhasheq 'type uint8
|
|
|
|
|
'val 10
|
|
|
|
|
'parent parent)))
|
|
|
|
|
(check-equal? (dump (current-output-port)) (bytes 6))))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"encode should support void pointers"
|
|
|
|
|
(parameterize ([current-output-port (open-output-bytes)])
|
|
|
|
|