From f22bdc35a3555e1a09f33b1ebbcb01f537a9b292 Mon Sep 17 00:00:00 2001 From: polwex Date: Wed, 16 Jul 2025 22:21:11 +0700 Subject: not bad not bad --- test/test_wildcard.ml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/test_wildcard.ml (limited to 'test') 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 -- cgit v1.2.3