diff --git a/pitfall/pitfall/helper.rkt b/pitfall/pitfall/helper.rkt index 75c628e3..08b1dfdf 100644 --- a/pitfall/pitfall/helper.rkt +++ b/pitfall/pitfall/helper.rkt @@ -133,10 +133,20 @@ (define-syntax-rule (test-when cond expr) (if cond (raise-test-exn expr) expr)) +(define string% + (class* object% (writable<%>) + (super-new) + (init-field [data #f]) + (define (get-string) + (with-handlers ([exn:fail:object? (λ (exn) data)]) + (send this toString))) + (define/public (custom-write port) (write (get-string) port)) + (define/public (custom-display port) (display (get-string) port)))) + (define mixin-tester% (class object% (super-new) - (define/public (addContent val) val))) + (define/public (addContent val) (make-object string% val)))) (define-syntax (as-method stx) (syntax-case stx ()