summaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorOri Bernstein <ori@markovcorp.com>2018-11-16 13:41:34 -0800
committerOri Bernstein <ori@markovcorp.com>2018-11-16 13:41:34 -0800
commit875d2f385513fef710c0f7b193b9981d980773dd (patch)
tree578eb822167365aa7f9d67d4f4ac09a2211ab357 /lib/std
parente822c8c079058b4561311f5f0ba81d28c5efa30c (diff)
downloadmc-875d2f385513fef710c0f7b193b9981d980773dd.tar.gz
Add strfind tests.
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/test/strfind.myr43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/std/test/strfind.myr b/lib/std/test/strfind.myr
new file mode 100644
index 0000000..f95affc
--- /dev/null
+++ b/lib/std/test/strfind.myr
@@ -0,0 +1,43 @@
+use std
+use testr
+
+const main = {
+ testr.run([
+ [.name="forward-head-1c", .fn={ctx; fwdfindat(ctx, 0, "abc", "a")}],
+ [.name="forward-head-2c", .fn={ctx; fwdfindat(ctx, 0, "abc", "ab")}],
+ [.name="forward-fullmatch", .fn={ctx; fwdfindat(ctx, 1, "abc", "bc")}],
+ [.name="forward-dup-1c", .fn={ctx; fwdfindat(ctx, 0, "abcabc", "a")}],
+ [.name="forward-dup-2c", .fn={ctx; fwdfindat(ctx, 0, "abcabc", "ab")}],
+ [.name="reverse-head-1c", .fn={ctx; revfindat(ctx, 0, "abc", "a")}],
+ [.name="reverse-head-2c", .fn={ctx; revfindat(ctx, 0, "abc", "ab")}],
+ [.name="reverse-fullmatch", .fn={ctx; revfindat(ctx, 1, "abc", "bc")}],
+ [.name="reverse-dup-1c", .fn={ctx; revfindat(ctx, 3, "abcabc", "a")}],
+ [.name="reverse-dup-2c", .fn={ctx; revfindat(ctx, 3, "abcabc", "ab")}],
+ ][:])
+}
+
+const fwdfindat = {ctx, idx, h, n
+ match std.strfind(h, n)
+ | `std.Some i:
+ if i == idx
+ testr.ok(ctx)
+ else
+ testr.fail(ctx, "wrong location {} != {} ('{}' in '{}')", i, idx, n, h)
+ ;;
+ | `std.None:
+ testr.fail(ctx, "'{}' not in '{}'\n", n, h)
+ ;;
+}
+
+const revfindat = {ctx, idx, h, n
+ match std.strrfind(h, n)
+ | `std.Some i:
+ if i == idx
+ testr.ok(ctx)
+ else
+ testr.fail(ctx, "wrong location {} != {} ('{}' in '{}')", i, idx, n, h)
+ ;;
+ | `std.None:
+ testr.fail(ctx, "'{}' not in '{}'\n", n, h)
+ ;;
+}