fix VerseRef.verseNum setter mis-port - #60
Open
irahopkinson wants to merge 1 commit into
Open
Conversation
The setter assigned the backing field and nothing else, marked with a `ToDo`
placeholder. It was missing both of the other things the C# `VerseRef.VerseNum`
setter does:
if (value < 0)
throw new VerseRefException("VerseNum can not be negative");
verseNum = (short)value;
verse = null;
So negative verse numbers were accepted, and assigning `verseNum` left the
range/segment string in place. Setting `verseNum = 9` on `LUK 3:4b-5a` left a
stale `4b-5a` in the `verse` getter and `hasMultiple` still `true`.
Uses `this._verse = undefined` rather than `null`, per the repo convention of
preferring `undefined` for missing values. The C# `(short)` cast is not
replicated.
The C# test that covers the range-clearing is `CopyVerseFrom`, which sets
`VerseNum = 9` on a `LUK 3:4b-6a` source and then asserts the copied `Verse` is
`"9"`. That test cannot be ported yet — `copyVerseFrom` is not implemented in
this port — so the cases are added as TS-only tests instead: the negative
guard, the zero boundary, and the clearing of both a range and a segment.
`BuildVerseRefByProps` already exercised `verseNum = 0/15/17` and still passes;
those are plain numbers with no verse string to clear.
Behaviour change for consumers: unlike the sibling `chapterNum` setter fixed in
#58, this setter worked before, so code reading `verse`/`hasMultiple` after
assigning `verseNum` will see different results.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #60 +/- ##
==========================================
+ Coverage 83.93% 84.68% +0.74%
==========================================
Files 4 4
Lines 330 333 +3
Branches 77 80 +3
==========================================
+ Hits 277 282 +5
+ Misses 33 30 -3
- Partials 20 21 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
verseNumsetter assigned the backing field and nothing else, still carryingits
ToDoplaceholder:The C#
VerseRef.VerseNumit ports does two more things:
So the TS accepted negative verse numbers, and assigning
verseNumleft anyrange or segment string in place:
This mirrors #58, which fixed the sibling
chapterNumsetter the same way.this._verse = undefinedis used rather thannull, per the repo convention ofpreferring
undefinedfor missing values, and the C#(short)cast is notreplicated.
Unlike
chapterNum— which recursed into itself and blew the stack on everyassignment, so nothing could have depended on it — this setter works today.
Clearing
_versechanges what theversegetter andhasMultiplereturn forcode that currently functions: anything that assigns
verseNumto a ref holdinga range or segment and then reads
versewill now get the new number instead ofthe old range string.
That is the correct, C#-faithful behaviour, and the old value was stale/incorrect
— but it is a break, not a pure bugfix in the semver sense. This may warrant
more than a patch bump. No version bump is included here; that call is left to
the maintainer.
Tests
Worked TDD: tests written first, confirmed red (3 failures — no throw on
negative,
'4b-5a'and'4b'both stale), then fixed.The C# test that actually covers the range-clearing is
CopyVerseFrom— it setsVerseNum = 9on aLUK 3:4b-6asource, then asserts the copiedVerseis"9"rather than"4b-6a". It can't be ported yet:copyVerseFromisn'timplemented in this port. Nothing else in
VerseRefTests.csassignsVerseNumon a ranged ref, so the cases go in the existing
describe('Extra (TS-only tests)') > describe('Property setters')blockalongside the
chapterNumones:VerseRefExceptionverseNumclears a range ('4b-5a'→'9',hasMultiplefalse)verseNumclears a segment ('4b'→'9')BuildVerseRefByPropsalready exercisedverseNum = 0/15/17and still passes —those are plain numbers with no verse string to clear.
Also removes the now-fixed
set verseNumbullet from CLAUDE.md's "Known portinggaps".
Verification
Full CI sequence, all passing:
lint— clean at--max-warnings 0prettier:ci— no files differbuild—tscclean,dist/regenerated with no unexpected diffvitest run— 47 passed (3 files)npx tsc -p tsconfig.test.json --noEmit— clean (CI doesn't run this; testfiles are otherwise unchecked)
🤖 Generated with Claude Code