MCPcopy Index your code
hub / github.com/danvk/webdiff / assertCharDiff

Function assertCharDiff

ts/codediff/__tests__/addcharacterdiffs_test.ts:169–199  ·  view source on GitHub ↗
(
    beforeText: string,
    beforeExpectation: string,
    afterText: string,
    afterExpectation: string,
  )

Source from the content-addressed store, hash-verified

167 });
168
169 function assertCharDiff(
170 beforeText: string,
171 beforeExpectation: string,
172 afterText: string,
173 afterExpectation: string,
174 ) {
175 const codes = computeCharacterDiffs(beforeText, afterText);
176 if (codes === null) {
177 expect(codes).not.toBeNull();
178 throw new Error();
179 }
180 // 'Declined to generate a diff when one was expected.');
181
182 const [beforeCodes, afterCodes] = codes;
183
184 const process = function (codes: CharacterDiff[], txt: string) {
185 return codes
186 .map(function (code) {
187 let part = txt.substring(code[1], code[2]);
188 if (code[0] != null) part = '[' + part + ']';
189 return part;
190 })
191 .join('');
192 };
193
194 const beforeActual = process(beforeCodes, beforeText),
195 afterActual = process(afterCodes, afterText);
196
197 expect(beforeActual).toEqual(beforeExpectation);
198 expect(afterActual).toEqual(afterExpectation);
199 }
200
201 // See https://github.com/danvk/github-syntax/issues/17
202 test('pure add with assertCharDiff', () => {

Callers 1

Calls 2

computeCharacterDiffsFunction · 0.90
processFunction · 0.85

Tested by

no test coverage detected