(diff, operator)
| 144 | } |
| 145 | |
| 146 | function printMyersDiff(diff, operator) { |
| 147 | let message = ''; |
| 148 | let skipped = false; |
| 149 | let nopCount = 0; |
| 150 | |
| 151 | for (let diffIdx = diff.length - 1; diffIdx >= 0; diffIdx--) { |
| 152 | const { 0: operation, 1: value } = diff[diffIdx]; |
| 153 | const previousOperation = diffIdx < diff.length - 1 ? diff[diffIdx + 1][0] : null; |
| 154 | |
| 155 | // Avoid grouping if only one line would have been grouped otherwise |
| 156 | if (previousOperation === kOperations.NOP && operation !== previousOperation) { |
| 157 | if (nopCount === kNopLinesToCollapse + 1) { |
| 158 | message += `${colors.white} ${diff[diffIdx + 1][1]}\n`; |
| 159 | } else if (nopCount === kNopLinesToCollapse + 2) { |
| 160 | message += `${colors.white} ${diff[diffIdx + 2][1]}\n`; |
| 161 | message += `${colors.white} ${diff[diffIdx + 1][1]}\n`; |
| 162 | } else if (nopCount >= kNopLinesToCollapse + 3) { |
| 163 | message += `${colors.blue}...${colors.white}\n`; |
| 164 | message += `${colors.white} ${diff[diffIdx + 1][1]}\n`; |
| 165 | skipped = true; |
| 166 | } |
| 167 | nopCount = 0; |
| 168 | } |
| 169 | |
| 170 | if (operation === kOperations.INSERT) { |
| 171 | if (operator === 'partialDeepStrictEqual') { |
| 172 | message += `${colors.gray}${colors.hasColors ? ' ' : '+'} ${value}${colors.white}\n`; |
| 173 | } else { |
| 174 | message += `${colors.green}+${colors.white} ${value}\n`; |
| 175 | } |
| 176 | } else if (operation === kOperations.DELETE) { |
| 177 | message += `${colors.red}-${colors.white} ${value}\n`; |
| 178 | } else if (operation === kOperations.NOP) { |
| 179 | if (nopCount < kNopLinesToCollapse) { |
| 180 | message += `${colors.white} ${value}\n`; |
| 181 | } |
| 182 | nopCount++; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | message = message.trimEnd(); |
| 187 | |
| 188 | return { message: `\n${message}`, skipped }; |
| 189 | } |
| 190 | |
| 191 | module.exports = { myersDiff, printMyersDiff, printSimpleMyersDiff }; |
no outgoing calls
no test coverage detected
searching dependent graphs…