aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-09-23 15:18:02 -0400
committerAndrew Kelley <superjoe30@gmail.com>2016-09-23 15:18:02 -0400
commite06885d64e3569719e9479c7069da7ad426a70d3 (patch)
tree075258e85acce6c4d5fb3a29225fc0d97fabfb26 /test
parent9ec6a78f121c8f61c10ea02f6949f27b0228ba16 (diff)
downloadzig-e06885d64e3569719e9479c7069da7ad426a70d3.tar.gz
zig-e06885d64e3569719e9479c7069da7ad426a70d3.zip
enums support member functions
Diffstat (limited to 'test')
-rw-r--r--test/cases/enum_with_members.zig30
-rw-r--r--test/self_hosted.zig1
2 files changed, 31 insertions, 0 deletions
diff --git a/test/cases/enum_with_members.zig b/test/cases/enum_with_members.zig
new file mode 100644
index 0000000000..cff5883b19
--- /dev/null
+++ b/test/cases/enum_with_members.zig
@@ -0,0 +1,30 @@
+const std = @import("std");
+const assert = std.debug.assert;
+const io = std.io;
+const str = std.str;
+
+enum ET {
+ SINT: i32,
+ UINT: u32,
+
+ pub fn print(a: &ET, buf: []u8) -> %usize {
+ return switch (*a) {
+ SINT => |x| { io.bufPrintInt(i32, buf, x) },
+ UINT => |x| { io.bufPrintInt(u32, buf, x) },
+ }
+ }
+}
+
+#attribute("test")
+fn enumWithMembers() {
+ const a = ET.SINT { -42 };
+ const b = ET.UINT { 42 };
+ var buf: [20]u8 = undefined;
+
+ assert(%%a.print(buf) == 3);
+ assert(str.eql(buf[0...3], "-42"));
+
+ assert(%%b.print(buf) == 2);
+ assert(str.eql(buf[0...2], "42"));
+}
+
diff --git a/test/self_hosted.zig b/test/self_hosted.zig
index 7b58684b05..80920758a4 100644
--- a/test/self_hosted.zig
+++ b/test/self_hosted.zig
@@ -13,6 +13,7 @@ const test_var_params = @import("cases/var_params.zig");
const test_const_slice_child = @import("cases/const_slice_child.zig");
const test_switch_prong_implicit_cast = @import("cases/switch_prong_implicit_cast.zig");
const test_switch_prong_err_enum = @import("cases/switch_prong_err_enum.zig");
+const test_enum_with_members = @import("cases/enum_with_members.zig");
// normal comment
/// this is a documentation comment