Ignore:
Timestamp:
09/28/09 21:01:46 (11 years ago)
Author:
Moritz Heidkamp
Message:

use irregex for route matching (per Peter Bex)

File:
1 edited

Legend:

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

    r16094 r16104  
    1111                                ("/bar" (get "nested")))
    1212                               (post "ha!")))])
    13 
    1413    (test-assert (lset= '(get post) (map car routes)))
    1514
     
    2221                          (map car (alist-ref 'post routes)))))))
    2322
    24 
    2523(test-group "basic matching"
    2624
    2725  (test "this is the body"
    28         ((uri-match 'get "/" (make-routes '((get "this is the body"))))))
     26        ((uri-match 'get "/" (make-routes '(("/" (get "this is the body")))))))
    2927
    3028  (test "against the path of a uri-reference" "something!"
    3129        ((uri-match 'get (uri-reference "http://foo/bar") (make-routes '(("/bar" (get "something!")))))))
    3230
    33   (test-assert (not (uri-match 'get "/" (make-routes '((post "won't reach me"))))))
     31  (test-assert (not (uri-match 'get "/" (make-routes '(("/" (post "won't reach me")))))))
    3432
    3533  (test-group "with nesting"
     
    4745     
    4846      (test-assert (string= "105" ((uri-match 'get "/foo/10/5" routes))))
     47      (test-assert (not (uri-match 'get "/foo/bar/10" routes)))))
     48 
     49  (test-group "with irregex capture groups"
     50    (let ([routes (make-routes
     51                   `(("/foo" ((seq "/" (submatch (+ num)))
     52                              ((seq "/" (submatch (+ num)))
     53                               (get ,string-append))))))])
     54      (test-assert (string= "105" ((uri-match 'get "/foo/10/5" routes))))
     55      (test-assert (not (uri-match 'get "/foo/bar/10" routes)))))
     56 
     57  (test-group "with irregex named capture groups"
     58    (let ([routes (make-routes
     59                   `(("/foo" ((seq "/" (submatch (+ num)))
     60                              ((seq "/" (or (submatch-named b (+ num))
     61                                            (submatch-named c (+ alpha))))
     62                               (get ,(lambda (a #!key (b "b") (c "c"))
     63                                       (string-append a b c))))))))])
     64      (test "105c" ((uri-match 'get "/foo/10/5" routes)))
     65      (test "10bx" ((uri-match 'get "/foo/10/x" routes)))
    4966      (test-assert (not (uri-match 'get "/foo/bar/10" routes))))))
    5067
     
    5269(test-group "matcher"
    5370         
    54   (let ([matcher (make-uri-matcher '((get "is") ("/this" (post "it") ("/or" (put "what?")))))])
     71  (let ([matcher (make-uri-matcher '(("/" (get "is")) ("/this" (post "it") ("/or" (put "what?")))))])
    5572
    5673    (test-assert (equal? "is" ((matcher 'get "/"))))
Note: See TracChangeset for help on using the changeset viewer.