Skip to content

Commit d7c4e6f

Browse files
committed
test: add pager_contents to subject.parse() specs
1 parent 6bff3ca commit d7c4e6f

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

tests/specs/neogit/lib/git/log_spec.lua

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,67 @@ describe("lib.git.log.parse", function()
230230
" ",
231231
" ---@param selection Selection",
232232
},
233+
pager_contents = {
234+
{
235+
" ---@param first_line number",
236+
" ---@param last_line number",
237+
" ---@param partial boolean",
238+
"----@return SelectedHunk[],string[]",
239+
"+---@return SelectedHunk[]",
240+
" function M.get_item_hunks(item, first_line, last_line, partial)",
241+
" if item.folded or item.hunks == nil then",
242+
"- return {}, {}",
243+
"+ return {}",
244+
" end",
245+
" ",
246+
" local hunks = {}",
247+
"- local lines = {}",
248+
" ",
249+
" for _, h in ipairs(item.hunks) do",
250+
"- -- Transform to be relative to the current item/file",
251+
"- local first_line = first_line - item.first",
252+
"- local last_line = last_line - item.first",
253+
"-",
254+
"- if h.diff_from <= last_line and h.diff_to >= first_line then",
255+
"- -- Relative to the hunk",
256+
"+ if h.first <= last_line and h.last >= first_line then",
257+
" local from, to",
258+
"+",
259+
" if partial then",
260+
"- from = h.diff_from + math.max(first_line - h.diff_from, 0)",
261+
"- to = math.min(last_line, h.diff_to)",
262+
"+ local length = last_line - first_line",
263+
"+ from = h.diff_from + math.max((first_line - item.first) - h.diff_from, 0)",
264+
"+ to = from + length",
265+
" else",
266+
" from = h.diff_from + 1",
267+
" to = h.diff_to",
268+
" end",
269+
" ",
270+
" local hunk_lines = {}",
271+
"-",
272+
" for i = from, to do",
273+
" table.insert(hunk_lines, item.diff.lines[i])",
274+
" end",
275+
},
276+
{
277+
" setmetatable(o, o)",
278+
" ",
279+
" table.insert(hunks, o)",
280+
"-",
281+
"- for i = from, to do",
282+
"- table.insert(lines, item.diff.lines[i + h.diff_from])",
283+
"- end",
284+
" end",
285+
" end",
286+
" ",
287+
"- return hunks, lines",
288+
"+ return hunks",
289+
" end",
290+
" ",
291+
" ---@param selection Selection",
292+
},
293+
},
233294
stats = {
234295
additions = 0,
235296
deletions = 0,
@@ -317,6 +378,19 @@ describe("lib.git.log.parse", function()
317378
' of this software and associated documentation files (the "Software"), to deal',
318379
" in the Software without restriction, including without limitation the rights",
319380
},
381+
pager_contents = {
382+
{
383+
" MIT License",
384+
" ",
385+
"+hello",
386+
" Copyright (c) 2020 TimUntersberger",
387+
" ",
388+
"+world",
389+
" Permission is hereby granted, free of charge, to any person obtaining a copy",
390+
' of this software and associated documentation files (the "Software"), to deal',
391+
" in the Software without restriction, including without limitation the rights",
392+
},
393+
},
320394
stats = {
321395
additions = 0,
322396
deletions = 0,

0 commit comments

Comments
 (0)