[plt-scheme] testing local functions

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Wed Sep 23 09:48:02 EDT 2009

parse-post can be lifted to the top level in that example.

As the documentation [1] says:

(extract-binding/single id binds) → string?
id : symbol?
binds : (listof (cons/c symbol? string?))

So you can give it any alist of strings.

Jay

1. http://docs.plt-scheme.org/web-server/http.html#(def._((lib._web-server/http/bindings..ss)._extract-binding/single))

On Tue, Sep 22, 2009 at 1:55 PM, Scott Hickey <jshickey at yahoo.com> wrote:
> I am working through the web server tutorial. I was wondering if there is a
> way to write tests for functions like parse-post in the code below. It seems
> like there are two issues to resolve: 1) the scope of parse-post 2)
> constructing a test binding.
> (define (render-blog-page request)
>   (local [(define (response-generator make-url)
>             `(html (head (title "My Blog"))
>                    (body
>                     (h1 "My Blog")
>                     ,(render-posts make-url)
>                     (form ((action
>                             ,(make-url insert-post-handler)))
>                           (input ((name "title")))
>                           (input ((name "body")))
>                           (input ((type "submit")))))))
>
>           (define (parse-post bindings)
>             (make-post (extract-binding/single 'title' bindings)
>                        (extract-binding/single 'body' bindings)))
>
>           (define (insert-post-handler request)
>             (blog-insert-post!
>              BLOG (parse-post (request-bindings request)))
>             (render-blog-page request))]
>
>     (send/suspend/dispatch response-generator)))
>
> Scott Hickey
> Senior Consultant
> Object Partners, Inc.
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.