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