this repo has no description

zig init

altagos.dev 65cd6ad9

+117
+2
.gitignore
··· 1 + .zig-cache/ 2 + zig-out/
+50
build.zig
··· 1 + const std = @import("std"); 2 + 3 + pub fn build(b: *std.Build) void { 4 + const target = b.standardTargetOptions(.{}); 5 + const optimize = b.standardOptimizeOption(.{}); 6 + 7 + const mod = b.addModule("ft", .{ 8 + .root_source_file = b.path("src/root.zig"), 9 + .target = target, 10 + }); 11 + 12 + const exe = b.addExecutable(.{ 13 + .name = "factorio_toolbox", 14 + .root_module = b.createModule(.{ 15 + .root_source_file = b.path("src/main.zig"), 16 + .target = target, 17 + .optimize = optimize, 18 + .imports = &.{ 19 + .{ .name = "ft", .module = mod }, 20 + }, 21 + }), 22 + }); 23 + b.installArtifact(exe); 24 + 25 + const run_step = b.step("run", "Run the app"); 26 + const run_cmd = b.addRunArtifact(exe); 27 + 28 + run_step.dependOn(&run_cmd.step); 29 + run_cmd.step.dependOn(b.getInstallStep()); 30 + 31 + if (b.args) |args| { 32 + run_cmd.addArgs(args); 33 + } 34 + 35 + const mod_tests = b.addTest(.{ 36 + .name = "mod tests", 37 + .root_module = mod, 38 + }); 39 + const run_mod_tests = b.addRunArtifact(mod_tests); 40 + 41 + const exe_tests = b.addTest(.{ 42 + .name = "exe tests", 43 + .root_module = exe.root_module, 44 + }); 45 + const run_exe_tests = b.addRunArtifact(exe_tests); 46 + 47 + const test_step = b.step("test", "Run tests"); 48 + test_step.dependOn(&run_mod_tests.step); 49 + test_step.dependOn(&run_exe_tests.step); 50 + }
+15
build.zig.zon
··· 1 + .{ 2 + .name = .factorio_toolbox, 3 + .version = "0.0.0", 4 + .fingerprint = 0x5506658b7a972311, // Changing this has security and trust implications. 5 + .minimum_zig_version = "0.16.0-dev.747+493ad58ff", 6 + .dependencies = .{}, 7 + .paths = .{ 8 + "build.zig", 9 + "build.zig.zon", 10 + "src", 11 + // For example... 12 + //"LICENSE", 13 + //"README.md", 14 + }, 15 + }
+27
src/main.zig
··· 1 + const std = @import("std"); 2 + const ft = @import("ft"); 3 + 4 + pub fn main() !void { 5 + // Prints to stderr, ignoring potential errors. 6 + std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); 7 + try ft.bufferedPrint(); 8 + } 9 + 10 + test "simple test" { 11 + const gpa = std.testing.allocator; 12 + var list: std.ArrayList(i32) = .empty; 13 + defer list.deinit(gpa); // Try commenting this out and see if zig detects the memory leak! 14 + try list.append(gpa, 42); 15 + try std.testing.expectEqual(@as(i32, 42), list.pop()); 16 + } 17 + 18 + test "fuzz example" { 19 + const Context = struct { 20 + fn testOne(context: @This(), input: []const u8) anyerror!void { 21 + _ = context; 22 + // Try passing `--fuzz` to `zig build test` and see if it manages to fail this test case! 23 + try std.testing.expect(!std.mem.eql(u8, "canyoufindme", input)); 24 + } 25 + }; 26 + try std.testing.fuzz(Context{}, Context.testOne, .{}); 27 + }
+23
src/root.zig
··· 1 + //! By convention, root.zig is the root source file when making a library. 2 + const std = @import("std"); 3 + 4 + pub fn bufferedPrint() !void { 5 + // Stdout is for the actual output of your application, for example if you 6 + // are implementing gzip, then only the compressed bytes should be sent to 7 + // stdout, not any debugging messages. 8 + var stdout_buffer: [1024]u8 = undefined; 9 + var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer); 10 + const stdout = &stdout_writer.interface; 11 + 12 + try stdout.print("Run `zig build test` to run the tests.\n", .{}); 13 + 14 + try stdout.flush(); // Don't forget to flush! 15 + } 16 + 17 + pub fn add(a: i32, b: i32) i32 { 18 + return a + b; 19 + } 20 + 21 + test "basic add functionality" { 22 + try std.testing.expect(add(3, 7) == 10); 23 + }