當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。