import { describe, it, expect } from 'vitest'; import { cardContentHash } from '../src/content-hash.ts'; describe('cardContentHash', () => { it('liefert deterministischen 64-char-hex-String (SHA-256)', async () => { const h = await cardContentHash({ type: 'basic', fields: { front: 'Q', back: 'A' }, }); expect(h).toMatch(/^[0-9a-f]{64}$/); }); it('ist invariant gegenüber Field-Reihenfolge', async () => { const a = await cardContentHash({ type: 'basic', fields: { front: 'Q', back: 'A' }, }); const b = await cardContentHash({ type: 'basic', fields: { back: 'A', front: 'Q' }, }); expect(a).toBe(b); }); it('unterscheidet basic und basic-reverse', async () => { const a = await cardContentHash({ type: 'basic', fields: { front: 'Q', back: 'A' }, }); const b = await cardContentHash({ type: 'basic-reverse', fields: { front: 'Q', back: 'A' }, }); expect(a).not.toBe(b); }); it('unterscheidet zwei Cloze-Karten mit unterschiedlichem Cluster-Markup', async () => { const a = await cardContentHash({ type: 'cloze', fields: { text: 'Die {{c1::Hauptstadt}} ist {{c2::Paris}}.' }, }); const b = await cardContentHash({ type: 'cloze', fields: { text: 'Die Hauptstadt ist {{c1::Paris}}.' }, }); expect(a).not.toBe(b); }); it('unterscheidet Karten mit Whitespace-Drift', async () => { const a = await cardContentHash({ type: 'basic', fields: { front: 'Q', back: 'A' }, }); const b = await cardContentHash({ type: 'basic', fields: { front: 'Q ', back: 'A' }, }); expect(a).not.toBe(b); }); });