Skip to content

Commit 70604a0

Browse files
committed
xapi-stdext-std: test String.replace
I added some cases in preparation to change its implementation Signed-off-by: Pau Ruiz Safont <pau.safont@vates.tech>
1 parent 1139d3a commit 70604a0

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

ocaml/libs/xapi-stdext/lib/xapi-stdext-std/xstringext_test.ml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,27 @@ let test_rtrim =
7272
in
7373
("rtrim", List.map test spec)
7474

75-
let () = Alcotest.run "Xstringext" [test_split; test_rtrim]
75+
let test_replace =
76+
let spec =
77+
[
78+
(("*", "WILDCHAR", ""), "")
79+
; (("*", "", "*"), "")
80+
; (("*", "WILDCHAR", "*"), "WILDCHAR")
81+
; (("*", "WILDCHAR", "**"), "WILDCHARWILDCHAR")
82+
; (("*", "WILDCHAR", "***"), "WILDCHARWILDCHARWILDCHAR")
83+
; (({|"|}, "", ""), "")
84+
; (({|"|}, "", "a"), "a")
85+
; (({|"|}, "", {|"a"|}), "a")
86+
; (({|"|}, "", {|a"a|}), "aa")
87+
]
88+
in
89+
let test ((char, by, case), expected) =
90+
let name =
91+
Printf.sprintf "replace %S by %S in %S is %S" char (String.escaped by)
92+
(String.escaped case) (String.escaped expected)
93+
in
94+
test_string (XString.replace char by) (name, case, expected)
95+
in
96+
("replace", List.map test spec)
97+
98+
let () = Alcotest.run "Xstringext" [test_split; test_rtrim; test_replace]

0 commit comments

Comments
 (0)