summaryrefslogtreecommitdiff
path: root/lib/std/test
diff options
context:
space:
mode:
authorOri Bernstein <ori@markovcorp.com>2018-01-26 11:52:39 -0800
committerOri Bernstein <ori@markovcorp.com>2018-01-26 11:52:39 -0800
commit83bca2aaa7635be1ef17fdd5e3b02348b79f7dcc (patch)
tree44c3ef66d1f911c71bbe1c5b329451718f660810 /lib/std/test
parentd6095b1b433002ab661f3ebdd3bf8275f2f1925f (diff)
downloadmc-83bca2aaa7635be1ef17fdd5e3b02348b79f7dcc.tar.gz
Contbuild wants strreplace.
Diffstat (limited to 'lib/std/test')
-rw-r--r--lib/std/test/strreplace.myr27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/std/test/strreplace.myr b/lib/std/test/strreplace.myr
new file mode 100644
index 0000000..63ba7e0
--- /dev/null
+++ b/lib/std/test/strreplace.myr
@@ -0,0 +1,27 @@
+use std
+use testr
+
+const main = {
+ testr.run([
+ [.name="fullstr",
+ .fn={ctx; swap(ctx, "src", "src", "dst", "dst")}],
+ [.name="head",
+ .fn={ctx; swap(ctx, "srcstuff", "src", "dst", "dststuff")}],
+ [.name="tail",
+ .fn={ctx; swap(ctx, "stuffsrc", "src", "dst", "stuffdst")}],
+ [.name="middle",
+ .fn={ctx; swap(ctx, "stusrcff", "src", "dst", "studstff")}],
+ [.name="multi",
+ .fn={ctx; swap(ctx, "srcstusrcffsrc", "src", "dst", "dststudstffdst")}],
+ [.name="overlap",
+ .fn={ctx; swap(ctx, "aaaaa", "aaa", "bbb", "bbbaa")}],
+ ][:])
+}
+
+const swap = {ctx, in, src, dst, expected
+ var r
+
+ r = std.strreplace(in, src, dst)
+ testr.check(ctx, std.eq(r, expected), "got {}, expected {}\n", r, expected)
+ std.slfree(r)
+}