6 Text and String Expectations
procedure
(expect-regexp-match pattern [result-exp]) → expectation?
pattern : regexp?
result-exp :
(or/c (listof (or/c string? bytes? #f expectation?)) expectation?) = expect-not-false
> (expect! "This is some message" (expect-regexp-match #rx"some")) > (expect! "12x4x6" (expect-regexp-match #rx"x." '("x4"))) > (expect! "12x4x6" (expect-regexp-match #rx"x." '("x6"))) expected a different value
subject: "12x4x6"
in: the results of matching #rx"x."
in: item at position 0
expected: equal? to "x6"
actual: "x4"
procedure
(expect-string-contains? str) → expectation?
str : string?
> (expect! "This is some message" (expect-string-contains? "some message")) > (expect! "This is some message" (expect-string-contains? "foo")) expected a value to be contained
subject: "This is some message"
expected: "foo" contained with string-contains?
actual: "This is some message"
procedure
(expect-output exp [#:call call-exp]) → expectation?
exp : (or/c string? regexp? expectation?) call-exp : expectation? = expect-not-raise
> (define (foo) (display "foo!!!")) > (expect! foo (expect-output "foo!!!")) > (expect! foo (expect-output #rx"foo")) > (expect! foo (expect-output "bar")) expected a different value
subject: #<procedure:foo>
in: the string written to the output port
expected: equal? to "bar"
actual: "foo!!!"
If call-exp is provided, the input thunk is additionally checked against call-exp. This allows asserting both the output of a thunk and other properties of the thunk without calling it twice, for the rare times when multiple calls should be avoided.
> (define (foo) (display "foo!!!")) > (expect! foo (expect-output "foo!!!" #:call (expect-return (void)))) > (expect! foo (expect-output "foo!!!" #:call (expect-raise))) expected any value raised
subject: #<procedure:foo>
in: the raised value
expected: anything
actual: nothing
6.1 String Attributes and Contexts
struct
(struct regexp-match-context context (regexp) #:transparent) regexp : regexp?
procedure
(make-regexp-match-context regexp) → regexp-match-context?
regexp : regexp?
struct
(struct regexp-match-attribute attribute (regexp) #:transparent) regexp : regexp?
procedure
(make-regexp-match-attribute regexp) → regexp-match-attribute?
regexp : regexp?
value