Changeset 16093 in project


Ignore:
Timestamp:
09/26/09 20:21:00 (10 years ago)
Author:
Moritz Heidkamp
Message:

uri-match now returns thunks which return the body of the matched route instead of strings

Location:
release/4/uri-match
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/4/uri-match/tests/run.scm

    r15906 r16093  
    2626
    2727  (test-assert (equal? "this is the body"
    28                        (uri-match 'get "/" (make-routes '((get "this is the body"))))))
     28                       ((uri-match 'get "/" (make-routes '((get "this is the body")))))))
    2929
    3030  (test-assert (not (uri-match 'get "/" (make-routes '((post "won't reach me"))))))
    3131
    3232  (test-group "with nesting"
    33     (test-assert (equal? "foo" (uri-match 'post "/foo/bar" (make-routes '(("/foo" ("/bar" (post "foo"))))))))
     33    (test-assert (equal? "foo" ((uri-match 'post "/foo/bar" (make-routes '(("/foo" ("/bar" (post "foo")))))))))
    3434
    3535    (test-group "with procedure body"
    3636      (test-assert (eq? 'something
    37                         (uri-match 'get "/me" (make-routes `(("/me" (get ,(lambda () 'something))))))))
     37                        ((uri-match 'get "/me" (make-routes `(("/me" (get ,(lambda () 'something)))))))))
    3838
    39       (test-assert (= 100 (uri-match 'get "/numbers/100"
    40                                      (make-routes `(("/numbers/(\\d+)" (get ,(lambda (n) (string->number n)))))))))))
     39      (test-assert (= 100 ((uri-match 'get "/numbers/100"
     40                                      (make-routes `(("/numbers/(\\d+)" (get ,(lambda (n) (string->number n))))))))))))
    4141
    4242  (test-group "with capture groups"
    4343    (let ([routes (make-routes `(("/foo" ("/(\\d+)" ("/(\\d+)" (get ,string-append))))))])
    4444     
    45       (test-assert (string= "105" (uri-match 'get "/foo/10/5" routes)))
     45      (test-assert (string= "105" ((uri-match 'get "/foo/10/5" routes))))
    4646      (test-assert (not (uri-match 'get "/foo/bar/10" routes))))))
    4747
     
    5151  (let ([matcher (make-uri-matcher '((get "is") ("/this" (post "it") ("/or" (put "what?")))))])
    5252
    53     (test-assert (equal? "is" (matcher 'get "/")))
     53    (test-assert (equal? "is" ((matcher 'get "/"))))
    5454
    55     (test-assert (equal? "it" (matcher 'post "/this")))
     55    (test-assert (equal? "it" ((matcher 'post "/this"))))
    5656
    57     (test-assert (equal? "what?" (matcher 'put "/this/or")))))
     57    (test-assert (equal? "what?" ((matcher 'put "/this/or"))))))
  • release/4/uri-match/uri-match.scm

    r15906 r16093  
    44(import chicken scheme)
    55(use uri-common srfi-1 srfi-13 data-structures regex)
     6
    67
    78;; Transforms something like this:
     
    4445           (if matches
    4546               (let ([body (cadar routes)])
    46                  (if (procedure? body) 
    47                      (apply body (cdr matches))
    48                      body))
     47                 (if (procedure? body)
     48                     (lambda () (apply body (cdr matches)))
     49                     (lambda () body)))
    4950               (find (cdr routes)))))))
    5051
     
    5253;; Accepts a route list like make-routes and returns a procedure for
    5354;; matching against these.
    54 
    5555(define (make-uri-matcher routes)
    5656  (let ([routes (make-routes routes)])
Note: See TracChangeset for help on using the changeset viewer.