summaryrefslogtreecommitdiff
path: root/src/ninep/tree.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep/tree.zig')
-rw-r--r--src/ninep/tree.zig132
1 files changed, 66 insertions, 66 deletions
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig
index 8d3c599f..59ef5ef4 100644
--- a/src/ninep/tree.zig
+++ b/src/ninep/tree.zig
@@ -115,7 +115,7 @@ pub fn changesPane(p: *Pardes, req: Req) bool {
return switch (req.op) {
.write => true,
.setattr => truncates(req),
- .open => req.node == @intFromEnum(TopFile.new),
+ .open => req.node == @backingInt(TopFile.new),
.release => req.remove or holdsLines(p, req) or holdsPage(p, req),
.read => holdsPage(p, req),
.lookup, .getattr, .readdir => false,
@@ -258,7 +258,7 @@ pub const TopFile = enum(u5) {
/// The files opened lately, closed ones too, a line each:
/// `open|closed <path>`, most recent first.
recent,
- /// `pardes -`'s: a directory written, its +Pager made or emptied; a
+ /// `pardes -`'s: a directory written, a new +Pager made there; a
/// read of the same open answers its serial.
pager,
@@ -279,7 +279,7 @@ pub const TopFile = enum(u5) {
}
};
-pub const root: u64 = @intFromEnum(TopFile.root);
+pub const root: u64 = @backingInt(TopFile.root);
/// Declaration order is readdir order.
pub const PaneFile = enum(u5) {
@@ -363,11 +363,11 @@ pub const Node = packed struct(u64) {
pub fn of(serial: u32, file: PaneFile) u64 {
std.debug.assert(serial != 0);
- return @bitCast(Node{ .file = @intFromEnum(file), .serial = serial });
+ return @bitCast(Node{ .file = @backingInt(file), .serial = serial });
}
pub fn ofCol(serial: u32, file: ColFile) u64 {
- return @bitCast(Node{ .file = @intFromEnum(file), .serial = col_bit | @as(u59, serial) });
+ return @bitCast(Node{ .file = @backingInt(file), .serial = col_bit | @as(u59, serial) });
}
pub fn target(node: u64) ?Target {
@@ -424,9 +424,9 @@ pub fn resolveSelf(p: *Pardes, path: []const u8) ?u64 {
// `new` is reached in /pane, where the panes it makes are.
const top = std.meta.stringToEnum(TopFile, first) orelse return sources.node(normalized);
if (top == .root or top == .new or top == .pane or parts.next() != null) return null;
- return @intFromEnum(top);
+ return @backingInt(top);
}
- const next = parts.next() orelse return @intFromEnum(TopFile.pane);
+ const next = parts.next() orelse return @backingInt(TopFile.pane);
// `new` is served on the wire but deliberately unreachable from an editor
// path: this resolves Look targets and hover previews, and a preview that
// opened `new` to see what was there would make a pane per hover.
@@ -509,7 +509,7 @@ pub fn fitErr(text: []const u8, out: []u8) []const u8 {
test "a reason past 128 bytes keeps its end: the path in it gives up its middle" {
var out: [128]u8 = undefined;
- const long = "Save /home/someone/projects/" ++ "deep/" ** 30 ++ "file.txt: no such directory";
+ const long = "Save /home/someone/projects/" ++ std.mem.asBytes(&@as([30][5]u8, @splat("deep/".*))) ++ "file.txt: no such directory";
const fit = fitErr(long, &out);
try testing.expect(fit.len <= 128);
try testing.expect(std.mem.startsWith(u8, fit, "Save /home/someone/"));
@@ -517,7 +517,7 @@ test "a reason past 128 bytes keeps its end: the path in it gives up its middle"
try testing.expect(std.mem.indexOf(u8, fit, "…") != null);
try testing.expect(std.unicode.utf8ValidateSlice(fit));
// No path: the whole text's middle goes, the end stays.
- const words = "why " ** 40 ++ "the reason";
+ const words = std.mem.asBytes(&@as([40][4]u8, @splat("why ".*))) ++ "the reason";
try testing.expect(std.mem.endsWith(u8, fitErr(words, &out), "the reason"));
try testing.expectEqualStrings("short", fitErr("short", &out));
// Through the tree: a look at a long ./ name not there, a miss, says
@@ -525,7 +525,7 @@ test "a reason past 128 bytes keeps its end: the path in it gives up its middle"
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
var line: [512]u8 = undefined;
- const r = th.wr(p, Node.of(serialOf(p), .look), try std.fmt.bufPrint(&line, "./{s}x.txt\n", .{"no-such-dir/" ** 20}));
+ const r = th.wr(p, Node.of(serialOf(p), .look), try std.fmt.bufPrint(&line, "./{s}x.txt\n", .{std.mem.asBytes(&@as([20][12]u8, @splat("no-such-dir/".*)))}));
try testing.expectEqual(Status.ok, r.reply.status);
try testing.expect(th.logHas(p, "x.txt: no such file"));
}
@@ -606,7 +606,7 @@ fn attrOf(p: *Pardes, target: Target) ?Reply.Attr {
switch (target) {
.top => |f| return .{
.name = f.fileName(),
- .node = @intFromEnum(f),
+ .node = @backingInt(f),
.dir = f.dir(),
.mode = f.mode(),
.size = topSize(p, f),
@@ -695,11 +695,11 @@ fn lookup(p: *Pardes, req: Req, target: Target) Reply {
const parent: u64 = switch (target) {
.top => |top| if (top.dir()) root else return Reply.fail(req.tag, E.NOTDIR),
.pane => |t| switch (t.file) {
- .dir => @intFromEnum(TopFile.pane),
+ .dir => @backingInt(TopFile.pane),
.pty => Node.of(t.serial, .dir),
else => return Reply.fail(req.tag, E.NOTDIR),
},
- .col => |c| if (c.file == .dir) @intFromEnum(TopFile.col) else return Reply.fail(req.tag, E.NOTDIR),
+ .col => |c| if (c.file == .dir) @backingInt(TopFile.col) else return Reply.fail(req.tag, E.NOTDIR),
};
return handle(p, .{ .tag = req.tag, .op = .getattr, .node = parent });
}
@@ -709,12 +709,12 @@ fn lookup(p: *Pardes, req: Req, target: Target) Reply {
.root => root: {
if (std.mem.eql(u8, name, "os")) return fs.osHandle(p, .{ .tag = req.tag, .op = .getattr, .node = fs.os_root });
// `new` is reached in /pane, where the panes it makes are.
- if (std.meta.stringToEnum(TopFile, name)) |t| if (t != .root and t != .new) break :root @intFromEnum(t);
+ if (std.meta.stringToEnum(TopFile, name)) |t| if (t != .root and t != .new) break :root @backingInt(t);
if (sources.node(name)) |n| return sources.handle(p, .{ .tag = req.tag, .op = .getattr, .node = n });
return Reply.fail(req.tag, E.NOENT);
},
.pane => pane: {
- if (std.mem.eql(u8, name, new_pane)) break :pane @intFromEnum(TopFile.new);
+ if (std.mem.eql(u8, name, new_pane)) break :pane @backingInt(TopFile.new);
// A pane directory is its serial, in decimal digits and never 0.
if (name.len > 10) return Reply.fail(req.tag, E.NOENT);
for (name) |c| if (c < '0' or c > '9') return Reply.fail(req.tag, E.NOENT);
@@ -778,13 +778,13 @@ fn readdir(p: *Pardes, req: Req, target: Target) Reply {
// The guide, then what describes the session, then the
// files that act, then the directories.
inline for (.{ TopFile.README, TopFile.index, TopFile.status, TopFile.focus, TopFile.ctl, TopFile.commands, TopFile.recent, TopFile.look, TopFile.exec, TopFile.pager, TopFile.log, TopFile.screen, TopFile.listeners, TopFile.layout, TopFile.tag, TopFile.tagexec, TopFile.pane, TopFile.col }) |t| {
- if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @intFromEnum(t), t.dir(), t.fileName());
+ if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @backingInt(t), t.dir(), t.fileName());
}
if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, fs.os_root, true, "os");
sources.stage(p, out, "", &skip);
},
.pane => {
- if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @intFromEnum(TopFile.new), false, TopFile.new.fileName());
+ if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @backingInt(TopFile.new), false, TopFile.new.fileName());
var last: u32 = 0;
while (nextSerialAfter(p, last)) |serial| {
last = serial;
@@ -1380,7 +1380,7 @@ test "a listing read in chunks is what it was at the open, however the panes cha
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
for ([_]TopFile{ .index, .layout, .recent, .ctl }) |file| {
- const node = @intFromEnum(file);
+ const node = @backingInt(file);
const whole = try testing.allocator.dupe(u8, th.rd(p, node, 0, 1 << 16).bytes);
defer testing.allocator.free(whole);
const h = th.call(p, .{ .tag = 1, .op = .open, .node = node }).reply.handle;
@@ -1391,7 +1391,7 @@ test "a listing read in chunks is what it was at the open, however the panes cha
// Something changes between the chunks.
const made = try th.newPane(p);
_ = th.wr(p, Node.of(made, .name), "/tmp/pardes-frozen-listing.txt\n");
- _ = th.wr(p, @intFromEnum(TopFile.ctl), "Verbose off\n");
+ _ = th.wr(p, @backingInt(TopFile.ctl), "Verbose off\n");
while (true) {
const more = th.call(p, .{ .tag = 2, .op = .read, .node = node, .handle = h, .off = got.items.len, .size = 7 }).bytes;
if (more.len == 0) break;
@@ -1399,7 +1399,7 @@ test "a listing read in chunks is what it was at the open, however the panes cha
}
_ = th.call(p, .{ .tag = 3, .op = .release, .node = node, .handle = h, .opened = true });
try testing.expectEqualStrings(whole, got.items);
- _ = th.wr(p, @intFromEnum(TopFile.ctl), "Verbose on\n");
+ _ = th.wr(p, @backingInt(TopFile.ctl), "Verbose on\n");
}
}
@@ -1420,7 +1420,7 @@ test "filesystem inspection preserves pending and displayed Look hover" {
} });
try testing.expect(p.look_hover_wait != null);
const body = Node.of(serialOf(p), .body);
- const screen_node = @intFromEnum(TopFile.screen);
+ const screen_node = @backingInt(TopFile.screen);
for (0..2) |phase| {
if (phase == 1) {
for (0..delay) |_| p.update(.tick);
@@ -1431,7 +1431,7 @@ test "filesystem inspection preserves pending and displayed Look hover" {
const requests = [_]Req{
.{ .tag = 1, .op = .lookup, .node = root, .data = "screen" },
.{ .tag = 1, .op = .lookup, .node = root, .data = "status" },
- .{ .tag = 1, .op = .getattr, .node = @intFromEnum(TopFile.pane) },
+ .{ .tag = 1, .op = .getattr, .node = @backingInt(TopFile.pane) },
.{ .tag = 2, .op = .getattr, .node = body },
.{ .tag = 3, .op = .open, .node = body },
.{ .tag = 4, .op = .read, .node = body, .size = 5 },
@@ -1460,14 +1460,14 @@ test "log stats 0 however much it holds, a stream as acme's generated files are"
defer p.deinit();
_ = th.wr(p, Node.of(th.serialOf(p), .exec), "Msg a record for the log\n");
try testing.expect(th.logHas(p, "a record for the log"));
- try testing.expectEqual(@as(u64, 0), call(p, .{ .tag = 1, .op = .getattr, .node = @intFromEnum(TopFile.log) }).reply.attr.size);
+ try testing.expectEqual(@as(u64, 0), call(p, .{ .tag = 1, .op = .getattr, .node = @backingInt(TopFile.log) }).reply.attr.size);
}
test "filesystem pane creation and truncation cancel Look hover" {
const requests = [_]Req{
// Opening `new` is what makes a pane now; walking to it makes none,
// and so must leave a pending hover alone.
- .{ .tag = 2, .op = .open, .node = @intFromEnum(TopFile.new) },
+ .{ .tag = 2, .op = .open, .node = @backingInt(TopFile.new) },
.{ .tag = 3, .op = .setattr, .node = 0, .truncate = true },
};
for (requests) |request| {
@@ -1494,17 +1494,17 @@ test "README names every file the tree serves" {
return false;
}
};
- inline for (@typeInfo(TopFile).@"enum".fields) |f| {
- const t: TopFile = @enumFromInt(f.value);
+ inline for (@typeInfo(TopFile).@"enum".field_values) |value| {
+ const t: TopFile = @fromBackingInt(@intCast(value));
if (t != .root and !words.has(t.fileName())) {
std.debug.print("README does not mention /{s}\n", .{t.fileName()});
return error.Undocumented;
}
}
- inline for (@typeInfo(PaneFile).@"enum".fields) |f| {
- const t: PaneFile = @enumFromInt(f.value);
+ inline for (@typeInfo(PaneFile).@"enum".field_values) |value| {
+ const t: PaneFile = @fromBackingInt(@intCast(value));
const ok = if (t == .dir) true else if (t.inPty() and t != .pty)
- std.mem.indexOf(u8, fs.help, "pty/" ++ comptime @as(PaneFile, @enumFromInt(f.value)).fileName()) != null
+ std.mem.indexOf(u8, fs.help, "pty/" ++ comptime @as(PaneFile, @fromBackingInt(@intCast(value))).fileName()) != null
else
words.has(t.fileName());
if (!ok) {
@@ -1532,8 +1532,8 @@ test "readdir lists the root and a pane directory without creating anything" {
try testing.expectEqualStrings(name, top[i].name);
try testing.expectEqual(i >= 16, top[i].dir);
}
- try testing.expectEqual(@intFromEnum(TopFile.pane), top[16].node);
- try testing.expectEqual(@intFromEnum(TopFile.col), top[17].node);
+ try testing.expectEqual(@backingInt(TopFile.pane), top[16].node);
+ try testing.expectEqual(@backingInt(TopFile.col), top[17].node);
try testing.expectEqual(fs.os_root, top[18].node);
var idbuf: [16]u8 = undefined;
try testing.expect(th.nameAt(top, try std.fmt.bufPrint(&idbuf, "{d}", .{serial})) == null);
@@ -1556,7 +1556,7 @@ test "readdir lists the root and a pane directory without creating anything" {
try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .getattr, .node = entry.node }).reply.status);
try testing.expectEqual(before, p.next_serial);
}
- const panes_dir = rdir(p, @intFromEnum(TopFile.pane), 0);
+ const panes_dir = rdir(p, @backingInt(TopFile.pane), 0);
const listed = th.dirents(panes_dir.bytes, &buf);
var idname: [16]u8 = undefined;
const own = th.nameAt(listed, try std.fmt.bufPrint(&idname, "{d}", .{serial})).?;
@@ -1567,16 +1567,16 @@ test "readdir lists the root and a pane directory without creating anything" {
// client that stats every name a listing gave it inert.
const shown = th.nameAt(listed, new_pane).?;
try testing.expect(!shown.dir);
- try testing.expectEqual(Status.ok, look_up(p, @intFromEnum(TopFile.pane), new_pane).reply.status);
- try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .getattr, .node = @intFromEnum(TopFile.new) }).reply.status);
+ try testing.expectEqual(Status.ok, look_up(p, @backingInt(TopFile.pane), new_pane).reply.status);
+ try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .getattr, .node = @backingInt(TopFile.new) }).reply.status);
try testing.expectEqual(before, p.next_serial);
const dir = rdir(p, Node.of(serial, .dir), 0);
const files = th.dirents(dir.bytes, &buf);
try testing.expectEqual(@as(usize, 18), files.len);
for ([_][]const u8{
- "name", "body", "tag", "ctl", "addr", "dot", "limit", "data", "xdata",
- "sel", "dirty", "mark", "scroll", "errors", "event", "look", "exec", "tagexec",
+ "name", "body", "tag", "ctl", "addr", "dot", "limit", "data", "xdata",
+ "sel", "dirty", "mark", "scroll", "errors", "event", "look", "exec", "tagexec",
}, 0..) |name, i|
try testing.expectEqualStrings(name, files[i].name);
try testing.expect(th.nameAt(files, ".") == null);
@@ -1590,7 +1590,7 @@ test "readdir lists the root and a pane directory without creating anything" {
try testing.expectEqual(before, p.next_serial);
try testing.expectEqual(E.NOTDIR, rdir(p, Node.of(serial, .body), 0).errno());
- try testing.expectEqual(E.NOTDIR, rdir(p, @intFromEnum(TopFile.index), 0).errno());
+ try testing.expectEqual(E.NOTDIR, rdir(p, @backingInt(TopFile.index), 0).errno());
}
test "lookup resolves top files, pane serials and pane files" {
@@ -1599,7 +1599,7 @@ test "lookup resolves top files, pane serials and pane files" {
defer p.deinit();
const serial = serialOf(p);
- try testing.expectEqual(@as(u64, @intFromEnum(TopFile.index)), look_up(p, root, "index").reply.attr.node);
+ try testing.expectEqual(@as(u64, @backingInt(TopFile.index)), look_up(p, root, "index").reply.attr.node);
try testing.expect(!look_up(p, root, "status").reply.attr.dir);
try testing.expectEqual(@as(u16, 0o444), look_up(p, root, "status").reply.attr.mode);
try testing.expectEqual(@as(u16, 0o666), look_up(p, root, "look").reply.attr.mode);
@@ -1609,17 +1609,17 @@ test "lookup resolves top files, pane serials and pane files" {
try testing.expectEqual(E.NOENT, look_up(p, root, "nosuchthing").errno());
try testing.expectEqual(E.NOENT, look_up(p, root, "self").errno());
try testing.expectEqual(E.NOENT, look_up(p, root, "cons").errno());
- try testing.expectEqual(E.NOTDIR, look_up(p, @intFromEnum(TopFile.index), "x").errno());
+ try testing.expectEqual(E.NOTDIR, look_up(p, @backingInt(TopFile.index), "x").errno());
var idbuf: [16]u8 = undefined;
const serial_name = try std.fmt.bufPrint(&idbuf, "{d}", .{serial});
try testing.expectEqual(E.NOENT, look_up(p, root, serial_name).errno());
- const dir = look_up(p, @intFromEnum(TopFile.pane), serial_name);
+ const dir = look_up(p, @backingInt(TopFile.pane), serial_name);
try testing.expectEqual(Node.of(serial, .dir), dir.reply.attr.node);
try testing.expect(dir.reply.attr.dir);
try testing.expectEqualStrings(serial_name, dir.reply.attr.name);
- try testing.expectEqual(E.NOENT, look_up(p, @intFromEnum(TopFile.pane), "99999").errno());
- try testing.expectEqual(E.NOENT, look_up(p, @intFromEnum(TopFile.pane), "0").errno());
+ try testing.expectEqual(E.NOENT, look_up(p, @backingInt(TopFile.pane), "99999").errno());
+ try testing.expectEqual(E.NOENT, look_up(p, @backingInt(TopFile.pane), "0").errno());
const body = look_up(p, Node.of(serial, .dir), "body");
try testing.expectEqual(Node.of(serial, .body), body.reply.attr.node);
@@ -1636,19 +1636,19 @@ test "opening /pane/new makes a pane and removing one closes it" {
const p = try withFile(gpa, "first\n");
defer p.deinit();
const before = p.next_serial;
- const panes_dir = @intFromEnum(TopFile.pane);
+ const panes_dir = @backingInt(TopFile.pane);
// Browsing /pane creates nothing, and neither does walking or stat-ing
// `new` itself: only an open does. That is what lets `new` be listed at
// all, since `ls -l` stats every name a listing handed it.
try testing.expectEqual(Status.ok, rdir(p, panes_dir, 0).reply.status);
try testing.expectEqual(Status.ok, look_up(p, panes_dir, new_pane).reply.status);
- try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .getattr, .node = @intFromEnum(TopFile.new) }).reply.status);
+ try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .getattr, .node = @backingInt(TopFile.new) }).reply.status);
try testing.expectEqual(before, p.next_serial);
// The open makes the pane and hands back its serial; the read only
// observes, so two reads of one fid answer the same pane.
- const made = call(p, .{ .tag = 2, .op = .open, .node = @intFromEnum(TopFile.new) });
+ const made = call(p, .{ .tag = 2, .op = .open, .node = @backingInt(TopFile.new) });
try testing.expectEqual(Status.ok, made.reply.status);
try testing.expectEqual(before + 1, p.next_serial);
const serial = before + 1;
@@ -1656,7 +1656,7 @@ test "opening /pane/new makes a pane and removing one closes it" {
var expected: [16]u8 = undefined;
const want = try std.fmt.bufPrint(&expected, "{d}\n", .{serial});
for (0..2) |_| {
- const answer = call(p, .{ .tag = 3, .op = .read, .node = @intFromEnum(TopFile.new), .handle = made.reply.handle, .size = 64 });
+ const answer = call(p, .{ .tag = 3, .op = .read, .node = @backingInt(TopFile.new), .handle = made.reply.handle, .size = 64 });
try testing.expectEqualStrings(want, answer.bytes);
}
@@ -1670,10 +1670,10 @@ test "opening /pane/new makes a pane and removing one closes it" {
// A second open is a second pane, and releasing a clone fid leaves the
// pane it made standing.
- const second = call(p, .{ .tag = 4, .op = .open, .node = @intFromEnum(TopFile.new) });
+ const second = call(p, .{ .tag = 4, .op = .open, .node = @backingInt(TopFile.new) });
try testing.expectEqual(Status.ok, second.reply.status);
try testing.expect(second.reply.handle != made.reply.handle);
- _ = call(p, .{ .tag = 5, .op = .release, .node = @intFromEnum(TopFile.new), .handle = made.reply.handle, .opened = true });
+ _ = call(p, .{ .tag = 5, .op = .release, .node = @backingInt(TopFile.new), .handle = made.reply.handle, .opened = true });
try testing.expect(p.paneBySerial(serial) != null);
try testing.expectEqualStrings("hi", p.panes[id].?.file.?.content);
@@ -1691,7 +1691,7 @@ test "opening /pane/new makes a pane and removing one closes it" {
// Tremove closes the pane it names, and nothing else in the tree.
try testing.expectEqual(E.PERM, th.rmdir(p, Node.of(serial, .body)).errno());
- try testing.expectEqual(E.PERM, th.rmdir(p, @intFromEnum(TopFile.index)).errno());
+ try testing.expectEqual(E.PERM, th.rmdir(p, @backingInt(TopFile.index)).errno());
try testing.expect(p.paneBySerial(serial) != null);
try testing.expectEqual(Status.ok, th.rmdir(p, Node.of(serial, .dir)).reply.status);
try testing.expect(p.paneBySerial(serial) == null);
@@ -1702,7 +1702,7 @@ test "every open that holds something is one record, named by its handle only on
const p = try th.withTerm(testing.allocator);
defer p.deinit();
const serial = serialOf(p);
- const log = @intFromEnum(TopFile.log);
+ const log = @backingInt(TopFile.log);
const event = Node.of(serial, .event);
const run = Node.of(serial, .pty_run);
const logged = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
@@ -1731,15 +1731,15 @@ test "directories walk to their parents" {
defer p.deinit();
for ([_]struct { node: u64, parent: u64 }{
.{ .node = root, .parent = root },
- .{ .node = @intFromEnum(TopFile.pane), .parent = root },
- .{ .node = Node.of(serialOf(p), .dir), .parent = @intFromEnum(TopFile.pane) },
+ .{ .node = @backingInt(TopFile.pane), .parent = root },
+ .{ .node = Node.of(serialOf(p), .dir), .parent = @backingInt(TopFile.pane) },
.{ .node = fs.os_root, .parent = root },
}) |case| {
const result = look_up(p, case.node, "..");
try testing.expectEqual(Status.ok, result.reply.status);
try testing.expectEqual(case.parent, result.reply.attr.node);
}
- try testing.expectEqual(E.NOTDIR, look_up(p, @intFromEnum(TopFile.index), "..").errno());
+ try testing.expectEqual(E.NOTDIR, look_up(p, @backingInt(TopFile.index), "..").errno());
try testing.expectEqual(E.NOTDIR, look_up(p, Node.of(serialOf(p), .body), "..").errno());
}
@@ -1750,10 +1750,10 @@ test "editor paths resolve to the same nodes the wire serves" {
var path: [64]u8 = undefined;
try testing.expectEqual(root, resolveSelf(p, "").?);
try testing.expectEqual(root, resolveSelf(p, "/./pane/../").?);
- try testing.expectEqual(@intFromEnum(TopFile.index), resolveSelf(p, "index").?);
- try testing.expectEqual(@intFromEnum(TopFile.status), resolveSelf(p, "status").?);
+ try testing.expectEqual(@backingInt(TopFile.index), resolveSelf(p, "index").?);
+ try testing.expectEqual(@backingInt(TopFile.status), resolveSelf(p, "status").?);
try testing.expect(resolveSelf(p, "new") == null);
- try testing.expectEqual(@intFromEnum(TopFile.pane), resolveSelf(p, "pane").?);
+ try testing.expectEqual(@backingInt(TopFile.pane), resolveSelf(p, "pane").?);
try testing.expectEqual(Node.of(serial, .dir), resolveSelf(p, try std.fmt.bufPrint(&path, "pane/{d}", .{serial})).?);
try testing.expectEqual(Node.of(serial, .sel), resolveSelf(p, try std.fmt.bufPrint(&path, "pane/{d}/sel", .{serial})).?);
try testing.expect(resolveSelf(p, try std.fmt.bufPrint(&path, "pane/{d}/pty/ctl", .{serial})) == null);
@@ -1802,7 +1802,7 @@ test "random placements, refused or not, leave no pane under its tag and two row
const action = r.uintLessThan(u8, 8);
switch (action) {
0 => _ = th.wr(p, Node.of(at, .exec), "New\n"),
- 1 => _ = call(p, .{ .tag = 1, .op = .open, .node = @intFromEnum(TopFile.new) }),
+ 1 => _ = call(p, .{ .tag = 1, .op = .open, .node = @backingInt(TopFile.new) }),
2 => _ = th.wr(p, Node.of(at, .exec), "Newcol\n"),
3 => _ = th.wr(p, Node.of(at, .exec), "Edit =\n"),
4 => _ = th.wr(p, Node.of(at, .exec), "Tty\n"),
@@ -1825,7 +1825,7 @@ test "at the pane cap, pane/new, look and New each say so, and look reads back e
// Tall enough that the column holds every pane at its tag and two rows,
// and wide enough that each tag, the session directory's +New, is one.
p.update(.{ .resize = .{ .cols = 400, .rows = pardes.MAX_PANES * 4 } });
- const new = @intFromEnum(TopFile.new);
+ const new = @backingInt(TopFile.new);
while (p.freeSlot() != null) try testing.expectEqual(Status.ok, call(p, .{ .tag = 1, .op = .open, .node = new }).reply.status);
var want: [64]u8 = undefined;
const said = try std.fmt.bufPrint(&want, "no space for a pane: {d} max", .{pardes.MAX_PANES});
@@ -1842,7 +1842,7 @@ test "at the pane cap, pane/new, look and New each say so, and look reads back e
var dir_buf: [4096]u8 = undefined;
const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
var line: [4200]u8 = undefined;
- const look_node = @intFromEnum(TopFile.look);
+ const look_node = @backingInt(TopFile.look);
const looked = th.wr(p, look_node, try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{dir}));
try testing.expect(looked.errno() != 0);
try testing.expect(std.mem.indexOf(u8, looked.reply.ename, said) != null);
@@ -1859,7 +1859,7 @@ test "at the pane cap, pane/new, look and New each say so, and look reads back e
test "nothing a mount's close or a no-op truncate sends waits on the editor: a held line runs at its next step" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- const exec = @intFromEnum(TopFile.exec);
+ const exec = @backingInt(TopFile.exec);
// `> exec` truncates nothing; `> body` does.
try testing.expect(!needsQuiet(p, .{ .tag = 1, .op = .setattr, .node = exec, .truncate = true }));
try testing.expect(!changesPane(p, .{ .tag = 1, .op = .setattr, .node = exec, .truncate = true }));
@@ -1877,7 +1877,7 @@ test "nothing a mount's close or a no-op truncate sends waits on the editor: a h
test "a command line cut across writes runs once whole, and the last runs at release; an Edit block waits for its end" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const exec = @intFromEnum(TopFile.exec);
+ const exec = @backingInt(TopFile.exec);
const h = call(p, .{ .tag = 1, .op = .open, .node = exec, .omode = 1 }).reply.handle;
try testing.expect(h != 0);
// Each piece fills its Twrite (a client's one write cut at msize).
@@ -1908,12 +1908,12 @@ test "a refused open, create or remove says why in words and logs no err; a refu
const serial = serialOf(p);
// pane/new is read, never written: a write is refused, and is no
// failure the log tells of.
- const new = th.wr(p, @intFromEnum(TopFile.new), "x\n");
+ const new = th.wr(p, @backingInt(TopFile.new), "x\n");
try testing.expectEqual(Status.err, new.reply.status);
try testing.expectEqualStrings("permission denied", new.reply.ename);
const made = call(p, .{ .tag = 2, .op = .open, .node = Node.of(serial, .body), .create = true });
try testing.expectEqualStrings("permission denied", made.reply.ename);
- const gone = th.rmdir(p, @intFromEnum(TopFile.index));
+ const gone = th.rmdir(p, @backingInt(TopFile.index));
try testing.expectEqual(Status.err, gone.reply.status);
try testing.expect(gone.reply.ename.len > 0 and !std.ascii.isUpper(gone.reply.ename[0]));
// An OTRUNC open's truncation of data after a failed addr: refused, no err.
@@ -1963,7 +1963,7 @@ test "a write with no newline waits for its newline or the close, whatever its s
test "look and exec read back what their own open's write touched; a fresh open reads the session's last" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const exec = @intFromEnum(TopFile.exec);
+ const exec = @backingInt(TopFile.exec);
const first = p.panes[0].?.serial;
const mine = call(p, .{ .tag = 1, .op = .open, .node = exec, .omode = 2 }).reply.handle;
const theirs = call(p, .{ .tag = 2, .op = .open, .node = exec, .omode = 2 }).reply.handle;
@@ -2015,7 +2015,7 @@ test "a rename of a pane's directory or file is refused as not permitted" {
test "no placement leaves a pane shorter than its tag and two rows; a full column refuses the next" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
- const new = @intFromEnum(TopFile.new);
+ const new = @backingInt(TopFile.new);
var made: usize = 1;
const refused = while (made < pardes.MAX_PANES) : (made += 1) {
const a = call(p, .{ .tag = 1, .op = .open, .node = new });
@@ -2080,7 +2080,7 @@ test "a pane made from pane/new goes last in its column, even when the last pane
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
for (0..3) |_| {
- const made = call(p, .{ .tag = 1, .op = .open, .node = @intFromEnum(TopFile.new) }).reply.handle;
+ const made = call(p, .{ .tag = 1, .op = .open, .node = @backingInt(TopFile.new) }).reply.handle;
p.sync();
try testing.expectEqual(made, p.panes[p.col_panes[0][p.col_n[0] - 1]].?.serial);
}