-- Given two pairs of arrays of strings:
-- Compare the pair of comparison arrays line-by-line.
-- Format the corresponding lines in the pair of displayable arrays.

local function diffLinesUnified2(
	aLinesDisplay: { [number]: string },
	bLinesDisplay: { [number]: string },
	aLinesCompare: { [number]: string },
	bLinesCompare: { [number]: string },
	options: DiffOptions?
): string
	if isEmptyString(aLinesDisplay) and isEmptyString(aLinesCompare) then
		aLinesDisplay = {}
		aLinesCompare = {}
	end
	if isEmptyString(bLinesDisplay) and isEmptyString(bLinesCompare) then
		bLinesDisplay = {}
		bLinesCompare = {}
	end

	if #aLinesDisplay ~= #aLinesCompare or #bLinesDisplay ~= #bLinesCompare then
		-- Fall back to diff of display lines.
		return diffLinesUnified(aLinesDisplay, bLinesDisplay, options)
	end

	local diffs = diffLinesRaw(aLinesCompare, bLinesCompare)

	-- Replace comparison lines with displayable lines.
	local aIndex = 0
	local bIndex = 0
	for _, d in ipairs(diffs) do
		local case = d[1]
		if case == DIFF_DELETE then
			d[2] = aLinesDisplay[aIndex + 1]
			aIndex += 1
		elseif case == DIFF_INSERT then
			d[2] = bLinesDisplay[bIndex + 1]
			bIndex += 1
		else
			d[2] = bLinesDisplay[bIndex + 1]
			aIndex += 1
			bIndex += 1
		end
	end

	return printDiffLines(diffs, normalizeDiffOptions(options))
end
