MCPcopy
hub / github.com/amark/gun / inlineDiff

Function inlineDiff

test/mocha.js:1938–1962  ·  view source on GitHub ↗

* Returns an inline diff between 2 strings with coloured ANSI output * * @api private * @param {Error} err with actual/expected * @param {boolean} escape * @return {string} Diff

(err, escape)

Source from the content-addressed store, hash-verified

1936 * @return {string} Diff
1937 */
1938function inlineDiff(err, escape) {
1939 var msg = errorDiff(err, 'WordsWithSpace', escape);
1940
1941 // linenos
1942 var lines = msg.split('\n');
1943 if (lines.length > 4) {
1944 var width = String(lines.length).length;
1945 msg = lines.map(function(str, i) {
1946 return pad(++i, width) + ' |' + ' ' + str;
1947 }).join('\n');
1948 }
1949
1950 // legend
1951 msg = '\n'
1952 + color('diff removed', 'actual')
1953 + ' '
1954 + color('diff added', 'expected')
1955 + '\n\n'
1956 + msg
1957 + '\n';
1958
1959 // indent
1960 msg = msg.replace(/^/gm, ' ');
1961 return msg;
1962}
1963
1964/**
1965 * Returns a unified diff between two strings.

Callers 1

mocha.jsFile · 0.85

Calls 2

errorDiffFunction · 0.85
padFunction · 0.85

Tested by

no test coverage detected