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.
typesetting/pitfall/restructure/test.rkt

22 lines
607 B
Racket

8 years ago
#lang restructure/racket
(require "main.rkt")
(define Person
(make-object RStruct
(list (cons 'name (make-object RString uint8 'utf8))
(cons 'age uint8))))
8 years ago
;; decode a person from a buffer
8 years ago
(define stream-in (make-object RDecodeStream #"\4MikeA"))
(define x (send Person decode stream-in))
8 years ago
(test-module
8 years ago
(check-equal? (hash-ref x 'name) "Mike")
(check-equal? (hash-ref x 'age) 65))
8 years ago
;; encode a person from a hash
8 years ago
(define stream-out (make-object REncodeStream))
(send Person encode stream-out (hasheq 'name "Mike" 'age 65))
8 years ago
(test-module
8 years ago
(check-equal? (send stream-out dump) #"\4MikeA"))