Skip to content

Commit

Permalink
Merge pull request #7 from inhabitedtype/path_test
Browse files Browse the repository at this point in the history
path_test: add tests for empty path strings
  • Loading branch information
seliopou committed Oct 20, 2015
2 parents 448bee0 + 03d7dcc commit cd488c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/dispatch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ let path_split path =
List.rev result
in
match path with
"" -> []
| "" -> []
| _ ->
if String.get path 0 = '/'
if String.get path 0 = '/'
then loop 1 []
else loop 0 []

Expand Down
13 changes: 12 additions & 1 deletion lib_test/test_dispatch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,18 @@ let empty () =
@? begin match dispatch [] "/" with
| Error _ -> true
| _ -> false
end
end;
"an empty path string will get mapped to root"
@? begin match dispatch ["/", fun _ _ -> ()] "" with
| Ok () -> true
| _ -> false
end;
"an empty route path will match root"
@? begin match dispatch ["", fun _ _ -> ()] "/" with
| Ok () -> true
| _ -> false
end;
;;

let single () =
let table = ["/", (fun ps p -> ((), ps, p))] in
Expand Down

0 comments on commit cd488c0

Please sign in to comment.