diff --git a/pitfall/restructure/test/bitfield-test.rkt b/pitfall/restructure/test/bitfield-test.rkt index a3e9ac03..9565e762 100644 --- a/pitfall/restructure/test/bitfield-test.rkt +++ b/pitfall/restructure/test/bitfield-test.rkt @@ -25,7 +25,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Bitfield.coffee ; it 'should have the right size', -> ; bitfield.size().should.equal 1 -(check-equal? (send bitfield size) 1) +(check-equal? (size bitfield) 1) ; ; it 'should decode', -> @@ -53,13 +53,12 @@ https://github.com/mbutterick/restructure/blob/master/test/Bitfield.coffee ; ; bitfield.encode stream, Jack: yes, Kack: no, Lack: no, Mack: yes, Nack: yes, Oack: no, Pack: yes, Quack: yes -(let ([stream (+EncodeStream)]) - (send bitfield encode stream (mhasheq 'Quack #t - 'Nack #t - 'Lack #f - 'Oack #f - 'Pack #t - 'Mack #t - 'Jack #t - 'Kack #f)) - (check-equal? (send stream dump) (+Buffer (list (bitwise-ior JACK MACK PACK NACK QUACK))))) +(check-equal? (encode bitfield #f (mhasheq 'Quack #t + 'Nack #t + 'Lack #f + 'Oack #f + 'Pack #t + 'Mack #t + 'Jack #t + 'Kack #f)) + (+Buffer (list (bitwise-ior JACK MACK PACK NACK QUACK)))) diff --git a/pitfall/restructure/test/buffer-test.rkt b/pitfall/restructure/test/buffer-test.rkt index e20dab0c..336e46c8 100644 --- a/pitfall/restructure/test/buffer-test.rkt +++ b/pitfall/restructure/test/buffer-test.rkt @@ -16,8 +16,8 @@ https://github.com/mbutterick/restructure/blob/master/test/Buffer.coffee (let ([stream (+DecodeStream (+Buffer '(#xab #xff #x1f #xb6)))] [buf (+BufferT 2)]) - (check-equal? (send buf decode stream) (+Buffer '(#xab #xff))) - (check-equal? (send buf decode stream) (+Buffer '(#x1f #xb6)))) + (check-equal? (decode buf stream) (+Buffer '(#xab #xff))) + (check-equal? (decode buf stream) (+Buffer '(#x1f #xb6)))) ; @@ -29,8 +29,8 @@ https://github.com/mbutterick/restructure/blob/master/test/Buffer.coffee (let ([stream (+DecodeStream (+Buffer '(#xab #xff #x1f #xb6)))] [buf (+BufferT 'len)]) - (check-equal? (send buf decode stream (hash 'len 3)) (+Buffer '(#xab #xff #x1f))) - (check-equal? (send buf decode stream (hash 'len 1)) (+Buffer '(#xb6)))) + (check-equal? (decode buf stream (hash 'len 3)) (+Buffer '(#xab #xff #x1f))) + (check-equal? (decode buf stream (hash 'len 1)) (+Buffer '(#xb6)))) ; @@ -40,7 +40,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Buffer.coffee ; buf.size(new Buffer [0xab, 0xff]).should.equal 2 (let ([buf (+BufferT 2)]) - (check-equal? (send buf size (+Buffer '(#xab #xff))) 2)) + (check-equal? (size buf (+Buffer '(#xab #xff))) 2)) ; ; it 'should use defined length if no value given', -> @@ -48,7 +48,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Buffer.coffee ; array.size().should.equal 10 (let ([array (+BufferT 10)]) - (check-equal? (send array size) 10)) + (check-equal? (size array) 10)) ; @@ -67,9 +67,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Buffer.coffee (let ([stream (+EncodeStream)] [buf (+BufferT 2)]) - (send buf encode stream (+Buffer '(#xab #xff))) - (send buf encode stream (+Buffer '(#x1f #xb6))) - (check-equal? (send stream dump) (+Buffer '(#xab #xff #x1f #xb6)))) + (encode buf stream (+Buffer '(#xab #xff))) + (encode buf stream (+Buffer '(#x1f #xb6))) + (check-equal? (dump stream) (+Buffer '(#xab #xff #x1f #xb6)))) ; it 'should encode length before buffer', (done) -> @@ -84,5 +84,5 @@ https://github.com/mbutterick/restructure/blob/master/test/Buffer.coffee (let ([stream (+EncodeStream)] [buf (+BufferT uint8)]) - (send buf encode stream (+Buffer '(#xab #xff))) - (check-equal? (send stream dump) (+Buffer '(2 #xab #xff)))) \ No newline at end of file + (encode buf stream (+Buffer '(#xab #xff))) + (check-equal? (dump stream) (+Buffer '(2 #xab #xff)))) \ No newline at end of file diff --git a/pitfall/restructure/test/enum-test.rkt b/pitfall/restructure/test/enum-test.rkt index b74048f2..74d14885 100644 --- a/pitfall/restructure/test/enum-test.rkt +++ b/pitfall/restructure/test/enum-test.rkt @@ -11,8 +11,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Enum.coffee ; e.size().should.equal 1 (define e (+Enum uint8 '("foo" "bar" "baz"))) - -(check-equal? (send e size) 1) +(check-equal? (size e) 1) ; @@ -23,9 +22,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Enum.coffee ; e.decode(stream).should.equal 'foo' (let ([stream (+DecodeStream (+Buffer '(1 2 0)))]) - (check-equal? (send e decode stream) "bar") - (check-equal? (send e decode stream) "baz") - (check-equal? (send e decode stream) "foo")) + (check-equal? (decode e stream) "bar") + (check-equal? (decode e stream) "baz") + (check-equal? (decode e stream) "foo")) ; ; it 'should encode', (done) -> @@ -40,9 +39,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Enum.coffee ; stream.end() (let ([stream (+EncodeStream)]) - (send e encode stream "bar") - (send e encode stream "baz") - (send e encode stream "foo") + (encode e stream "bar") + (encode e stream "baz") + (encode e stream "foo") (check-equal? (send stream dump) (+Buffer '(1 2 0)))) ; @@ -51,4 +50,4 @@ https://github.com/mbutterick/restructure/blob/master/test/Enum.coffee ; should.throw -> ; e.encode stream, 'unknown' -(check-exn exn:fail:contract? (λ () (send e encode (+EncodeStream) "unknown"))) \ No newline at end of file +(check-exn exn:fail:contract? (λ () (encode e (+EncodeStream) "unknown"))) \ No newline at end of file diff --git a/pitfall/restructure/test/lazy-array-test.rkt b/pitfall/restructure/test/lazy-array-test.rkt index 0ddb7b48..31a9ac57 100644 --- a/pitfall/restructure/test/lazy-array-test.rkt +++ b/pitfall/restructure/test/lazy-array-test.rkt @@ -26,14 +26,14 @@ https://github.com/mbutterick/restructure/blob/master/test/LazyArray.coffee (let* ([stream (+DecodeStream (+Buffer '(1 2 3 4 5)))] [array (+LazyArray uint8 4)]) - (define arr (send array decode stream)) + (define arr (decode array stream)) (check-false (Array? arr)) (check-equal? (ref arr 'len) 4) - (check-equal? (send stream pos) 4) - (check-equal? (send arr get 0) 1) - (check-equal? (send arr get 1) 2) - (check-equal? (send arr get 2) 3) - (check-equal? (send arr get 3) 4)) + (check-equal? (pos stream) 4) + (check-equal? (get arr 0) 1) + (check-equal? (get arr 1) 2) + (check-equal? (get arr 2) 3) + (check-equal? (get arr 3) 4)) @@ -47,7 +47,7 @@ https://github.com/mbutterick/restructure/blob/master/test/LazyArray.coffee (let* ([stream (+DecodeStream (+Buffer '(1 2 3 4 5)))] [array (+LazyArray uint8 4)]) - (define arr (send array decode stream)) + (define arr (decode array stream)) (check-equal? (send arr to-list) '(1 2 3 4))) ; @@ -60,7 +60,7 @@ https://github.com/mbutterick/restructure/blob/master/test/LazyArray.coffee #;(let* ([stream (+DecodeStream (+Buffer '(1 2 3 4 5)))] [array (+LazyArray uint8 4)]) - (define arr (send array decode stream)) + (define arr (decode array stream)) (check-equal? (send arr inspect) (format "~a" '(1 2 3 4)))) ; @@ -73,7 +73,7 @@ https://github.com/mbutterick/restructure/blob/master/test/LazyArray.coffee (let* ([stream (+DecodeStream (+Buffer '(4 1 2 3 4 5)))] [array (+LazyArray uint8 uint8)]) - (define arr (send array decode stream)) + (define arr (decode array stream)) (check-equal? (send arr to-list) '(1 2 3 4))) ; @@ -87,8 +87,8 @@ https://github.com/mbutterick/restructure/blob/master/test/LazyArray.coffee (let* ([stream (+DecodeStream (+Buffer '(1 2 3 4 5)))] [array (+LazyArray uint8 4)]) - (define arr (send array decode stream)) - (check-equal? (send array size arr) 4)) + (define arr (decode array stream)) + (check-equal? (size array arr) 4)) ; ; describe 'encode', -> @@ -107,7 +107,5 @@ https://github.com/mbutterick/restructure/blob/master/test/LazyArray.coffee (let* ([stream (+DecodeStream (+Buffer '(1 2 3 4 5)))] [array (+LazyArray uint8 4)]) - (define arr (send array decode stream)) - (define enc (+EncodeStream)) - (send array encode enc arr) - (check-equal? (send enc dump) (+Buffer '(1 2 3 4)))) \ No newline at end of file + (define arr (decode array stream)) + (check-equal? (encode array #f arr) (+Buffer '(1 2 3 4)))) \ No newline at end of file diff --git a/pitfall/restructure/test/number-test.rkt b/pitfall/restructure/test/number-test.rkt index 65f06b87..843874bb 100644 --- a/pitfall/restructure/test/number-test.rkt +++ b/pitfall/restructure/test/number-test.rkt @@ -27,15 +27,15 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; stream.end() (let ([stream (+DecodeStream (bytes #xab #xff))]) - (check-equal? (send uint8 decode stream) #xab) - (check-equal? (send uint8 decode stream) #xff)) + (check-equal? (decode uint8 stream) #xab) + (check-equal? (decode uint8 stream) #xff)) -(check-equal? (send uint8 size) 1) +(check-equal? (size uint8) 1) (let ([stream (+EncodeStream)]) - (send uint8 encode stream #xab) - (send uint8 encode stream #xff) - (check-equal? (send stream dump) (bytes #xab #xff))) + (encode uint8 stream #xab) + (encode uint8 stream #xff) + (check-equal? (dump stream) (bytes #xab #xff))) ; @@ -44,7 +44,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; uint16.should.equal uint16be ;; modified test: `uint16` is the same endianness as the platform -(check-equal? (send uint16 decode (bytes 0 1)) (send (if (system-big-endian?) +(check-equal? (decode uint16 (bytes 0 1)) (send (if (system-big-endian?) uint16be uint16le) decode (bytes 0 1))) @@ -66,9 +66,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; uint16be.encode(stream, 0xabff) ; stream.end() -(check-equal? (send uint16be decode (+DecodeStream (bytes #xab #xff))) #xabff) -(check-equal? (send uint16be size) 2) -(check-equal? (send uint16be encode #f #xabff) (bytes #xab #xff)) +(check-equal? (decode uint16be (+DecodeStream (bytes #xab #xff))) #xabff) +(check-equal? (size uint16be) 2) +(check-equal? (encode uint16be #f #xabff) (bytes #xab #xff)) ; ; describe 'uint16le', -> @@ -88,9 +88,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; uint16le.encode(stream, 0xabff) ; stream.end() -(check-equal? (send uint16le decode (+DecodeStream (bytes #xff #xab))) #xabff) -(check-equal? (send uint16le size) 2) -(check-equal? (send uint16le encode #f #xabff) (bytes #xff #xab)) +(check-equal? (decode uint16le (+DecodeStream (bytes #xff #xab))) #xabff) +(check-equal? (size uint16le) 2) +(check-equal? (encode uint16le #f #xabff) (bytes #xff #xab)) ; ; describe 'uint24', -> @@ -98,7 +98,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; uint24.should.equal uint24be ;; modified test: `uint24` is the same endianness as the platform -(check-equal? (send uint24 decode (bytes 0 1 2)) (send (if (system-big-endian?) +(check-equal? (decode uint24 (bytes 0 1 2)) (send (if (system-big-endian?) uint24be uint24le) decode (bytes 0 1 2))) @@ -120,9 +120,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; uint24be.encode(stream, 0xffab24) ; stream.end() -(check-equal? (send uint24be decode (+DecodeStream (bytes #xff #xab #x24))) #xffab24) -(check-equal? (send uint24be size) 3) -(check-equal? (send uint24be encode #f #xffab24) (bytes #xff #xab #x24)) +(check-equal? (decode uint24be (+DecodeStream (bytes #xff #xab #x24))) #xffab24) +(check-equal? (size uint24be) 3) +(check-equal? (encode uint24be #f #xffab24) (bytes #xff #xab #x24)) ; ; describe 'uint24le', -> @@ -142,9 +142,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; uint24le.encode(stream, 0xffab24) ; stream.end() -(check-equal? (send uint24le decode (+DecodeStream (bytes #x24 #xab #xff))) #xffab24) -(check-equal? (send uint24le size) 3) -(check-equal? (send uint24le encode #f #xffab24) (bytes #x24 #xab #xff)) +(check-equal? (decode uint24le (+DecodeStream (bytes #x24 #xab #xff))) #xffab24) +(check-equal? (size uint24le) 3) +(check-equal? (encode uint24le #f #xffab24) (bytes #x24 #xab #xff)) ; ; describe 'uint32', -> @@ -152,7 +152,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; uint32.should.equal uint32be ;; modified test: `uint32` is the same endianness as the platform -(check-equal? (send uint32 decode (bytes 0 1 2 3)) (send (if (system-big-endian?) +(check-equal? (decode uint32 (bytes 0 1 2 3)) (send (if (system-big-endian?) uint32be uint32le) decode (bytes 0 1 2 3))) @@ -174,9 +174,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; uint32be.encode(stream, 0xffab24bf) ; stream.end() -(check-equal? (send uint32be decode (+DecodeStream (bytes #xff #xab #x24 #xbf))) #xffab24bf) -(check-equal? (send uint32be size) 4) -(check-equal? (send uint32be encode #f #xffab24bf) (bytes #xff #xab #x24 #xbf)) +(check-equal? (decode uint32be (+DecodeStream (bytes #xff #xab #x24 #xbf))) #xffab24bf) +(check-equal? (size uint32be) 4) +(check-equal? (encode uint32be #f #xffab24bf) (bytes #xff #xab #x24 #xbf)) ; ; describe 'uint32le', -> @@ -196,9 +196,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; uint32le.encode(stream, 0xffab24bf) ; stream.end() -(check-equal? (send uint32le decode (+DecodeStream (bytes #xbf #x24 #xab #xff))) #xffab24bf) -(check-equal? (send uint32le size) 4) -(check-equal? (send uint32le encode #f #xffab24bf) (bytes #xbf #x24 #xab #xff)) +(check-equal? (decode uint32le (+DecodeStream (bytes #xbf #x24 #xab #xff))) #xffab24bf) +(check-equal? (size uint32le) 4) +(check-equal? (encode uint32le #f #xffab24bf) (bytes #xbf #x24 #xab #xff)) ; @@ -222,15 +222,15 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; stream.end() (let ([stream (+DecodeStream (bytes #x7f #xff))]) - (check-equal? (send int8 decode stream) 127) - (check-equal? (send int8 decode stream) -1)) + (check-equal? (decode int8 stream) 127) + (check-equal? (decode int8 stream) -1)) -(check-equal? (send int8 size) 1) +(check-equal? (size int8) 1) (let ([stream (+EncodeStream)]) - (send int8 encode stream 127) - (send int8 encode stream -1) - (check-equal? (send stream dump) (bytes #x7f #xff))) + (encode int8 stream 127) + (encode int8 stream -1) + (check-equal? (dump stream) (bytes #x7f #xff))) ; @@ -239,7 +239,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; int16.should.equal int16be ;; modified test: `int16` is the same endianness as the platform -(check-equal? (send int16 decode (bytes 0 1)) (send (if (system-big-endian?) +(check-equal? (decode int16 (bytes 0 1)) (send (if (system-big-endian?) int16be int16le) decode (bytes 0 1))) @@ -263,13 +263,13 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; stream.end() (let ([stream (+DecodeStream (bytes #xff #xab))]) - (check-equal? (send int16be decode stream) -85)) + (check-equal? (decode int16be stream) -85)) -(check-equal? (send int16be size) 2) +(check-equal? (size int16be) 2) (let ([stream (+EncodeStream)]) - (send int16be encode stream -85) - (check-equal? (send stream dump) (bytes #xff #xab))) + (encode int16be stream -85) + (check-equal? (dump stream) (bytes #xff #xab))) ; ; describe 'int16le', -> @@ -290,9 +290,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; stream.end() -(check-equal? (send int16le decode (+DecodeStream (bytes #xab #xff))) -85) -(check-equal? (send int16le size) 2) -(check-equal? (send int16le encode #f -85) (bytes #xab #xff)) +(check-equal? (decode int16le (+DecodeStream (bytes #xab #xff))) -85) +(check-equal? (size int16le) 2) +(check-equal? (encode int16le #f -85) (bytes #xab #xff)) ; @@ -301,7 +301,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; int24.should.equal int24be ;; modified test: `int24` is the same endianness as the platform -(check-equal? (send int24 decode (bytes 0 1 2)) (send (if (system-big-endian?) +(check-equal? (decode int24 (bytes 0 1 2)) (send (if (system-big-endian?) int24be int24le) decode (bytes 0 1 2))) @@ -324,9 +324,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; int24be.encode(stream, -21724) ; stream.end() -(check-equal? (send int24be decode (+DecodeStream (bytes #xff #xab #x24))) -21724) -(check-equal? (send int24be size) 3) -(check-equal? (send int24be encode #f -21724) (bytes #xff #xab #x24)) +(check-equal? (decode int24be (+DecodeStream (bytes #xff #xab #x24))) -21724) +(check-equal? (size int24be) 3) +(check-equal? (encode int24be #f -21724) (bytes #xff #xab #x24)) ; ; describe 'int24le', -> @@ -347,9 +347,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; stream.end() ; -(check-equal? (send int24le decode (+DecodeStream (bytes #x24 #xab #xff))) -21724) -(check-equal? (send int24le size) 3) -(check-equal? (send int24le encode #f -21724) (bytes #x24 #xab #xff)) +(check-equal? (decode int24le (+DecodeStream (bytes #x24 #xab #xff))) -21724) +(check-equal? (size int24le) 3) +(check-equal? (encode int24le #f -21724) (bytes #x24 #xab #xff)) @@ -358,7 +358,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; int32.should.equal int32be ;; modified test: `int32` is the same endianness as the platform -(check-equal? (send int32 decode (bytes 0 1 2 3)) (send (if (system-big-endian?) +(check-equal? (decode int32 (bytes 0 1 2 3)) (send (if (system-big-endian?) int32be int32le) decode (bytes 0 1 2 3))) @@ -382,9 +382,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; int32be.encode(stream, -5561153) ; stream.end() -(check-equal? (send int32be decode (+DecodeStream (bytes #xff #xab #x24 #xbf))) -5561153) -(check-equal? (send int32be size) 4) -(check-equal? (send int32be encode #f -5561153) (bytes #xff #xab #x24 #xbf)) +(check-equal? (decode int32be (+DecodeStream (bytes #xff #xab #x24 #xbf))) -5561153) +(check-equal? (size int32be) 4) +(check-equal? (encode int32be #f -5561153) (bytes #xff #xab #x24 #xbf)) ; ; describe 'int32le', -> @@ -404,9 +404,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; int32le.encode(stream, -5561153) ; stream.end() -(check-equal? (send int32le decode (+DecodeStream (bytes #xbf #x24 #xab #xff))) -5561153) -(check-equal? (send int32le size) 4) -(check-equal? (send int32le encode #f -5561153) (bytes #xbf #x24 #xab #xff)) +(check-equal? (decode int32le (+DecodeStream (bytes #xbf #x24 #xab #xff))) -5561153) +(check-equal? (size int32le) 4) +(check-equal? (encode int32le #f -5561153) (bytes #xbf #x24 #xab #xff)) ; ; describe 'float', -> @@ -414,7 +414,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; float.should.equal floatbe ;; modified test: `float` is the same endianness as the platform -(check-equal? (send float decode (bytes 0 1 2 3)) (send (if (system-big-endian?) +(check-equal? (decode float (bytes 0 1 2 3)) (send (if (system-big-endian?) floatbe floatle) decode (bytes 0 1 2 3))) @@ -436,9 +436,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; floatbe.encode(stream, 250.55) ; stream.end() -(check-= (send floatbe decode (+DecodeStream (bytes #x43 #x7a #x8c #xcd))) 250.55 0.01) -(check-equal? (send floatbe size) 4) -(check-equal? (send floatbe encode #f 250.55) (bytes #x43 #x7a #x8c #xcd)) +(check-= (decode floatbe (+DecodeStream (bytes #x43 #x7a #x8c #xcd))) 250.55 0.01) +(check-equal? (size floatbe) 4) +(check-equal? (encode floatbe #f 250.55) (bytes #x43 #x7a #x8c #xcd)) ; ; describe 'floatle', -> @@ -459,9 +459,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; stream.end() -(check-= (send floatle decode (+DecodeStream (bytes #xcd #x8c #x7a #x43))) 250.55 0.01) -(check-equal? (send floatle size) 4) -(check-equal? (send floatle encode #f 250.55) (bytes #xcd #x8c #x7a #x43)) +(check-= (decode floatle (+DecodeStream (bytes #xcd #x8c #x7a #x43))) 250.55 0.01) +(check-equal? (size floatle) 4) +(check-equal? (encode floatle #f 250.55) (bytes #xcd #x8c #x7a #x43)) ; ; describe 'double', -> @@ -469,7 +469,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; double.should.equal doublebe ;; modified test: `double` is the same endianness as the platform -(check-equal? (send double decode (bytes 0 1 2 3 4 5 6 7)) (send (if (system-big-endian?) +(check-equal? (decode double (bytes 0 1 2 3 4 5 6 7)) (send (if (system-big-endian?) doublebe doublele) decode (bytes 0 1 2 3 4 5 6 7))) @@ -491,9 +491,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; doublebe.encode(stream, 1234.56) ; stream.end() -(check-equal? (send doublebe decode (+DecodeStream (bytes #x40 #x93 #x4a #x3d #x70 #xa3 #xd7 #x0a))) 1234.56) -(check-equal? (send doublebe size) 8) -(check-equal? (send doublebe encode #f 1234.56) (bytes #x40 #x93 #x4a #x3d #x70 #xa3 #xd7 #x0a)) +(check-equal? (decode doublebe (+DecodeStream (bytes #x40 #x93 #x4a #x3d #x70 #xa3 #xd7 #x0a))) 1234.56) +(check-equal? (size doublebe) 8) +(check-equal? (encode doublebe #f 1234.56) (bytes #x40 #x93 #x4a #x3d #x70 #xa3 #xd7 #x0a)) ; ; describe 'doublele', -> @@ -513,9 +513,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; doublele.encode(stream, 1234.56) ; stream.end() -(check-equal? (send doublele decode (+DecodeStream (bytes #x0a #xd7 #xa3 #x70 #x3d #x4a #x93 #x40))) 1234.56) -(check-equal? (send doublele size) 8) -(check-equal? (send doublele encode #f 1234.56) (bytes #x0a #xd7 #xa3 #x70 #x3d #x4a #x93 #x40)) +(check-equal? (decode doublele (+DecodeStream (bytes #x0a #xd7 #xa3 #x70 #x3d #x4a #x93 #x40))) 1234.56) +(check-equal? (size doublele) 8) +(check-equal? (encode doublele #f 1234.56) (bytes #x0a #xd7 #xa3 #x70 #x3d #x4a #x93 #x40)) ; ; describe 'fixed16', -> @@ -523,7 +523,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; fixed16.should.equal fixed16be ;; modified test: `fixed16` is the same endianness as the platform -(check-equal? (send fixed16 decode (bytes 0 1)) (send (if (system-big-endian?) +(check-equal? (decode fixed16 (bytes 0 1)) (send (if (system-big-endian?) fixed16be fixed16le) decode (bytes 0 1))) @@ -545,9 +545,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; fixed16be.encode(stream, 25.34) ; stream.end() -(check-= (send fixed16be decode (+DecodeStream (bytes #x19 #x57))) 25.34 0.01) -(check-equal? (send fixed16be size) 2) -(check-equal? (send fixed16be encode #f 25.34) (bytes #x19 #x57)) +(check-= (decode fixed16be (+DecodeStream (bytes #x19 #x57))) 25.34 0.01) +(check-equal? (size fixed16be) 2) +(check-equal? (encode fixed16be #f 25.34) (bytes #x19 #x57)) ; ; describe 'fixed16le', -> @@ -567,9 +567,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; fixed16le.encode(stream, 25.34) ; stream.end() -(check-= (send fixed16le decode (+DecodeStream (bytes #x57 #x19))) 25.34 0.01) -(check-equal? (send fixed16le size) 2) -(check-equal? (send fixed16le encode #f 25.34) (bytes #x57 #x19)) +(check-= (decode fixed16le (+DecodeStream (bytes #x57 #x19))) 25.34 0.01) +(check-equal? (size fixed16le) 2) +(check-equal? (encode fixed16le #f 25.34) (bytes #x57 #x19)) ; ; describe 'fixed32', -> @@ -577,7 +577,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; fixed32.should.equal fixed32be ;; modified test: `fixed32` is the same endianness as the platform -(check-equal? (send fixed32 decode (bytes 0 1 2 3)) (send (if (system-big-endian?) +(check-equal? (decode fixed32 (bytes 0 1 2 3)) (send (if (system-big-endian?) fixed32be fixed32le) decode (bytes 0 1 2 3))) @@ -599,9 +599,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; fixed32be.encode(stream, 250.55) ; stream.end() -(check-= (send fixed32be decode (+DecodeStream (bytes #x00 #xfa #x8c #xcc))) 250.55 0.01) -(check-equal? (send fixed32be size) 4) -(check-equal? (send fixed32be encode #f 250.55) (bytes #x00 #xfa #x8c #xcc)) +(check-= (decode fixed32be (+DecodeStream (bytes #x00 #xfa #x8c #xcc))) 250.55 0.01) +(check-equal? (size fixed32be) 4) +(check-equal? (encode fixed32be #f 250.55) (bytes #x00 #xfa #x8c #xcc)) ; ; describe 'fixed32le', -> @@ -621,6 +621,6 @@ https://github.com/mbutterick/restructure/blob/master/test/Number.coffee ; fixed32le.encode(stream, 250.55) ; stream.end() -(check-= (send fixed32le decode (+DecodeStream (bytes #xcc #x8c #xfa #x00))) 250.55 0.01) -(check-equal? (send fixed32le size) 4) -(check-equal? (send fixed32le encode #f 250.55) (bytes #xcc #x8c #xfa #x00)) \ No newline at end of file +(check-= (decode fixed32le (+DecodeStream (bytes #xcc #x8c #xfa #x00))) 250.55 0.01) +(check-equal? (size fixed32le) 4) +(check-equal? (encode fixed32le #f 250.55) (bytes #xcc #x8c #xfa #x00)) \ No newline at end of file diff --git a/pitfall/restructure/test/optional-test.rkt b/pitfall/restructure/test/optional-test.rkt index d0138690..34e29f93 100644 --- a/pitfall/restructure/test/optional-test.rkt +++ b/pitfall/restructure/test/optional-test.rkt @@ -15,7 +15,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Optional.coffee (let ([stream (+DecodeStream (+Buffer '(0)))] [optional (+Optional uint8 #f)]) - (check-equal? (send optional decode stream) (void)) + (check-equal? (decode optional stream) (void)) (check-equal? (· stream pos) 0)) @@ -27,7 +27,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Optional.coffee (let ([stream (+DecodeStream (+Buffer '(0)))] [optional (+Optional uint8 (λ _ #f))]) - (check-equal? (send optional decode stream) (void)) + (check-equal? (decode optional stream) (void)) (check-equal? (· stream pos) 0)) ; @@ -39,7 +39,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Optional.coffee (let ([stream (+DecodeStream (+Buffer '(0)))] [optional (+Optional uint8)]) - (check-not-equal? (send optional decode stream) (void)) + (check-not-equal? (decode optional stream) (void)) (check-equal? (· stream pos) 1)) ; @@ -51,7 +51,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Optional.coffee (let ([stream (+DecodeStream (+Buffer '(0)))] [optional (+Optional uint8 #t)]) - (check-not-equal? (send optional decode stream) (void)) + (check-not-equal? (decode optional stream) (void)) (check-equal? (· stream pos) 1)) ; @@ -64,7 +64,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Optional.coffee (let ([stream (+DecodeStream (+Buffer '(0)))] [optional (+Optional uint8 (λ _ #t))]) - (check-not-equal? (send optional decode stream) (void)) + (check-not-equal? (decode optional stream) (void)) (check-equal? (· stream pos) 1)) ; @@ -131,8 +131,8 @@ https://github.com/mbutterick/restructure/blob/master/test/Optional.coffee (let ([stream (+EncodeStream)] [optional (+Optional uint8 #f)]) - (send optional encode stream 128) - (check-equal? (send stream dump) (+Buffer empty))) + (encode optional stream 128) + (check-equal? (dump stream) (+Buffer empty))) ; ; it 'should not encode when condition is a function and falsy', (done) -> @@ -147,8 +147,8 @@ https://github.com/mbutterick/restructure/blob/master/test/Optional.coffee (let ([stream (+EncodeStream)] [optional (+Optional uint8 (λ _ #f))]) - (send optional encode stream 128) - (check-equal? (send stream dump) (+Buffer empty))) + (encode optional stream 128) + (check-equal? (dump stream) (+Buffer empty))) ; @@ -164,8 +164,8 @@ https://github.com/mbutterick/restructure/blob/master/test/Optional.coffee (let ([stream (+EncodeStream)] [optional (+Optional uint8)]) - (send optional encode stream 128) - (check-equal? (send stream dump) (+Buffer '(128)))) + (encode optional stream 128) + (check-equal? (dump stream) (+Buffer '(128)))) ; ; it 'should encode when condition is truthy', (done) -> @@ -180,8 +180,8 @@ https://github.com/mbutterick/restructure/blob/master/test/Optional.coffee (let ([stream (+EncodeStream)] [optional (+Optional uint8 #t)]) - (send optional encode stream 128) - (check-equal? (send stream dump) (+Buffer '(128)))) + (encode optional stream 128) + (check-equal? (dump stream) (+Buffer '(128)))) ; ; it 'should encode when condition is a function and truthy', (done) -> @@ -196,5 +196,5 @@ https://github.com/mbutterick/restructure/blob/master/test/Optional.coffee (let ([stream (+EncodeStream)] [optional (+Optional uint8 (λ _ #t))]) - (send optional encode stream 128) - (check-equal? (send stream dump) (+Buffer '(128)))) \ No newline at end of file + (encode optional stream 128) + (check-equal? (dump stream) (+Buffer '(128)))) \ No newline at end of file diff --git a/pitfall/restructure/test/pointer-test.rkt b/pitfall/restructure/test/pointer-test.rkt index b2689268..383d37a6 100644 --- a/pitfall/restructure/test/pointer-test.rkt +++ b/pitfall/restructure/test/pointer-test.rkt @@ -16,7 +16,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee (let ([stream (+DecodeStream (+Buffer '(0)))] [pointer (+Pointer uint8 uint8)]) - (check-false (send pointer decode stream (mhash '_startOffset 50)))) + (check-false (decode pointer stream (mhash '_startOffset 50)))) ; ; it 'should use local offsets from start of parent by default', -> @@ -27,7 +27,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee (let ([stream (+DecodeStream (+Buffer '(1 53)))] [pointer (+Pointer uint8 uint8)]) - (check-equal? (send pointer decode stream (mhash '_startOffset 0)) 53)) + (check-equal? (decode pointer stream (mhash '_startOffset 0)) 53)) ; @@ -39,7 +39,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee (let ([stream (+DecodeStream (+Buffer '(1 53)))] [pointer (+Pointer uint8 uint8 (mhash 'type 'immediate))]) - (check-equal? (send pointer decode stream) 53)) + (check-equal? (decode pointer stream) 53)) ; ; it 'should support offsets relative to the parent', -> @@ -51,8 +51,8 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee (let ([stream (+DecodeStream (+Buffer '(0 0 1 53)))] [pointer (+Pointer uint8 uint8 (mhash 'type 'parent))]) - (send stream pos 2) - (check-equal? (send pointer decode stream (mhash 'parent (mhash '_startOffset 2))) 53)) + (pos stream 2) + (check-equal? (decode pointer stream (mhash 'parent (mhash '_startOffset 2))) 53)) ; @@ -65,8 +65,8 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee (let ([stream (+DecodeStream (+Buffer '(1 2 4 0 0 0 53)))] [pointer (+Pointer uint8 uint8 (mhash 'type 'global))]) - (send stream pos 2) - (check-equal? (send pointer decode stream (mhash 'parent (mhash 'parent (mhash '_startOffset 2)))) 53)) + (pos stream 2) + (check-equal? (decode pointer stream (mhash 'parent (mhash 'parent (mhash '_startOffset 2)))) 53)) ; it 'should support offsets relative to a property on the parent', -> @@ -76,7 +76,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee (let ([stream (+DecodeStream (+Buffer '(1 0 0 0 0 53)))] [pointer (+Pointer uint8 uint8 (mhash 'relativeTo (λ (ctx) (· ctx parent ptr))))]) - (check-equal? (send pointer decode stream (mhash '_startOffset 0 'parent (mhash 'ptr 4))) 53)) + (check-equal? (decode pointer stream (mhash '_startOffset 0 'parent (mhash 'ptr 4))) 53)) ; @@ -87,7 +87,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee (let ([stream (+DecodeStream (+Buffer '(4)))] [pointer (+Pointer uint8 'void)]) - (check-equal? (send pointer decode stream (mhash '_startOffset 0)) 4)) + (check-equal? (decode pointer stream (mhash '_startOffset 0)) 4)) @@ -103,7 +103,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee (let ([stream (+DecodeStream (+Buffer '(1 53)))] [struct (+Struct (dictify 'ptr (+Pointer uint8 uint8 (mhasheq 'lazy #t))))]) - (define res (send struct decode stream)) + (define res (decode struct stream)) (check-true (LazyThunk? (hash-ref (get-field kv res) 'ptr))) (check-equal? (· res ptr) 53)) @@ -118,7 +118,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee (let ([pointer (+Pointer uint8 uint8)] [ctx (mhash 'pointerSize 0)]) - (check-equal? (send pointer size 10 ctx) 1) + (check-equal? (size pointer 10 ctx) 1) (check-equal? (· ctx pointerSize) 1)) @@ -131,7 +131,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee (let ([pointer (+Pointer uint8 uint8 (mhash 'type 'immediate))] [ctx (mhash 'pointerSize 0)]) - (check-equal? (send pointer size 10 ctx) 1) + (check-equal? (size pointer 10 ctx) 1) (check-equal? (· ctx pointerSize) 1)) ; @@ -143,7 +143,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee (let ([pointer (+Pointer uint8 uint8 (mhash 'type 'parent))] [ctx (mhash 'parent (mhash 'pointerSize 0))]) - (check-equal? (send pointer size 10 ctx) 1) + (check-equal? (size pointer 10 ctx) 1) (check-equal? (· ctx parent pointerSize) 1)) ; @@ -155,7 +155,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee (let ([pointer (+Pointer uint8 uint8 (mhash 'type 'global))] [ctx (mhash 'parent (mhash 'parent (mhash 'parent (mhash 'pointerSize 0))))]) - (check-equal? (send pointer size 10 ctx) 1) + (check-equal? (size pointer 10 ctx) 1) (check-equal? (· ctx parent parent parent pointerSize) 1)) @@ -167,7 +167,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee (let ([pointer (+Pointer uint8 'void)] [ctx (mhash 'pointerSize 0)]) - (check-equal? (send pointer size (+VoidPointer uint8 50) ctx) 1) + (check-equal? (size pointer (+VoidPointer uint8 50) ctx) 1) (check-equal? (· ctx pointerSize) 1)) @@ -181,7 +181,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee (let ([pointer (+Pointer uint8 'void)] [ctx (mhash 'pointerSize 0)]) - (check-exn exn:fail:contract? (λ () (send pointer size 30 ctx)))) + (check-exn exn:fail:contract? (λ () (size pointer 30 ctx)))) ; it 'should return a fixed size without a value', -> @@ -189,7 +189,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee ; pointer.size().should.equal 1 (let ([pointer (+Pointer uint8 uint8)]) - (check-equal? (send pointer size) 1)) + (check-equal? (size pointer) 1)) ; ; describe 'encode', -> @@ -218,9 +218,9 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee 'startOffset 0 'pointerOffset 0 'pointers null)]) - (send ptr encode stream #f ctx) + (encode ptr stream #f ctx) (check-equal? (· ctx pointerSize) 0) - (check-equal? (send stream dump) (+Buffer '(0)))) + (check-equal? (dump stream) (+Buffer '(0)))) ; ; it 'should handle local offsets', (done) -> @@ -251,12 +251,12 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee 'startOffset 0 'pointerOffset 1 'pointers null)]) - (send ptr encode stream 10 ctx) + (encode ptr stream 10 ctx) (check-equal? (· ctx pointerOffset) 2) (check-equal? (· ctx pointers) (list (mhasheq 'type uint8 'val 10 'parent ctx))) - (check-equal? (send stream dump) (+Buffer '(1)))) + (check-equal? (dump stream) (+Buffer '(1)))) ; @@ -287,12 +287,12 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee 'startOffset 0 'pointerOffset 1 'pointers null)]) - (send ptr encode stream 10 ctx) + (encode ptr stream 10 ctx) (check-equal? (· ctx pointerOffset) 2) (check-equal? (· ctx pointers) (list (mhasheq 'type uint8 'val 10 'parent ctx))) - (check-equal? (send stream dump) (+Buffer '(0)))) + (check-equal? (dump stream) (+Buffer '(0)))) ; @@ -324,12 +324,12 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee 'startOffset 3 'pointerOffset 5 'pointers null))]) - (send ptr encode stream 10 ctx) + (encode ptr stream 10 ctx) (check-equal? (· ctx parent pointerOffset) 6) (check-equal? (· ctx parent pointers) (list (mhasheq 'type uint8 'val 10 'parent ctx))) - (check-equal? (send stream dump) (+Buffer '(2)))) + (check-equal? (dump stream) (+Buffer '(2)))) ; @@ -366,12 +366,12 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee 'startOffset 3 'pointerOffset 5 'pointers null))))]) - (send ptr encode stream 10 ctx) + (encode ptr stream 10 ctx) (check-equal? (· ctx parent parent parent pointerOffset) 6) (check-equal? (· ctx parent parent parent pointers) (list (mhasheq 'type uint8 'val 10 'parent ctx))) - (check-equal? (send stream dump) (+Buffer '(5)))) + (check-equal? (dump stream) (+Buffer '(5)))) ; @@ -406,12 +406,12 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee 'pointerOffset 10 'pointers null 'val (mhash 'ptr 4))]) - (send ptr encode stream 10 ctx) + (encode ptr stream 10 ctx) (check-equal? (· ctx pointerOffset) 11) (check-equal? (· ctx pointers) (list (mhasheq 'type uint8 'val 10 'parent ctx))) - (check-equal? (send stream dump) (+Buffer '(6)))) + (check-equal? (dump stream) (+Buffer '(6)))) ; ; it 'should support void pointers', (done) -> @@ -441,12 +441,12 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee 'startOffset 0 'pointerOffset 1 'pointers null)]) - (send ptr encode stream (+VoidPointer uint8 55) ctx) + (encode ptr stream (+VoidPointer uint8 55) ctx) (check-equal? (· ctx pointerOffset) 2) (check-equal? (· ctx pointers) (list (mhasheq 'type uint8 'val 55 'parent ctx))) - (check-equal? (send stream dump) (+Buffer '(1)))) + (check-equal? (dump stream) (+Buffer '(1)))) @@ -470,4 +470,4 @@ https://github.com/mbutterick/restructure/blob/master/test/Pointer.coffee 'startOffset 0 'pointerOffset 1 'pointers null)]) - (check-exn exn:fail:contract? (λ () (send ptr encode stream 44 ctx)))) \ No newline at end of file + (check-exn exn:fail:contract? (λ () (encode ptr stream 44 ctx)))) \ No newline at end of file diff --git a/pitfall/restructure/test/reserved-test.rkt b/pitfall/restructure/test/reserved-test.rkt index 37d0028e..f98d050e 100644 --- a/pitfall/restructure/test/reserved-test.rkt +++ b/pitfall/restructure/test/reserved-test.rkt @@ -11,7 +11,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Reserved.coffee ; reserved.size().should.equal 1 (let ([reserved (+Reserved uint8)]) - (check-equal? (send reserved size) 1)) + (check-equal? (size reserved) 1)) ; ; it 'should allow custom counts and types', -> @@ -19,7 +19,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Reserved.coffee ; reserved.size().should.equal 20 (let ([reserved (+Reserved uint16be 10)]) - (check-equal? (send reserved size) 20)) + (check-equal? (size reserved) 20)) ; ; it 'should decode', -> @@ -30,8 +30,8 @@ https://github.com/mbutterick/restructure/blob/master/test/Reserved.coffee (let ([stream (+DecodeStream (+Buffer '(0 0)))] [reserved (+Reserved uint16be)]) - (check-equal? (send reserved decode stream) (void)) - (check-equal? (send stream pos) 2)) + (check-equal? (decode reserved stream) (void)) + (check-equal? (pos stream) 2)) ; ; it 'should encode', (done) -> @@ -46,5 +46,5 @@ https://github.com/mbutterick/restructure/blob/master/test/Reserved.coffee (let ([stream (+EncodeStream)] [reserved (+Reserved uint16be)]) - (send reserved encode stream) - (check-equal? (send stream dump) (+Buffer '(0 0)))) \ No newline at end of file + (encode reserved stream) + (check-equal? (dump stream) (+Buffer '(0 0)))) \ No newline at end of file diff --git a/pitfall/restructure/test/string-test.rkt b/pitfall/restructure/test/string-test.rkt index a12efc0f..4ee5b0f5 100644 --- a/pitfall/restructure/test/string-test.rkt +++ b/pitfall/restructure/test/string-test.rkt @@ -15,7 +15,7 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee (let ([stream (+DecodeStream (+Buffer "testing"))] [string (+StringT 7)]) - (check-equal? (send string decode stream) "testing")) + (check-equal? (decode string stream) "testing")) ; ; it 'should decode length from parent key', -> @@ -25,7 +25,7 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee (let ([stream (+DecodeStream (+Buffer "testing"))] [string (+StringT 'len)]) - (check-equal? (send string decode stream (mhash 'len 7)) "testing")) + (check-equal? (decode string stream (mhash 'len 7)) "testing")) ; @@ -35,9 +35,9 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee ; string.decode(stream).should.equal 'testing' ; octal \7 will print as \a -(let ([stream (+DecodeStream (+Buffer "\7testing"))] +(let ([stream (+DecodeStream (+Buffer "\x07testing"))] [string (+StringT uint8)]) - (check-equal? (send string decode stream (mhash 'len 7)) "testing")) + (check-equal? (decode string stream (mhash 'len 7)) "testing")) ; ; it 'should decode utf8', -> @@ -47,7 +47,7 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee (let ([stream (+DecodeStream (+Buffer "🍻"))] [string (+StringT 4 'utf8)]) - (check-equal? (send string decode stream) "🍻")) + (check-equal? (decode string stream) "🍻")) ; ; it 'should decode encoding computed from function', -> ; stream = new DecodeStream new Buffer '🍻' @@ -56,7 +56,7 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee (let ([stream (+DecodeStream (+Buffer "🍻"))] [string (+StringT 4 (λ _ 'utf8))]) - (check-equal? (send string decode stream) "🍻")) + (check-equal? (decode string stream) "🍻")) ; ; it 'should decode null-terminated string and read past terminator', -> @@ -65,10 +65,10 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee ; string.decode(stream).should.equal '🍻' ; stream.pos.should.equal 5 -(let ([stream (+DecodeStream (+Buffer "🍻\0"))] +(let ([stream (+DecodeStream (+Buffer "🍻\x00"))] [string (+StringT #f 'utf8)]) - (check-equal? (send string decode stream) "🍻") - (check-equal? (send stream pos) 5)) + (check-equal? (decode string stream) "🍻") + (check-equal? (pos stream) 5)) ; ; it 'should decode remainder of buffer when null-byte missing', -> @@ -78,7 +78,7 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee (let ([stream (+DecodeStream (+Buffer "🍻"))] [string (+StringT #f 'utf8)]) - (check-equal? (send string decode stream) "🍻")) + (check-equal? (decode string stream) "🍻")) ; ; describe 'size', -> @@ -87,7 +87,7 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee ; string.size('testing').should.equal 7 (let ([string (+StringT 7)]) - (check-equal? (send string size "testing") 7)) + (check-equal? (size string "testing") 7)) ; ; it 'should use correct encoding', -> @@ -95,7 +95,7 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee ; string.size('🍻').should.equal 4 (let ([string (+StringT 10 'utf8)]) - (check-equal? (send string size "🍻") 4)) + (check-equal? (size string "🍻") 4)) ; ; it 'should use encoding from function', -> @@ -103,7 +103,7 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee ; string.size('🍻').should.equal 4 (let ([string (+StringT 10 (λ _ 'utf8))]) - (check-equal? (send string size "🍻") 4)) + (check-equal? (size string "🍻") 4)) ; ; it 'should add size of length field before string', -> @@ -111,7 +111,7 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee ; string.size('🍻').should.equal 5 (let ([string (+StringT uint8 'utf8)]) - (check-equal? (send string size "🍻") 5)) + (check-equal? (size string "🍻") 5)) ; todo ; it 'should work with utf16be encoding', -> @@ -125,7 +125,7 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee ; string.size('🍻').should.equal 5 (let ([string (+StringT #f 'utf8)]) - (check-equal? (send string size "🍻") 5)) + (check-equal? (size string "🍻") 5)) ; ; it 'should use defined length if no value given', -> @@ -133,7 +133,7 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee ; array.size().should.equal 10 (let ([string (+StringT 10)]) - (check-equal? (send string size) 10)) + (check-equal? (size string) 10)) ; ; describe 'encode', -> @@ -149,8 +149,8 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee (let ([string (+StringT 7)] [stream (+EncodeStream)]) - (send string encode stream "testing") - (check-equal? (send stream dump) #"testing")) + (encode string stream "testing") + (check-equal? (dump stream) #"testing")) ; @@ -166,8 +166,8 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee (let ([string (+StringT uint8)] [stream (+EncodeStream)]) - (send string encode stream "testing") - (check-equal? (send stream dump) #"\7testing")) + (encode string stream "testing") + (check-equal? (dump stream) #"\x07testing")) ; ; it 'should encode length as number before string utf8', (done) -> @@ -182,8 +182,8 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee (let ([string (+StringT uint8 'utf8)] [stream (+EncodeStream)]) - (send string encode stream "testing 😜") - (check-equal? (send stream dump) (+Buffer "\14testing 😜" 'utf8))) + (encode string stream "testing 😜") + (check-equal? (dump stream) (+Buffer "\x0ctesting 😜" 'utf8))) ; ; it 'should encode utf8', (done) -> @@ -198,8 +198,8 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee (let ([string (+StringT 4 'utf8)] [stream (+EncodeStream)]) - (send string encode stream "🍻") - (check-equal? (send stream dump) (+Buffer "🍻"))) + (encode string stream "🍻") + (check-equal? (dump stream) (+Buffer "🍻"))) ; ; it 'should encode encoding computed from function', (done) -> @@ -214,8 +214,8 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee (let ([string (+StringT 4 (λ _ 'utf8))] [stream (+EncodeStream)]) - (send string encode stream "🍻") - (check-equal? (send stream dump) (+Buffer "🍻"))) + (encode string stream "🍻") + (check-equal? (dump stream) (+Buffer "🍻"))) ; ; it 'should encode null-terminated string', (done) -> @@ -231,5 +231,5 @@ https://github.com/mbutterick/restructure/blob/master/test/String.coffee (let ([string (+StringT #f 'utf8)] [stream (+EncodeStream)]) - (send string encode stream "🍻") - (check-equal? (send stream dump) (+Buffer "🍻\0"))) \ No newline at end of file + (encode string stream "🍻") + (check-equal? (dump stream) (+Buffer "🍻\x00"))) \ No newline at end of file diff --git a/pitfall/restructure/test/struct-test.rkt b/pitfall/restructure/test/struct-test.rkt index f4d0eef5..ae7e58bd 100644 --- a/pitfall/restructure/test/struct-test.rkt +++ b/pitfall/restructure/test/struct-test.rkt @@ -21,7 +21,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee (let ([stream (+DecodeStream (+Buffer "\x05devon\x15"))] [struct (+Struct (dictify 'name (+StringT uint8) 'age uint8))]) - (check-equal? (send (send struct decode stream) kv) + (check-equal? (dump (decode struct stream)) (mhasheq 'name "devon" 'age 21))) @@ -44,7 +44,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee [struct (+Struct (dictify 'name (+StringT uint8) 'age uint8))]) (set-field! process struct (λ (o stream _) (ref-set! o 'canDrink (>= (· o age) 21)) o)) - (check-equal? (send (send struct decode stream) kv) + (check-equal? (dump (decode struct stream)) (mhasheq 'name "devon" 'age 32 'canDrink #t))) @@ -65,7 +65,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee [struct (+Struct (dictify 'name (+StringT uint8) 'age uint8 'canDrink (λ (o) (>= (ref o 'age) 21))))]) - (check-equal? (send (send struct decode stream) kv) + (check-equal? (dump (decode struct stream)) (mhasheq 'name "devon" 'age 32 'canDrink #t))) @@ -80,7 +80,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee (let ([struct (+Struct (dictify 'name (+StringT uint8) 'age uint8))]) - (check-equal? (send struct size (hasheq 'name "devon" 'age 32)) 7)) + (check-equal? (size struct (hasheq 'name "devon" 'age 32)) 7)) ; it 'should compute the correct size with pointers', -> @@ -99,7 +99,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee (let ([struct (+Struct (dictify 'name (+StringT uint8) 'age uint8 'ptr (+Pointer uint8 (+StringT uint8))))]) - (check-equal? (send struct size (mhash 'name "devon" 'age 21 'ptr "hello")) 14)) + (check-equal? (size struct (mhash 'name "devon" 'age 21 'ptr "hello")) 14)) ; @@ -113,7 +113,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee (let ([struct (+Struct (dictify 'name (+StringT 4) 'age uint8))]) - (check-equal? (send struct size) 5)) + (check-equal? (size struct) 5)) ; @@ -128,7 +128,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee (let ([struct (+Struct (dictify 'name (+StringT uint8) 'age uint8))]) - (check-exn exn:fail:contract? (λ () (send struct size)))) + (check-exn exn:fail:contract? (λ () (size struct)))) ; ; describe 'encode', -> @@ -151,7 +151,7 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee (let ([stream (+DecodeStream (+Buffer "\x05devon\x15"))] [struct (+Struct (dictify 'name (+StringT uint8) 'age uint8))]) - (check-equal? (send (send struct decode stream) kv) + (check-equal? (dump (decode struct stream)) (mhasheq 'name "devon" 'age 21))) ; @@ -180,8 +180,8 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee 'name (+StringT 'nameLength) 'age uint8))]) (set-field! preEncode struct (λ (val stream) (ref-set! val 'nameLength (length (ref val 'name))))) - (send struct encode stream (mhasheq 'name "devon" 'age 21)) - (check-equal? (send stream dump) + (encode struct stream (mhasheq 'name "devon" 'age 21)) + (check-equal? (dump stream) (+Buffer "\x05devon\x15"))) @@ -209,5 +209,5 @@ https://github.com/mbutterick/restructure/blob/master/test/Struct.coffee [struct (+Struct (dictify 'name (+StringT uint8) 'age uint8 'ptr (+Pointer uint8 (+StringT uint8))))]) - (send struct encode stream (mhasheq 'name "devon" 'age 21 'ptr "hello")) - (check-equal? (send stream dump) (+Buffer "\x05devon\x15\x08\x05hello"))) \ No newline at end of file + (encode struct stream (mhasheq 'name "devon" 'age 21 'ptr "hello")) + (check-equal? (dump stream) (+Buffer "\x05devon\x15\x08\x05hello"))) \ No newline at end of file diff --git a/pitfall/restructure/test/versioned-struct-test.rkt b/pitfall/restructure/test/versioned-struct-test.rkt index 41792390..c82adabc 100644 --- a/pitfall/restructure/test/versioned-struct-test.rkt +++ b/pitfall/restructure/test/versioned-struct-test.rkt @@ -39,12 +39,12 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'gender uint8)))]) (let ([stream (+DecodeStream (+Buffer "\x00\x05devon\x15"))]) - (check-equal? (send (send struct decode stream) kv) (mhasheq 'name "devon" + (check-equal? (dump (decode struct stream)) (mhasheq 'name "devon" 'age 21 'version 0))) (let ([stream (+DecodeStream (+Buffer "\x01\x0adevon 👍\x15\x00"))]) - (check-equal? (send (send struct decode stream) kv) (mhasheq 'name "devon 👍" + (check-equal? (dump (decode struct stream)) (mhasheq 'name "devon 👍" 'age 21 'version 1 'gender 0)))) @@ -76,7 +76,7 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'gender uint8)))]) (let ([stream (+DecodeStream (+Buffer "\x05\x05devon\x15"))]) - (check-exn exn:fail:contract? (λ () (send struct decode stream))))) + (check-exn exn:fail:contract? (λ () (decode struct stream))))) ; ; it 'should support common header block', -> @@ -115,13 +115,13 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'gender uint8)))]) (let ([stream (+DecodeStream (+Buffer "\x00\x15\x01\x05devon"))]) - (check-equal? (send (send struct decode stream) kv) (mhasheq 'name "devon" + (check-equal? (dump (decode struct stream)) (mhasheq 'name "devon" 'age 21 'alive 1 'version 0))) (let ([stream (+DecodeStream (+Buffer "\x01\x15\x01\x0adevon 👍\x00"))]) - (check-equal? (send (send struct decode stream) kv) (mhasheq 'name "devon 👍" + (check-equal? (dump (decode struct stream)) (mhasheq 'name "devon 👍" 'age 21 'version 1 'alive 1 @@ -160,12 +160,12 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'gender uint8)))]) (let ([stream (+DecodeStream (+Buffer "\x05devon\x15"))]) - (check-equal? (send (send struct decode stream (mhash 'version 0)) kv) (mhasheq 'name "devon" + (check-equal? (dump (decode struct stream (mhash 'version 0))) (mhasheq 'name "devon" 'age 21 'version 0))) (let ([stream (+DecodeStream (+Buffer "\x0adevon 👍\x15\x00" 'utf8))]) - (check-equal? (send (send struct decode stream (mhash 'version 1)) kv) (mhasheq 'name "devon 👍" + (check-equal? (dump (decode struct stream (mhash 'version 1))) (mhasheq 'name "devon 👍" 'age 21 'version 1 'gender 0)))) @@ -212,16 +212,16 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'isDessert uint8)))))]) (let ([stream (+DecodeStream (+Buffer "\x00\x05devon\x15"))]) - (check-equal? (send (send struct decode stream (mhash 'version 0)) kv) (mhasheq 'name "devon" + (check-equal? (dump (decode struct stream (mhash 'version 0))) (mhasheq 'name "devon" 'age 21 'version 0))) (let ([stream (+DecodeStream (+Buffer "\x01\x00\x05pasta"))]) - (check-equal? (send (send struct decode stream (mhash 'version 0)) kv) (mhasheq 'name "pasta" + (check-equal? (dump (decode struct stream (mhash 'version 0))) (mhasheq 'name "pasta" 'version 0))) (let ([stream (+DecodeStream (+Buffer "\x01\x01\x09ice cream\x01"))]) - (check-equal? (send (send struct decode stream (mhash 'version 0)) kv) (mhasheq 'name "ice cream" + (check-equal? (dump (decode struct stream (mhash 'version 0))) (mhasheq 'name "ice cream" 'isDessert 1 'version 1)))) @@ -257,7 +257,7 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'gender uint8)))]) (set-field! process struct (λ (o stream ctx) (ref-set! o 'processed "true") o)) (let ([stream (+DecodeStream (+Buffer "\x00\x05devon\x15"))]) - (check-equal? (send (send struct decode stream) kv) (mhasheq 'name "devon" + (check-equal? (dump (decode struct stream)) (mhasheq 'name "devon" 'processed "true" 'age 21 'version 0)))) @@ -297,11 +297,11 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'gender uint8)))]) - (check-equal? (send struct size (mhasheq 'name "devon" + (check-equal? (size struct (mhasheq 'name "devon" 'age 21 'version 0)) 8) - (check-equal? (send struct size (mhasheq 'name "devon 👍" + (check-equal? (size struct (mhasheq 'name "devon 👍" 'gender 0 'age 21 'version 1)) 14)) @@ -332,7 +332,7 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'gender uint8)))]) - (check-exn exn:fail:contract? (λ () (send struct size (mhasheq 'name "devon" + (check-exn exn:fail:contract? (λ () (size struct (mhasheq 'name "devon" 'age 21 'version 5))))) @@ -374,12 +374,12 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 1 (dictify 'name (+StringT uint8 'utf8) 'gender uint8)))]) - (check-equal? (send struct size (mhasheq 'name "devon" + (check-equal? (size struct (mhasheq 'name "devon" 'age 21 'alive 1 'version 0)) 9) - (check-equal? (send struct size (mhasheq 'name "devon 👍" + (check-equal? (size struct (mhasheq 'name "devon 👍" 'gender 0 'age 21 'alive 1 @@ -414,7 +414,7 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'ptr (+Pointer uint8 (+StringT uint8)))))]) - (check-equal? (send struct size (mhasheq 'name "devon" + (check-equal? (size struct (mhasheq 'name "devon" 'age 21 'version 1 'ptr "hello")) 15)) @@ -444,7 +444,7 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'gender uint8)))]) - (check-exn exn:fail:contract? (λ () (send struct size)))) + (check-exn exn:fail:contract? (λ () (size struct)))) ; ; describe 'encode', -> @@ -484,14 +484,14 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'gender uint8)))] [stream (+EncodeStream)]) - (send struct encode stream (mhasheq 'name "devon" + (encode struct stream (mhasheq 'name "devon" 'age 21 'version 0)) - (send struct encode stream (mhasheq 'name "devon 👍" + (encode struct stream (mhasheq 'name "devon 👍" 'age 21 'gender 0 'version 1)) - (check-equal? (send stream dump) (+Buffer "\x00\x05devon\x15\x01\x0adevon 👍\x15\x00" 'utf8))) + (check-equal? (dump stream) (+Buffer "\x00\x05devon\x15\x01\x0adevon 👍\x15\x00" 'utf8))) ; @@ -520,7 +520,7 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'gender uint8)))] [stream (+EncodeStream)]) - (check-exn exn:fail:contract? (λ () (send struct encode stream (mhasheq 'name "devon" + (check-exn exn:fail:contract? (λ () (encode struct stream (mhasheq 'name "devon" 'age 21 'version 5))))) @@ -566,18 +566,18 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'gender uint8)))] [stream (+EncodeStream)]) - (send struct encode stream (mhasheq 'name "devon" + (encode struct stream (mhasheq 'name "devon" 'age 21 'alive 1 'version 0)) - (send struct encode stream (mhasheq 'name "devon 👍" + (encode struct stream (mhasheq 'name "devon 👍" 'gender 0 'age 21 'alive 1 'version 1)) - (check-equal? (send stream dump) (+Buffer "\x00\x15\x01\x05devon\x01\x15\x01\x0adevon 👍\x00" 'utf8))) + (check-equal? (dump stream) (+Buffer "\x00\x15\x01\x05devon\x01\x15\x01\x0adevon 👍\x00" 'utf8))) @@ -613,12 +613,12 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'age uint8 'ptr (+Pointer uint8 (+StringT uint8)))))] [stream (+EncodeStream)]) - (send struct encode stream (mhasheq 'version 1 + (encode struct stream (mhasheq 'version 1 'name "devon" 'age 21 'ptr "hello")) - (check-equal? (send stream dump) (+Buffer "\x01\x05devon\x15\x09\x05hello" 'utf8))) + (check-equal? (dump stream) (+Buffer "\x01\x05devon\x15\x09\x05hello" 'utf8))) ; @@ -661,10 +661,10 @@ https://github.com/mbutterick/restructure/blob/master/test/VersionedStruct.coffe 'gender uint8)))] [stream (+EncodeStream)]) (set-field! preEncode struct (λ (val stream) (ref-set! val 'version (if (ref val 'gender) 1 0)))) - (send struct encode stream (mhasheq 'name "devon" + (encode struct stream (mhasheq 'name "devon" 'age 21 'version 0)) - (send struct encode stream (mhasheq 'name "devon 👍" + (encode struct stream (mhasheq 'name "devon 👍" 'age 21 'gender 0)) - (check-equal? (send stream dump) (+Buffer "\x00\x05devon\x15\x01\x0adevon 👍\x15\x00" 'utf8))) \ No newline at end of file + (check-equal? (dump stream) (+Buffer "\x00\x05devon\x15\x01\x0adevon 👍\x15\x00" 'utf8))) \ No newline at end of file