diff options
Diffstat (limited to 'src/ninep/tree.zig')
| -rw-r--r-- | src/ninep/tree.zig | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig index dfcf7097..f7ca0cb7 100644 --- a/src/ninep/tree.zig +++ b/src/ninep/tree.zig @@ -519,29 +519,6 @@ pub fn fitErr(text: []const u8, out: []u8) []const u8 { return std.fmt.bufPrint(out, "{s}" ++ ell ++ "{s}", .{ text[0..a], text[b..] }) catch text[0..out.len]; } -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/" ++ 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/")); - try testing.expect(std.mem.endsWith(u8, fit, "file.txt: no such directory")); - 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 = 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 - // why at the end of its err record, the name giving 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", .{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")); -} - /// A refusal with no reason of its own said in Plan 9's words, not the C /// library's (`Operation not permitted`); each maps back to its errno in /// 9ns (enameToErrno), EPERM's to EACCES as Plan 9's does. @@ -1383,17 +1360,6 @@ fn writeNow(p: *Pardes, req: Req, target: Target) Reply { // ---- tests ---- -test { - _ = events; - _ = pane; - _ = addr; - _ = ctl; - _ = pty; - _ = cols; - _ = sources; - _ = screen; -} - const testing = std.testing; const th = @import("testing.zig"); const config = @import("../config.zig"); @@ -1405,6 +1371,40 @@ const look_up = th.look_up; const withFile = th.withFile; const serialOf = th.serialOf; +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/" ++ 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/")); + try testing.expect(std.mem.endsWith(u8, fit, "file.txt: no such directory")); + 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 = 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 + // why at the end of its err record, the name giving 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", .{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")); +} + +test { + _ = events; + _ = pane; + _ = addr; + _ = ctl; + _ = pty; + _ = cols; + _ = sources; + _ = screen; +} + test "a listing read in chunks is what it was at the open, however the panes change between reads" { const p = try th.withFile(testing.allocator, "x\n"); defer p.deinit(); |
