You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.3 KiB
Racket
53 lines
1.3 KiB
Racket
7 years ago
|
#lang reader (submod "racket.rkt" reader)
|
||
7 years ago
|
|
||
|
#|
|
||
|
approximates
|
||
|
https://github.com/mbutterick/restructure/blob/master/test/Enum.coffee
|
||
|
|#
|
||
|
|
||
|
;describe 'Enum', ->
|
||
|
; e = new Enum uint8, ['foo', 'bar', 'baz']
|
||
|
; it 'should have the right size', ->
|
||
|
; e.size().should.equal 1
|
||
|
|
||
|
(define e (+Enum uint8 '("foo" "bar" "baz")))
|
||
7 years ago
|
(check-equal? (size e) 1)
|
||
7 years ago
|
|
||
|
|
||
|
;
|
||
|
; it 'should decode', ->
|
||
|
; stream = new DecodeStream new Buffer [1, 2, 0]
|
||
|
; e.decode(stream).should.equal 'bar'
|
||
|
; e.decode(stream).should.equal 'baz'
|
||
|
; e.decode(stream).should.equal 'foo'
|
||
|
|
||
|
(let ([stream (+DecodeStream (+Buffer '(1 2 0)))])
|
||
7 years ago
|
(check-equal? (decode e stream) "bar")
|
||
|
(check-equal? (decode e stream) "baz")
|
||
|
(check-equal? (decode e stream) "foo"))
|
||
7 years ago
|
|
||
|
;
|
||
|
; it 'should encode', (done) ->
|
||
|
; stream = new EncodeStream
|
||
|
; stream.pipe concat (buf) ->
|
||
|
; buf.should.deep.equal new Buffer [1, 2, 0]
|
||
|
; done()
|
||
|
;
|
||
|
; e.encode stream, 'bar'
|
||
|
; e.encode stream, 'baz'
|
||
|
; e.encode stream, 'foo'
|
||
|
; stream.end()
|
||
|
|
||
|
(let ([stream (+EncodeStream)])
|
||
7 years ago
|
(encode e stream "bar")
|
||
|
(encode e stream "baz")
|
||
|
(encode e stream "foo")
|
||
7 years ago
|
(check-equal? (send stream dump) (+Buffer '(1 2 0))))
|
||
|
|
||
|
;
|
||
|
; it 'should throw on unknown option', ->
|
||
|
; stream = new EncodeStream
|
||
|
; should.throw ->
|
||
|
; e.encode stream, 'unknown'
|
||
|
|
||
7 years ago
|
(check-exn exn:fail:contract? (λ () (encode e (+EncodeStream) "unknown")))
|