authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-02-14 02:58:15 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-02-14 02:58:15 -08:00
logf0711a7e22d94c87706a83c255e41f1821bdac92
treedd5011ad876ad090c433d2331624124fd5ce657a
parentf1bb7611d250bae8a3c7a217387c74a0061e2f77

update to 0.13 and add tests


5 files changed, 34 insertions(+), 2 deletions(-)

build.zig+12
......@@ -22,4 +22,16 @@ pub fn build(b: *std.Build) void {
2222
2323 const run_step = b.step("run", "Run the app");
2424 run_step.dependOn(&run_cmd.step);
25
26 const tests = b.addTest(.{
27 .root_source_file = b.path("test.zig"),
28 .target = target,
29 .optimize = mode,
30 });
31 deps.addAllTo(tests);
32
33 const test_step = b.step("test", "Run all library tests");
34 const tests_run = b.addRunArtifact(tests);
35 tests_run.has_side_effects = true;
36 test_step.dependOn(&tests_run.step);
2537}
licenses.txt+1
......@@ -1,5 +1,6 @@
11MIT:
22= https://spdx.org/licenses/MIT
33- This
4- git https://github.com/nektro/zig-expect
45- git https://github.com/nektro/zig-leven
56- git https://github.com/nektro/zig-licenses-text
src/lib.zig-2
......@@ -14,7 +14,6 @@ pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 {
1414 ind = i;
1515 }
1616 }
17
1817 return licenses.spdx[ind.?][0];
1918}
2019
......@@ -23,7 +22,6 @@ pub fn detectInDir(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 {
2322 (try testLicenseFile(alloc, dir, "LICENSE.md")) orelse
2423 (try testLicenseFile(alloc, dir, "LICENSE.txt")) orelse
2524 return null;
26
2725 defer alloc.free(b);
2826 return try detect(alloc, b);
2927}
test.zig created+19
......@@ -0,0 +1,19 @@
1const std = @import("std");
2const detect = @import("detect-license");
3const expect = @import("expect").expect;
4
5test {
6 std.testing.refAllDeclsRecursive(detect);
7}
8test {
9 const alloc = std.testing.allocator;
10 const src = @embedFile("./LICENSE");
11 const license = try detect.detect(alloc, src);
12 try expect(license).toEqualString("MIT");
13}
14test {
15 const alloc = std.testing.allocator;
16 const dir = std.fs.cwd();
17 const license = try detect.detectInDir(alloc, dir);
18 try expect(license).toEqualString("MIT");
19}
zig.mod+2
......@@ -6,3 +6,5 @@ description: Given an input text guess which SPDX license it most likely is an i
66dependencies:
77 - src: git https://github.com/nektro/zig-licenses-text
88 - src: git https://github.com/nektro/zig-leven
9root_dependencies:
10 - src: git https://github.com/nektro/zig-expect