diff options
author | Ori Bernstein <ori@eigenstate.org> | 2015-04-13 00:45:52 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2015-04-13 00:45:52 -0700 |
commit | 7f7f4995545803a947444b6babf04fb54cce0173 (patch) | |
tree | 784a9e1f194744234d0049d048329719f23c1048 /libregex/test/testmatch.myr | |
parent | 769c1e76b0af199cf5a8d3336de9f3f642f1b688 (diff) | |
download | mc-7f7f4995545803a947444b6babf04fb54cce0173.tar.gz |
Move code to subdir in preparation for merging with mc.
Diffstat (limited to 'libregex/test/testmatch.myr')
-rw-r--r-- | libregex/test/testmatch.myr | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libregex/test/testmatch.myr b/libregex/test/testmatch.myr new file mode 100644 index 0000000..2c0195b --- /dev/null +++ b/libregex/test/testmatch.myr @@ -0,0 +1,34 @@ +use std +use regex + +pkg = + const testmatch : (pat : byte[:], text : byte[:] -> void) + const dbgmatch : (pat : byte[:], text : byte[:] -> void) +;; + +const testmatch = {pat, text + run(regex.compile(pat), pat, text) +} + +const dbgmatch = {pat, text + run(regex.dbgcompile(pat), pat, text) +} + +const run = {regex, pat, text + var i + match regex + | `std.Ok re: + match regex.exec(re, text) + | `std.Some m: + std.put("Matched %s via %s : %i\n", text, pat, m.len) + for i = 0; i < m.len; i++ + std.put("\tmatch %i: %s\n", i, m[i]) + ;; + | `std.None: + std.put("No match of %s via %s\n", text, pat) + ;; + regex.free(re) + | `std.Fail err: + std.put("failed to compile regex") + ;; +} |