Untitled
unknown
plain_text
2 years ago
1.5 kB
13
Indexable
const std = @import("std");
const builtin = @import("builtin");
const expect = std.testing.expect;
//
pub fn main() !void {
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
// stdout is for the actual output of your application, for example if you
// are implementing gzip, then only the compressed bytes should be sent to
// stdout, not any debugging messages.
const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
try stdout.print("Run `zig build test` to run the tests.\n", .{});
try bw.flush(); // don't forget to flush!
}
const light = enum(u2) { red, green, blue, yellow };
const Coord = struct { x: f32 = 0, y: f32 = 0, z: f32 = 0 };
const Tag = enum(u2) { p1, p2, p3, p4 };
const Pack = union(Tag) { p1: i32, p2: f64, p3: bool, p4: u8 };
test "newtest" {
const status: light = light.yellow;
var point = Coord{ .x = 5.56, .y = 7.62, .z = 3.88 };
point.x = 9.99;
var packdata = Pack{ .p2 = 2.7 };
switch (packdata) {
.p1 => |*p1type| p1type.* += 1,
.p2 => |*p2type| p2type.* += 2,
.p3 => |*p3type| p3type.* = !p3type.*,
.p4 => |*p4type| p4type.* += 3,
}
std.debug.print("color code is: {d}\n", .{@intFromEnum(status)});
std.debug.print("coordinate is: {},{},{}\n", .{ point.x, point.y, point.z });
std.debug.print("pack parameter {}\n", .{packdata.p2});
}
Editor is loading...
Leave a Comment