diff options
Diffstat (limited to 'test/test_wildcard.ml')
-rw-r--r-- | test/test_wildcard.ml | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/test_wildcard.ml b/test/test_wildcard.ml new file mode 100644 index 0000000..b595d76 --- /dev/null +++ b/test/test_wildcard.ml @@ -0,0 +1,28 @@ +open OUnit2 +open Piaf +open Routes + +let static path_parts _db_pool _req = + let path = Routes.Parts.wildcard_match path_parts in + let full_path = "assets/" ^ path in + Ok (Response.of_string ~body:full_path `OK) + +let routes = + [ `GET, (s "assets" / wildcard) @--> static + ] + +let test_wildcard _ = + let router = one_of routes in + let target = "/assets/foo/bar" +in + match match' router ~target with + | FullMatch f -> + let res = f () () in + let body = Piaf.Body.to_string res.body in + assert_equal "assets/foo/bar" body + | _ -> assert_failure "No match" + +let suite = "wildcard" >::: [ "test_wildcard" >:: test_wildcard ] + +let () + = run_test_tt_main suite |