Changes
4 changed files (+83/-2)
-
-
@@ -69,6 +69,32 @@ b.getInstallStep().dependOn(&man.step);} } // "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,7 +190,59 @@ self.utc = true;return; } 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 {
-
-
-
@@ -147,3 +147,7 @@ return ExitCode.generic_error.code();}, } } test { _ = @import("./RunOptions.zig"); }
-
-
-
@@ -60,8 +60,7 @@ try env.put("TZ", "UTC");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);
-