Fix Path.descendent
It was broken for local paths with equal length
This commit is contained in:
parent
9e4390ddc4
commit
bbb6108924
|
@ -188,8 +188,9 @@ module Local = struct
|
||||||
| _ ->
|
| _ ->
|
||||||
let of_len = String.length of_ in
|
let of_len = String.length of_ in
|
||||||
let t_len = String.length t in
|
let t_len = String.length t in
|
||||||
if (t_len = of_len && t = of_) ||
|
if t_len = of_len then
|
||||||
(t_len >= of_len && t.[of_len] = '/' && String.is_prefix t ~prefix:of_) then
|
Option.some_if (t = of_) t
|
||||||
|
else if (t_len >= of_len && t.[of_len] = '/' && String.is_prefix t ~prefix:of_) then
|
||||||
Some (String.sub t ~pos:(of_len + 1) ~len:(t_len - of_len - 1))
|
Some (String.sub t ~pos:(of_len + 1) ~len:(t_len - of_len - 1))
|
||||||
else
|
else
|
||||||
None
|
None
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
(* -*- tuareg -*- *)
|
(* -*- tuareg -*- *)
|
||||||
|
|
||||||
open Jbuilder;;
|
open Jbuilder;;
|
||||||
open Import;;
|
open Import;;
|
||||||
|
|
||||||
|
@ -10,37 +9,23 @@ let r = Path.(relative root);;
|
||||||
Path.(let p = relative root "foo" in descendant p ~of_:p)
|
Path.(let p = relative root "foo" in descendant p ~of_:p)
|
||||||
[%%expect{|
|
[%%expect{|
|
||||||
val r : string -> Jbuilder.Path.t = <fun>
|
val r : string -> Jbuilder.Path.t = <fun>
|
||||||
Exception: Invalid_argument "String.sub / Bytes.sub".
|
- : Jbuilder.Path.t option = Some foo
|
||||||
Raised at file "pervasives.ml", line 33, characters 25-45
|
|
||||||
Called from file "string.ml", line 47, characters 2-23
|
|
||||||
Called from file "src/path.ml", line 193, characters 13-71
|
|
||||||
Called from file "toplevel/toploop.ml", line 180, characters 17-56
|
|
||||||
|}]
|
|}]
|
||||||
|
|
||||||
(* different strings but same length *)
|
(* different strings but same length *)
|
||||||
Path.(descendant (relative root "foo") ~of_:(relative root "bar"))
|
Path.(descendant (relative root "foo") ~of_:(relative root "bar"))
|
||||||
[%%expect{|
|
[%%expect{|
|
||||||
Exception: Invalid_argument "index out of bounds".
|
- : Jbuilder.Path.t option = None
|
||||||
Raised by primitive operation at file "src/path.ml", line 192, characters 29-39
|
|
||||||
Called from file "toplevel/toploop.ml", line 180, characters 17-56
|
|
||||||
|}]
|
|}]
|
||||||
|
|
||||||
Path.(descendant (r "foo") ~of_:(r "foo/"))
|
Path.(descendant (r "foo") ~of_:(r "foo/"))
|
||||||
[%%expect{|
|
[%%expect{|
|
||||||
Exception: Invalid_argument "String.sub / Bytes.sub".
|
- : Jbuilder.Path.t option = Some foo
|
||||||
Raised at file "pervasives.ml", line 33, characters 25-45
|
|
||||||
Called from file "string.ml", line 47, characters 2-23
|
|
||||||
Called from file "src/path.ml", line 193, characters 13-71
|
|
||||||
Called from file "toplevel/toploop.ml", line 180, characters 17-56
|
|
||||||
|}]
|
|}]
|
||||||
|
|
||||||
Path.(descendant (r "foo/") ~of_:(r "foo"))
|
Path.(descendant (r "foo/") ~of_:(r "foo"))
|
||||||
[%%expect{|
|
[%%expect{|
|
||||||
Exception: Invalid_argument "String.sub / Bytes.sub".
|
- : Jbuilder.Path.t option = Some foo
|
||||||
Raised at file "pervasives.ml", line 33, characters 25-45
|
|
||||||
Called from file "string.ml", line 47, characters 2-23
|
|
||||||
Called from file "src/path.ml", line 193, characters 13-71
|
|
||||||
Called from file "toplevel/toploop.ml", line 180, characters 17-56
|
|
||||||
|}]
|
|}]
|
||||||
|
|
||||||
Path.(descendant (r "foo/bar") ~of_:(r "foo"))
|
Path.(descendant (r "foo/bar") ~of_:(r "foo"))
|
||||||
|
|
Loading…
Reference in New Issue