// Release 38 lane C: the audio check's word diff -- the quote's words aligned with what the worker heard. // // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test lib/research/wordDiff.test.ts import test from "node:test"; import assert from "node:assert/strict"; import { heardShare, quoteWordDiff } from "./wordDiff"; test("a quote heard whole: every word the same, the window's other words left out", () => { const d = quoteWordDiff("the lighthouse keeper called in", "okay so the lighthouse keeper called in last night"); assert.equal(d.matched, 5); assert.equal(d.words, 5); assert.deepEqual(d.ops.map((o) => o.op), ["same", "same", "same", "same", "same"]); assert.equal(heardShare(d), 1); }); test("a quote the captions rewrote: the missing and the extra words, in place", () => { const d = quoteWordDiff("the lighthouse keeper rang in", "and then the lighthouse keeper called in again"); assert.equal(d.matched, 4); assert.deepEqual( d.ops.map((o) => `${o.op[0]}:${o.word}`), ["s:the", "s:lighthouse", "s:keeper", "m:rang", "e:called", "s:in"], ); }); test("punctuation and case do not count; nothing heard is all missing", () => { assert.equal(quoteWordDiff("How much was it? You cut it all,", "how much was it you cut it all").matched, 8); const none = quoteWordDiff("not said at all", ""); assert.equal(none.matched, 0); assert.deepEqual(none.ops.map((o) => o.op), ["missing", "missing", "missing", "missing"]); assert.equal(quoteWordDiff("", "words").words, 0); assert.equal(quoteWordDiff("alpha beta", "gamma delta").matched, 0); });