import { test, expect } from 'vitest'; import { indexBook, normalizeStrongs, occurrences } from './strongs.js'; test('normalizeStrongs accepts the usual spellings and rejects the rest', () => { expect(normalizeStrongs('g4102')).toBe('G4102'); expect(normalizeStrongs(' H07225 ')).toBe('H7225'); expect(normalizeStrongs('H1234a')).toBe('H1234'); expect(normalizeStrongs('4102')).toBeNull(); expect(normalizeStrongs('')).toBeNull(); expect(normalizeStrongs(undefined)).toBeNull(); }); test('occurrences groups verses by book and counts a verse once however often the word repeats', () => { const index = new Map(); indexBook(index, 'JHN', { 3: { 16: [{ s: 'G25' }, { s: 'G25' }, { s: 'G2316' }], 17: [{ s: 'G2316' }] }, 1: { 1: [{ s: 'G3056' }, { s: 'G2316' }] }, }); indexBook(index, 'ROM', { 5: { 8: [{ s: 'G25' }, { s: 'G2316' }] } }); const love = occurrences(index, 'g25'); expect(love.total).toBe(2); expect(love.books.map((b) => [b.book, b.name, b.count])).toEqual([['JHN', 'John', 1], ['ROM', 'Romans', 1]]); const god = occurrences(index, 'G2316'); expect(god.total).toBe(4); expect(god.books[0].refs).toEqual([[1, 1], [3, 16], [3, 17]]); // sorted by chapter then verse }); test('an unknown or invalid number comes back empty', () => { const index = new Map(); expect(occurrences(index, 'G99999')).toEqual({ strongs: 'G99999', total: 0, books: [] }); expect(occurrences(index, 'nonsense')).toEqual({ strongs: null, total: 0, books: [] }); }); test('malformed interlinear data is skipped, not thrown', () => { const index = new Map(); expect(() => indexBook(index, 'GEN', { 1: { 1: null, 2: 'x', 3: [null, { s: 5 }, { s: 'H430' }] } })).not.toThrow(); expect(occurrences(index, 'H430').total).toBe(1); });