import { verbatimOverlap, normWords } from '../overlap'; const SOURCE = `Saudi Arabia will apply excise tax to sweetened drinks from January 2026, Gulf News reported, adding another category to a tax architecture that already captures selected products across the Gulf region. For businesses outside the region, the broader lesson is that excise tax in the GCC should be viewed as a shared framework with local variations that change launch economics.`; describe('normWords', () => { it('lowercases, strips punctuation, collapses whitespace', () => { expect(normWords('Hello, WORLD! (2026)')).toEqual(['hello', 'world', '2026']); expect(normWords('')).toEqual([]); expect(normWords(null as unknown as string)).toEqual([]); }); }); describe('verbatimOverlap', () => { it('flags a long verbatim copy (whole sentence lifted from the source)', () => { const copied = 'Saudi Arabia will apply excise tax to sweetened drinks from January 2026, Gulf News reported.'; const r = verbatimOverlap(copied, [SOURCE]); expect(r.longestRunWords).toBeGreaterThanOrEqual(12); expect(r.overlapRatio).toBeGreaterThan(0.5); expect(r.sample).toContain('excise tax to sweetened drinks'); }); it('passes a genuine paraphrase of the same facts', () => { const paraphrase = 'From 2026 the Kingdom broadens its excise regime to cover sugary beverages, a reminder that Gulf tax rules differ market by market.'; const r = verbatimOverlap(paraphrase, [SOURCE]); expect(r.longestRunWords).toBeLessThan(6); expect(r.overlapRatio).toBeLessThan(0.15); }); it('ignores a short shared phrase (< minRun words)', () => { // "excise tax" is shared but only 2 words — below the 6-word shingle. const r = verbatimOverlap('Companies weighing excise tax exposure should plan ahead.', [SOURCE]); expect(r.longestRunWords).toBe(0); }); it('is case- and punctuation-insensitive', () => { const copied = 'SHOULD BE VIEWED AS A SHARED FRAMEWORK — with local variations!!!'; const r = verbatimOverlap(copied, [SOURCE]); expect(r.longestRunWords).toBeGreaterThanOrEqual(6); expect(r.sample).toContain('shared framework'); }); it('returns zeros for empty candidate or no sources', () => { expect(verbatimOverlap('', [SOURCE])).toEqual({ longestRunWords: 0, overlapRatio: 0, sample: '' }); expect(verbatimOverlap('anything here', [])).toEqual({ longestRunWords: 0, overlapRatio: 0, sample: '' }); expect(verbatimOverlap('anything here', [''])).toEqual({ longestRunWords: 0, overlapRatio: 0, sample: '' }); }); it('finds the copied span across multiple sources', () => { const copied = 'a tax architecture that already captures selected products'; const r = verbatimOverlap(copied, ['unrelated text about camels', SOURCE]); expect(r.longestRunWords).toBeGreaterThanOrEqual(7); }); });