diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 03:51:15 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | 79a1e816ceb13ef81b712007716c8add2de75434 (patch) | |
| tree | 1714b1bf19da3a58be2623ffe29e3f8be1b21fe3 /test/behaviour | |
| parent | a22b579ad2df8d1811f0e194fa1bbc06e2282cf8 (diff) | |
| parent | f1af015f01e4e8d42f6224c4d4063f3aea218f5a (diff) | |
| download | pardes-79a1e816ceb13ef81b712007716c8add2de75434.tar.gz pardes-79a1e816ceb13ef81b712007716c8add2de75434.zip | |
integration: the terminal a module of its own, with the plumber whole and the walker's cheaper compile
A merge of term-phase1a and pardes-next, no conflicts. core-test (the core with no terminal) 411 passed, 535 skipped of 946; shell-test (the same tests, the terminal compiled in) 989/989, on tui.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/behaviour')
| -rw-r--r-- | test/behaviour/addons.zig | 13 | ||||
| -rw-r--r-- | test/behaviour/plumber.zig | 43 |
2 files changed, 51 insertions, 5 deletions
diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig index 9b96a3d6..451cb1e3 100644 --- a/test/behaviour/addons.zig +++ b/test/behaviour/addons.zig @@ -185,7 +185,7 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the try std.testing.expect(has(try s.read("/screen"), "\"src\":[0,0,4,2]")); } -test "addons: a Plumb rule to a loaded kind opens that kind's pane, is refused naming one not loaded, and with its kind gone the look falls through to text" { +test "addons: a plumbing rule to a loaded kind opens that kind's pane; to one not loaded, or with its kind gone, the look falls through to text" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); try load(&s, Session.image_addon); @@ -196,9 +196,14 @@ test "addons: a Plumb rule to a loaded kind opens that kind's pane, is refused n // A PNG under a name no kind claims. const png = "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x02\x00\x00\x00\x90wS\xde\x00\x00\x00\x0cIDATx\x9cc\xf8\xcf\xc0\x00\x00\x03\x01\x01\x00\xc9\xfe\x92\xef\x00\x00\x00\x00IEND\xaeB`\x82"; try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "red.pic", .data = png }); - try std.testing.expect(try s.refused("/ctl", "Plumb suffix .pic to nokind\n") != 0); - try std.testing.expect(has(s.said, "Plumb: invalid port: url, dir, file or a loaded kind")); - try s.write("/ctl", "Plumb suffix .pic to image\n"); + // A port no kind reads is no refusal (plumber(4) never refuses one): + // nothing reads it, the rule set starts nothing, and Look looks itself. + const rule = "type is text\ndata matches '.*\\.pic'\narg isfile $data\nplumb to {s}\n\ninclude basic\n"; + try s.replace("/plumb/rules", s.at(rule, .{"nokind"})); + try s.write("/look", s.at("{s}/red.pic\n", .{dir})); + try std.testing.expect(has(try s.read(s.at("/pane/{d}/tag", .{try s.focused()})), "red.pic")); + try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Del\n"); + try s.replace("/plumb/rules", s.at(rule, .{"image"})); try s.write("/look", s.at("{s}/red.pic\n", .{dir})); try std.testing.expectEqual(try paneOf(&s, "image"), try s.focused()); try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Del\n"); diff --git a/test/behaviour/plumber.zig b/test/behaviour/plumber.zig index f87c0449..4726714b 100644 --- a/test/behaviour/plumber.zig +++ b/test/behaviour/plumber.zig @@ -14,7 +14,7 @@ test "plumber: plumb/rules reads the rules in force, a write adds rule sets, > r try std.testing.expect(has(try s.read("/plumb/rules"), "type\tis\ttext\ndata\tmatches\t'https?://.*'\nplumb\tto\tweb\n\n")); // Added, the last rule set at the close. try s.write("/plumb/rules", "type is text\ndata matches 'gopher://.*'\nplumb to web\n"); - try std.testing.expect(std.mem.endsWith(u8, try s.read("/plumb/rules"), "plumb\tto\tedit\n\ntype\tis\ttext\ndata\tmatches\t'gopher://.*'\nplumb\tto\tweb\n\n")); + try std.testing.expect(std.mem.endsWith(u8, try s.read("/plumb/rules"), "attr\tadd\taction=showdiff\nplumb\tto\tedit\n\ntype\tis\ttext\ndata\tmatches\t'gopher://.*'\nplumb\tto\tweb\n\n")); // A rule set refused at the write it is whole in, said with its line; // the rules stay as they were. const before = try s.read("/plumb/rules"); @@ -63,3 +63,44 @@ test "plumber: plumb/send takes a message in its six lines and data, written in try s.write("/plumb/send", s.at("test\n\n{s}\ntext\n\n{d}\nplumbed.txt:2", .{ dir, "plumbed.txt:2".len })); try std.testing.expect(has(try s.read("/index"), "/plumbed.txt")); } + +test "plumber: a port's file is read by programs: each open made before a send gets its own copy, one made after none, and a client rule's message waits for the port's first reader" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "seen.txt", .data = "one\ntwo\n" }); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; + // A file for each port the rules name, read-only, as plumber(4)'s. + try std.testing.expectEqual(@as(u16, 0o444), (try s.stat("/plumb/web")).mode & 0o777); + try std.testing.expectEqual(@as(u16, 0o444), (try s.stat("/plumb/edit")).mode & 0o777); + // Two readers of edit, then a look: each reads the look's message, + // and the editor opens the file all the same. + const a = try s.hold("/plumb/edit", 0); + const b = try s.hold("/plumb/edit", 0); + try s.write("/look", s.at("{s}/seen.txt\n", .{dir})); + const want = s.at("pardes\nedit\n{s}\ntext\n\n{d}\n{s}/seen.txt", .{ "/", dir.len + "/seen.txt".len, dir }); + try std.testing.expectEqualStrings(want, try s.readFid(a)); + try std.testing.expectEqualStrings(want, try s.readFid(b)); + try std.testing.expect(has(try s.read("/index"), "/seen.txt")); + // An open made after the send has nothing: its read waits. + const late = try s.hold("/plumb/edit", 0); + try std.testing.expectError(error.Refused, s.readFid(late)); + s.clunk(late); + s.clunk(a); + s.clunk(b); + // A port only a program reads, its rule a client: the message waits + // for the port's first reader, the program started read nothing. + try s.write("/plumb/rules", "type is text\ndata matches 'letter-[0-9]+'\nplumb to seemail\nplumb client true\n\n"); + try s.write("/plumb/send", "test\n\n/\ntext\n\n9\nletter-42"); + const first = try s.hold("/plumb/seemail", 0); + try std.testing.expectEqualStrings("test\nseemail\n/\ntext\n\n9\nletter-42", try s.readFid(first)); + try std.testing.expectError(error.Refused, s.readFid(first)); + // Once read, a port's message goes to its readers, no program started. + try s.write("/plumb/send", "test\n\n/\ntext\n\n9\nletter-43"); + try std.testing.expectEqualStrings("test\nseemail\n/\ntext\n\n9\nletter-43", try s.readFid(first)); + s.clunk(first); + // Not to be written. + try std.testing.expectError(error.Refused, s.hold("/plumb/seemail", 1)); +} |
