|
| 1 | +#lang racket/base |
| 2 | +(module test racket/base |
| 3 | + (require (for-syntax racket/base syntax/parse racket/struct-info racket/match)) |
| 4 | + |
| 5 | + (define-syntax (get-constr stx) |
| 6 | + (syntax-parse stx |
| 7 | + [(_ sname:id) |
| 8 | + (define si (extract-struct-info (syntax-local-value #'sname (lambda () #f)))) |
| 9 | + (match-define (list* struct-desc constr rst) si) |
| 10 | + constr])) |
| 11 | + (provide get-constr)) |
| 12 | + |
| 13 | +(module typed typed/racket/base |
| 14 | + (require (submod ".." test)) |
| 15 | + (require typed/rackunit) |
| 16 | + (struct kiwi ()) |
| 17 | + (struct apple () #:constructor-name make-apple) |
| 18 | + (struct pear () #:type-name PEAR) |
| 19 | + (struct dragon-fruit () #:type-name DragonFruit #:constructor-name make-dragon-fruit) |
| 20 | + (provide (struct-out apple) |
| 21 | + (struct-out kiwi) |
| 22 | + (struct-out PEAR) |
| 23 | + (struct-out DragonFruit)) |
| 24 | + |
| 25 | + (check-equal? (object-name (get-constr apple)) 'make-apple) |
| 26 | + (check-equal? (object-name (get-constr kiwi)) 'kiwi) |
| 27 | + (check-equal? (object-name (get-constr apple)) 'make-apple) |
| 28 | + (check-equal? (object-name (get-constr pear)) 'pear) |
| 29 | + (check-equal? (object-name (get-constr dragon-fruit)) 'make-dragon-fruit) |
| 30 | + (check-equal? (object-name (get-constr DragonFruit)) 'make-dragon-fruit) |
| 31 | + (check-equal? (object-name (get-constr PEAR)) 'pear)) |
| 32 | + |
| 33 | +(require rackunit) |
| 34 | +(require 'typed) |
| 35 | +(require 'test) |
| 36 | +(check-equal? (object-name (get-constr apple)) 'make-apple) |
| 37 | +(check-equal? (object-name (get-constr kiwi)) 'kiwi) |
| 38 | +(check-equal? (object-name (get-constr apple)) 'make-apple) |
| 39 | +(check-equal? (object-name (get-constr DragonFruit)) 'make-dragon-fruit) |
| 40 | +(check-equal? (object-name (get-constr PEAR)) 'pear) |
0 commit comments