IF Commons GitHub

logical/diff

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0003-anyfs-cli-logical FR-006

A line diff in the unified form (commons anyfs-cli 0003-anyfs-cli-logical FR-006): the shortest edit of the lines of one text into the other by the longest common subsequence, written as hunks with three lines of context. It is bounded: two texts whose product of lines is over four million are not compared line by line, and the result says so, so that a diff of two huge files is a sentence and not a stall.

import { unifiedDiff } from "./diff.ts";
unifiedDiff("a\nb\n", "a\nc\n", "x", "y"); // { kind: "differ", text: "--- x\n+++ y\n@@ -1,2 +1,2 @@\n a\n-b\n+c\n" }

Source: commons/anyfs-cli/src/logical/diff.ts

1 of 3 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

DiffResulttypeno test imports it
type DiffResult =
  | { readonly kind: "same" }
  | { readonly kind: "differ"; readonly text: string; readonly added: number; readonly removed: number }
  | { readonly kind: "too-large"; readonly lines: number };

What comparing two texts gave.

DIFF_LIMITconstno test imports it
const DIFF_LIMIT: 4000000

The most lines of the one times the lines of the other that are compared.

unifiedDifffunction
function unifiedDiff(before: string, after: string, beforeName: string, afterName: string): DiffResult

The unified diff of two texts, with the names of the two sides in its header.

Imported by 12 tests of the run (12 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.