zig/test/cases/enum_with_members.zig
Andrew Kelley b581da41f8 remove compiler directives
* add `setFnTest`, `setFnVisible`, `setFnStaticEval`,
   `setFnNoInline` builtin functions to replace previous
   directive functionality
 * add `coldcc` and `nakedcc` as keywords which can be used as part
   of a function prototype.
 * `setDebugSafety` builtin can be used to set debug safety features
   at a per block scope level.
 * closes #169
2016-09-28 02:33:32 -04:00

32 lines
649 B
Zig

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) },
}
}
}
fn enumWithMembers() {
@setFnTest(this, true);
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"));
}