Skip to content

Commit

Permalink
sync with new updates on main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragsoni committed Nov 20, 2021
1 parent 1a7f60a commit e2ff83e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,9 @@ let streaming_handler req =
Response.make ~body:(Body.of_stream ?length body) () |> Lwt.return
;;
let print_param_handler req =
Printf.sprintf "Hello, %s\n" (Router.param req "name")
|> Response.of_plain_text
|> Lwt.return
;;
let _ =
App.empty
|> App.post "/hello/stream" streaming_handler
|> App.get "/hello/:name" print_param_handler
|> App.get "/person/:name/:age" print_person_handler
|> App.patch "/person" update_person_handler
|> App.run_command
Expand Down
7 changes: 0 additions & 7 deletions example/hello_world/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,9 @@ let streaming_handler req =
Response.make ~body:(Body.of_stream ?length body) () |> Lwt.return
;;

let print_param_handler req =
Printf.sprintf "Hello, %s\n" (Router.param req "name")
|> Response.of_plain_text
|> Lwt.return
;;

let _ =
App.empty
|> App.post "/hello/stream" streaming_handler
|> App.get "/hello/:name" print_param_handler
|> App.get "/person/:name/:age" print_person_handler
|> App.patch "/person" update_person_handler
|> App.run_command
Expand Down
15 changes: 9 additions & 6 deletions opium/test/opium_router_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ let%expect_test "we can extract parameter after match" =
test_match_url router "/foo/100/baz";
test_match_url router "/foo/100";
test_match_url router "/foo/100/200/300";
[%expect {|
[%expect
{|
matched with params: ((named ((bar baz))) (unnamed (100)) (full_splat ()))
no match
no match |}]
Expand Down Expand Up @@ -143,8 +144,7 @@ let%expect_test "nodes are matched correctly" =
let test = test_match router in
test "/foo/bar" "Wrong";
test "/foo/baz" "Right";
[%expect
{| |}]
[%expect {| |}]
;;
let%expect_test "full splat node matches" =
Expand All @@ -153,7 +153,8 @@ let%expect_test "full splat node matches" =
test "/foo/bar";
test "/foo/bar/foo";
test "/foo/";
[%expect {|
[%expect
{|
matched with params: ((named ()) (unnamed ()) (full_splat (bar)))
matched with params: ((named ()) (unnamed ()) (full_splat (bar/foo)))
matched with params: ((named ()) (unnamed ()) (full_splat ())) |}]
Expand All @@ -179,7 +180,8 @@ let%expect_test "two parameters" =
let router = of_routes' [ "/test/:format/:name/:baz" ] in
let test = test_match_url router in
test "/test/json/bar/blah";
[%expect {|
[%expect
{|
matched with params: ((named ((baz blah) (name bar) (format json)))
(unnamed ()) (full_splat ())) |}]
;;
Expand All @@ -192,7 +194,8 @@ let%expect_test "full splat" =
test "/";
test "";
test "/user/123/foo/bar";
[%expect{|
[%expect
{|
matched with params: ((named ()) (unnamed ()) (full_splat (test)))
matched with params: ((named ()) (unnamed ()) (full_splat (test/)))
matched with params: ((named ()) (unnamed ()) (full_splat ()))
Expand Down

0 comments on commit e2ff83e

Please sign in to comment.