UNPKG

versification

Version:

A library for parsing Paratext's vrs files.

257 lines (205 loc) 9.48 kB
import {expect} from 'chai'; import VerseRef from '../src/VerseRef' import Versification from '../src/Versification' import * as testData from './testData.js'; describe('VerseRef', () => { it('Basic test', () => { const verseRef = VerseRef.frombcv(40001001); expect(verseRef.book()).to.be.equal('MAT'); expect(verseRef.chapter()).to.be.equal('1'); expect(verseRef.verse()).to.be.equal('1'); expect(verseRef.toString()).to.be.equal('MAT 1:1'); }); it('End of chapter test', () => { const verseRef = VerseRef.frombcv(39004006); expect(verseRef.book()).to.be.equal('MAL'); expect(verseRef.chapter()).to.be.equal('4'); expect(verseRef.verse()).to.be.equal('6'); expect(verseRef.toString()).to.be.equal('MAL 4:6'); }); it('From (number) string', () => { const verseRef = VerseRef.frombcv('40001001'); expect(verseRef.book()).to.be.equal('MAT'); expect(verseRef.chapter()).to.be.equal('1'); expect(verseRef.verse()).to.be.equal('1'); expect(verseRef.toString()).to.be.equal('MAT 1:1'); }); describe('fromBookChapterVerse', () => { it('simple valid verse ref', () => { const verseRef = VerseRef.fromBookChapterVerse(1, 1, 1); expect(verseRef.book()).to.be.equal('GEN'); expect(verseRef.chapter()).to.be.equal('1'); expect(verseRef.verse()).to.be.equal('1'); expect(verseRef.toString()).to.be.equal('GEN 1:1'); }); }); describe('fromBookIdChapterVerse', () => { it('simple valid verse ref', () => { const verseRef = VerseRef.fromBookIdChapterVerse('GEN', '1', '1'); expect(verseRef.book()).to.be.equal('GEN'); expect(verseRef.chapter()).to.be.equal('1'); expect(verseRef.verse()).to.be.equal('1'); expect(verseRef.toString()).to.be.equal('GEN 1:1'); }); it('number types for chapter and verse', () => { const verseRef = VerseRef.fromBookIdChapterVerse('GEN', 1, 1); expect(verseRef.book()).to.be.equal('GEN'); expect(verseRef.chapter()).to.be.equal('1'); expect(verseRef.verse()).to.be.equal('1'); expect(verseRef.toString()).to.be.equal('GEN 1:1'); }); it('versification specified', () => { const englishVersification = new Versification(testData.eng); const verseRef = VerseRef.fromBookIdChapterVerse('GEN', '1', '1', englishVersification); expect(verseRef.book()).to.be.equal('GEN'); expect(verseRef.chapter()).to.be.equal('1'); expect(verseRef.verse()).to.be.equal('1'); expect(verseRef.toString()).to.be.equal('GEN 1:1'); expect(verseRef.versification()).to.be.equal(englishVersification); }); it('null chapter and verse (for non type safe invokes)', () => { // @ts-ignore - while not allowed js clients can do it. const verseRef = VerseRef.fromBookIdChapterVerse('GEN', null, null); expect(verseRef).to.be.undefined; }); it('undefined chapter and verse (for non type safe invokes)', () => { // @ts-ignore - while not allowed js clients can do it. const verseRef = VerseRef.fromBookIdChapterVerse('GEN'); expect(verseRef).to.be.undefined; }); }); describe('parse', () => { it('simple valid verse ref', () => { const verseRef = VerseRef.parse('MAT 1:21'); expect(verseRef?.book()).to.be.equal('MAT'); expect(verseRef?.chapter()).to.be.equal('1'); expect(verseRef?.verse()).to.be.equal('21'); expect(verseRef?.bbbcccvvv()).to.be.equal(40001021); expect(verseRef?.toString()).to.be.equal('MAT 1:21'); }); it('verse range', () => { const verseRef = VerseRef.parse('MAT 1:21-22'); expect(verseRef?.book()).to.be.equal('MAT'); expect(verseRef?.chapter()).to.be.equal('1'); expect(verseRef?.verse()).to.be.equal('21-22'); expect(verseRef?.bbbcccvvv()).to.be.equal(40001021); expect(verseRef?.toString()).to.be.equal('MAT 1:21-22'); }); it('split verse', () => { const verseRef = VerseRef.parse('MAT 1:21a'); expect(verseRef?.book()).to.be.equal('MAT'); expect(verseRef?.chapter()).to.be.equal('1'); expect(verseRef?.verse()).to.be.equal('21a'); expect(verseRef?.bbbcccvvv()).to.be.equal(40001021); expect(verseRef?.toString()).to.be.equal('MAT 1:21a'); }); it('Invalid versification', () => { // @ts-ignore expect(() => VerseRef.parse('PSA 3:2', 'not a versification object')).to.throw('versification : "not a versification object" is wrong type.'); // @ts-ignore expect(() => VerseRef.parse('PSA 3:2', {})).to.throw('versification : "[object Object]" is wrong type.'); // @ts-ignore expect(() => VerseRef.parse('PSA 3:2', [])).to.throw('versification : "" is wrong type.'); // @ts-ignore expect(() => VerseRef.parse('PSA 3:2', null)).to.not.throw(); }); }); describe('equals', () => { it('undefined', () => { const a = VerseRef.parse('PSA 3:2'); expect(a?.equals(undefined)).to.be.false; }) it('same verse ref - unspecified versification', () => { const a = VerseRef.parse('PSA 3:2'); const b = VerseRef.parse('PSA 3:2'); expect(a?.equals(b)).to.be.true; }); it('different verse ref - unspecified versification', () => { const a = VerseRef.parse('PSA 3:2'); const b = VerseRef.parse('PSA 3:3'); expect(a?.equals(b)).to.be.false; }); it('difference versification - equivalent verse', () => { const englishVersification = new Versification(testData.eng); const originalVersification = new Versification(testData.original); const englishVerseRef = VerseRef.parse('PSA 3:2', englishVersification); const originalVerseRef = VerseRef.parse('PSA 3:3', originalVersification); expect(englishVerseRef?.equals(originalVerseRef)).to.be.true; expect(originalVerseRef?.equals(englishVerseRef)).to.be.true; }); }); describe('changeVersification', () => { it('change versification', () => { const englishVersification = new Versification(testData.eng); const originalVersification = new Versification(testData.original); const verseRef = VerseRef.parse('PSA 3:2', englishVersification); verseRef?.changeVersification(originalVersification); expect(verseRef?.toString()).to.be.equal('PSA 3:3'); expect(verseRef?.versification().name).to.be.equal(originalVersification.name); expect(verseRef?.bbbcccvvv()).to.be.equal(19003003); expect(verseRef?.book()).to.be.equal("PSA"); }); }); describe('isDefinedByVersification', () => { it('in versification', () => { const englishVersification = new Versification(testData.eng); const verseRef = VerseRef.parse('MAT 1:1', englishVersification); expect(verseRef.isDefinedByVersification()).to.be.true; }); it('verse not in versification', () => { const englishVersification = new Versification(testData.eng); const verseRef = VerseRef.parse('MAT 1:26', englishVersification); expect(verseRef.isDefinedByVersification()).to.be.false; }); it('chapter not in versification', () => { const englishVersification = new Versification(testData.eng); const verseRef = VerseRef.parse('PSA 151:1', englishVersification); expect(verseRef.isDefinedByVersification()).to.be.false; }); it('book not in (this reduced size test) versification', () => { const englishVersification = new Versification(testData.eng); const verseRef = VerseRef.parse('NUM 1:1', englishVersification); expect(verseRef.isDefinedByVersification()).to.be.false; }); it('versification undefined - considers everything to be in undefined versification', () => { const verseRef = VerseRef.parse('GEN 999:987'); expect(verseRef.isDefinedByVersification()).to.be.true; }); it('excluded verse', () => { const lxxVersification = new Versification(testData.lxx); const verseRef = VerseRef.parse('GEN 31:51', lxxVersification); expect(verseRef.isDefinedByVersification()).to.be.false; }); }); });