Add unit tests for String.{take,drop,split_n}

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-08-26 14:41:05 +03:00
parent e43dcc919d
commit 7f18816447
2 changed files with 99 additions and 0 deletions

View File

@ -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)))))

View File

@ -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"]]).
|}]