@ -57,37 +57,37 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
( test-case
" pointer: size "
( let ( [ parent ( mhash ' pointerSize 0 ) ] )
( let ( [ parent ( mhash x:pointer-size-key 0 ) ] )
( check-equal? ( size ( x:pointer ) 10 #:parent parent ) 1 )
( check-equal? ( hash-ref parent ' pointerSize ) 1 ) ) )
( check-equal? ( hash-ref parent x:pointer-size-key ) 1 ) ) )
( test-case
" pointer: size should add to immediate pointerSize "
( let ( [ parent ( mhash ' pointerSize 0 ) ] )
( let ( [ parent ( mhash x:pointer-size-key 0 ) ] )
( check-equal? ( size ( x:pointer #:relative-to ' immediate ) 10 #:parent parent ) 1 )
( check-equal? ( hash-ref parent ' pointerSize ) 1 ) ) )
( check-equal? ( hash-ref parent x:pointer-size-key ) 1 ) ) )
( test-case
" pointer: size should add to parent pointerSize "
( let ( [ parent ( mhash x:parent-key ( mhash ' pointerSize 0 ) ) ] )
( let ( [ parent ( mhash x:parent-key ( mhash x:pointer-size-key 0 ) ) ] )
( check-equal? ( size ( x:pointer #:relative-to ' parent ) 10 #:parent parent ) 1 )
( check-equal? ( hash-ref* parent x:parent-key ' pointerSize ) 1 ) ) )
( check-equal? ( hash-ref* parent x:parent-key x:pointer-size-key ) 1 ) ) )
( test-case
" pointer: size should add to global pointerSize "
( let ( [ parent ( mhash x:parent-key ( mhash x:parent-key ( mhash x:parent-key ( mhash ' pointerSize 0 ) ) ) ) ] )
( let ( [ parent ( mhash x:parent-key ( mhash x:parent-key ( mhash x:parent-key ( mhash x:pointer-size-key 0 ) ) ) ) ] )
( check-equal? ( size ( x:pointer #:relative-to ' global ) 10 #:parent parent ) 1 )
( check-equal? ( hash-ref* parent x:parent-key x:parent-key x:parent-key ' pointerSize ) 1 ) ) )
( check-equal? ( hash-ref* parent x:parent-key x:parent-key x:parent-key x:pointer-size-key ) 1 ) ) )
( test-case
" pointer: size should handle void pointers "
( let ( [ parent ( mhash ' pointerSize 0 ) ] )
( let ( [ parent ( mhash x:pointer-size-key 0 ) ] )
( check-equal? ( size ( x:pointer uint8 ' void ) ( x:void-pointer uint8 50 ) #:parent parent ) 1 )
( check-equal? ( hash-ref parent ' pointerSize ) 1 ) ) )
( check-equal? ( hash-ref parent x:pointer-size-key ) 1 ) ) )
( test-case
" pointer: size should throw if no type and not a void pointer "
( let ( [ parent ( mhash ' pointerSize 0 ) ] )
( let ( [ parent ( mhash x:pointer-size-key 0 ) ] )
( check-exn exn:fail:contract? ( λ ( ) ( size ( x:pointer uint8 ' void ) 30 #:parent parent ) ) ) ) )
( test-case
@ -97,24 +97,24 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
( test-case
" pointer: encode should handle null pointers "
( parameterize ( [ current-output-port ( open-output-bytes ) ] )
( define parent ( mhash ' pointerSize 0
( define parent ( mhash x:pointer-size-key 0
' startOffset 0
' pointerOffset 0
' pointers null ) )
x:pointer-offset-key 0
x:pointers-key null ) )
( encode ( x:pointer ) #f #:parent parent )
( check-equal? ( hash-ref parent ' pointerSize ) 0 )
( check-equal? ( hash-ref parent x:pointer-size-key ) 0 )
( check-equal? ( get-output-bytes ( current-output-port ) ) ( bytes 0 ) ) ) )
( test-case
" pointer: encode should handle local offsets "
( parameterize ( [ current-output-port ( open-output-bytes ) ] )
( define parent ( mhash ' pointerSize 0
( define parent ( mhash x:pointer-size-key 0
' startOffset 0
' pointerOffset 1
' pointers null ) )
x:pointer-offset-key 1
x:pointers-key null ) )
( encode ( x:pointer ) 10 #:parent parent )
( check-equal? ( hash-ref parent ' pointerOffset ) 2 )
( check-equal? ( hash-ref parent ' pointers ) ( list ( mhasheq ' type uint8
( check-equal? ( hash-ref parent x:pointer-offset-key ) 2 )
( check-equal? ( hash-ref parent x:pointers-key ) ( list ( mhasheq ' type uint8
' val 10
x:parent-key parent ) ) )
( check-equal? ( get-output-bytes ( current-output-port ) ) ( bytes 1 ) ) ) )
@ -122,13 +122,13 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
( test-case
" pointer: encode should handle immediate offsets "
( parameterize ( [ current-output-port ( open-output-bytes ) ] )
( define parent ( mhash ' pointerSize 0
( define parent ( mhash x:pointer-size-key 0
' startOffset 0
' pointerOffset 1
' pointers null ) )
x:pointer-offset-key 1
x:pointers-key null ) )
( encode ( x:pointer #:relative-to ' immediate ) 10 #:parent parent )
( check-equal? ( hash-ref parent ' pointerOffset ) 2 )
( check-equal? ( hash-ref parent ' pointers ) ( list ( mhasheq ' type uint8
( check-equal? ( hash-ref parent x:pointer-offset-key ) 2 )
( check-equal? ( hash-ref parent x:pointers-key ) ( list ( mhasheq ' type uint8
' val 10
x:parent-key parent ) ) )
( check-equal? ( get-output-bytes ( current-output-port ) ) ( bytes 0 ) ) ) )
@ -136,13 +136,13 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
( test-case
" pointer: encode should handle offsets relative to parent "
( parameterize ( [ current-output-port ( open-output-bytes ) ] )
( define parent ( mhash x:parent-key ( mhash ' pointerSize 0
( define parent ( mhash x:parent-key ( mhash x:pointer-size-key 0
' startOffset 3
' pointerOffset 5
' pointers null ) ) )
x:pointer-offset-key 5
x:pointers-key null ) ) )
( encode ( x:pointer #:relative-to ' parent ) 10 #:parent parent )
( check-equal? ( hash-ref* parent x:parent-key ' pointerOffset ) 6 )
( check-equal? ( hash-ref* parent x:parent-key ' pointers ) ( list ( mhasheq ' type uint8
( check-equal? ( hash-ref* parent x:parent-key x:pointer-offset-key ) 6 )
( check-equal? ( hash-ref* parent x:parent-key x:pointers-key ) ( list ( mhasheq ' type uint8
' val 10
x:parent-key parent ) ) )
( check-equal? ( get-output-bytes ( current-output-port ) ) ( bytes 2 ) ) ) )
@ -152,13 +152,13 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
( parameterize ( [ current-output-port ( open-output-bytes ) ] )
( define parent ( mhash x:parent-key
( mhash x:parent-key
( mhash x:parent-key ( mhash ' pointerSize 0
( mhash x:parent-key ( mhash x:pointer-size-key 0
' startOffset 3
' pointerOffset 5
' pointers null ) ) ) ) )
x:pointer-offset-key 5
x:pointers-key null ) ) ) ) )
( encode ( x:pointer #:relative-to ' global ) 10 #:parent parent )
( check-equal? ( hash-ref* parent x:parent-key x:parent-key x:parent-key ' pointerOffset ) 6 )
( check-equal? ( hash-ref* parent x:parent-key x:parent-key x:parent-key ' pointers )
( check-equal? ( hash-ref* parent x:parent-key x:parent-key x:parent-key x:pointer-offset-key ) 6 )
( check-equal? ( hash-ref* parent x:parent-key x:parent-key x:parent-key x:pointers-key )
( list ( mhasheq ' type uint8
' val 10
x:parent-key parent ) ) )
@ -167,20 +167,20 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee
( test-case
" pointer: encode should support void pointers "
( parameterize ( [ current-output-port ( open-output-bytes ) ] )
( define parent ( mhash ' pointerSize 0
( define parent ( mhash x:pointer-size-key 0
' startOffset 0
' pointerOffset 1
' pointers null ) )
x:pointer-offset-key 1
x:pointers-key null ) )
( encode ( x:pointer uint8 ' void ) ( x:void-pointer uint8 55 ) #:parent parent )
( check-equal? ( hash-ref parent ' pointerOffset ) 2 )
( check-equal? ( hash-ref parent ' pointers ) ( list ( mhasheq ' type uint8 ' val 55 x:parent-key parent ) ) )
( check-equal? ( hash-ref parent x:pointer-offset-key ) 2 )
( check-equal? ( hash-ref parent x:pointers-key ) ( list ( mhasheq ' type uint8 ' val 55 x:parent-key parent ) ) )
( check-equal? ( get-output-bytes ( current-output-port ) ) ( bytes 1 ) ) ) )
( test-case
" pointer: encode should throw if not a void pointer instance "
( parameterize ( [ current-output-port ( open-output-bytes ) ] )
( define parent ( mhash ' pointerSize 0
( define parent ( mhash x:pointer-size-key 0
' startOffset 0
' pointerOffset 1
' pointers null ) )
x:pointer-offset-key 1
x:pointers-key null ) )
( check-exn exn:fail:contract? ( λ ( ) ( encode ( x:pointer uint8 ' void ) 44 #:parent parent ) ) ) ) )