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 {...@@ -22,4 +22,16 @@ pub fn build(b: *std.Build) void {
2222
23 const run_step = b.step("run", "Run the app");23 const run_step = b.step("run", "Run the app");
24 run_step.dependOn(&run_cmd.step);24 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);
25}37}
licenses.txt+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1MIT:1MIT:
2= https://spdx.org/licenses/MIT2= https://spdx.org/licenses/MIT
3- This3- This
4- git https://github.com/nektro/zig-expect
4- git https://github.com/nektro/zig-leven5- git https://github.com/nektro/zig-leven
5- git https://github.com/nektro/zig-licenses-text6- 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 {...@@ -14,7 +14,6 @@ pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 {
14 ind = i;14 ind = i;
15 }15 }
16 }16 }
17
18 return licenses.spdx[ind.?][0];17 return licenses.spdx[ind.?][0];
19}18}
2019
...@@ -23,7 +22,6 @@ pub fn detectInDir(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 {...@@ -23,7 +22,6 @@ pub fn detectInDir(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 {
23 (try testLicenseFile(alloc, dir, "LICENSE.md")) orelse22 (try testLicenseFile(alloc, dir, "LICENSE.md")) orelse
24 (try testLicenseFile(alloc, dir, "LICENSE.txt")) orelse23 (try testLicenseFile(alloc, dir, "LICENSE.txt")) orelse
25 return null;24 return null;
26
27 defer alloc.free(b);25 defer alloc.free(b);
28 return try detect(alloc, b);26 return try detect(alloc, b);
29}27}
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...@@ -6,3 +6,5 @@ description: Given an input text guess which SPDX license it most likely is an i
6dependencies:6dependencies:
7 - src: git https://github.com/nektro/zig-licenses-text7 - src: git https://github.com/nektro/zig-licenses-text
8 - src: git https://github.com/nektro/zig-leven8 - src: git https://github.com/nektro/zig-leven
9root_dependencies:
10 - src: git https://github.com/nektro/zig-expect