From ed30f45bde967a942fcef15a1b05b736c446e010 Mon Sep 17 00:00:00 2001 From: Jason Wall Date: Thu, 6 Aug 2020 20:46:53 -0400 Subject: [PATCH] fix bug in parser --- app/db/src/app/common/bible-reference.spec.ts | 76 ++++++++++--------- app/db/src/app/common/bible-reference.ts | 9 ++- 2 files changed, 46 insertions(+), 39 deletions(-) diff --git a/app/db/src/app/common/bible-reference.spec.ts b/app/db/src/app/common/bible-reference.spec.ts index 63248cfa..ea9eb6b1 100644 --- a/app/db/src/app/common/bible-reference.spec.ts +++ b/app/db/src/app/common/bible-reference.spec.ts @@ -1,39 +1,41 @@ import { BibleReference } from './bible-reference'; describe('Reference', () => { - // it('Should parse the reference: Gen 1:1', () => { - // const ref = new BibleReference('Gen 1:1').toString(); - // expect(ref).toBe('Genesis 1:1'); - // }); + it('Should parse the reference: Gen 1:1', () => { + const ref = new BibleReference('Gen 1:1').toString(); + expect(ref).toBe('Genesis 1:1'); + }); - // it('Should parse the reference: Gen 1:1-11', () => { - // const ref = new BibleReference('Gen 1:1-11').toString(); - // expect(ref).toBe('Genesis 1:1 - 11'); - // }); + it('Should parse the reference: Gen 1:1-11', () => { + const ref = new BibleReference('Gen 1:1-11').toString(); + expect(ref).toBe('Genesis 1:1 - 11'); + }); - // it('Should parse the reference: Gen 1-2', () => { - // const ref = new BibleReference('Gen 1-2').toString(); - // expect(ref).toBe('Genesis 1:1 - 2:*'); - // }); + it('Should parse the reference: Gen 1-2', () => { + const ref = new BibleReference('Gen 1-2').toString(); + expect(ref).toBe('Genesis 1:1 - 2:*'); + }); - // it('Should parse the reference: John 3:16', () => { - // const ref = new BibleReference('John 3:16').toString(); - // expect(ref).toBe('John 3:16'); - // }); + it('Should parse the reference: John 3:16', () => { + const ref = new BibleReference('John 3:16').toString(); + expect(ref).toBe('John 3:16'); + }); - // it('Should parse the reference: John 3-6', () => { - // const ref = new BibleReference('Jn 3-6').toString(); - // expect(ref).toBe('John 3:1 - 6:*'); - // }); + it('Should parse the reference: John 3-6', () => { + const ref = new BibleReference('Jn 3-6').toString(); + expect(ref).toBe('John 3:1 - 6:*'); + }); - // it('Should parse the reference: 1 Corinthians 3:5-6:5', () => { - // const ref = new BibleReference('1 Corinthians 3:5-6:5').toString(); - // expect(ref).toBe('1 Corinthians 3:5 - 6:5'); - // }); + it('Should parse the reference: 1 Corinthians 3:5-6:5', () => { + const ref = new BibleReference('1 Corinthians 3:5-6:5').toString(); + expect(ref).toBe('1 Corinthians 3:5 - 6:5'); + }); - // it('Should parse the reference: 2 Samuel 5:5-6:5', () => { - // expect(new BibleReference('II sam 5:5-6:5').toString()).toBe('2 Samuel 5:5 - 6:5'); - // }); + it('Should parse the reference: 2 Samuel 5:5-6:5', () => { + expect(new BibleReference('II sam 5:5-6:5').toString()).toBe( + '2 Samuel 5:5 - 6:5' + ); + }); const booknames = [ { abbr: 'gen', actual: 'Genesis' }, @@ -274,6 +276,7 @@ describe('Reference', () => { expect( new BibleReference(bk.abbr + ' ' + i + '-' + (i + 1)).toString() ).toBe(bk.actual + ' ' + i + ':1 - ' + (i + 1) + ':*'); + expect( new BibleReference( bk.abbr + ' ' + i + ':3-' + (i + 1) + ':6' @@ -281,17 +284,18 @@ describe('Reference', () => { ).toBe(bk.actual + ' ' + i + ':3 - ' + (i + 1) + ':6'); } - // expect(new BibleReference(bk.abbr + ' 1:4-2:5').toString()).toBe( - // bk.actual + ' 1:4 - 2:5' - // ); - // expect(new BibleReference(bk.abbr + ' 1:1 - 5').toString()).toBe( - // bk.actual + ' 1:1 - 5' - // ); - // expect(new BibleReference(bk.abbr + ' 1:4 - 5').toString()).toBe( - // bk.actual + ' 1:4 - 5' - // ); + expect(new BibleReference(bk.abbr + ' 1:4-2:5').toString()).toBe( + bk.actual + ' 1:4 - 2:5' + ); + expect(new BibleReference(bk.abbr + ' 1:1 - 5').toString()).toBe( + bk.actual + ' 1:1 - 5' + ); + expect(new BibleReference(bk.abbr + ' 1:4 - 5').toString()).toBe( + bk.actual + ' 1:4 - 5' + ); }); } + const refs = [ { src: '2 sam 3:4-6:8', actual: '2 Samuel 3:4 - 6:8' }, // { "src": "gen 50 - ex 2", "actual": "Genesis 50:1 - Exodus 2:*" }, diff --git a/app/db/src/app/common/bible-reference.ts b/app/db/src/app/common/bible-reference.ts index 38c3497e..be95c56d 100644 --- a/app/db/src/app/common/bible-reference.ts +++ b/app/db/src/app/common/bible-reference.ts @@ -1910,12 +1910,13 @@ export class BibleReference { } private parseReference() { - this.parseNumberReference(); + this.parseKeyReference(); if (this.ref.length === 0) { return; } this.parseBook(false); this.parseFirstNum(false); + const foundFirstVerse = this.ref.search(/:.*-/) !== -1; this.maybeParseSecondNum(false); this.maybeParseRangeSep(); @@ -1926,10 +1927,12 @@ export class BibleReference { this.maybeParseSecondNum(true); } - private parseNumberReference() { + // we're trying to parse references in the form of 41:2:3 + private parseKeyReference() { this.ref = this.ref.toLowerCase().trim(); + const parts = this.ref.split(':'); - if (parts.length === 3 && parts.every((i) => parseInt(i, 10) > 0)) { + if (this.ref.match(/\d+:\d+:\d+/) !== null) { const fbook = BibleReference.bookName(parseInt(parts[0], 10)); this.Section.book = fbook;