From d6a5e284b88afa52b2995ea790e3a5b8243e0217 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 6 Feb 2025 04:36:23 -0800 Subject: [PATCH] revamp and add tests --- .gitignore | 6 ++++++ build.zig | 19 +++++++++++++++++++ licenses.txt | 4 ++++ mime.zig | 6 +----- test.zig | 10 ++++++++++ zigmod.yml | 2 ++ 6 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 .gitignore create mode 100644 build.zig create mode 100644 licenses.txt create mode 100644 test.zig diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..755aa68f03a30361a954cb1bfbf823ba9fa604ae --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.zig-cache +zig-out +.zigmod +deps.zig +files.zig +zigmod.lock diff --git a/build.zig b/build.zig new file mode 100644 index 0000000000000000000000000000000000000000..b47f682c58763b46ddfb8587ce76b7c62554c234 --- /dev/null +++ b/build.zig @@ -0,0 +1,19 @@ +const std = @import("std"); +const deps = @import("./deps.zig"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug; + + const tests = b.addTest(.{ + .root_source_file = b.path("test.zig"), + .target = target, + .optimize = mode, + }); + deps.addAllTo(tests); + + const test_step = b.step("test", "Run all library tests"); + const tests_run = b.addRunArtifact(tests); + tests_run.has_side_effects = true; + test_step.dependOn(&tests_run.step); +} diff --git a/licenses.txt b/licenses.txt new file mode 100644 index 0000000000000000000000000000000000000000..728089f444b1699f3c94f6841d719abda91c029f --- /dev/null +++ b/licenses.txt @@ -0,0 +1,4 @@ +MIT: += https://spdx.org/licenses/MIT +- This +- git https://github.com/nektro/zig-expect diff --git a/mime.zig b/mime.zig index 2999294b6c5cca5b4ee79e67820e548f4fb73319..0b20c3017497f6ac4dc02b9c996b45f7ec8b1133 100644 --- a/mime.zig +++ b/mime.zig @@ -4,7 +4,7 @@ const string = []const u8; // Many entries added from https://pagure.io/mailcap/blob/master/f/mime.types // Last updated as of 9699055a1b4dfb90f7594ee2e8dda705fa56d3b8 -const types = std.ComptimeStringMap(string, .{ +pub const map = std.StaticStringMap(string).initComptime(.{ .{ ".1", "application/x-troff-man" }, .{ ".123", "application/vnd.lotus-1-2-3" }, .{ ".1clr", "application/clr" }, @@ -1408,7 +1408,3 @@ const types = std.ComptimeStringMap(string, .{ .{ ".zone", "text/dns" }, .{ ".zst", "application/zstd" }, }); - -pub fn typeByExtension(comptime ext: string) ?string { - return types.get(ext); -} diff --git a/test.zig b/test.zig new file mode 100644 index 0000000000000000000000000000000000000000..804c0b05528d0b311888ce0a723404b1bbed3675 --- /dev/null +++ b/test.zig @@ -0,0 +1,10 @@ +const std = @import("std"); +const mime = @import("mime"); +const expect = @import("expect").expect; + +test { + try expect(mime.map.get(".html")).toEqualString("text/html"); +} +test { + try expect(mime.map.get(".sillybogo")).toBeNull(); +} diff --git a/zigmod.yml b/zigmod.yml index a0b50e5f7da454e52fc2e7a1bd2bde9ed328f9b2..06bda89fa558071dbd8ec8fd9214d267addd3d22 100644 --- a/zigmod.yml +++ b/zigmod.yml @@ -2,3 +2,5 @@ id: f3k4y5cdrgemtq38ztm7kqjnr3tq9az396e8vu2a name: mime main: mime.zig license: MIT +root_dependencies: + - src: git https://github.com/nektro/zig-expect -- 2.54.0