From d762a2f314aaba34502bc7b515e4116322561408 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Thu, 24 Jan 2019 14:25:21 +0900 Subject: [PATCH] update diff types --- types/diff/diff-tests.ts | 25 +++++++++++++++++-------- types/diff/index.d.ts | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/types/diff/diff-tests.ts b/types/diff/diff-tests.ts index 845b307132..ca00b1f458 100644 --- a/types/diff/diff-tests.ts +++ b/types/diff/diff-tests.ts @@ -86,18 +86,19 @@ function verifyPatchMethods(oldStr: string, newStr: string, uniDiff: diff.Parsed throw new Error('Patch did not match uniDiff'); } } -function verifyApplyMethods(oldStr: string, newStr: string, uniDiff: diff.ParsedDiff) { +function verifyApplyMethods(oldStr: string, newStr: string, uniDiffStr: string) { + const uniDiff = diff.parsePatch(uniDiffStr)[0]; const verifyApply = [diff.applyPatch(oldStr, uniDiff), diff.applyPatch(oldStr, [uniDiff])]; - diff.applyPatches([uniDiff], { - loadFile: (index, callback) => { + const options: diff.ApplyPatchesOptions = { + loadFile(index, callback) { index; // $ExpectType ParsedDiff callback(undefined, one); }, - patched: (index, content) => { + patched(index, content) { index; // $ExpectType ParsedDiff verifyApply.push(content); }, - complete: (err?: Error) => { + complete(err) { if (err) { throw err; } @@ -108,7 +109,16 @@ function verifyApplyMethods(oldStr: string, newStr: string, uniDiff: diff.Parsed } }); }, - }); + compareLine(_, line, operator, patchContent) { + if (operator === ' ') { + return true; + } + return line === patchContent; + }, + fuzzFactor: 0 + }; + diff.applyPatches([uniDiff], options); + diff.applyPatches(uniDiffStr, options); } const uniDiffPatch = diff.structuredPatch('oldFile.ts', 'newFile.ts', one, other, 'old', 'new', { @@ -117,5 +127,4 @@ const uniDiffPatch = diff.structuredPatch('oldFile.ts', 'newFile.ts', one, other verifyPatchMethods(one, other, uniDiffPatch); const uniDiffStr = diff.createPatch('file.ts', one, other, 'old', 'new', { context: 1 }); -const uniDiffApply = diff.parsePatch(uniDiffStr)[0]; -verifyApplyMethods(one, other, uniDiffApply); +verifyApplyMethods(one, other, uniDiffStr); diff --git a/types/diff/index.d.ts b/types/diff/index.d.ts index fa0e4e2e3d..5afb72192e 100644 --- a/types/diff/index.d.ts +++ b/types/diff/index.d.ts @@ -98,7 +98,7 @@ export interface ApplyPatchOptions { ) => boolean; } -export interface ApplyPatchesOptions { +export interface ApplyPatchesOptions extends ApplyPatchOptions { loadFile(index: ParsedDiff, callback: (err: any, data: string) => void): void; patched(index: ParsedDiff, content: string, callback: (err: any) => void): void; complete(err: any): void;