diff options
Diffstat (limited to 'test/behaviour')
| -rw-r--r-- | test/behaviour/columns_and_tags.zig | 3 | ||||
| -rw-r--r-- | test/behaviour/event.zig | 11 | ||||
| -rw-r--r-- | test/behaviour/limits.zig | 11 | ||||
| -rw-r--r-- | test/behaviour/look_and_exec.zig | 42 | ||||
| -rw-r--r-- | test/behaviour/settings.zig | 34 | ||||
| -rw-r--r-- | test/behaviour/tree.zig | 15 |
6 files changed, 116 insertions, 0 deletions
diff --git a/test/behaviour/columns_and_tags.zig b/test/behaviour/columns_and_tags.zig index b9e3b3f5..22f55774 100644 --- a/test/behaviour/columns_and_tags.zig +++ b/test/behaviour/columns_and_tags.zig @@ -133,6 +133,9 @@ test "columns-and-tags: Delcol on the last column leaves the window, drawn and t try s.write("/ctl", "Newcol\n"); try s.write(s.at("/col/{d}/ctl", .{try s.column(0)}), "New\n"); try expectEqualStrings(s.at("{d}:{d}", .{ try s.column(0), try s.focused() }), try s.columns()); + // And 9P's new makes a pane there. + const made = try s.newPane(); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), s.at("\n{d} ", .{made})) != null); } test "columns-and-tags: New is a column tag's word, in no pane's tag nor the workspace's" { diff --git a/test/behaviour/event.zig b/test/behaviour/event.zig index 77a80e30..65222175 100644 --- a/test/behaviour/event.zig +++ b/test/behaviour/event.zig @@ -69,3 +69,14 @@ test "event: a bad event record says what is wrong with it" { try std.testing.expect(has(s.said, c[1])); } } + +test "event: a write to the body is an EI record to the reader holding event" { + var s = try Session.initFile(std.testing.allocator, "replaced\n"); + defer s.deinit(); + const n = try s.focused(); + const event = try s.hold(s.at("/pane/{d}/event", .{n}), 0); + defer s.clunk(event); + try s.write(s.at("/pane/{d}/body", .{n}), "event\n"); + const record = try s.readFid(event); + try std.testing.expect(std.mem.startsWith(u8, record, "EI") and has(record, "event\n")); +} diff --git a/test/behaviour/limits.zig b/test/behaviour/limits.zig index d84d4490..35dde65e 100644 --- a/test/behaviour/limits.zig +++ b/test/behaviour/limits.zig @@ -38,3 +38,14 @@ test "limits: a ctl line over 1 MiB is refused once, EINVAL, and its tail is not // What came after the long line's newline ran. try s.expect(s.at("/pane/{d}/body", .{n}), ""); } + +test "limits: a ctl line with no newline is held whatever its write's size, and runs at the close, its failure in the log" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const ctl = try s.hold(s.at("/pane/{d}/ctl", .{try s.focused()}), 1); + const line = "bogus" ++ @as([20000]u8, @splat('x')); + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(ctl, line)); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "ctl: unknown control message") == null); + s.clunk(ctl); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "ctl: unknown control message") != null); +} diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index 0d8056da..c46ca394 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -713,3 +713,45 @@ test "look-and-exec: a pane's tagexec runs a word as a click in its tag, and rea try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "from the tag") != null); try s.expect(tagexec, s.at("{d}\n", .{n})); } + +test "look-and-exec: a look at a directory opens a pane listing it, as acme's directory window: named with a trailing /, its entries, ctl's isdir 1, get reading it again" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.createDirPath(std.testing.io, "listed/sub"); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "listed/.dot", .data = "" }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const dir = s.at("{s}/listed", .{try tmpPath(&s, &tmp)}); + const scratch = try s.newPane(); + try s.write(s.at("/pane/{d}/look", .{scratch}), s.at("{s}\n", .{dir})); + const serial = try std.fmt.parseInt(u32, std.mem.trim(u8, try s.read("/look"), "\n"), 10); + try std.testing.expect(serial != scratch); + const words = struct { + fn of(text: []const u8, buf: [][]const u8) []const []const u8 { + var it = std.mem.tokenizeAny(u8, text, " \n"); + var n: usize = 0; + while (it.next()) |w| : (n += 1) buf[n] = w; + return buf[0..n]; + } + }.of; + var buf: [16][]const u8 = undefined; + var rows = std.mem.tokenizeScalar(u8, try s.read("/index"), '\n'); + const row = while (rows.next()) |r| { + if (std.mem.startsWith(u8, r, s.at("{d} ", .{serial}))) break words(r, &buf); + } else return error.NoRow; + try std.testing.expectEqualStrings("text", row[1]); + try std.testing.expectEqualStrings("0", row[2]); + try std.testing.expectEqualStrings(s.at("{s}/", .{dir}), row[3]); + const body = words(try s.read(s.at("/pane/{d}/body", .{serial})), &buf); + try std.testing.expectEqual(@as(usize, 2), body.len); + try std.testing.expectEqualStrings(".dot", body[0]); + try std.testing.expectEqualStrings("sub/", body[1]); + try std.testing.expectEqualStrings("1", words(try s.read(s.at("/pane/{d}/ctl", .{serial})), &buf)[3]); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "listed/later", .data = "" }); + try s.write(s.at("/pane/{d}/ctl", .{serial}), "get\n"); + const again = words(try s.read(s.at("/pane/{d}/body", .{serial})), &buf); + try std.testing.expectEqual(@as(usize, 3), again.len); + try std.testing.expectEqualStrings(".dot", again[0]); + try std.testing.expectEqualStrings("later", again[1]); + try std.testing.expectEqualStrings("sub/", again[2]); +} diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig index a24a3010..9a14ff50 100644 --- a/test/behaviour/settings.zig +++ b/test/behaviour/settings.zig @@ -269,3 +269,37 @@ test "settings: every on/off setting the root ctl reads flips when its word is w try std.testing.expectEqualStrings("Theme acme", try setting(&s, "Theme")); try std.testing.expectEqualStrings("Shell /bin/sh", try setting(&s, "Shell")); } + +/// A cell's style (one of `Session.styles`) as its bold flag and ink. +fn look(s: *Session, style: []const u8) !struct { bool, []const u8 } { + const a = s.arena.allocator(); + const json = try std.json.parseFromSliceLeaky(std.json.Value, a, style, .{}); + return .{ json.object.get("bold").?.bool, try std.json.Stringify.valueAlloc(a, json.object.get("fg").?, .{}) }; +} + +test "settings: a keyword is coloured apart from the text beside it, and not bold (SyntaxBold is off by default), at a long file's end" { + var s = try Session.initFile(std.testing.allocator, "initial\n"); + defer s.deinit(); + const n = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{n}), "keywords.zig\n"); + var source: std.ArrayList(u8) = .empty; + for (0..9999) |_| try source.appendSlice(s.arena.allocator(), "// padding\n"); + try source.appendSlice(s.arena.allocator(), "fn check() void {\n if (true) return;\n}\n"); + try s.replace(s.at("/pane/{d}/body", .{n}), source.items); + const screen = try s.screen(); + const styles = try s.styles(); + const cols = std.mem.indexOfScalar(u8, screen, '\n').?; + try std.testing.expectEqual(styles.len, cols * (std.mem.count(u8, screen, "\n") + 1)); + for ([_][]const u8{ "fn", "if" }) |word| { + const col, const row = try s.where(s.at("{s} ", .{word})); + const at = row * cols + col; + _, const ink = try look(&s, styles[at]); + for (styles[at..][0..word.len]) |cell| { + const bold, const each = try look(&s, cell); + try std.testing.expect(!bold); + try std.testing.expectEqualStrings(ink, each); + } + _, const plain = try look(&s, styles[at + word.len]); + try std.testing.expect(!std.mem.eql(u8, ink, plain)); + } +} diff --git a/test/behaviour/tree.zig b/test/behaviour/tree.zig index 7f9b37a4..56806589 100644 --- a/test/behaviour/tree.zig +++ b/test/behaviour/tree.zig @@ -42,3 +42,18 @@ test "tree: a terminal is listed as term with its directory as name, which a wri try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/name", .{n}), "/elsewhere\n")); try std.testing.expect(std.mem.startsWith(u8, s.said, "invalid rename: a terminal is named")); } + +test "tree: a body takes a 60 KB write whole, a truncating one replaces it, and a pane not there is refused" { + var s = try Session.initFile(std.testing.allocator, "initial\n"); + defer s.deinit(); + var payload: std.ArrayList(u8) = .empty; + for (0..3000) |_| try payload.appendSlice(s.arena.allocator(), "const value = \"λ\";\n"); + const n = try s.newPane(); + const body = s.at("/pane/{d}/body", .{n}); + try s.write(body, payload.items); + try s.expect(body, payload.items); + try s.replace(body, "replaced\n"); + try s.expect(body, "replaced\n"); + try std.testing.expectError(error.Refused, s.read("/pane/4294967295/body")); + try s.expect(body, "replaced\n"); +} |
