Fix Path.explode

This commit is contained in:
Jeremie Dimino 2018-01-19 22:43:40 +00:00
parent 321543a56b
commit 92c7927432
2 changed files with 26 additions and 2 deletions

View File

@ -411,13 +411,17 @@ let split_first_component t =
None
let explode t =
if is_local t then
if is_root t then
Some []
else if is_local t then
Some (String.split t ~on:'/')
else
None
let explode_exn t =
if is_local t then
if is_root t then
[]
else if is_local t then
String.split t ~on:'/'
else
Sexp.code_error "Path.explode_exn" ["path", Atom t]

View File

@ -47,3 +47,23 @@ Path.(descendant (r "foo") ~of_:Path.root)
[%%expect{|
- : Jbuilder.Path.t option = Some foo
|}]
Path.explode (Path.of_string "a/b/c");
[%%expect{|
- : string list option = Some ["a"; "b"; "c"]
|}]
Path.explode (Path.of_string "a/b");
[%%expect{|
- : string list option = Some ["a"; "b"]
|}]
Path.explode (Path.of_string "a");
[%%expect{|
- : string list option = Some ["a"]
|}]
Path.explode (Path.of_string "");
[%%expect{|
- : string list option = Some []
|}]