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

Function unifiedDiff

test/mocha.js:1972–2002  ·  view source on GitHub ↗

* Returns a unified diff between two strings. * * @api private * @param {Error} err with actual/expected * @param {boolean} escape * @return {string} The diff.

(err, escape)

Source from the content-addressed store, hash-verified

1970 * @return {string} The diff.
1971 */
1972function unifiedDiff(err, escape) {
1973 var indent = ' ';
1974 function cleanUp(line) {
1975 if (escape) {
1976 line = escapeInvisibles(line);
1977 }
1978 if (line[0] === '+') {
1979 return indent + colorLines('diff added', line);
1980 }
1981 if (line[0] === '-') {
1982 return indent + colorLines('diff removed', line);
1983 }
1984 if (line.match(/\@\@/)) {
1985 return null;
1986 }
1987 if (line.match(/\\ No newline/)) {
1988 return null;
1989 }
1990 return indent + line;
1991 }
1992 function notBlank(line) {
1993 return typeof line !== 'undefined' && line !== null;
1994 }
1995 var msg = diff.createPatch('string', err.actual, err.expected);
1996 var lines = msg.split('\n').splice(4);
1997 return '\n '
1998 + colorLines('diff added', '+ expected') + ' '
1999 + colorLines('diff removed', '- actual')
2000 + '\n\n'
2001 + lines.map(cleanUp).filter(notBlank).join('\n');
2002}
2003
2004/**
2005 * Return a character diff for `err`.

Callers 1

mocha.jsFile · 0.85

Calls 1

colorLinesFunction · 0.85

Tested by

no test coverage detected