From c8beff612824258557deb16ce2fac113ae18d577 Mon Sep 17 00:00:00 2001 From: Damien Daspit Date: Mon, 28 Oct 2024 16:58:29 -0500 Subject: [PATCH] Add ParatextProjectSettings tests --- src/corpora/paratext-project-settings.test.ts | 134 ++++++++++++++++++ src/corpora/paratext-project-settings.ts | 3 +- 2 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 src/corpora/paratext-project-settings.test.ts diff --git a/src/corpora/paratext-project-settings.test.ts b/src/corpora/paratext-project-settings.test.ts new file mode 100644 index 0000000..629f03f --- /dev/null +++ b/src/corpora/paratext-project-settings.test.ts @@ -0,0 +1,134 @@ +import { ScrVers } from '@sillsdev/scripture'; + +import { ParatextProjectSettings } from './paratext-project-settings'; +import { UsfmStylesheet } from './usfm-stylesheet'; + +describe('ParatextProjectSettings', () => { + it('getBookFileName - book number', () => { + const settings = createSettings('41'); + expect(settings.getBookFileName('MRK')).toEqual('PROJ42.SFM'); + }); + + it('getBookFileName - book number and id', () => { + const settings = createSettings('41MAT'); + expect(settings.getBookFileName('MRK')).toEqual('PROJ42MRK.SFM'); + }); + + it('getBookFileName - book id', () => { + const settings = createSettings('MAT'); + expect(settings.getBookFileName('MRK')).toEqual('PROJMRK.SFM'); + }); + + it('getBookFileName - book number with zero padding', () => { + const settings = createSettings('41'); + expect(settings.getBookFileName('GEN')).toEqual('PROJ01.SFM'); + }); + + it('getBookFileName - XXG', () => { + const settings = createSettings('41'); + expect(settings.getBookFileName('XXG')).toEqual('PROJ100.SFM'); + }); + + it('getBookFileName - book number with A prefix', () => { + const settings = createSettings('41'); + expect(settings.getBookFileName('FRT')).toEqual('PROJA0.SFM'); + }); + + it('getBookFileName - book number with B prefix', () => { + const settings = createSettings('41'); + expect(settings.getBookFileName('TDX')).toEqual('PROJB0.SFM'); + }); + + it('getBookFileName - book number with C prefix', () => { + const settings = createSettings('41'); + expect(settings.getBookFileName('3MQ')).toEqual('PROJC0.SFM'); + }); + + it('getBookId - book number', () => { + const settings = createSettings('41'); + expect(settings.getBookId('PROJ42.SFM')).toEqual('MRK'); + }); + + it('getBookId - book number and id', () => { + const settings = createSettings('41MAT'); + expect(settings.getBookId('PROJ42MRK.SFM')).toEqual('MRK'); + }); + + it('getBookId - book id', () => { + const settings = createSettings('MAT'); + expect(settings.getBookId('PROJMRK.SFM')).toEqual('MRK'); + }); + + it('getBookId - book number with zero padding', () => { + const settings = createSettings('41'); + expect(settings.getBookId('PROJ01.SFM')).toEqual('GEN'); + }); + + it('getBookId - XXG - book number', () => { + const settings = createSettings('41'); + expect(settings.getBookId('PROJ100.SFM')).toEqual('XXG'); + }); + + it('getBookId - XXG - book number and id', () => { + const settings = createSettings('41MAT'); + expect(settings.getBookId('PROJ100XXG.SFM')).toEqual('XXG'); + }); + + it('getBookId - book number with A prefix', () => { + const settings = createSettings('41'); + expect(settings.getBookId('PROJA0.SFM')).toEqual('FRT'); + }); + + it('getBookId - book number with B prefix', () => { + const settings = createSettings('41'); + expect(settings.getBookId('PROJB0.SFM')).toEqual('TDX'); + }); + + it('getBookId - book number with C prefix', () => { + const settings = createSettings('41'); + expect(settings.getBookId('PROJC0.SFM')).toEqual('3MQ'); + }); + + it('getBookId - wrong prefix', () => { + const settings = createSettings('41'); + expect(settings.getBookId('WRONG42.SFM')).toBeUndefined(); + }); + + it('getBookId - wrong suffix', () => { + const settings = createSettings('41'); + expect(settings.getBookId('PROJ42.TXT')).toBeUndefined(); + }); + + it('getBookId - wrong book number', () => { + const settings = createSettings('41'); + expect(settings.getBookId('PROJ42MRK.SFM')).toBeUndefined(); + }); + + it('getBookId - wrong book id', () => { + const settings = createSettings('MAT'); + expect(settings.getBookId('PROJ42.SFM')).toBeUndefined(); + }); + + it('getBookId - wrong book number and id', () => { + const settings = createSettings('41MAT'); + expect(settings.getBookId('PROJMRK.SFM')).toBeUndefined(); + expect(settings.getBookId('PROJ100.SFM')).toBeUndefined(); + }); +}); + +function createSettings(fileNameForm: string): ParatextProjectSettings { + return new ParatextProjectSettings( + 'Name', + 'Name', + 'utf8', + ScrVers.English, + new UsfmStylesheet('usfm.sty'), + 'PROJ', + fileNameForm, + '.SFM', + 'Major', + '', + 'BiblicalTerms.xml', + 'en', + ); +} diff --git a/src/corpora/paratext-project-settings.ts b/src/corpora/paratext-project-settings.ts index 43d843b..ca3c16f 100644 --- a/src/corpora/paratext-project-settings.ts +++ b/src/corpora/paratext-project-settings.ts @@ -51,8 +51,7 @@ export class ParatextProjectSettings { let bookPart: string; if (this.fileNameForm === 'MAT') { bookPart = bookId; - } - if (this.fileNameForm === '40' || this.fileNameForm === '41') { + } else if (this.fileNameForm === '40' || this.fileNameForm === '41') { bookPart = getBookFileNameDigits(bookId); } else { bookPart = getBookFileNameDigits(bookId) + bookId;