• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript diff.createPatch函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中diff.createPatch函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createPatch函数的具体用法?TypeScript createPatch怎么用?TypeScript createPatch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了createPatch函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: createUnifiedDiff

 /**
  * Returns a string highlighting the differences between the actual
  * and expected strings.
  *
  * @protected
  * @param {*} actual
  * @param {*} expected
  * @returns {string}
  * @memberof LiveDocReporter
  */
 protected createUnifiedDiff(actual, expected): string {
     var indent = '';
     const _this = this;
     function cleanUp(line) {
         if (line[0] === '+') {
             return indent + _this.colorTheme.statusPass(line);
         }
         if (line[0] === '-') {
             return indent + _this.colorTheme.statusFail(line);
         }
         if (line.match(/@@/)) {
             return '--';
         }
         if (line.match(/\\ No newline/)) {
             return null;
         }
         return indent + line;
     }
     function notBlank(line) {
         return typeof line !== 'undefined' && line !== null;
     }
     var msg = diff.createPatch('string', actual.toString(), expected.toString());
     var lines = msg.split('\n').splice(5);
     return (
         '\n' +
         _this.colorTheme.statusPass('+ expected') +
         ' ' +
         _this.colorTheme.statusFail('- actual') +
         '\n\n' +
         lines
             .map(cleanUp)
             .filter(notBlank)
             .join('\n')
     );
 }
开发者ID:dotnetprofessional,项目名称:LiveDoc,代码行数:45,代码来源:LiveDocReporter.ts


示例2: compareAgainstGolden

/**
 * compareAgainstGoldens compares a test output against the content in a golden
 * path, updating the content of the golden when UPDATE_GOLDENS is true.
 *
 * @param output The expected output, where the empty string indicates
 *    the file is expected to exist and be empty, while null indicates
 *    the file is expected to not exist.  (This subtlety is used for
 *    externs files, where the majority of tests are not expected to
 *    produce one.)
 */
function compareAgainstGolden(output: string|null, path: string) {
  const golden = readGolden(path);
  let patchedGolden = patchGolden(golden, path);

  // Make sure we have proper line endings when testing on Windows.
  if (patchedGolden != null) patchedGolden = patchedGolden.replace(/\r\n/g, '\n');
  if (output != null) output = output.replace(/\r\n/g, '\n');

  const patchPath = calcPatchPath(path);
  if (UPDATE_GOLDENS) {
    if (golden !== null && golden !== output) {
      console.log(`Updating golden patch file for ${path} with ${patchPath}`);
      const patchOutput =
          diff.createPatch(path, golden || '', output || '', 'golden', 'tsickle with transformer')!;
      fs.writeFileSync(patchPath, patchOutput, 'utf-8');
    } else {
      // The desired golden state is for there to be no output file.
      // Ensure no file exists.
      try {
        fs.unlinkSync(patchPath);
      } catch (e) {
        // ignore.
      }
    }
  } else {
    expect(output).to.equal(patchedGolden, `${path} with ${patchPath}`);
  }
}
开发者ID:lucidsoftware,项目名称:tsickle,代码行数:38,代码来源:tsickle_transformer_test.ts


示例3: switch

 diffResult.diffSet.forEach(function(entry) {
   switch (entry.state) {
     case 'equal':
       return;
     case 'left':
       const expectedFileRelPath =
           path.join(entry.relativePath || '/', entry.name1);
       errorOutputLines.push((chalk.bold.green(' + ' + expectedFileRelPath)));
       return;
     case 'right':
       const actualFileRelPath =
           path.join(entry.relativePath || '/', entry.name2);
       errorOutputLines.push((chalk.bold.red(' - ' + actualFileRelPath)));
       return;
     case 'distinct':
       const diffedFileRelPath =
           path.join(entry.relativePath || '/', entry.name1);
       const expectedFilePath = path.join(entry.path1, entry.name1);
       const actualFilePath = path.join(entry.path2, entry.name2);
       const patch = diff.createPatch(
           'string',
           fs.readFileSync(expectedFilePath, 'utf8'),
           fs.readFileSync(actualFilePath, 'utf8'),
           'expected',
           'converted');
       errorOutputLines.push((chalk.bold.red('<> ' + diffedFileRelPath)));
       errorOutputLines.push(formatDiffPatch(patch));
       return;
     default:
       throw new Error('Unexpected diff-entry format: ' + entry);
   }
 });
开发者ID:,项目名称:,代码行数:32,代码来源:


示例4:

const errorMsgFromJson = (actual: string, expected: string): string => `
----------[expected]----------
${expected}
----------[actual]------------
${actual}
----------[diff]--------------
${JsDiff.createPatch("Diff", expected, actual, "expected", "actual")}
------------------------------
`;
开发者ID:tadashi-aikawa,项目名称:todoistoggl,代码行数:9,代码来源:ReadableAssert.ts


示例5: verifyAgainstGoldenFile

export function verifyAgainstGoldenFile(
    entrypoint: string, goldenFile: string, options: SerializationOptions = {}): string {
  const actual = publicApi(entrypoint, options);
  const expected = fs.readFileSync(goldenFile).toString();

  if (actual === expected) {
    return '';
  } else {
    const patch = createPatch(goldenFile, expected, actual, 'Golden file', 'Generated API');

    // Remove the header of the patch
    const start = patch.indexOf('\n', patch.indexOf('\n') + 1) + 1;

    return patch.substring(start);
  }
}
开发者ID:alxhub,项目名称:ts-api-guardian,代码行数:16,代码来源:main.ts


示例6: it

  it(`Package "${testPackage.dir}"`, () => {
    if (actual !== expected) {
      // Compute the patch and strip the header
      let patch =
          createPatch(goldenFile, expected, actual, 'Golden file', 'Generated file', {context: 5});
      const endOfHeader = patch.indexOf('\n', patch.indexOf('\n') + 1) + 1;
      patch = patch.substring(endOfHeader);

      // Use string concatentation instead of whitespace inside a single template string
      // to make the structure message explicit.
      const failureMessage = `example ng_package differs from golden file\n` +
          `    Diff:\n` +
          `    ${patch}\n\n` +
          `    To accept the new golden file, run:\n` +
          `      bazel run ${process.env['BAZEL_TARGET']}.accept\n`;

      fail(failureMessage);
    }
  });
开发者ID:DeepanParikh,项目名称:angular,代码行数:19,代码来源:example_package.spec.ts


示例7: getEngineByTargetDir

        args.files.forEach(filePath => {
            if (opts.verbose) {
                console.warn(`processing ${filePath}...`);
            }
            const content = fs.readFileSync(filePath, { encoding: "utf8" });
            const engine = getEngineByTargetDir(path.dirname(filePath));
            const changeSet = engine.makeChangeSet(filePath);
            if (changeSet.diffs.length !== 0) {
                invalidFiles.push(filePath);
            }

            if (opts.stdout) {
                const result = changeSet.applyChangeSets(content);
                process.stdout.write(result);

            } else if (opts.diff) {
                const result = changeSet.applyChangeSets(content);
                const patch = diff.createPatch(filePath, content, result, "before", "replaced");
                console.log(patch);

            } else if (opts.replace) {
                const result = changeSet.applyChangeSets(content);
                if (content !== result) {
                    fs.writeFileSync(filePath, result);
                    console.warn(`replaced ${filePath}`);
                }

            } else {
                changeSet.diffs.forEach(diff => {
                    const before = changeSet.content.substr(diff.index, diff.tailIndex - diff.index);
                    const after = diff.newText;
                    if (after == null) {
                        return;
                    }
                    const lineColumn = indexToLineColumn(diff.index, changeSet.content);
                    console.log(`${changeSet.filePath}(${lineColumn.line + 1},${lineColumn.column + 1}): ${before} → ${after}`);
                });
            }
        });
开发者ID:vvakame,项目名称:prh,代码行数:39,代码来源:cli.ts


示例8: callback

        loadFile: (index, callback) => {
            index; // $ExpectType ParsedDiff
            callback(undefined, one);
        },
        patched: (index, content) => {
            index; // $ExpectType ParsedDiff
            verifyApply.push(content);
        },
        complete: (err?: Error) => {
            if (err) {
                throw err;
            }

            verifyApply.forEach(result => {
                if (result !== newStr) {
                    throw new Error('Result did not match newStr');
                }
            });
        },
    });
}

const uniDiffPatch = diff.structuredPatch('oldFile.ts', 'newFile.ts', one, other, 'old', 'new', {
    context: 1,
});
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);
开发者ID:frankwallis,项目名称:DefinitelyTyped,代码行数:30,代码来源:diff-tests.ts



注:本文中的diff.createPatch函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript diff.diffChars函数代码示例发布时间:2022-05-25
下一篇:
TypeScript dialogflow-fulfillment.WebhookClient类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap