* Returns an inline diff between 2 strings with coloured ANSI output. * * @api private * @param {String} actual * @param {String} expected * @return {string} Diff
(actual, expected)
| 2180 | * @return {string} Diff |
| 2181 | */ |
| 2182 | function inlineDiff(actual, expected) { |
| 2183 | var msg = errorDiff(actual, expected); |
| 2184 | |
| 2185 | // linenos |
| 2186 | var lines = msg.split('\n'); |
| 2187 | if (lines.length > 4) { |
| 2188 | var width = String(lines.length).length; |
| 2189 | msg = lines |
| 2190 | .map(function(str, i) { |
| 2191 | return pad(++i, width) + ' |' + ' ' + str; |
| 2192 | }) |
| 2193 | .join('\n'); |
| 2194 | } |
| 2195 | |
| 2196 | // legend |
| 2197 | msg = |
| 2198 | '\n' + |
| 2199 | color('diff removed', 'actual') + |
| 2200 | ' ' + |
| 2201 | color('diff added', 'expected') + |
| 2202 | '\n\n' + |
| 2203 | msg + |
| 2204 | '\n'; |
| 2205 | |
| 2206 | // indent |
| 2207 | msg = msg.replace(/^/gm, ' '); |
| 2208 | return msg; |
| 2209 | } |
| 2210 | |
| 2211 | /** |
| 2212 | * Returns a unified diff between two strings with coloured ANSI output. |