www

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

typed-rackunit-extensions.scrbl (2990B)


      1 #lang scribble/manual
      2 @require[scribble-math
      3          "utils.rkt"
      4          @for-label[phc-toolkit/typed-rackunit-extensions]]
      5 @title{Extensions for @racketmodname[typed/rackunit]}
      6 @author{@author+email["Suzanne Soy" "racket@suzanne.soy"]}
      7 
      8 @defmodule[phc-toolkit/typed-rackunit-extensions
      9            #:use-sources
     10            [(submod (lib "phc-toolkit/typed-rackunit-extensions.rkt") typed)]]
     11 
     12 @defform[#:literals (:)
     13          (check-ann value type)
     14          #:grammar [(value (ExpressionOf type))
     15                     (type Type)]]{
     16  Verifies at compile-time that the given value is of the
     17  given type. The file will not compile if this check fails.
     18  
     19  TODO: do the check at run-time, like @racket[check-tc].}
     20 
     21 @defform[(check-tc . body)]{
     22  Verifies at run-time that the statments in @racket[body]
     23  typecheck without any error.
     24 
     25  TODO: fix possible problems with source location when the
     26  test fails.}
     27 
     28 @defform[(check-not-tc . body)]{
     29  Verifies at run-time that the statments in @racket[body]
     30  contain a type error. This can be used to check that the
     31  types provided by a library or generated by a macro are
     32  strong enough, by verifying that type errors that should be
     33  caught are caught.
     34 
     35  TODO: fix possible problems with source location when the
     36  test fails.}
     37 
     38 @defproc[(check-equal?-classes [class (∀ (A) (Pairof String (Listof A)))] ...)
     39          Void]{
     40  Verivies that the given elements form equality classes as
     41  indicated.
     42 
     43  The @racket[car] of each class indicates its name, and the
     44  @racket[rest] is a list of element which belong to that
     45  class. All elements of the same class should have the same
     46  type @racket[Aᵢ], but elements of two different classes can
     47  have different types @racket[Aᵢ] and @racket[Aⱼ].
     48 
     49  This function checks that all elements of the same class
     50  are @racket[equal?], and that any two elements of two
     51  distinct classes are different. It also checks that
     52  elements are equal to themeselves, and checks equalities
     53  and inequalities in both directions, i.e. 
     54  @racket[(and (equal? a b) (equal? b a))] for equalities,
     55  and @racket[(and (not (equal? a b)) (not (equal? b a)))]
     56  for inequalities.
     57 
     58  Be aware that this function has @${O(n²)} time complexity,
     59  with @${n} being the total number of elements in all
     60  classes.}
     61 
     62 @defform[#:literals (:)
     63          (check-equal?-classes: [maybe-nameᵢ maybe-typeᵢ elementᵢⱼ ...] ...)
     64          #:grammar [(maybe-nameᵢ (code:line)
     65                                  (code:line #:name String))
     66                     (maybe-typeᵢ (code:line)
     67                                  (code:line : tᵢ))
     68                     (tᵢ Type)
     69                     (elementᵢⱼ (ExpressionOf tᵢ or Any))]]{
     70  Macro form of @racket[check-equal?-classes]. It is
     71  equivalent to
     72  @racket[(check-equal?-classes
     73           (list nameᵢ elementᵢ ...) ...)], but also checks
     74  that each @racket[elementᵢⱼ] is of the corresponding 
     75  @racket[tᵢ] type, if specified.}
     76 
     77 @include-section{typed-rackunit-extensions-untyped.scrbl}