//! docs/typ/builtins.typ, the builtins' glossary. const std = @import("std"); const Session = @import("session").Session; test "builtins: Mini maps a file of the pane's directory over pardes's own source of that name, in one pane, refreshed only when asked again" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "build.zig", .data = "x\n" }); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "a\n" }); var dir: [4096]u8 = undefined; const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)]; var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); try s.write("/look", s.at("{s}/a.txt\n", .{at})); const a = try s.focused(); // The directory's one-line build.zig, one braille row, not pardes's. try s.write(s.at("/pane/{d}/exec", .{a}), "Mini build.zig\n"); const mini = try s.focused(); try std.testing.expect(mini != a); const body = s.at("/pane/{d}/body", .{mini}); try s.expect(body, "⠁\n"); const index = try s.read("/index"); try s.write(s.at("/pane/{d}/exec", .{mini}), "Mini build.zig\n"); try std.testing.expectEqual(mini, try s.focused()); try s.expect("/index", index); // A snapshot: the file grown on disk shows only at the next Mini. try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "build.zig", .data = "xx\n" }); try s.expect(body, "⠁\n"); try s.write(s.at("/pane/{d}/exec", .{mini}), "Mini build.zig\n"); try s.expect(body, "⠉\n"); try s.expect("/index", index); // Save asks for a path; nothing is written for it. try s.write(s.at("/pane/{d}/exec", .{mini}), "Save\n"); try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), s.at("ask {d} save path\n", .{mini})) != null); try std.testing.expectEqual(@as(usize, 0), s.saved); } test "builtins: Help holds every builtin with its whole documentation, `Help ` that one's alone, and B2 on a builtin's name in it runs it" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); try s.write(s.at("/pane/{d}/exec", .{try s.focused()}), "Help\n"); const help = try s.focused(); const body = s.at("/pane/{d}/body", .{help}); const all = try s.read(body); const commands = try s.read("/commands"); var words = std.mem.tokenizeScalar(u8, commands, '\n'); while (words.next()) |line| { const name = line[0..std.mem.indexOfScalar(u8, line, ' ').?]; // One alone: its row, a blank, its documentation, a blank, then what // the list does not say; the one +Help, filled again. try s.write(s.at("/pane/{d}/exec", .{help}), s.at("Help {s}\n", .{name})); try std.testing.expectEqual(help, try s.focused()); const one = try s.read(body); const doc_end = std.mem.indexOf(u8, one, "\n\nkeys: ").?; const row = one[0..std.mem.indexOfScalar(u8, one, '\n').?]; const documented = one[0..doc_end]; // The list holds it whole: its row, its documentation under it. try std.testing.expect(std.mem.indexOf(u8, all, s.at("{s}\n{s}\n\n", .{ row, documented[row.len + 2 ..] })) != null); // Its documentation begins with its summary, /commands' line. try std.testing.expect(std.mem.startsWith(u8, documented[row.len + 2 ..], line[std.mem.indexOf(u8, line, " -- ").? + 4 ..])); // And holds no other word's. var others = std.mem.tokenizeScalar(u8, commands, '\n'); while (others.next()) |other| if (!std.mem.eql(u8, other, line)) try std.testing.expect(std.mem.indexOf(u8, one, other[std.mem.indexOf(u8, other, " -- ").? + 4 ..]) == null); } // A word that is neither a builtin, as the registry spells it, nor SPC // keys is said, the +Help left as it was. const kept = try s.read(body); try std.testing.expect(try s.refused("/ctl", "Help diff\n") != 0); try s.expect(body, kept); // SPC keys: the builtins under them. try s.write("/ctl", "Help c\n"); try std.testing.expect(std.mem.startsWith(u8, try s.read(body), "pardes builtins under SPC c\n")); // All text is text: B2 on a builtin's name in the +Help runs it. try s.write("/ctl", "Help Newcol\n"); const before = std.mem.count(u8, try s.columns(), ":"); // (its row, `SPC c n Newcol`: the topbar's Newcol is drawn first) try s.click("c n Newcol", "c n N".len, 2); try std.testing.expectEqual(before + 1, std.mem.count(u8, try s.columns(), ":")); } test "builtins: Build prints this build into a +Build pane" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); try s.write(s.at("/pane/{d}/exec", .{try s.focused()}), "Build\n"); const index = try s.read("/index"); var serial: ?u32 = null; var lines = std.mem.splitScalar(u8, index, '\n'); while (lines.next()) |line| if (std.mem.indexOf(u8, line, "+Build") != null) { serial = try std.fmt.parseInt(u32, line[0..std.mem.indexOfScalar(u8, line, ' ').?], 10); }; const body = try s.read(s.at("/pane/{d}/body", .{serial orelse return error.NoBuildPane})); try std.testing.expect(std.mem.startsWith(u8, body, "pardes ")); for ([_][]const u8{ "\ncommit ", "\nchange ", "\nbuilt ", "\nzig 0.17", "\nmode ", "\nplatform ", "\ndependencies\n" }) |want| try std.testing.expect(std.mem.indexOf(u8, body, want) != null); }