From 9e4390ddc444d1d6604aafafda4045a22c871d79 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 20 Dec 2017 13:49:45 +0700 Subject: [PATCH] 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 --- test/unit-tests/jbuild | 7 +++++ test/unit-tests/path.mlt | 64 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 test/unit-tests/path.mlt diff --git a/test/unit-tests/jbuild b/test/unit-tests/jbuild index 5c16ecfa..f660a4af 100644 --- a/test/unit-tests/jbuild +++ b/test/unit-tests/jbuild @@ -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} ${<}))))) diff --git a/test/unit-tests/path.mlt b/test/unit-tests/path.mlt new file mode 100644 index 00000000..f690221c --- /dev/null +++ b/test/unit-tests/path.mlt @@ -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 = +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 +|}]