Skip to content

Commit 406cef6

Browse files
authored
Improve VerseRef test coverage (#12)
- also fix coverage link in README
1 parent 78411a4 commit 406cef6

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Contributions via Pull Request are welcome. Keep changes to porting the C# sourc
171171
[gitghub-codeql-status]: https://github.com/sillsdev/scripture/actions/workflows/codeql-analysis.yml/badge.svg
172172
[gitghub-codeql-url]: https://github.com/sillsdev/scripture/actions/workflows/codeql-analysis.yml
173173
[github-codecov-status]: https://codecov.io/gh/sillsdev/scripture/branch/main/graph/badge.svg?token=N51WM8PR2E
174-
[github-codecov-url]: :https://codecov.io/gh/sillsdev/scripture
174+
[github-codecov-url]: https://codecov.io/gh/sillsdev/scripture
175175
[github-tag-image]: https://img.shields.io/github/tag/sillsdev/scripture.svg?label=version
176176
[github-tag-url]: https://github.com/sillsdev/scripture/releases/latest
177177
[github-license]: https://github.com/sillsdev/scripture/blob/main/LICENSE

src/verse-ref.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,29 @@ describe('VerseRef', () => {
155155
expect(vref.versification).toEqual(ScrVers.Septuagint);
156156
});
157157
});
158+
159+
// Tests that don't exist in the C#.
160+
describe('Extra (TS-only tests)', () => {
161+
it('should convert to empty string', () => {
162+
const vref = new VerseRef();
163+
expect(vref.toString()).toEqual('');
164+
});
165+
166+
it('should convert to string', () => {
167+
const vref = new VerseRef(1, 2, 3, ScrVers.Septuagint);
168+
expect(vref.toString()).toEqual('GEN 2:3');
169+
});
170+
171+
it('should confirm when refs are equal', () => {
172+
const vref = new VerseRef(1, 2, 3, ScrVers.Septuagint);
173+
const vrefClone = vref.clone();
174+
expect(vref.equals(vrefClone)).toBe(true);
175+
});
176+
177+
it('should confirm when refs are not equal', () => {
178+
const vref = new VerseRef(1, 2, 3, ScrVers.Septuagint);
179+
const vrefNotEqual = new VerseRef(1, 20, 3, ScrVers.Septuagint);
180+
expect(vref.equals(vrefNotEqual)).toBe(false);
181+
});
182+
});
158183
});

src/verse-ref.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,15 +469,16 @@ export class VerseRef {
469469

470470
/**
471471
* Compares this `VerseRef` with supplied one.
472-
* @param verseRef - `VerseRef` to compare this one to.
472+
* @param verseRef - object to compare this one to.
473473
* @returns `true` if this `VerseRef` is equal to the supplied on, `false` otherwise.
474474
*/
475-
equals(verseRef: VerseRef): boolean {
475+
equals(verseRef: object): boolean {
476+
if (!(verseRef instanceof VerseRef)) return false;
476477
return (
477478
verseRef._bookNum === this._bookNum &&
478479
verseRef._chapterNum === this._chapterNum &&
479480
verseRef._verseNum === this._verseNum &&
480-
verseRef._verse === this._verse &&
481+
verseRef.verse === this.verse &&
481482
verseRef.versification != null &&
482483
this.versification != null &&
483484
verseRef.versification.equals(this.versification)

0 commit comments

Comments
 (0)