Add tests Path.descendent

Some of them are failing because it it doesn't work when the paths are equal or
have the same length
This commit is contained in:
Rudi Grinberg 2017-12-20 13:49:45 +07:00 committed by Jérémie Dimino
parent feaca3058b
commit 9e4390ddc4
2 changed files with 71 additions and 0 deletions

View File

@ -37,3 +37,10 @@
(glob_files ${SCOPE_ROOT}/src/*.cmi)
(glob_files ${SCOPE_ROOT}/vendor/re/*.cmi)))
(action (chdir ${SCOPE_ROOT} (run ${exe:expect_test.exe} ${<})))))
(alias
((name runtest)
(deps (path.mlt
(glob_files ${SCOPE_ROOT}/src/*.cmi)
(glob_files ${SCOPE_ROOT}/vendor/re/*.cmi)))
(action (chdir ${SCOPE_ROOT} (run ${exe:expect_test.exe} ${<})))))

64
test/unit-tests/path.mlt Normal file
View File

@ -0,0 +1,64 @@
(* -*- tuareg -*- *)
open Jbuilder;;
open Import;;
let r = Path.(relative root);;
#install_printer Path.pp;;
Path.(let p = relative root "foo" in descendant p ~of_:p)
[%%expect{|
val r : string -> Jbuilder.Path.t = <fun>
Exception: Invalid_argument "String.sub / Bytes.sub".
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 *)
Path.(descendant (relative root "foo") ~of_:(relative root "bar"))
[%%expect{|
Exception: Invalid_argument "index out of bounds".
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/"))
[%%expect{|
Exception: Invalid_argument "String.sub / Bytes.sub".
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"))
[%%expect{|
Exception: Invalid_argument "String.sub / Bytes.sub".
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"))
[%%expect{|
- : Jbuilder.Path.t option = Some bar
|}]
Path.(descendant Path.root ~of_:(r "foo"))
[%%expect{|
- : Jbuilder.Path.t option = None
|}]
Path.(descendant Path.root ~of_:Path.root)
[%%expect{|
- : Jbuilder.Path.t option = Some
|}]
Path.(descendant (r "foo") ~of_:Path.root)
[%%expect{|
- : Jbuilder.Path.t option = Some foo
|}]