Fix Path.explode
This commit is contained in:
parent
321543a56b
commit
92c7927432
|
@ -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]
|
||||
|
|
|
@ -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 []
|
||||
|}]
|
||||
|
|
Loading…
Reference in New Issue