summaryrefslogtreecommitdiff
path: root/test/test_wildcard.ml
blob: b595d7687e0d0278f5ec7cd95fc58952641616f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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