From c53fd0b0e6fc49215c8704301a4331c477e3caa2 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 5 Jul 2017 11:57:36 -0700 Subject: [PATCH] roxify --- pitfall/xenomorph/test/struct-test.rkt | 32 ++++----- .../xenomorph/test/versioned-struct-test.rkt | 70 +++++++++---------- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/pitfall/xenomorph/test/struct-test.rkt b/pitfall/xenomorph/test/struct-test.rkt index 9247ec09..949962ec 100644 --- a/pitfall/xenomorph/test/struct-test.rkt +++ b/pitfall/xenomorph/test/struct-test.rkt @@ -10,33 +10,33 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee ; describe 'decode', -> ; it 'should decode into an object', -> -(parameterize ([current-input-port (open-input-bytes #"\x05devon\x15")]) +(parameterize ([current-input-port (open-input-bytes #"\x05roxyb\x15")]) (check-equal? (dump (decode (+Struct (dictify 'name (+StringT uint8) 'age uint8)))) - (mhasheq 'name "devon" 'age 21))) + (mhasheq 'name "roxyb" 'age 21))) ; it 'should support process hook', -> -(parameterize ([current-input-port (open-input-bytes #"\x05devon\x20")]) +(parameterize ([current-input-port (open-input-bytes #"\x05roxyb\x20")]) (define struct (+Struct (dictify 'name (+StringT uint8) 'age uint8))) (set-field! post-decode struct (位 (o . _) (ref-set! o 'canDrink (>= (路 o age) 21)) o)) (check-equal? (dump (decode struct)) - (mhasheq 'name "devon" 'age 32 'canDrink #t))) + (mhasheq 'name "roxyb" 'age 32 'canDrink #t))) ; it 'should support function keys', -> -(parameterize ([current-input-port (open-input-bytes #"\x05devon\x20")]) +(parameterize ([current-input-port (open-input-bytes #"\x05roxyb\x20")]) (define struct (+Struct (dictify 'name (+StringT uint8) 'age uint8 'canDrink (位 (o) (>= (ref o 'age) 21))))) (check-equal? (dump (decode struct)) - (mhasheq 'name "devon" 'age 32 'canDrink #t))) + (mhasheq 'name "roxyb" 'age 32 'canDrink #t))) @@ -48,7 +48,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee (check-equal? (size (+Struct (dictify 'name (+StringT uint8) 'age uint8)) - (hasheq 'name "devon" 'age 32)) 7) + (hasheq 'name "roxyb" 'age 32)) 7) @@ -58,7 +58,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee 'name (+StringT uint8) 'age uint8 'ptr (+Pointer uint8 (+StringT uint8)))) - (mhash 'name "devon" 'age 21 'ptr "hello")) 14) + (mhash 'name "roxyb" 'age 21 'ptr "hello")) 14) ; it 'should get the correct size when no value is given', -> @@ -79,7 +79,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee ; it 'should encode objects to buffers', (done) -> ; stream = new EncodeStream ; stream.pipe concat (buf) -> -; buf.should.deep.equal new Buffer '\x05devon\x15' +; buf.should.deep.equal new Buffer '\x05roxyb\x15' ; done() ; ; struct = new Struct @@ -87,15 +87,15 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee ; age: uint8 ; ; struct.encode stream, -; name: 'devon' +; name: 'roxyb' ; age: 21 ; ; stream.end() -(parameterize ([current-input-port (open-input-bytes #"\x05devon\x15")]) +(parameterize ([current-input-port (open-input-bytes #"\x05roxyb\x15")]) (check-equal? (dump (decode (+Struct (dictify 'name (+StringT uint8) 'age uint8)))) - (mhasheq 'name "devon" 'age 21))) + (mhasheq 'name "roxyb" 'age 21))) ; it 'should support preEncode hook', (done) -> @@ -105,8 +105,8 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee 'name (+StringT 'nameLength) 'age uint8))) (set-field! pre-encode struct (位 (val port) (ref-set! val 'nameLength (length (ref val 'name))) val)) - (encode struct (mhasheq 'name "devon" 'age 21)) - (check-equal? (dump (current-output-port)) #"\x05devon\x15")) + (encode struct (mhasheq 'name "roxyb" 'age 21)) + (check-equal? (dump (current-output-port)) #"\x05roxyb\x15")) ; it 'should encode pointer data after structure', (done) -> @@ -115,6 +115,6 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee (define struct (+Struct (dictify 'name (+StringT uint8) 'age uint8 'ptr (+Pointer uint8 (+StringT uint8))))) - (encode struct (mhasheq 'name "devon" 'age 21 'ptr "hello")) - (check-equal? (dump (current-output-port)) #"\x05devon\x15\x08\x05hello")) + (encode struct (mhasheq 'name "roxyb" 'age 21 'ptr "hello")) + (check-equal? (dump (current-output-port)) #"\x05roxyb\x15\x08\x05hello")) diff --git a/pitfall/xenomorph/test/versioned-struct-test.rkt b/pitfall/xenomorph/test/versioned-struct-test.rkt index 1a598f1e..d25ba6fd 100644 --- a/pitfall/xenomorph/test/versioned-struct-test.rkt +++ b/pitfall/xenomorph/test/versioned-struct-test.rkt @@ -17,13 +17,13 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'gender uint8)))]) - (parameterize ([current-input-port (open-input-bytes #"\x00\x05devon\x15")]) - (check-equal? (dump (decode struct)) (mhasheq 'name "devon" + (parameterize ([current-input-port (open-input-bytes #"\x00\x05roxyb\x15")]) + (check-equal? (dump (decode struct)) (mhasheq 'name "roxyb" 'age 21 'version 0))) - (parameterize ([current-input-port (open-input-bytes (string->bytes/utf-8 "\x01\x0adevon 馃憤\x15\x00"))]) - (check-equal? (dump (decode struct)) (mhasheq 'name "devon 馃憤" + (parameterize ([current-input-port (open-input-bytes (string->bytes/utf-8 "\x01\x0aroxyb 馃\x15\x00"))]) + (check-equal? (dump (decode struct)) (mhasheq 'name "roxyb 馃" 'age 21 'version 1 'gender 0)))) @@ -39,7 +39,7 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'gender uint8)))]) - (parameterize ([current-input-port (open-input-bytes #"\x05\x05devon\x15")]) + (parameterize ([current-input-port (open-input-bytes #"\x05\x05roxyb\x15")]) (check-exn exn:fail:contract? (位 () (decode struct))))) @@ -54,14 +54,14 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 1 (dictify 'name (+StringT uint8 'utf8) 'gender uint8)))]) - (parameterize ([current-input-port (open-input-bytes #"\x00\x15\x01\x05devon")]) - (check-equal? (dump (decode struct)) (mhasheq 'name "devon" + (parameterize ([current-input-port (open-input-bytes #"\x00\x15\x01\x05roxyb")]) + (check-equal? (dump (decode struct)) (mhasheq 'name "roxyb" 'age 21 'alive 1 'version 0))) - (parameterize ([current-input-port (open-input-bytes (string->bytes/utf-8 "\x01\x15\x01\x0adevon 馃憤\x00"))]) - (check-equal? (dump (decode struct)) (mhasheq 'name "devon 馃憤" + (parameterize ([current-input-port (open-input-bytes (string->bytes/utf-8 "\x01\x15\x01\x0aroxyb 馃\x00"))]) + (check-equal? (dump (decode struct)) (mhasheq 'name "roxyb 馃" 'age 21 'version 1 'alive 1 @@ -78,13 +78,13 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'gender uint8)))]) - (parameterize ([current-input-port (open-input-bytes #"\x05devon\x15")]) - (check-equal? (dump (decode struct #:parent (mhash 'version 0))) (mhasheq 'name "devon" + (parameterize ([current-input-port (open-input-bytes #"\x05roxyb\x15")]) + (check-equal? (dump (decode struct #:parent (mhash 'version 0))) (mhasheq 'name "roxyb" 'age 21 'version 0))) - (parameterize ([current-input-port (open-input-bytes (string->bytes/utf-8 "\x0adevon 馃憤\x15\x00"))]) - (check-equal? (dump (decode struct #:parent (mhash 'version 1))) (mhasheq 'name "devon 馃憤" + (parameterize ([current-input-port (open-input-bytes (string->bytes/utf-8 "\x0aroxyb 馃\x15\x00"))]) + (check-equal? (dump (decode struct #:parent (mhash 'version 1))) (mhasheq 'name "roxyb 馃" 'age 21 'version 1 'gender 0)))) @@ -104,8 +104,8 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 1 (dictify 'name (+StringT uint8) 'isDessert uint8)))))]) - (parameterize ([current-input-port (open-input-bytes #"\x00\x05devon\x15")]) - (check-equal? (dump (decode struct #:parent (mhash 'version 0))) (mhasheq 'name "devon" + (parameterize ([current-input-port (open-input-bytes #"\x00\x05roxyb\x15")]) + (check-equal? (dump (decode struct #:parent (mhash 'version 0))) (mhasheq 'name "roxyb" 'age 21 'version 0))) @@ -130,8 +130,8 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'gender uint8)))]) (set-field! post-decode struct (位 (o stream ctx) (ref-set! o 'processed "true") o)) - (parameterize ([current-input-port (open-input-bytes #"\x00\x05devon\x15")]) - (check-equal? (dump (decode struct)) (mhasheq 'name "devon" + (parameterize ([current-input-port (open-input-bytes #"\x00\x05roxyb\x15")]) + (check-equal? (dump (decode struct)) (mhasheq 'name "roxyb" 'processed "true" 'age 21 'version 0)))) @@ -149,11 +149,11 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'gender uint8)))]) - (check-equal? (size struct (mhasheq 'name "devon" + (check-equal? (size struct (mhasheq 'name "roxyb" 'age 21 'version 0)) 8) - (check-equal? (size struct (mhasheq 'name "devon 馃憤" + (check-equal? (size struct (mhasheq 'name "roxyb 馃" 'gender 0 'age 21 'version 1)) 14)) @@ -172,7 +172,7 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'gender uint8)))]) - (check-exn exn:fail:contract? (位 () (size struct (mhasheq 'name "devon" + (check-exn exn:fail:contract? (位 () (size struct (mhasheq 'name "roxyb" 'age 21 'version 5))))) @@ -188,12 +188,12 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 1 (dictify 'name (+StringT uint8 'utf8) 'gender uint8)))]) - (check-equal? (size struct (mhasheq 'name "devon" + (check-equal? (size struct (mhasheq 'name "roxyb" 'age 21 'alive 1 'version 0)) 9) - (check-equal? (size struct (mhasheq 'name "devon 馃憤" + (check-equal? (size struct (mhasheq 'name "roxyb 馃" 'gender 0 'age 21 'alive 1 @@ -212,7 +212,7 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'ptr (+Pointer uint8 (+StringT uint8)))))]) - (check-equal? (size struct (mhasheq 'name "devon" + (check-equal? (size struct (mhasheq 'name "roxyb" 'age 21 'version 1 'ptr "hello")) 15)) @@ -246,14 +246,14 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'gender uint8)))] [port (open-output-bytes)]) - (encode struct (mhasheq 'name "devon" + (encode struct (mhasheq 'name "roxyb" 'age 21 'version 0) port) - (encode struct (mhasheq 'name "devon 馃憤" + (encode struct (mhasheq 'name "roxyb 馃" 'age 21 'gender 0 'version 1) port) - (check-equal? (dump port) (string->bytes/utf-8 "\x00\x05devon\x15\x01\x0adevon 馃憤\x15\x00"))) + (check-equal? (dump port) (string->bytes/utf-8 "\x00\x05roxyb\x15\x01\x0aroxyb 馃\x15\x00"))) ; @@ -267,7 +267,7 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'gender uint8)))] [port (open-output-bytes)]) - (check-exn exn:fail:contract? (位 () (encode struct port (mhasheq 'name "devon" + (check-exn exn:fail:contract? (位 () (encode struct port (mhasheq 'name "roxyb" 'age 21 'version 5))))) @@ -284,18 +284,18 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'gender uint8)))] [stream (open-output-bytes)]) - (encode struct (mhasheq 'name "devon" + (encode struct (mhasheq 'name "roxyb" 'age 21 'alive 1 'version 0) stream) - (encode struct (mhasheq 'name "devon 馃憤" + (encode struct (mhasheq 'name "roxyb 馃" 'gender 0 'age 21 'alive 1 'version 1) stream) - (check-equal? (dump stream) (string->bytes/utf-8 "\x00\x15\x01\x05devon\x01\x15\x01\x0adevon 馃憤\x00"))) + (check-equal? (dump stream) (string->bytes/utf-8 "\x00\x15\x01\x05roxyb\x01\x15\x01\x0aroxyb 馃\x00"))) @@ -310,11 +310,11 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'ptr (+Pointer uint8 (+StringT uint8)))))] [stream (open-output-bytes)]) (encode struct (mhasheq 'version 1 - 'name "devon" + 'name "roxyb" 'age 21 'ptr "hello") stream) - (check-equal? (dump stream) (string->bytes/utf-8 "\x01\x05devon\x15\x09\x05hello"))) + (check-equal? (dump stream) (string->bytes/utf-8 "\x01\x05roxyb\x15\x09\x05hello"))) @@ -330,10 +330,10 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'gender uint8)))] [stream (open-output-bytes)]) (set-field! pre-encode struct (位 (val port) (ref-set! val 'version (if (ref val 'gender) 1 0)) val)) - (encode struct (mhasheq 'name "devon" + (encode struct (mhasheq 'name "roxyb" 'age 21 'version 0) stream) - (encode struct (mhasheq 'name "devon 馃憤" + (encode struct (mhasheq 'name "roxyb 馃" 'age 21 'gender 0) stream) - (check-equal? (dump stream) (string->bytes/utf-8 "\x00\x05devon\x15\x01\x0adevon 馃憤\x15\x00"))) + (check-equal? (dump stream) (string->bytes/utf-8 "\x00\x05roxyb\x15\x01\x0aroxyb 馃\x15\x00")))