Skip to content

Commit 7651a39

Browse files
authored
Make ActualVerseRef & ExpectedVerseRef more robust and helpful (#362)
1 parent 278cd39 commit 7651a39

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/SIL.Machine/Corpora/UsfmVersificationErrorDetector.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public string ExpectedVerseRef
104104
// an exception with certain invalid verse data; use TryParse instead.
105105
if (!VerseRef.TryParse($"{_bookNum} {_expectedChapter}:{_expectedVerse}", out VerseRef defaultVerseRef))
106106
{
107-
return "";
107+
return DefaultVerse(_expectedChapter, _expectedVerse);
108108
}
109109
if (Type == UsfmVersificationErrorType.ExtraVerse)
110110
return "";
@@ -144,10 +144,30 @@ out VerseRef correctedVerseRangeRef
144144
return defaultVerseRef.ToString();
145145
}
146146
}
147-
public string ActualVerseRef =>
148-
_verseRef != null
149-
? _verseRef.Value.ToString()
150-
: new VerseRef(_bookNum, _actualChapter, _actualVerse).ToString();
147+
public string ActualVerseRef
148+
{
149+
get
150+
{
151+
if (_verseRef != null)
152+
{
153+
return _verseRef.ToString();
154+
}
155+
else
156+
{
157+
if (VerseRef.TryParse($"{_bookNum} {_actualChapter}:{_actualVerse}", out VerseRef actualVerseRef))
158+
{
159+
return actualVerseRef.ToString();
160+
}
161+
}
162+
return DefaultVerse(_actualChapter, _actualVerse);
163+
}
164+
}
165+
166+
private string DefaultVerse(int chapter, int verse)
167+
{
168+
string verseString = _actualVerse == -1 ? "" : verse.ToString();
169+
return $"{Canon.BookNumberToId(_bookNum)} {chapter}:{verseString}";
170+
}
151171
}
152172

153173
public class UsfmVersificationErrorDetector : UsfmParserHandlerBase

tests/SIL.Machine.Tests/Corpora/ParatextProjectVersificationErrorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace SIL.Machine.Corpora;
99
public class ParatextProjectQuoteConventionDetectorTests
1010
{
1111
[Test]
12-
public void GetUsfmVersificationErrors_Noerrors()
12+
public void GetUsfmVersificationErrors_NoErrors()
1313
{
1414
var env = new TestEnvironment(
1515
files: new Dictionary<string, string>()

0 commit comments

Comments
 (0)