{"size": 2309, "ext": "scrbl", "max_stars_repo_path": "mock/private/function.scrbl", "max_stars_repo_name": "countvajhula/racket-mock", "max_stars_repo_stars_event_min_datetime": "2015-08-21T21:58:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-28T19:27:13.000Z", "max_issues_repo_path": "mock/private/function.scrbl", "max_issues_repo_name": "countvajhula/racket-mock", "max_issues_repo_issues_event_min_datetime": "2015-08-21T22:02:33.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-14T21:18:59.000Z", "max_forks_repo_path": "mock/private/function.scrbl", "max_forks_repo_name": "countvajhula/racket-mock", "max_forks_repo_forks_event_min_datetime": "2015-08-21T23:18:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-11T01:47:51.000Z"}
{"max_stars_count": 22, "max_issues_count": 131, "max_forks_count": 10, "avg_line_length": 38.4833333333, "max_line_length": 80, "alphanum_fraction": 0.6673884799}
#lang scribble/manual
@(require "util-doc.rkt")

@title{Behavior Construction Utilities}

@defproc[(const/kw [v any/c]) procedure?]{
 Like @racket[const], but the returned procedure accepts keyword arguments.
 @(mock-examples
   ((const/kw 'a) 1)
   ((const/kw 'a) #:foo 2))
 @history[#:added "1.5"]}

@defthing[void/kw (unconstrained-domain-> void?)]{
 Like @racket[void], but accepts keyword arguments.
 @(mock-examples
   (void/kw 1)
   (void/kw #:foo 2))
 @history[#:added "1.5"]}

@defproc[(const-raise [v any/c]) procedure?]{
 Like @racket[const/kw], but instead of returning @racket[v] the returned
 procedure always @racket[raise]s @racket[v] whenever it's called.
 @(mock-examples
   (eval:error ((const-raise 'a) 1))
   (eval:error ((const-raise 'a) #:foo 2)))
 @history[#:added "1.5"]}

@defproc[(const-raise-exn
          [#:message msg string? "failure"]
          [#:constructor ctor
           (-> string? continuation-mark-set? any/c) make-exn:fail])
         procedure?]{
 Like @racket[const-raise], but designed for raising exceptions. More precisely,
 the returned procedure raises the result of
 @racket[(ctor msg (current-continuation-marks))] whenever it's called.
 @(mock-examples
   (eval:error ((const-raise-exn) 1))
   (eval:error ((const-raise-exn #:message "some other failure") #:foo 2))
   (define (exn/custom-message msg marks)
     (make-exn:fail (format "custom: ~a" msg) marks))
   (eval:error ((const-raise-exn #:constructor exn/custom-message) #:bar 3)))
 @history[#:added "1.5"]}

@defproc[(const-series [v any/c] ... [#:reset? reset? boolean? #f]) procedure?]{
 Returns a procedure that ignores positional and keyword arguments and returns
 the first @racket[v] when called for the first time, the second @racket[v] when
 called for the second time, the third on the third time, and so on until no
 more @racket[v]s remain. Then, calls cause the procedure to fail with an
 exception if @racket[reset?] is false. Otherwise, the pattern resets.
 @(mock-examples
   (define ab-proc (const-series 'a 'b))
   (eval:check (ab-proc 1) 'a)
   (eval:check (ab-proc #:foo 2) 'b)
   (eval:error (ab-proc #:bar 3))
   (define ab-proc (const-series 'a 'b #:repeat? #t))
   (eval:check (ab-proc) 'a)
   (eval:check (ab-proc) 'b)
   (eval:check (ab-proc) 'a))
 @history[#:added "1.5"]}
