当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript diff.diffLines函数代码示例

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


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

示例1: consoleTestResultHandler

export function consoleTestResultHandler(testResult: TestResult): boolean {
    let didAllTestsPass = true;

    for (const fileName of Object.keys(testResult.results)) {
        const results = testResult.results[fileName];
        process.stdout.write(`${fileName}:`);

        const markupDiffResults = diff.diffLines(results.markupFromMarkup, results.markupFromLinter);
        const fixesDiffResults = diff.diffLines(results.fixesFromLinter, results.fixesFromMarkup);
        const didMarkupTestPass = !markupDiffResults.some((diff) => !!diff.added || !!diff.removed);
        const didFixesTestPass = !fixesDiffResults.some((diff) => !!diff.added || !!diff.removed);

        /* tslint:disable:no-console */
        if (didMarkupTestPass && didFixesTestPass) {
            console.log(colors.green(" Passed"));
        } else {
            console.log(colors.red(" Failed!"));
            didAllTestsPass = false;
            if (!didMarkupTestPass) {
                displayDiffResults(markupDiffResults, MARKUP_FILE_EXTENSION);
            }
            if (!didFixesTestPass) {
                displayDiffResults(fixesDiffResults, FIXES_FILE_EXTENSION);
            }
        }
        /* tslint:enable:no-console */
    }

    return didAllTestsPass;
}
开发者ID:arusakov,项目名称:tslint,代码行数:30,代码来源:test.ts

示例2: consoleTestResultHandler

export function consoleTestResultHandler(testResult: TestResult): boolean {
    let didAllTestsPass = true;

    for (const fileName of Object.keys(testResult.results)) {
        const results = testResult.results[fileName];
        process.stdout.write(`${fileName}:`);

        const diffResults = diff.diffLines(results.markupFromMarkup, results.markupFromLinter);
        const didTestPass = !diffResults.some((diff) => diff.added || diff.removed);

        /* tslint:disable:no-console */
        if (didTestPass) {
            console.log(colors.green(" Passed"));
        } else {
            console.log(colors.red(" Failed!"));
            console.log(colors.green(`Expected (from ${FILE_EXTENSION} file)`));
            console.log(colors.red("Actual (from TSLint)"));

            didAllTestsPass = false;

            for (const diffResult of diffResults) {
                let color = colors.grey;
                if (diffResult.added) {
                    color = colors.green;
                } else if (diffResult.removed) {
                    color = colors.red;
                }
                process.stdout.write(color(diffResult.value));
            }
        }
        /* tslint:enable:no-console */
    }

    return didAllTestsPass;
}
开发者ID:arnaudvalle,项目名称:tslint,代码行数:35,代码来源:test.ts

示例3: it

    it("tests every rule", () => {
        const rules = fs.readdirSync(srcRulesDir)
            .filter((file) => /Rule.ts$/.test(file))
            .map((file) => file.substr(0, file.length - "Rule.ts".length))
            .sort()
            .join("\n");
        const tests = fs.readdirSync(testRulesDir)
            .filter((file) => !file.startsWith("_") && fs.statSync(path.join(testRulesDir, file)).isDirectory())
            .map(camelize)
            .sort()
            .join("\n");
        const diffResults = diff.diffLines(rules, tests);
        let testFailed = false;
        for (const result of diffResults) {
            if (result.added) {
                console.warn("Test has no matching rule: " + result.value);
                testFailed = true;
            } else if (result.removed) {
                console.warn("Missing test: " + result.value);
                testFailed = true;
            }
        }

        assert.isFalse(testFailed, "List of rules doesn't match list of tests");
    });
开发者ID:arusakov,项目名称:tslint,代码行数:25,代码来源:ruleLoaderTests.ts

示例4: _eval

/**
 * Evaluate the code snippet.
 */
function _eval (input: string) {
  const lines = EVAL_INSTANCE.lines
  const isCompletion = !/\n$/.test(input)
  const undo = appendEval(input)
  let output: string

  try {
    output = service.compile(EVAL_INSTANCE.input, EVAL_PATH, -lines)
  } catch (err) {
    undo()
    throw err
  }

  // Use `diff` to check for new JavaScript to execute.
  const changes = diffLines(EVAL_INSTANCE.output, output)

  if (isCompletion) {
    undo()
  } else {
    EVAL_INSTANCE.output = output
  }

  return changes.reduce((result, change) => {
    return change.added ? exec(change.value, EVAL_FILENAME) : result
  }, undefined)
}
开发者ID:santoshkanuri,项目名称:ts-node,代码行数:29,代码来源:bin.ts

示例5: consoleTestResultHandler

export function consoleTestResultHandler(testResult: TestResult, logger: Logger): boolean {
    // needed to get colors to show up when passing through Grunt
    (chalk as any).enabled = true;

    let didAllTestsPass = true;

    for (const fileName of Object.keys(testResult.results)) {
        const results = testResult.results[fileName];
        logger.log(`${fileName}:`);

        if (results.skipped) {
            logger.log(chalk.yellow(` Skipped, requires typescript ${results.requirement}\n`));
        } else {
            const markupDiffResults = diff.diffLines(
                results.markupFromMarkup,
                results.markupFromLinter,
            );
            const fixesDiffResults = diff.diffLines(
                results.fixesFromLinter,
                results.fixesFromMarkup,
            );
            const didMarkupTestPass = !markupDiffResults.some(
                hunk => hunk.added === true || hunk.removed === true,
            );
            const didFixesTestPass = !fixesDiffResults.some(
                hunk => hunk.added === true || hunk.removed === true,
            );

            if (didMarkupTestPass && didFixesTestPass) {
                logger.log(chalk.green(" Passed\n"));
            } else {
                logger.log(chalk.red(" Failed!\n"));
                didAllTestsPass = false;
                if (!didMarkupTestPass) {
                    displayDiffResults(markupDiffResults, MARKUP_FILE_EXTENSION, logger);
                }
                if (!didFixesTestPass) {
                    displayDiffResults(fixesDiffResults, FIXES_FILE_EXTENSION, logger);
                }
            }
        }
    }

    return didAllTestsPass;
}
开发者ID:abierbaum,项目名称:tslint,代码行数:45,代码来源:test.ts

示例6: consoleTestResultHandler

export function consoleTestResultHandler(testResult: TestResult): boolean {
    // needed to get colors to show up when passing through Grunt
    (colors as any).enabled = true;

    let didAllTestsPass = true;

    for (const fileName of Object.keys(testResult.results)) {
        const results = testResult.results[fileName];
        process.stdout.write(`${fileName}:`);

        /* tslint:disable:no-console */
        if (results.skipped) {
            console.log(colors.yellow(` Skipped, requires typescript ${results.requirement}`));
        } else {
            const markupDiffResults = diff.diffLines(results.markupFromMarkup, results.markupFromLinter);
            const fixesDiffResults = diff.diffLines(results.fixesFromLinter, results.fixesFromMarkup);
            const didMarkupTestPass = !markupDiffResults.some((hunk) => hunk.added === true || hunk.removed === true);
            const didFixesTestPass = !fixesDiffResults.some((hunk) => hunk.added === true || hunk.removed === true);

            if (didMarkupTestPass && didFixesTestPass) {
                console.log(colors.green(" Passed"));
            } else {
                console.log(colors.red(" Failed!"));
                didAllTestsPass = false;
                if (!didMarkupTestPass) {
                    displayDiffResults(markupDiffResults, MARKUP_FILE_EXTENSION);
                }
                if (!didFixesTestPass) {
                    displayDiffResults(fixesDiffResults, FIXES_FILE_EXTENSION);
                }
            }
        }
        /* tslint:enable:no-console */
    }

    return didAllTestsPass;
}
开发者ID:IllusionMH,项目名称:tslint,代码行数:37,代码来源:test.ts

示例7: _eval

/**
 * Evaluate the code snippet.
 */
function _eval (code: string, context: any) {
  const undo = evalFile.input
  const isCompletion = !/\n$/.test(code)

  // Increment eval constants for the compiler to pick up changes.
  evalFile.input += code
  evalFile.version++

  let output: string

  // Undo on TypeScript compilation errors.
  try {
    output = service().compile(evalFile.input, EVAL_PATH)
  } catch (error) {
    evalFile.input = undo

    throw error
  }

  // Use `diff` to check for new JavaScript to execute.
  const changes = diffLines(evalFile.output, output)

  // Revert the code if running in "completion" environment. Updated the output
  // to diff against future executions when evaling code.
  if (isCompletion) {
    evalFile.input = undo
  } else {
    evalFile.output = output
  }

  let result: any

  // Iterate over the diff and evaluate `added` lines. The only removed lines
  // should be the source map and lines that stay the same are ignored.
  for (const change of changes) {
    if (change.added) {
      const script = createScript(change.value, EVAL_FILENAME)

      result = script.runInNewContext(context)
    }
  }

  return result
}
开发者ID:cartant,项目名称:ts-node,代码行数:47,代码来源:_bin.ts

示例8: diffSnapshotFile

export async function diffSnapshotFile(
  filename: string,
  hashDir: string
): Promise<string> {
  const snapshotFile = path.join(hashDir, filename);
  const snapshotBuffer = await fs.readFile(snapshotFile);

  let diffText = "";

  if (conflict(filename, snapshotBuffer)) {
    const textBuffer = await fs.readFile(filename);
    const diff = diffLines(snapshotBuffer.toString(), textBuffer.toString());

    diff.forEach(
      (line): void => {
        const color = line.added ? "green" : line.removed ? "red" : "white";
        diffText += chalk[color](line.value);
      }
    );
  }

  return diffText;
}
开发者ID:jlenoble,项目名称:generator-wupjs,代码行数:23,代码来源:snapshots.ts

示例9: diffLists

function diffLists(actual: string[], expected: string[]): diff.IDiffResult[] {
    return diff.diffLines(actual.join("\n"), expected.join("\n"));
}
开发者ID:IllusionMH,项目名称:tslint,代码行数:3,代码来源:ruleLoaderTests.ts

示例10: exec

 exec("cd examples/protractor && npm test -s", (error, stdout) => {
     const expected = readFileSync("spec/resources/node-protractor.out", {encoding: "utf-8"});
     const {added, removed} = filter(JsDiff.diffLines(expected, stdout));
     expect(added).toEqual(removed);
     done();
 });
开发者ID:bcaudan,项目名称:jasmine-spec-reporter,代码行数:6,代码来源:integration.spec.ts


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