Repository navigation
Add TryGetChapters to ScriptureRangeParser - #497
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #497 +/- ##
=======================================
Coverage 74.07% 74.08%
=======================================
Files 456 456
Lines 38164 38178 +14
Branches 5228 5229 +1
=======================================
+ Hits 28270 28283 +13
- Misses 8734 8735 +1
Partials 1160 1160 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Enkidu93
left a comment
There was a problem hiding this comment.
@Enkidu93 reviewed 5 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on ddaspit).
ddaspit
left a comment
There was a problem hiding this comment.
Two findings from a local review: one blocking, one minor. Built the branch (0 warnings) and ran the 86 existing ScriptureRangeParser tests (all pass); the empty-section behavior below was confirmed with a throwaway test against this branch.
| chapters = GetChapters(chapterSelections); | ||
| return true; | ||
| } | ||
| catch (ArgumentException) |
There was a problem hiding this comment.
Critical — catching only ArgumentException lets an empty section escape as an unhandled InvalidOperationException from section.Last() (line 53), so TryGetChapters throws instead of returning false.
Confirmed on a local build of this branch: "MAT;", "MAT;;MRK", ";", and " ; " all throw. That is the input class the Try* overload exists to absorb.
Either skip empty sections in GetChapters, or throw ArgumentException for them so this catch covers them.
There was a problem hiding this comment.
Done. I updated the tests to accept an exception type to support this.
There was a problem hiding this comment.
I think it would be better to explicitly throw an ArgumentException from ParseSection rather than catch the InvalidOperationException from Last(). This would make it more consistent.
There was a problem hiding this comment.
Done. Sounds great.
| if (char.IsDigit(section.Last()) && section.Length > 3) | ||
| public static bool TryGetChapters( | ||
| string chapterSelections, | ||
| ScrVers versification, |
There was a problem hiding this comment.
Minor — versification sits before the out parameter, so it cannot carry the ScrVers versification = null default that static GetChapters has just above; every caller must pass null explicitly.
Moving it after out chapters, or adding a two-argument overload, restores parity with GetChapters.
There was a problem hiding this comment.
I would prefer to create an overload rather than move it after the out parameter.
There was a problem hiding this comment.
The overload:
public static bool TryGetChapters(
string chapterSelections,
out Dictionary<string, List<int>> chapters
) => new ScriptureRangeParser().TryGetChapters(chapterSelections, out chapters);gives the error:
CS0111 Type 'ScriptureRangeParser' already defines a member called 'TryGetChapters' with the same parameter types
as it conflicts with:
public bool TryGetChapters(string chapterSelections, out Dictionary<string, List<int>> chapters)That is why my original version was just:
public static bool TryGetChapters(
string chapterSelections,
ScrVers versification,
out Dictionary<string, List<int>> chapters
) => new ScriptureRangeParser(versification).TryGetChapters(chapterSelections, out chapters);From what I can see our two options are having the optional paramter after the out parameter, or make versification non-optional for the static member.
There was a problem hiding this comment.
Oh, I missed the instance method. Never mind. You can change it back to the original version with the required versification.
170f122 to
99cb98b
Compare
pmachapman
left a comment
There was a problem hiding this comment.
@pmachapman made 2 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on ddaspit).
| if (char.IsDigit(section.Last()) && section.Length > 3) | ||
| public static bool TryGetChapters( | ||
| string chapterSelections, | ||
| ScrVers versification, |
| chapters = GetChapters(chapterSelections); | ||
| return true; | ||
| } | ||
| catch (ArgumentException) |
There was a problem hiding this comment.
Done. I updated the tests to accept an exception type to support this.
ddaspit
left a comment
There was a problem hiding this comment.
@ddaspit reviewed 5 files and all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on pmachapman).
| if (char.IsDigit(section.Last()) && section.Length > 3) | ||
| public static bool TryGetChapters( | ||
| string chapterSelections, | ||
| ScrVers versification, |
There was a problem hiding this comment.
I would prefer to create an overload rather than move it after the out parameter.
pmachapman
left a comment
There was a problem hiding this comment.
@pmachapman made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on ddaspit).
| if (char.IsDigit(section.Last()) && section.Length > 3) | ||
| public static bool TryGetChapters( | ||
| string chapterSelections, | ||
| ScrVers versification, |
There was a problem hiding this comment.
The overload:
public static bool TryGetChapters(
string chapterSelections,
out Dictionary<string, List<int>> chapters
) => new ScriptureRangeParser().TryGetChapters(chapterSelections, out chapters);gives the error:
CS0111 Type 'ScriptureRangeParser' already defines a member called 'TryGetChapters' with the same parameter types
as it conflicts with:
public bool TryGetChapters(string chapterSelections, out Dictionary<string, List<int>> chapters)That is why my original version was just:
public static bool TryGetChapters(
string chapterSelections,
ScrVers versification,
out Dictionary<string, List<int>> chapters
) => new ScriptureRangeParser(versification).TryGetChapters(chapterSelections, out chapters);From what I can see our two options are having the optional paramter after the out parameter, or make versification non-optional for the static member.
ddaspit
left a comment
There was a problem hiding this comment.
@ddaspit made 2 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on pmachapman).
| if (char.IsDigit(section.Last()) && section.Length > 3) | ||
| public static bool TryGetChapters( | ||
| string chapterSelections, | ||
| ScrVers versification, |
There was a problem hiding this comment.
Oh, I missed the instance method. Never mind. You can change it back to the original version with the required versification.
| chapters = GetChapters(chapterSelections); | ||
| return true; | ||
| } | ||
| catch (ArgumentException) |
There was a problem hiding this comment.
I think it would be better to explicitly throw an ArgumentException from ParseSection rather than catch the InvalidOperationException from Last(). This would make it more consistent.
99cb98b to
a9d9f5a
Compare
pmachapman
left a comment
There was a problem hiding this comment.
@pmachapman made 2 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on ddaspit).
| if (char.IsDigit(section.Last()) && section.Length > 3) | ||
| public static bool TryGetChapters( | ||
| string chapterSelections, | ||
| ScrVers versification, |
| chapters = GetChapters(chapterSelections); | ||
| return true; | ||
| } | ||
| catch (ArgumentException) |
There was a problem hiding this comment.
Done. Sounds great.
ddaspit
left a comment
There was a problem hiding this comment.
@ddaspit reviewed 2 files and all commit messages, made 1 comment, and resolved 2 discussions.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on pmachapman).
Fixes #486
I noticed that the ScriptureRangeParser was not in a namespace, so set the namespace to SIL.Machine.Scripture. If it was not an oversight, I can revert it to remain in the SIL.Machine namespace.
I also took the opportunity to update the unit tests to use new .Net 10 language features.
This change is