www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

test-parent.rkt (2318B)


      1 #lang typed/racket
      2 
      3 (require typed-struct-props
      4          typed/rackunit)
      5 (define-syntax (test-not-equal? stx)
      6   (syntax-case stx ()
      7     [(_ name v1 v2)
      8      (syntax/loc stx
      9        (test-false name (equal? v1 v2)))]))
     10 
     11 (struct/props (A) foo-parent ([f : A]) #:transparent
     12               #:property prop:equal+hash (list (λ (a b rec) #f)
     13                                                (λ (a rec) 42)
     14                                                (λ (a rec) 43)))
     15 
     16 (struct (A) foo foo-parent ([g : Number]) #:transparent)
     17 
     18 (test-not-exn "The structure's constructor and type work properly"
     19               (λ () (ann (foo "b" 12 ) (foo String))))
     20 
     21 (test-equal? "The structure's constructor and accessor for a field declared by
     22  the parent work properly"
     23              (ann (foo-parent-f (foo "b" 12)) String)
     24              "b")
     25 
     26 (test-equal? "The structure's constructor and accessor work properly"
     27              (ann (foo-g (foo "b" 12)) Number)
     28              12)
     29 
     30 (test-false "The equal? function supplied to #:equal+hash is used"
     31            (equal? (foo "b" 0) (foo "b" 0)))
     32   
     33 (test-equal? "The equal-hash-code function supplied to #:equal+hash is used"
     34                  (equal-hash-code (foo "c" 34))
     35                  (equal-hash-code (foo "d" 56)))
     36 
     37 (test-equal? "The equal-secondary hash-code function supplied to #:equal+hash is
     38  used"
     39           (equal-secondary-hash-code (foo 'e 78))
     40           (equal-secondary-hash-code (foo 'f 90)))
     41 
     42 
     43 
     44 
     45 (test-not-exn "The parent structure's constructor and type work properly"
     46               (λ () (ann (foo-parent "b") (foo-parent String))
     47                 (void)))
     48 
     49 (test-equal? "The parent structure's constructor and accessor work properly"
     50              (ann (foo-parent-f (foo-parent "b")) String)
     51              "b")
     52 
     53 (test-false "The equal? function supplied to #:equal+hash is used in the parent"
     54            (equal? (foo-parent 0) (foo-parent 0)))
     55   
     56 (test-equal? "The equal-hash-code function supplied to #:equal+hash is used in
     57  the parent"
     58                  (equal-hash-code (foo-parent 34))
     59                  (equal-hash-code (foo-parent 56)))
     60 
     61 (test-equal? "The equal-secondary hash-code function supplied to #:equal+hash is
     62  used in the parent"
     63                  (equal-secondary-hash-code (foo-parent 78))
     64                  (equal-secondary-hash-code (foo-parent 90)))