authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-02-06 04:36:23 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-02-06 04:36:23 -08:00
logd6a5e284b88afa52b2995ea790e3a5b8243e0217
treeeef39830cef6694339997e4a4c1bcf2dcb3bae7c
parenta6de80638189430453b81b579a0b14e811f8d3aa

revamp and add tests


6 files changed, 42 insertions(+), 5 deletions(-)

.gitignore created+6
......@@ -0,0 +1,6 @@
1.zig-cache
2zig-out
3.zigmod
4deps.zig
5files.zig
6zigmod.lock
build.zig created+19
......@@ -0,0 +1,19 @@
1const std = @import("std");
2const deps = @import("./deps.zig");
3
4pub fn build(b: *std.Build) void {
5 const target = b.standardTargetOptions(.{});
6 const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug;
7
8 const tests = b.addTest(.{
9 .root_source_file = b.path("test.zig"),
10 .target = target,
11 .optimize = mode,
12 });
13 deps.addAllTo(tests);
14
15 const test_step = b.step("test", "Run all library tests");
16 const tests_run = b.addRunArtifact(tests);
17 tests_run.has_side_effects = true;
18 test_step.dependOn(&tests_run.step);
19}
licenses.txt created+4
......@@ -0,0 +1,4 @@
1MIT:
2= https://spdx.org/licenses/MIT
3- This
4- git https://github.com/nektro/zig-expect
mime.zig+1-5
......@@ -4,7 +4,7 @@ const string = []const u8;
44// Many entries added from https://pagure.io/mailcap/blob/master/f/mime.types
55// Last updated as of 9699055a1b4dfb90f7594ee2e8dda705fa56d3b8
66
7const types = std.ComptimeStringMap(string, .{
7pub const map = std.StaticStringMap(string).initComptime(.{
88 .{ ".1", "application/x-troff-man" },
99 .{ ".123", "application/vnd.lotus-1-2-3" },
1010 .{ ".1clr", "application/clr" },
......@@ -1408,7 +1408,3 @@ const types = std.ComptimeStringMap(string, .{
14081408 .{ ".zone", "text/dns" },
14091409 .{ ".zst", "application/zstd" },
14101410});
1411
1412pub fn typeByExtension(comptime ext: string) ?string {
1413 return types.get(ext);
1414}
test.zig created+10
......@@ -0,0 +1,10 @@
1const std = @import("std");
2const mime = @import("mime");
3const expect = @import("expect").expect;
4
5test {
6 try expect(mime.map.get(".html")).toEqualString("text/html");
7}
8test {
9 try expect(mime.map.get(".sillybogo")).toBeNull();
10}
zigmod.yml+2
......@@ -2,3 +2,5 @@ id: f3k4y5cdrgemtq38ztm7kqjnr3tq9az396e8vu2a
22name: mime
33main: mime.zig
44license: MIT
5root_dependencies:
6 - src: git https://github.com/nektro/zig-expect