Changes
4 changed files (+83/-2)
-
-
@@ -69,6 +69,32 @@ pub fn build(b: *std.Build) void {} } // "zig build test" { const step = b.step("test", "Run unit tests"); const t = b.addTest(.{ .name = "unit_test", .target = target, .optimize = optimize, .root_source_file = b.path("src/main.zig"), }); t.linkLibC(); t.addCSourceFiles(.{ .files = &.{ "src/print.c", "src/sunriset.c", "src/sunwait.c", }, }); t.addIncludePath(b.path("src")); t.root_module.addCMacro("SUNWAIT_NOMAIN", ""); const run = b.addRunArtifact(t); step.dependOn(&run.step); } // "zig build behavior_test" { const step = b.step("behavior_test", "Run behavior matching tests");
-
-
-
@@ -190,9 +190,61 @@ fn parseArg(self: *@This(), arg: []const u8, args: *std.process.ArgIterator) Parreturn; } if (parseSuffixedLatitude(arg)) |lat| { self.latitude = lat; return; } if (parseSuffixedLongitude(arg)) |lon| { self.longitude = lon; return; } return ParseArgsError.UnknownArg; } fn parseSuffixedLatitude(x: []const u8) ?f64 { if (x.len <= 1) { return null; } const lastChar = x[x.len - 1]; const value = std.fmt.parseFloat(f64, x[0 .. x.len - 1]) catch return null; return switch (lastChar) { 'N' => value, 'S' => -value, else => null, }; } test parseSuffixedLatitude { try std.testing.expectEqual(29.977435, parseSuffixedLatitude("29.977435N")); try std.testing.expectEqual(-29.977435, parseSuffixedLatitude("29.977435S")); try std.testing.expectEqual(null, parseSuffixedLatitude("29.977435W")); } fn parseSuffixedLongitude(x: []const u8) ?f64 { if (x.len <= 1) { return null; } const lastChar = x[x.len - 1]; const value = std.fmt.parseFloat(f64, x[0 .. x.len - 1]) catch return null; return switch (lastChar) { 'E' => value, 'W' => -value, else => null, }; } test parseSuffixedLongitude { try std.testing.expectEqual(31.132484, parseSuffixedLongitude("31.132484E")); try std.testing.expectEqual(-31.132484, parseSuffixedLongitude("31.132484W")); try std.testing.expectEqual(null, parseSuffixedLongitude("31.132484N")); } pub fn toC(self: *const @This()) c.runStruct { return c.runStruct{ .latitude = self.latitude,
-
-
-
@@ -147,3 +147,7 @@ pub fn main() u8 {}, } } test { _ = @import("./RunOptions.zig"); }
-
-
-
@@ -60,8 +60,7 @@ test {const debug = try std.process.Child.run(.{ .allocator = std.testing.allocator, // TODO: Put coordinate once "poll" accepts lat/lon arguments .argv = &.{ config.new_bin, "--debug", "poll" }, .argv = &.{ config.new_bin, "--debug", "poll", "29.977435N", "31.132484E" }, .env_map = &env, }); defer std.testing.allocator.free(debug.stderr);
-