// Fragment quotes (release 28 Q2): what is one, and the full sentence code offers. import { test } from "node:test"; import assert from "node:assert/strict"; import { FRAGMENT_END_WORDS, fragmentOf, fullSentenceFor, isFragmentQuote } from "./fragment"; import { strictQuoteCheck } from "./verify"; import { cuesOf } from "../../testing/draft/corpus.mjs"; const cue = (start: number, text: string) => ({ start, end: start + 4.8, text }); test("a fragment: under four words, or a part ending on a function word", () => { assert.deepEqual(fragmentOf("I priced it as"), { why: "ends on “as”", part: "I priced it as" }); assert.equal(fragmentOf("never again")?.why, "under 4 words"); assert.equal(fragmentOf("my lawyer told me not to")?.why, "ends on “to”"); // Case and punctuation aside; an ellipsis part is judged on its own. assert.equal(fragmentOf("I paid for THE")?.why, "ends on “the”"); assert.equal(fragmentOf("I would never sell the bakery … to a chain and")?.part, "to a chain and"); // Whole sentences and clauses pass. assert.equal(fragmentOf("I would never sell the bakery to a chain"), null); assert.equal(fragmentOf("What are you even looking at?"), null, "sentence punctuation ends a sentence whatever its last word"); assert.equal(isFragmentQuote("the judges were friends of mine so it felt wrong"), false); assert.equal(fragmentOf(""), null); assert.ok(FRAGMENT_END_WORDS.includes("as") && FRAGMENT_END_WORDS.includes("her")); }); test("the full sentence: unpunctuated captions extend to the end of the quote's cue", async () => { const cues = (await cuesOf("synth-kitchen", "bread-day-01"))!; assert.equal(fullSentenceFor("I paid for the", cues, 45), "I paid for the new mixer myself"); const pie = (await cuesOf("synth-kitchen", "pie-stream-02"))!; assert.equal(fullSentenceFor("my lawyer told me not to", pie, 40), "my lawyer told me not to talk about the lease"); // Under four words: the cue's run holds it. assert.equal(fullSentenceFor("I did not", pie, 10), "I did not enter the contest this year"); // Not there verbatim: nothing to offer. assert.equal(fullSentenceFor("I sold the bakery as", cues, 15), null); }); test("the full sentence: punctuation, a new cue's capital, one more cue, and the cap", () => { const punct = [cue(0, "So the price. I priced it as a loss, and"), cue(5, "then I moved on. Next")]; assert.equal(fullSentenceFor("I priced it as", punct, 0), "I priced it as a loss, and then I moved on."); // A cue boundary where the next cue starts a sentence ends it (the pronoun I does not). const caps = [cue(0, "we said that the oven ran hot"), cue(5, "Then we left"), cue(10, "I think")]; assert.equal(fullSentenceFor("the oven ran", caps, 0), "the oven ran hot"); // Still under four words: back to the sentence's start. assert.equal(fullSentenceFor("ran hot", caps, 0), "we said that the oven ran hot"); // The quote's cue ends on a function word: one more cue. const more = [cue(0, "she told me that the shop is"), cue(5, "closing in the spring"), cue(10, "and nobody knew")]; assert.equal(fullSentenceFor("the shop is", more, 0), "the shop is closing in the spring"); // Too long to be offered. const long = [cue(0, `the ${"very ".repeat(40)}long one of`), cue(5, "and of")]; assert.equal(fullSentenceFor("the very very", long, 0, { maxWords: 10 }), null); }); test("the full sentence passes the strict check wherever the quote did", async () => { const cues = (await cuesOf("synth-kitchen", "bread-day-01"))!; const s = fullSentenceFor("I paid for the", cues, 45)!; assert.equal(strictQuoteCheck(s, cues, 45).ok, true); assert.equal(fragmentOf(s), null); });