From 09249c890f82878abe4c4ddde728339fcb362e20 Mon Sep 17 00:00:00 2001 From: Enkidu93 Date: Fri, 5 Dec 2025 14:10:20 -0500 Subject: [PATCH] Make ActualVerseRef & ExpectedVerseRef more robust and helpful; Fix test typo --- .../Corpora/UsfmVersificationErrorDetector.cs | 30 +++++++++++++++---- .../ParatextProjectVersificationErrorTests.cs | 2 +- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/SIL.Machine/Corpora/UsfmVersificationErrorDetector.cs b/src/SIL.Machine/Corpora/UsfmVersificationErrorDetector.cs index 4349b91f..c908a94e 100644 --- a/src/SIL.Machine/Corpora/UsfmVersificationErrorDetector.cs +++ b/src/SIL.Machine/Corpora/UsfmVersificationErrorDetector.cs @@ -104,7 +104,7 @@ public string ExpectedVerseRef // an exception with certain invalid verse data; use TryParse instead. if (!VerseRef.TryParse($"{_bookNum} {_expectedChapter}:{_expectedVerse}", out VerseRef defaultVerseRef)) { - return ""; + return DefaultVerse(_expectedChapter, _expectedVerse); } if (Type == UsfmVersificationErrorType.ExtraVerse) return ""; @@ -144,10 +144,30 @@ out VerseRef correctedVerseRangeRef return defaultVerseRef.ToString(); } } - public string ActualVerseRef => - _verseRef != null - ? _verseRef.Value.ToString() - : new VerseRef(_bookNum, _actualChapter, _actualVerse).ToString(); + public string ActualVerseRef + { + get + { + if (_verseRef != null) + { + return _verseRef.ToString(); + } + else + { + if (VerseRef.TryParse($"{_bookNum} {_actualChapter}:{_actualVerse}", out VerseRef actualVerseRef)) + { + return actualVerseRef.ToString(); + } + } + return DefaultVerse(_actualChapter, _actualVerse); + } + } + + private string DefaultVerse(int chapter, int verse) + { + string verseString = _actualVerse == -1 ? "" : verse.ToString(); + return $"{Canon.BookNumberToId(_bookNum)} {chapter}:{verseString}"; + } } public class UsfmVersificationErrorDetector : UsfmParserHandlerBase diff --git a/tests/SIL.Machine.Tests/Corpora/ParatextProjectVersificationErrorTests.cs b/tests/SIL.Machine.Tests/Corpora/ParatextProjectVersificationErrorTests.cs index 5b4d581f..822af209 100644 --- a/tests/SIL.Machine.Tests/Corpora/ParatextProjectVersificationErrorTests.cs +++ b/tests/SIL.Machine.Tests/Corpora/ParatextProjectVersificationErrorTests.cs @@ -9,7 +9,7 @@ namespace SIL.Machine.Corpora; public class ParatextProjectQuoteConventionDetectorTests { [Test] - public void GetUsfmVersificationErrors_Noerrors() + public void GetUsfmVersificationErrors_NoErrors() { var env = new TestEnvironment( files: new Dictionary()