MCPcopy Index your code
hub / github.com/nodejs/node / getStackedDiff

Function getStackedDiff

lib/internal/assert/assertion_error.js:125–153  ·  view source on GitHub ↗
(actual, expected)

Source from the content-addressed store, hash-verified

123}
124
125function getStackedDiff(actual, expected) {
126 const isStringComparison = typeof actual === 'string' && typeof expected === 'string';
127
128 let message = `\n${colors.green}+${colors.white} ${actual}\n${colors.red}- ${colors.white}${expected}`;
129 const stringsLen = actual.length + expected.length;
130 const maxTerminalLength = process.stderr.isTTY ? process.stderr.columns : 80;
131 const showIndicator = isStringComparison && (stringsLen <= maxTerminalLength);
132
133 if (showIndicator) {
134 let indicatorIdx = -1;
135
136 for (let i = 0; i < actual.length; i++) {
137 if (actual[i] !== expected[i]) {
138 // Skip the indicator for the first 2 characters because the diff is immediately apparent
139 // It is 3 instead of 2 to account for the quotes
140 if (i >= 3) {
141 indicatorIdx = i;
142 }
143 break;
144 }
145 }
146
147 if (indicatorIdx !== -1) {
148 message += `\n${StringPrototypeRepeat(' ', indicatorIdx + 2)}^`;
149 }
150 }
151
152 return { message };
153}
154
155function getSimpleDiff(originalActual, actual, originalExpected, expected) {
156 let stringsLen = actual.length + expected.length;

Callers 1

getSimpleDiffFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…