╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ undo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
191 try std.testing.expect(std.mem.startsWith(u8, data.items[0].description, "commit -m \"example commit\"")); 192 } 193 194 test "malformed undo history is shown as an error" { 195 var temp = std.testing.tmpDir(.{}); 196 defer temp.cleanup(); 197 var arena = std.heap.ArenaAllocator.init(allocator); 198 defer arena.deinit(); 199 const path = try temp.dir.realPathFileAlloc(io, ".", arena.allocator()); 200 const Repo = xit.repo.Repo(.xit, .{}); 201 var repo = try Repo.init(io, allocator, .{ .path = path }); 202 defer repo.deinit(io, allocator); 203 204 // append an invalid undo record without damaging the repository data. 205 const Corrupt = struct { 206 pub fn run(_: @This(), cursor: *Repo.DB.Cursor(.read_write)) !void { 207 const moment = try Repo.DB.HashMap(.read_write).init(cursor.*); 208 try moment.put(xit.hash.hashInt(.sha1, "undo"), .{ .bytes = "bad" }); 209 } 210 }; 211 const history = try Repo.DB.ArrayList(.read_write).init(repo.core.db.rootCursor()); 212 try history.appendContext(.{ .slot = try history.getSlot(-1) }, Corrupt{}); 213 214 var session = ui.Session{ .arena = &arena, .page_arena = &arena, .io = io, .local = .{ .path = path, .repo_kind = .xit }, .data = .{ .host_kind = .local } }; 215 // tabs switch in-page, so every tab carries the undo data and its failure 216 const files = try ui.Repo.init(&arena, &session, ui.RoutablePage.repoFilesRoute("", null, "", "", 0).?); 217 try std.testing.expectEqual(0, files.undo.?.items.len); 218 try std.testing.expectEqualStrings("InvalidUndoRecord", files.undo.?.failure.?); 219 const undo = try ui.Repo.init(&arena, &session, ui.RoutablePage.repoUndoRoute("", null).?); 220 try std.testing.expectEqualStrings("InvalidUndoRecord", undo.undo.?.failure.?); 221 222 var root = ui.Widget{ .repo_undo = try Undo.View.init(allocator, &undo.undo.?, &session) }; 223 defer root.deinit(allocator); 224 try root.build(allocator, constraint, root.getFocus()); 225 const html = try @import("../web.zig").generateHtml(allocator, &root, &session); 226 defer allocator.free(html); 227 try std.testing.expect(std.mem.indexOf(u8, html, "InvalidUndoRecord") != null); 228 } 229