mirror of
https://gitlab.com/walljm/dynamicbible.git
synced 2025-07-23 07:19:50 -04:00
fix bug in parser
This commit is contained in:
parent
cdb54947cb
commit
ed30f45bde
@ -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:*" },
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user