import { expect, test } from 'vitest'; import { formatPassage, matchBooks, parsePassageRef } from './passageRef.js'; const first = (text) => parsePassageRef(text)[0]; test('understands a book, chapter and verse in the usual ways', () => { expect(first('John 3:16')).toMatchObject({ book: 'JHN', chapter: 3, verse: 16 }); expect(first('jn 3 16')).toMatchObject({ book: 'JHN', chapter: 3, verse: 16 }); expect(first('Ps 23')).toMatchObject({ book: 'PSA', chapter: 23, verse: null }); expect(first('1 cor 13:4')).toMatchObject({ book: '1CO', chapter: 13, verse: 4 }); expect(first('1corinthians 13')).toMatchObject({ book: '1CO', chapter: 13 }); expect(first('song of solomon 2')).toMatchObject({ book: 'SNG', chapter: 2 }); expect(first('Rom. 8.28')).toMatchObject({ book: 'ROM', chapter: 8, verse: 28 }); }); test('a bare book name opens its first chapter', () => { expect(first('romans')).toMatchObject({ book: 'ROM', chapter: 1, hasChapter: false }); }); test('a name that fits several books lists them; a short form picks one', () => { expect(matchBooks('jo').length).toBeGreaterThan(1); expect(matchBooks('jn').map((b) => b.abbrev)).toEqual(['JHN']); }); test('rejects chapters a book does not have, and things that are not passages', () => { expect(parsePassageRef('jude 2')).toEqual([]); // Jude has one chapter expect(parsePassageRef('genesis 51')).toEqual([]); expect(parsePassageRef('')).toEqual([]); expect(parsePassageRef('3:16')).toEqual([]); expect(parsePassageRef('zzz 4')).toEqual([]); }); test('formats a place the way people write it', () => { expect(formatPassage(first('john 3:16'))).toBe('John 3:16'); expect(formatPassage(first('psalm 23'))).toBe('Psalms 23'); expect(formatPassage(first('romans'))).toBe('Romans'); });