From 87e94cc62003f01856f05c30fc7c7773109bb924 Mon Sep 17 00:00:00 2001 From: Ira Hopkinson Date: Tue, 24 Oct 2023 08:50:24 +1300 Subject: [PATCH] Improve VerseRef test coverage - also fix coverage link in README --- README.md | 2 +- src/verse-ref.test.ts | 25 +++++++++++++++++++++++++ src/verse-ref.ts | 7 ++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3d2db4f..fc19c75 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ Contributions via Pull Request are welcome. Keep changes to porting the C# sourc [gitghub-codeql-status]: https://github.com/sillsdev/scripture/actions/workflows/codeql-analysis.yml/badge.svg [gitghub-codeql-url]: https://github.com/sillsdev/scripture/actions/workflows/codeql-analysis.yml [github-codecov-status]: https://codecov.io/gh/sillsdev/scripture/branch/main/graph/badge.svg?token=N51WM8PR2E -[github-codecov-url]: :https://codecov.io/gh/sillsdev/scripture +[github-codecov-url]: https://codecov.io/gh/sillsdev/scripture [github-tag-image]: https://img.shields.io/github/tag/sillsdev/scripture.svg?label=version [github-tag-url]: https://github.com/sillsdev/scripture/releases/latest [github-license]: https://github.com/sillsdev/scripture/blob/main/LICENSE diff --git a/src/verse-ref.test.ts b/src/verse-ref.test.ts index 4719dad..340f074 100644 --- a/src/verse-ref.test.ts +++ b/src/verse-ref.test.ts @@ -155,4 +155,29 @@ describe('VerseRef', () => { expect(vref.versification).toEqual(ScrVers.Septuagint); }); }); + + // Tests that don't exist in the C#. + describe('Extra (TS-only tests)', () => { + it('should convert to empty string', () => { + const vref = new VerseRef(); + expect(vref.toString()).toEqual(''); + }); + + it('should convert to string', () => { + const vref = new VerseRef(1, 2, 3, ScrVers.Septuagint); + expect(vref.toString()).toEqual('GEN 2:3'); + }); + + it('should confirm when refs are equal', () => { + const vref = new VerseRef(1, 2, 3, ScrVers.Septuagint); + const vrefClone = vref.clone(); + expect(vref.equals(vrefClone)).toBe(true); + }); + + it('should confirm when refs are not equal', () => { + const vref = new VerseRef(1, 2, 3, ScrVers.Septuagint); + const vrefNotEqual = new VerseRef(1, 20, 3, ScrVers.Septuagint); + expect(vref.equals(vrefNotEqual)).toBe(false); + }); + }); }); diff --git a/src/verse-ref.ts b/src/verse-ref.ts index dd06d09..7546a71 100644 --- a/src/verse-ref.ts +++ b/src/verse-ref.ts @@ -469,15 +469,16 @@ export class VerseRef { /** * Compares this `VerseRef` with supplied one. - * @param verseRef - `VerseRef` to compare this one to. + * @param verseRef - object to compare this one to. * @returns `true` if this `VerseRef` is equal to the supplied on, `false` otherwise. */ - equals(verseRef: VerseRef): boolean { + equals(verseRef: object): boolean { + if (!(verseRef instanceof VerseRef)) return false; return ( verseRef._bookNum === this._bookNum && verseRef._chapterNum === this._chapterNum && verseRef._verseNum === this._verseNum && - verseRef._verse === this._verse && + verseRef.verse === this.verse && verseRef.versification != null && this.versification != null && verseRef.versification.equals(this.versification)