1 Data Model
Conceptually, an expectation is a function that returns a list of faults about its input. Faults are a difference between some expected attribute of the input and an actual attribute. Faults are often scoped to a context, which identifies where precisely in the input value the discrepency exists. This section documents each of these structures and how to use their basic functionalities.
procedure
(expectation? v) → boolean?
v : any/c
> (expectation? 6) #f
> (expectation? expect-true) #t
procedure
(expectation proc [#:name name]) → expectation?
proc : (-> any/c (listof fault?)) name : (or/c symbol? #f) = #f
> (define empty-expectation (expectation (λ (v) (list)) #:name 'empty)) > empty-expectation #<expectation:empty>
> (expectation-apply empty-expectation 'foo) '()
procedure
(expectation-apply exp v) → (listof faults?)
exp : expectation? v : any/c
> (expectation-apply (expect-equal? (list 1 2)) (list 1 2)) '()
> (expectation-apply (expect-equal? (list 1 2)) (list 1 'foo))
(list
(fault
"a different value"
(compare-attribute "equal? to 2" #<procedure:equal?> 2)
(self-attribute "'foo" 'foo)
(list (sequence-context "item at position 1" 1))))
procedure
(expectation-rename exp name) → expectation?
exp : expectation? name : (or/c symbol? #f)
> expect-any #<expectation:any>
> (expectation-rename expect-any 'anything-at-all) #<expectation:anything-at-all>
> (expectation-rename expect-any #f) #<expectation>
value
> (fault? 6) #f
> (fault? (fault #:summary "test fault" #:expected (make-self-attribute 'foo) #:actual (make-self-attribute 'bar))) #t
procedure
(fault #:summary summary #:expected expected #:actual actual [ #:contexts contexts]) → fault? summary : string? expected : attribute? actual : attribute? contexts : (listof context?) = (list)
> (fault #:summary "test fault" #:expected (make-self-attribute 'foo) #:actual (make-self-attribute 'bar))
(fault
"test fault"
(self-attribute "'foo" 'foo)
(self-attribute "'bar" 'bar)
'())
> (struct test-context context () #:transparent)
> (fault #:summary "test fault with contexts" #:expected (make-self-attribute 'foo) #:actual (make-self-attribute 'bar) #:contexts (list (test-context "test context") (test-context "nested test context")))
(fault
"test fault with contexts"
(self-attribute "'foo" 'foo)
(self-attribute "'bar" 'bar)
(list (test-context "test context") (test-context "nested test context")))
procedure
(fault-summary flt) → string?
flt : fault?
procedure
(fault-expected flt) → attribute?
flt : fault?
procedure
(fault-actual flt) → attribute?
flt : fault?
procedure
(fault-contexts flt) → (listof context?)
flt : fault?
struct
(struct splice-context context (values) #:transparent) values : (listof context?)
procedure
(make-splice-context ctxts [ #:description desc]) → splice-context? ctxts : (listof context?) desc : (or/c string? #f) = #f
> (define data-contexts (list (make-sequence-context 2) (make-sequence-context 6) (make-dict-context 'foo))) > (context-description (make-splice-context data-contexts)) "item at position 2 of item at position 6 of value for key 'foo"
> (context-description (make-splice-context data-contexts #:description ".foo[6][2]")) ".foo[6][2]"
struct
(struct self-attribute attribute (value) #:transparent) value : any/c
procedure
v : any/c
> (make-self-attribute 'foo) (self-attribute "'foo" 'foo)
value
value