|
|
|
@ -17,11 +17,11 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"versioned struct: decode should get version from number type"
|
|
|
|
|
(let ([vstruct (+xversioned-struct uint8
|
|
|
|
|
(let ([vstruct (x:versioned-struct uint8
|
|
|
|
|
(dictify
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii)
|
|
|
|
|
'age uint8)
|
|
|
|
|
1 (+xstruct 'name (+xstring #:length uint8 #:encoding 'utf8)
|
|
|
|
|
1 (x:struct 'name (x:string #:length uint8 #:encoding 'utf8)
|
|
|
|
|
'age uint8
|
|
|
|
|
'gender uint8)))])
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes #"\x00\x05roxyb\x15")])
|
|
|
|
@ -31,11 +31,11 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"versioned struct: decode should throw for unknown version"
|
|
|
|
|
(let ([vstruct (+xversioned-struct uint8
|
|
|
|
|
(let ([vstruct (x:versioned-struct uint8
|
|
|
|
|
(dictify
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii)
|
|
|
|
|
'age uint8)
|
|
|
|
|
1 (+xstruct 'name (+xstring #:length uint8 #:encoding 'utf8)
|
|
|
|
|
1 (x:struct 'name (x:string #:length uint8 #:encoding 'utf8)
|
|
|
|
|
'age uint8
|
|
|
|
|
'gender uint8)))])
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes #"\x05\x05roxyb\x15")])
|
|
|
|
@ -43,12 +43,12 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"versioned struct: decode should support common header block"
|
|
|
|
|
(let ([vstruct (+xversioned-struct uint8
|
|
|
|
|
(let ([vstruct (x:versioned-struct uint8
|
|
|
|
|
(dictify
|
|
|
|
|
'header (dictify 'age uint8
|
|
|
|
|
'alive uint8)
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii))
|
|
|
|
|
1 (+xstruct 'name (+xstring #:length uint8 #:encoding 'utf8)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii))
|
|
|
|
|
1 (x:struct 'name (x:string #:length uint8 #:encoding 'utf8)
|
|
|
|
|
'gender uint8)))])
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes #"\x00\x15\x01\x05roxyb")])
|
|
|
|
|
(check-equal? (decode vstruct) (mhasheq 'name "roxyb"
|
|
|
|
@ -64,11 +64,11 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"versioned struct: decode should support parent version key"
|
|
|
|
|
(let ([vstruct (+xversioned-struct 'version
|
|
|
|
|
(let ([vstruct (x:versioned-struct 'version
|
|
|
|
|
(dictify
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii)
|
|
|
|
|
'age uint8)
|
|
|
|
|
1 (+xstruct 'name (+xstring #:length uint8 #:encoding 'utf8)
|
|
|
|
|
1 (x:struct 'name (x:string #:length uint8 #:encoding 'utf8)
|
|
|
|
|
'age uint8
|
|
|
|
|
'gender uint8)))])
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes #"\x05roxyb\x15")])
|
|
|
|
@ -80,14 +80,14 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"versioned struct: decode should support sub versioned structs"
|
|
|
|
|
(let ([vstruct (+xversioned-struct uint8
|
|
|
|
|
(let ([vstruct (x:versioned-struct uint8
|
|
|
|
|
(dictify
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii)
|
|
|
|
|
'age uint8)
|
|
|
|
|
1 (+xversioned-struct uint8
|
|
|
|
|
1 (x:versioned-struct uint8
|
|
|
|
|
(dictify
|
|
|
|
|
0 (dictify 'name (+xstring uint8))
|
|
|
|
|
1 (dictify 'name (+xstring uint8)
|
|
|
|
|
0 (dictify 'name (x:string uint8))
|
|
|
|
|
1 (dictify 'name (x:string uint8)
|
|
|
|
|
'isDessert uint8)))))])
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes #"\x00\x05roxyb\x15")])
|
|
|
|
|
(check-equal? (decode vstruct #:parent (mhash 'version 0))
|
|
|
|
@ -101,12 +101,12 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"versioned struct: decode should support process hook"
|
|
|
|
|
(let ([vstruct (+xversioned-struct #:post-decode (λ (val) (dict-set! val 'processed "true") val)
|
|
|
|
|
(let ([vstruct (x:versioned-struct #:post-decode (λ (val) (dict-set! val 'processed "true") val)
|
|
|
|
|
uint8
|
|
|
|
|
(dictify
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii)
|
|
|
|
|
'age uint8)
|
|
|
|
|
1 (+xstruct 'name (+xstring #:length uint8 #:encoding 'utf8)
|
|
|
|
|
1 (x:struct 'name (x:string #:length uint8 #:encoding 'utf8)
|
|
|
|
|
'age uint8
|
|
|
|
|
'gender uint8)))])
|
|
|
|
|
(parameterize ([current-input-port (open-input-bytes #"\x00\x05roxyb\x15")])
|
|
|
|
@ -115,11 +115,11 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"versioned struct: size should compute the correct size"
|
|
|
|
|
(let ([vstruct (+xversioned-struct uint8
|
|
|
|
|
(let ([vstruct (x:versioned-struct uint8
|
|
|
|
|
(dictify
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii)
|
|
|
|
|
'age uint8)
|
|
|
|
|
1 (+xstruct 'name (+xstring #:length uint8 #:encoding 'utf8)
|
|
|
|
|
1 (x:struct 'name (x:string #:length uint8 #:encoding 'utf8)
|
|
|
|
|
'age uint8
|
|
|
|
|
'gender uint8)))])
|
|
|
|
|
(check-equal? (size vstruct (mhasheq 'name "roxyb"
|
|
|
|
@ -132,37 +132,37 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"versioned struct: size should throw for unknown version"
|
|
|
|
|
(let ([vstruct (+xversioned-struct uint8
|
|
|
|
|
(let ([vstruct (x:versioned-struct uint8
|
|
|
|
|
(dictify
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii)
|
|
|
|
|
'age uint8)
|
|
|
|
|
1 (+xstruct 'name (+xstring #:length uint8 #:encoding 'utf8)
|
|
|
|
|
1 (x:struct 'name (x:string #:length uint8 #:encoding 'utf8)
|
|
|
|
|
'age uint8
|
|
|
|
|
'gender uint8)))])
|
|
|
|
|
(check-exn exn:fail:contract? (λ () (size vstruct (mhasheq 'name "roxyb" 'age 21 'version 5))))))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"versioned struct: size should support common header block"
|
|
|
|
|
(let ([struct (+xversioned-struct uint8
|
|
|
|
|
(let ([struct (x:versioned-struct uint8
|
|
|
|
|
(dictify
|
|
|
|
|
'header (dictify 'age uint8
|
|
|
|
|
'alive uint8)
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii))
|
|
|
|
|
1 (+xstruct 'name (+xstring #:length uint8 #:encoding 'utf8)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii))
|
|
|
|
|
1 (x:struct 'name (x:string #:length uint8 #:encoding 'utf8)
|
|
|
|
|
'gender uint8)))])
|
|
|
|
|
(check-equal? (size struct (mhasheq 'name "roxyb" 'age 21 'alive 1 'version 0)) 9)
|
|
|
|
|
(check-equal? (size struct (mhasheq 'name "roxyb 🤘" 'gender 0 'age 21 'alive 1 'version 1)) 15)))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"versioned struct: size should compute the correct size with pointers"
|
|
|
|
|
(let ([vstruct (+xversioned-struct uint8
|
|
|
|
|
(let ([vstruct (x:versioned-struct uint8
|
|
|
|
|
(dictify
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii)
|
|
|
|
|
'age uint8)
|
|
|
|
|
1 (+xstruct 'name (+xstring #:length uint8 #:encoding 'utf8)
|
|
|
|
|
1 (x:struct 'name (x:string #:length uint8 #:encoding 'utf8)
|
|
|
|
|
'age uint8
|
|
|
|
|
'ptr (+xpointer #:offset-type uint8
|
|
|
|
|
#:type (+xstring uint8)))))])
|
|
|
|
|
'ptr (x:pointer #:offset-type uint8
|
|
|
|
|
#:type (x:string uint8)))))])
|
|
|
|
|
(check-equal? (size vstruct (mhasheq 'name "roxyb"
|
|
|
|
|
'age 21
|
|
|
|
|
'version 1
|
|
|
|
@ -170,22 +170,22 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"versioned struct: size should throw if no value is given"
|
|
|
|
|
(let ([vstruct (+xversioned-struct uint8
|
|
|
|
|
(let ([vstruct (x:versioned-struct uint8
|
|
|
|
|
(dictify
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii)
|
|
|
|
|
'age uint8)
|
|
|
|
|
1 (+xstruct 'name (+xstring #:length uint8 #:encoding 'utf8)
|
|
|
|
|
1 (x:struct 'name (x:string #:length uint8 #:encoding 'utf8)
|
|
|
|
|
'age uint8
|
|
|
|
|
'gender uint8)))])
|
|
|
|
|
(check-exn exn:fail:contract? (λ () (size vstruct)))))
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"versioned struct: encode should encode objects to buffers"
|
|
|
|
|
(let ([vstruct (+xversioned-struct uint8
|
|
|
|
|
(let ([vstruct (x:versioned-struct uint8
|
|
|
|
|
(dictify
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii)
|
|
|
|
|
'age uint8)
|
|
|
|
|
1 (+xstruct 'name (+xstring #:length uint8 #:encoding 'utf8)
|
|
|
|
|
1 (x:struct 'name (x:string #:length uint8 #:encoding 'utf8)
|
|
|
|
|
'age uint8
|
|
|
|
|
'gender uint8)))]
|
|
|
|
|
[op (open-output-bytes)])
|
|
|
|
@ -195,11 +195,11 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"versioned struct: encode should throw for unknown version"
|
|
|
|
|
(let ([vstruct (+xversioned-struct uint8
|
|
|
|
|
(let ([vstruct (x:versioned-struct uint8
|
|
|
|
|
(dictify
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii)
|
|
|
|
|
'age uint8)
|
|
|
|
|
1 (+xstruct 'name (+xstring #:length uint8 #:encoding 'utf8)
|
|
|
|
|
1 (x:struct 'name (x:string #:length uint8 #:encoding 'utf8)
|
|
|
|
|
'age uint8
|
|
|
|
|
'gender uint8)))]
|
|
|
|
|
[op (open-output-bytes)])
|
|
|
|
@ -207,12 +207,12 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"versioned struct: encode should support common header block"
|
|
|
|
|
(let ([vstruct (+xversioned-struct uint8
|
|
|
|
|
(let ([vstruct (x:versioned-struct uint8
|
|
|
|
|
(dictify
|
|
|
|
|
'header (dictify 'age uint8
|
|
|
|
|
'alive uint8)
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii))
|
|
|
|
|
1 (+xstruct 'name (+xstring #:length uint8 #:encoding 'utf8)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii))
|
|
|
|
|
1 (x:struct 'name (x:string #:length uint8 #:encoding 'utf8)
|
|
|
|
|
'gender uint8)))]
|
|
|
|
|
[op (open-output-bytes)])
|
|
|
|
|
(encode vstruct (mhasheq 'name "roxyb" 'age 21 'alive 1 'version 0) op)
|
|
|
|
@ -221,14 +221,14 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe
|
|
|
|
|
|
|
|
|
|
(test-case
|
|
|
|
|
"versioned struct: encode should encode pointer data after structure"
|
|
|
|
|
(let ([vstruct (+xversioned-struct uint8
|
|
|
|
|
(let ([vstruct (x:versioned-struct uint8
|
|
|
|
|
(dictify
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii)
|
|
|
|
|
'age uint8)
|
|
|
|
|
1 (+xstruct 'name (+xstring #:length uint8 #:encoding 'utf8)
|
|
|
|
|
1 (x:struct 'name (x:string #:length uint8 #:encoding 'utf8)
|
|
|
|
|
'age uint8
|
|
|
|
|
'ptr (+xpointer #:offset-type uint8
|
|
|
|
|
#:type (+xstring uint8)))))]
|
|
|
|
|
'ptr (x:pointer #:offset-type uint8
|
|
|
|
|
#:type (x:string uint8)))))]
|
|
|
|
|
[op (open-output-bytes)])
|
|
|
|
|
(encode vstruct (mhasheq 'version 1 'name "roxyb" 'age 21 'ptr "hello") op)
|
|
|
|
|
|
|
|
|
@ -236,11 +236,11 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe
|
|
|
|
|
|
|
|
|
|
#;(test-case
|
|
|
|
|
"versioned struct: encode should support preEncode hook"
|
|
|
|
|
(let ([vstruct (+xversioned-struct uint8
|
|
|
|
|
(let ([vstruct (x:versioned-struct uint8
|
|
|
|
|
(dictify
|
|
|
|
|
0 (dictify 'name (+xstring #:length uint8 #:encoding 'ascii)
|
|
|
|
|
0 (dictify 'name (x:string #:length uint8 #:encoding 'ascii)
|
|
|
|
|
'age uint8)
|
|
|
|
|
1 (+xstruct 'name (+xstring #:length uint8 #:encoding 'utf8)
|
|
|
|
|
1 (x:struct 'name (x:string #:length uint8 #:encoding 'utf8)
|
|
|
|
|
'age uint8
|
|
|
|
|
'gender uint8)))]
|
|
|
|
|
[op (open-output-bytes)])
|
|
|
|
|