mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
Merge branch 'master' into types-2.0-2016-08-10
This commit is contained in:
@@ -49,5 +49,43 @@ function printDiff(diff:jsdiff.IDiffResult[]) {
|
||||
console.log(addLineHeader(" ", part.value));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
function verifyPatchMethods(oldStr: string, newStr: string, uniDiff: jsdiff.IUniDiff) {
|
||||
var verifyPatch = jsdiff.parsePatch(
|
||||
jsdiff.createTwoFilesPatch("oldFile.ts", "newFile.ts", oldStr, newStr,
|
||||
"old", "new", { context: 1 }));
|
||||
if (JSON.stringify(verifyPatch) !== JSON.stringify(uniDiff)) {
|
||||
console.error("Patch did not match uniDiff");
|
||||
}
|
||||
}
|
||||
function verifyApplyMethods(oldStr: string, newStr: string, uniDiff: jsdiff.IUniDiff) {
|
||||
var verifyApply = [
|
||||
jsdiff.applyPatch(oldStr, uniDiff),
|
||||
jsdiff.applyPatch(oldStr, [uniDiff])
|
||||
];
|
||||
jsdiff.applyPatches([uniDiff], {
|
||||
loadFile: (index: number, callback: (err: Error, data: string) => void) => {
|
||||
callback(undefined, one);
|
||||
},
|
||||
patched: (index: number, content: string) => {
|
||||
verifyApply.push(content);
|
||||
},
|
||||
complete: (err?: Error) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
verifyApply.forEach(result => {
|
||||
if (result !== newStr) {
|
||||
console.error("Result did not match newStr");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
verifyPatchMethods(one, other, uniDiff);
|
||||
var uniDiff = jsdiff.structuredPatch("oldFile.ts", "newFile.ts", one, other,
|
||||
"old", "new", { context: 1 });
|
||||
verifyApplyMethods(one, other, uniDiff);
|
||||
|
||||
32
diff/index.d.ts
vendored
32
diff/index.d.ts
vendored
@@ -19,6 +19,22 @@ declare namespace JsDiff {
|
||||
componenets: IDiffResult[];
|
||||
}
|
||||
|
||||
interface IHunk {
|
||||
oldStart: number;
|
||||
oldLines: number;
|
||||
newStart: number;
|
||||
newLines: number;
|
||||
lines: string[];
|
||||
}
|
||||
|
||||
interface IUniDiff {
|
||||
oldFileName: string;
|
||||
newFileName: string;
|
||||
oldHeader: string;
|
||||
newHeader: string;
|
||||
hunks: IHunk[];
|
||||
}
|
||||
|
||||
class Diff {
|
||||
ignoreWhitespace:boolean;
|
||||
|
||||
@@ -49,9 +65,21 @@ declare namespace JsDiff {
|
||||
|
||||
function diffCss(oldStr:string, newStr:string):IDiffResult[];
|
||||
|
||||
function createPatch(fileName:string, oldStr:string, newStr:string, oldHeader:string, newHeader:string):string;
|
||||
function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): string;
|
||||
|
||||
function applyPatch(oldStr:string, uniDiff:string):string;
|
||||
function createTwoFilesPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): string;
|
||||
|
||||
function structuredPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): IUniDiff;
|
||||
|
||||
function applyPatch(oldStr: string, uniDiff: string | IUniDiff | IUniDiff[]): string;
|
||||
|
||||
function applyPatches(uniDiff: IUniDiff[], options: {
|
||||
loadFile: (index: number, callback: (err: Error, data: string) => void) => void,
|
||||
patched: (index: number, content: string) => void,
|
||||
complete: (err?: Error) => void
|
||||
}): void;
|
||||
|
||||
function parsePatch(diffStr: string, options?: {strict: boolean}): IUniDiff[];
|
||||
|
||||
function convertChangesToXML(changes:IDiffResult[]):string;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user