main.zig
1 const std = @import("std"); 2 const zitadel = @import("zitadel"); 3 4 pub fn main(init: std.process.Init) !void { 5 // Prints to stderr, ignoring potential errors. 6 std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); 7 try zitadel.bufferedPrint(init.io); 8 9 const x: i32 = 5; 10 const y: i32 = 16; 11 // const z: i32 = zitadel.add(x, y); 12 const z: i32 = zitadel.add_c(x, y); 13 14 // Zig 0.16+ IO: avoid global std.io helpers. 15 // Use the IO handles provided by std.process.Init, and buffer explicitly. 16 var stdout_buffer: [1024]u8 = undefined; 17 var stdout_writer = std.Io.File.stdout().writer(init.io, &stdout_buffer); 18 const stdout = &stdout_writer.interface; 19 20 try stdout.print("{d} + {d} = {d}\n", .{ x, y, z }); 21 try stdout.flush(); 22 } 23 24 test "simple test" { 25 const gpa = std.testing.allocator; 26 var list: std.ArrayList(i32) = .empty; 27 defer list.deinit(gpa); // Try commenting this out and see if zig detects the memory leak! 28 try list.append(gpa, 42); 29 try std.testing.expectEqual(@as(i32, 42), list.pop()); 30 } 31 32 test "fuzz example" { 33 const Context = struct { 34 fn testOne(context: @This(), input: []const u8) anyerror!void { 35 _ = context; 36 // Try passing `--fuzz` to `zig build test` and see if it manages to fail this test case! 37 try std.testing.expect(!std.mem.eql(u8, "canyoufindme", input)); 38 } 39 }; 40 try std.testing.fuzz(Context{}, Context.testOne, .{}); 41 }