···11+const std = @import("std");
22+const ft = @import("ft");
33+44+pub fn main() !void {
55+ // Prints to stderr, ignoring potential errors.
66+ std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
77+ try ft.bufferedPrint();
88+}
99+1010+test "simple test" {
1111+ const gpa = std.testing.allocator;
1212+ var list: std.ArrayList(i32) = .empty;
1313+ defer list.deinit(gpa); // Try commenting this out and see if zig detects the memory leak!
1414+ try list.append(gpa, 42);
1515+ try std.testing.expectEqual(@as(i32, 42), list.pop());
1616+}
1717+1818+test "fuzz example" {
1919+ const Context = struct {
2020+ fn testOne(context: @This(), input: []const u8) anyerror!void {
2121+ _ = context;
2222+ // Try passing `--fuzz` to `zig build test` and see if it manages to fail this test case!
2323+ try std.testing.expect(!std.mem.eql(u8, "canyoufindme", input));
2424+ }
2525+ };
2626+ try std.testing.fuzz(Context{}, Context.testOne, .{});
2727+}
+23
src/root.zig
···11+//! By convention, root.zig is the root source file when making a library.
22+const std = @import("std");
33+44+pub fn bufferedPrint() !void {
55+ // Stdout is for the actual output of your application, for example if you
66+ // are implementing gzip, then only the compressed bytes should be sent to
77+ // stdout, not any debugging messages.
88+ var stdout_buffer: [1024]u8 = undefined;
99+ var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
1010+ const stdout = &stdout_writer.interface;
1111+1212+ try stdout.print("Run `zig build test` to run the tests.\n", .{});
1313+1414+ try stdout.flush(); // Don't forget to flush!
1515+}
1616+1717+pub fn add(a: i32, b: i32) i32 {
1818+ return a + b;
1919+}
2020+2121+test "basic add functionality" {
2222+ try std.testing.expect(add(3, 7) == 10);
2323+}