diff options
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/src/main.zig b/src/main.zig index c36c4eb7..c7f1f960 100644 --- a/src/main.zig +++ b/src/main.zig @@ -286,15 +286,6 @@ fn hasPane(index: []const u8, serial: u32) bool { return false; } -test "--wait finds the pane /index names a file by, spaces and all, and sees it gone" { - const index = "1 term 0 /home/u 1\n4 text 1 /tmp/a b.txt 2\n"; - try std.testing.expectEqual(@as(?u32, 4), paneShowing(index, "/tmp/a b.txt")); - try std.testing.expectEqual(@as(?u32, null), paneShowing(index, "/tmp/a")); - try std.testing.expect(hasPane(index, 4) and !hasPane(index, 2)); - try std.testing.expect(isDel("new 5 /x\ndel 4 /tmp/a b.txt\n", 4)); - try std.testing.expect(!isDel("del 41 /x\n", 4) and !isDel("undel 4\n", 4)); -} - fn badArgs(io: std.Io, comptime fmt: []const u8, args: anytype) noreturn { die(io, fmt ++ "\nTry 'pardes --help'.", args); } @@ -349,18 +340,6 @@ fn libcResult(rc: usize) c_int { return -1; } -test "tcgetattr writes nothing past a Zig termios" { - if (comptime !(builtin.os.tag == .linux and builtin.abi.isGnu())) return error.SkipZigTest; - const master = std.c.open("/dev/ptmx", .{ .ACCMODE = .RDWR, .NOCTTY = true, .CLOEXEC = true }, @as(std.c.mode_t, 0)); - if (master < 0) return error.SkipZigTest; - defer _ = std.c.close(master); - var s: extern struct { t: std.c.termios, canary: [32]u8 } = .{ .t = undefined, .canary = @splat(0xAA) }; - try std.testing.expectEqual(0, std.c.tcgetattr(master, &s.t)); - try std.testing.expectEqualSlices(u8, &@as([32]u8, @splat(0xAA)), &s.canary); - try std.testing.expectEqual(0, std.c.tcsetattr(master, .NOW, &s.t)); - try std.testing.expectEqual(-1, std.c.tcgetattr(-1, &s.t)); -} - // init.gpa, what the tui, gui and detached shells allocate from, is their // own fixed arena (memory.host) in a release build, spilling to libc's // malloc, and std.start's DebugAllocator in Debug. Zig 0.17's std.start @@ -1072,6 +1051,38 @@ fn parseCtrlKey(raw: []const u8) ?u21 { return c; } +/// Where Recent's file (0.24) and the store before it were kept: +/// $XDG_STATE_HOME/pardes, else ~/.local/state/pardes. A state file that +/// holds no Recent yet reads them once (Db.zig). +fn oldRecentDir(arena: std.mem.Allocator, env: *const std.process.Environ.Map) ?[]const u8 { + if (env.get("XDG_STATE_HOME")) |base| if (base.len != 0 and std.Io.Dir.path.isAbsolute(base)) + return std.Io.Dir.path.join(arena, &.{ base, "pardes" }) catch null; + const home = env.get("HOME") orelse return null; + if (home.len == 0) return null; + return std.Io.Dir.path.join(arena, &.{ home, ".local", "state", "pardes" }) catch null; +} + +test "--wait finds the pane /index names a file by, spaces and all, and sees it gone" { + const index = "1 term 0 /home/u 1\n4 text 1 /tmp/a b.txt 2\n"; + try std.testing.expectEqual(@as(?u32, 4), paneShowing(index, "/tmp/a b.txt")); + try std.testing.expectEqual(@as(?u32, null), paneShowing(index, "/tmp/a")); + try std.testing.expect(hasPane(index, 4) and !hasPane(index, 2)); + try std.testing.expect(isDel("new 5 /x\ndel 4 /tmp/a b.txt\n", 4)); + try std.testing.expect(!isDel("del 41 /x\n", 4) and !isDel("undel 4\n", 4)); +} + +test "tcgetattr writes nothing past a Zig termios" { + if (comptime !(builtin.os.tag == .linux and builtin.abi.isGnu())) return error.SkipZigTest; + const master = std.c.open("/dev/ptmx", .{ .ACCMODE = .RDWR, .NOCTTY = true, .CLOEXEC = true }, @as(std.c.mode_t, 0)); + if (master < 0) return error.SkipZigTest; + defer _ = std.c.close(master); + var s: extern struct { t: std.c.termios, canary: [32]u8 } = .{ .t = undefined, .canary = @splat(0xAA) }; + try std.testing.expectEqual(0, std.c.tcgetattr(master, &s.t)); + try std.testing.expectEqualSlices(u8, &@as([32]u8, @splat(0xAA)), &s.canary); + try std.testing.expectEqual(0, std.c.tcsetattr(master, .NOW, &s.t)); + try std.testing.expectEqual(-1, std.c.tcgetattr(-1, &s.t)); +} + test { _ = pardes.config.User; _ = @import("crash.zig"); @@ -1096,14 +1107,3 @@ test { if (comptime pardes.platform == .gui) _ = @import("gui/gui.zig"); if (comptime pardes.font_picker) _ = @import("fonts.zig"); } - -/// Where Recent's file (0.24) and the store before it were kept: -/// $XDG_STATE_HOME/pardes, else ~/.local/state/pardes. A state file that -/// holds no Recent yet reads them once (Db.zig). -fn oldRecentDir(arena: std.mem.Allocator, env: *const std.process.Environ.Map) ?[]const u8 { - if (env.get("XDG_STATE_HOME")) |base| if (base.len != 0 and std.Io.Dir.path.isAbsolute(base)) - return std.Io.Dir.path.join(arena, &.{ base, "pardes" }) catch null; - const home = env.get("HOME") orelse return null; - if (home.len == 0) return null; - return std.Io.Dir.path.join(arena, &.{ home, ".local", "state", "pardes" }) catch null; -} |
