╭ changed ╮ │build.zig│ ╰─────────╯ ╭───────────────────────────────────────────────────────╮ │ 4 const target = b.standardTargetOptions(.{}); │ │ 5 const optimize = b.standardOptimizeOption(.{});│ │ 6 │ │ 7 + // main │ │ 8 const install_main_exe = blk: { │ │ 9 const exe = b.addExecutable(.{ │ │10 .name = "haxy", │ ╰───────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────╮ │32 │ │33 break :blk install_exe; │ │34 }; │ │35 + │ │36 + // module for using haxy as a library │ │37 + // (the commands below consume haxy this way) │ │38 + const haxy = b.addModule("haxy", .{ │ │39 + .root_source_file = b.path("src/lib.zig"), │ │40 + }); │ │41 + haxy.addImport("xit", b.dependency("xit", .{}).module("xit"));│ │42 │ │43 + // test │ │44 { │ │45 const unit_tests = b.addTest(.{ │ │46 .root_module = b.createModule(.{ │ ╰──────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────╮ │49 .optimize = optimize, │ │50 }), │ │51 }); │ │43 - unit_tests.root_module.addImport("xit", b.dependency("xit", .{}).module("xit"));│ │52 + unit_tests.root_module.addImport("haxy", haxy); │ │53 │ │54 const run_unit_tests = b.addRunArtifact(unit_tests); │ │55 run_unit_tests.has_side_effects = true; │ ╰────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────╮ │58 test_step.dependOn(&run_unit_tests.step);│ │59 } │ │60 │ │61 + // testnet │ │62 { │ │63 const unit_tests = b.addTest(.{ │ │64 .root_module = b.createModule(.{ │ ╰─────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────╮ │67 .optimize = optimize, │ │68 }), │ │69 }); │ │60 - unit_tests.root_module.addImport("xit", b.dependency("xit", .{}).module("xit"));│ │70 + unit_tests.root_module.addImport("haxy", haxy); │ │71 │ │72 const run_unit_tests = b.addRunArtifact(unit_tests); │ │73 run_unit_tests.has_side_effects = true; │ ╰────────────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ─────────╮ │src/test/event.zig│ ╰──────────────────╯ ╭───────────────────────────────────────────────────────╮ │ 1 const std = @import("std"); │ │ 2 -const builtin = @import("builtin"); │ │ 3 -const xit = @import("xit"); │ │ 2 +const hx = @import("haxy"); │ │ 3 +const evt = hx.event; │ │ 4 +const xit = hx.xit; │ │ 5 const rp = xit.repo; │ │ 6 const hash = xit.hash; │ │ 6 - │ │ 7 -const event_id_size: usize = 32; │ │ 8 - │ │ 9 -const EventData = union(enum) { │ │10 - issue: struct { │ │11 - title: []const u8, │ │12 - description: []const u8, │ │13 - tags: []const []const u8, │ │14 - }, │ │15 -}; │ │16 - │ │17 -const Event = struct { │ │18 - id: [event_id_size * 2]u8, │ │19 - data: EventData, │ │20 -}; │ │21 - │ │22 -fn randomId(random: std.Random) [event_id_size]u8 {│ │23 - var id_bytes: [event_id_size]u8 = undefined; │ │24 - random.bytes(&id_bytes); │ │25 - return id_bytes; │ │26 -} │ │ 7 │ │ 8 test "simple" { │ │ 9 const io = std.testing.io; │ ╰───────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────╮ │38 │ │39 var prng = std.Random.DefaultPrng.init(std.testing.random_seed);│ │40 │ │61 - const first_event_id = randomId(prng.random()); │ │41 + const first_event_id = evt.randomId(prng.random()); │ │42 │ │63 - const events_to_process = [_]Event{ │ │43 + const events_to_process = [_]evt.Event{ │ │44 .{ │ │45 .id = std.fmt.bytesToHex(first_event_id, .lower), │ │46 .data = .{ │ ╰────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────╮ │63 }, │ │64 }, │ │65 .{ │ │86 - .id = std.fmt.bytesToHex(randomId(prng.random()), .lower), │ │66 + .id = std.fmt.bytesToHex(evt.randomId(prng.random()), .lower), │ │67 .data = .{ │ │68 .issue = .{ │ │69 .title = "Search results ignore archived project filter",│ ╰─────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────╮ │73 }, │ │74 }, │ │75 .{ │ │96 - .id = std.fmt.bytesToHex(randomId(prng.random()), .lower), │ │76 + .id = std.fmt.bytesToHex(evt.randomId(prng.random()), .lower), │ │77 .data = .{ │ │78 .issue = .{ │ │79 .title = "Issue list does not persist selected sort order",│ ╰───────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────╮ │109 // read and parse all of the events from the repo│ │110 // │ │111 │ │132 - var events: std.ArrayList(Event) = .empty; │ │112 + var events: std.ArrayList(evt.Event) = .empty; │ │113 defer events.deinit(allocator); │ │114 │ │115 { │ ╰──────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯