diff --git a/src/path.ml b/src/path.ml index 301adaf1..c1bce7d3 100644 --- a/src/path.ml +++ b/src/path.ml @@ -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] diff --git a/test/unit-tests/path.mlt b/test/unit-tests/path.mlt index eac4c413..35e1a47e 100644 --- a/test/unit-tests/path.mlt +++ b/test/unit-tests/path.mlt @@ -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 [] +|}]