summaryrefslogtreecommitdiff
path: root/lib/std/test
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-06-07 09:54:09 -0700
committerOri Bernstein <ori@eigenstate.org>2017-06-07 09:54:09 -0700
commit5518b9657c07d4ee93ac1db4c97b6d4ec164d42b (patch)
treefbd276632a4e0a231694f3601dde3e515a0d8388 /lib/std/test
parent2698fe288642465ec636dca1c8f4ff88a22c5afe (diff)
downloadmc-5518b9657c07d4ee93ac1db4c97b6d4ec164d42b.tar.gz
Add address builder function.
Nice for building addresses with defaults.
Diffstat (limited to 'lib/std/test')
-rw-r--r--lib/std/test/netaddr.myr24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/std/test/netaddr.myr b/lib/std/test/netaddr.myr
new file mode 100644
index 0000000..fd9ab84
--- /dev/null
+++ b/lib/std/test/netaddr.myr
@@ -0,0 +1,24 @@
+use std
+use testr
+
+const main = {
+ testr.run([
+ /* 64 bit tests */
+ [.name="nop", .fn={ctx; matches(ctx, "tcp!foo!bar", "tcp!foo!bar", "nope", "nope")}],
+ [.name="addboth", .fn={ctx; matches(ctx, "tcp!foo!bar", "foo", "tcp", "bar")}],
+ [.name="addnet", .fn={ctx; matches(ctx, "tcp!foo!bar", "foo!bar", "tcp", "")}],
+ [.name="addport", .fn={ctx; matches(ctx, "tcp!foo!bar", "tcp!foo", "tcp", "bar")}],
+ [.name="addnetport", .fn={ctx; matches(ctx, "net!foo!bar", "foo", "", "bar")}],
+ ][:])
+}
+
+const matches = {ctx, expected, addr, net, port
+ var s
+
+ s = std.netaddr(addr, net, port)
+ testr.check(ctx, std.sleq(expected, s), \
+ "mismatch: expected {}, got {} from ({}, {}, {})\n", \
+ expected, s, addr, net, port)
+ std.slfree(s)
+}
+