summaryrefslogtreecommitdiff
path: root/src/ninep/events.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-09 00:52:52 -0300
committerGabriel Schneider <[email protected]>2026-11-09 01:28:28 -0300
commit5157579ff7f9ae0cfc3c7629e953da05bce340fc (patch)
tree02147789efdcea998981efcfe05d4bcb3e9bb7b0 /src/ninep/events.zig
parent4c4b9bf54d77dbc0f9f4e2619746908e501c6001 (diff)
downloadpardes-5157579ff7f9ae0cfc3c7629e953da05bce340fc.tar.gz
pardes-5157579ff7f9ae0cfc3c7629e953da05bce340fc.zip
tests: at the end of their files: every top-level test block of the 46 files that had one mid-file (the locality analysis's 45 and test/hxdiff.zig; gui.zig, macos.zig, look, host_io, 9p_io, terminal, tui, mouse, fs, replica, layout among them, 11,429 test lines), with the functions only tests call, moved after the file's code in their order, a mechanical move (.scratch/suites/tests_to_end.py), zig fmt'd; the unit suites pass as before (tui 1486/1487, gui 1536/1537, core 956/956 on both), macos.zig only parse-checked here
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/ninep/events.zig')
-rw-r--r--src/ninep/events.zig90
1 files changed, 45 insertions, 45 deletions
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index b00df909..20cb4e6e 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -592,37 +592,6 @@ fn editSpan(old: []const u8, off: usize, len: usize, bytes: []const u8) Span {
return .{ .at = @intCast(head), .removed = @intCast(old.len - tail - head), .inserted = @intCast(n - tail - head) };
}
-test "an edit's span is where the texts before and after it differ" {
- const reference = struct {
- fn span(old: []const u8, new: []const u8) Span {
- const both = @min(old.len, new.len);
- var head: usize = 0;
- while (head < both and old[head] == new[head]) head += 1;
- var tail: usize = 0;
- while (tail < both - head and old[old.len - 1 - tail] == new[new.len - 1 - tail]) tail += 1;
- return .{ .at = @intCast(head), .removed = @intCast(old.len - tail - head), .inserted = @intCast(new.len - tail - head) };
- }
- }.span;
- var prng = std.Random.DefaultPrng.init(3);
- const r = prng.random();
- var old: [24]u8 = undefined;
- var new: [48]u8 = undefined;
- var bytes: [24]u8 = undefined;
- for (0..20000) |_| {
- const old_len = r.uintAtMost(usize, old.len);
- for (old[0..old_len]) |*c| c.* = "ab"[r.uintLessThan(usize, 2)];
- const off = r.uintAtMost(usize, old_len);
- const len = r.uintAtMost(usize, old_len - off);
- const n = r.uintAtMost(usize, bytes.len);
- for (bytes[0..n]) |*c| c.* = "ab"[r.uintLessThan(usize, 2)];
- @memcpy(new[0..off], old[0..off]);
- @memcpy(new[off..][0..n], bytes[0..n]);
- @memcpy(new[off + n ..][0 .. old_len - off - len], old[off + len .. old_len]);
- const new_len = old_len - len + n;
- try std.testing.expectEqual(reference(old[0..old_len], new[0..new_len]), editSpan(old[0..old_len], off, len, bytes[0..n]));
- }
-}
-
/// Records `<origin><action><q0> <q1> <flag> <n> <text>` for a pane a
/// script reads; a text of max_record_text and over is sent as none. One
/// that follows another with no place of its own (a chorded exec's
@@ -859,6 +828,51 @@ const serialOf = th.serialOf;
const Node = tree.Node;
const Status = tree.Status;
+fn drainEvents(p: *Pardes, node: u64, store: []u8, out: [][]const u8) [][]const u8 {
+ var used: usize = 0;
+ var n: usize = 0;
+ while (n < out.len) {
+ const a = rd(p, node, 0, 4096);
+ if (a.reply.status != .ok) break;
+ @memcpy(store[used..][0..a.bytes.len], a.bytes);
+ out[n] = store[used..][0..a.bytes.len];
+ used += a.bytes.len;
+ n += 1;
+ }
+ return out[0..n];
+}
+
+test "an edit's span is where the texts before and after it differ" {
+ const reference = struct {
+ fn span(old: []const u8, new: []const u8) Span {
+ const both = @min(old.len, new.len);
+ var head: usize = 0;
+ while (head < both and old[head] == new[head]) head += 1;
+ var tail: usize = 0;
+ while (tail < both - head and old[old.len - 1 - tail] == new[new.len - 1 - tail]) tail += 1;
+ return .{ .at = @intCast(head), .removed = @intCast(old.len - tail - head), .inserted = @intCast(new.len - tail - head) };
+ }
+ }.span;
+ var prng = std.Random.DefaultPrng.init(3);
+ const r = prng.random();
+ var old: [24]u8 = undefined;
+ var new: [48]u8 = undefined;
+ var bytes: [24]u8 = undefined;
+ for (0..20000) |_| {
+ const old_len = r.uintAtMost(usize, old.len);
+ for (old[0..old_len]) |*c| c.* = "ab"[r.uintLessThan(usize, 2)];
+ const off = r.uintAtMost(usize, old_len);
+ const len = r.uintAtMost(usize, old_len - off);
+ const n = r.uintAtMost(usize, bytes.len);
+ for (bytes[0..n]) |*c| c.* = "ab"[r.uintLessThan(usize, 2)];
+ @memcpy(new[0..off], old[0..off]);
+ @memcpy(new[off..][0..n], bytes[0..n]);
+ @memcpy(new[off + n ..][0 .. old_len - off - len], old[off + len .. old_len]);
+ const new_len = old_len - len + n;
+ try std.testing.expectEqual(reference(old[0..old_len], new[0..new_len]), editSpan(old[0..old_len], off, len, bytes[0..n]));
+ }
+}
+
test "a stream read at an offset inside its last answer gets the rest of it again, as bash's read seeks back" {
const p = try withFile(testing.allocator, "one\n");
defer p.deinit();
@@ -921,20 +935,6 @@ test "event records are acme's bytes, one per read, and .again when empty" {
try testing.expectEqual(@as(u16, 0), p.fs.listeners);
}
-fn drainEvents(p: *Pardes, node: u64, store: []u8, out: [][]const u8) [][]const u8 {
- var used: usize = 0;
- var n: usize = 0;
- while (n < out.len) {
- const a = rd(p, node, 0, 4096);
- if (a.reply.status != .ok) break;
- @memcpy(store[used..][0..a.bytes.len], a.bytes);
- out[n] = store[used..][0..a.bytes.len];
- used += a.bytes.len;
- n += 1;
- }
- return out[0..n];
-}
-
test "a write through the filesystem is reported once, attributed to the file it came through" {
const gpa = testing.allocator;
const p = try withFile(gpa, "one\ntwo\n");