import { describe, expect, it } from 'vitest'; import { qrMatrix, qrShape } from './qr'; describe('qr', () => { const url = 'https://musicshare.app/u/alice'; it('produces a square grid with the three finder patterns', () => { const m = qrMatrix(url); const n = m.length; expect(n).toBeGreaterThanOrEqual(21); expect(m.every((row) => row.length === n)).toBe(true); // Finder pattern corners: dark outer ring, light inner ring, dark 3x3 centre. for (const [r, c] of [ [0, 0], [0, n - 7], [n - 7, 0], ] as const) { expect(m[r]![c]).toBe(true); expect(m[r + 1]![c + 1]).toBe(false); expect(m[r + 3]![c + 3]).toBe(true); } }); it('is deterministic and draws every dark module', () => { const a = qrShape(url); expect(qrShape(url)).toEqual(a); const darkCount = qrMatrix(url).flat().filter(Boolean).length; const drawn = [...a.path.matchAll(/h(\d+)v1/g)].reduce((sum, m) => sum + Number(m[1]), 0); expect(drawn).toBe(darkCount); }); it('grows for longer text', () => { expect(qrShape(`${url}?${'x'.repeat(200)}`).size).toBeGreaterThan(qrShape(url).size); }); });