diff --git a/test/unit-tests/dune b/test/unit-tests/dune index e0abe874..19c82f03 100644 --- a/test/unit-tests/dune +++ b/test/unit-tests/dune @@ -98,3 +98,13 @@ (progn (run %{exe:expect_test.exe} %{t}) (diff? %{t} %{t}.corrected))))) + +(alias + (name runtest) + (deps (:t string.mlt) + (glob_files %{project_root}/src/.dune.objs/*.cmi) + (glob_files %{project_root}/src/stdune/.stdune.objs/*.cmi)) + (action (chdir %{project_root} + (progn + (run %{exe:expect_test.exe} %{t}) + (diff? %{t} %{t}.corrected))))) \ No newline at end of file diff --git a/test/unit-tests/string.mlt b/test/unit-tests/string.mlt new file mode 100644 index 00000000..de13a06a --- /dev/null +++ b/test/unit-tests/string.mlt @@ -0,0 +1,89 @@ +(* -*- tuareg -*- *) +open! Stdune;; + +Printexc.record_backtrace false;; + +String.take "foobar" 3;; +[%%expect{| +- : unit = () +- : string = "foo" +|}] + +String.take "foobar" 0;; +[%%expect{| +- : string = "" +|}] + +String.take "foo" 10;; +[%%expect{| +- : string = "foo" +|}] + +String.take "" 10;; +[%%expect{| +- : string = "" +|}] + +String.take "" 0;; +[%%expect{| +- : string = "" +|}] + + +String.drop "" 0;; +[%%expect{| +- : string = "" +|}] + +String.drop "foo" 0;; +[%%expect{| +- : string = "foo" +|}] + +String.drop "foo" 5;; +[%%expect{| +- : string = "" +|}] + +String.drop "foobar" 3;; +[%%expect{| +- : string = "bar" +|}] + +String.split_n "foobar" 3;; +[%%expect{| +- : string * string = ("foo", "bar") +|}] + +String.split_n "foobar" 10;; +[%%expect{| +Exception: +Code_error + (List + [Atom "String.split_n"; List [Atom "s"; Atom "foobar"]; + List [Atom "n"; Atom "10"]]). +|}] + +String.split_n "foobar" 0;; +[%%expect{| +- : string * string = ("", "foobar") +|}] + +String.split_n "foobar" 6;; +[%%expect{| +- : string * string = ("foobar", "") +|}] + +String.split_n "" 0;; +[%%expect{| +- : string * string = ("", "") +|}] + +String.split_n "" 10;; +[%%expect{| +Exception: +Code_error + (List + [Atom "String.split_n"; List [Atom "s"; Atom ""]; + List [Atom "n"; Atom "10"]]). +|}]