Skip to content

Commit 1ebfe4c

Browse files
committed
Add additional tests; correct spelling of class names
1 parent b0dca36 commit 1ebfe4c

File tree

4 files changed

+87
-14
lines changed

4 files changed

+87
-14
lines changed

src/SIL.Machine/Corpora/UsfmVersificationMismatchDetector.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public bool CheckMismatch()
5252
Type = UsfmVersificationMismatchType.MissingChapter;
5353
return true;
5454
}
55-
if (_expectedVerse > _actualVerse)
55+
if (_expectedVerse > _actualVerse && _expectedChapter == _actualChapter)
5656
{
5757
Type = UsfmVersificationMismatchType.MissingVerse;
5858
return true;
@@ -162,7 +162,6 @@ public UsfmVersificationMismatchDetector(ScrVers versification)
162162
_errors = new List<UsfmVersificationMismatch>();
163163
}
164164

165-
public bool HasError => _errors.Count > 0;
166165
public IReadOnlyList<UsfmVersificationMismatch> Errors => _errors;
167166

168167
public override void EndUsfm(UsfmParserState state)
@@ -183,18 +182,6 @@ public override void EndUsfm(UsfmParserState state)
183182

184183
public override void StartBook(UsfmParserState state, string marker, string code)
185184
{
186-
if (_currentBook > 0 && Canon.IsCanonical(_currentBook))
187-
{
188-
var versificationMismatch = new UsfmVersificationMismatch(
189-
_currentBook,
190-
_versification.GetLastChapter(_currentBook),
191-
_versification.GetLastVerse(_currentBook, _versification.GetLastChapter(_currentBook)),
192-
_currentChapter,
193-
_currentVerse.AllVerses().Last().VerseNum
194-
);
195-
if (versificationMismatch.CheckMismatch())
196-
_errors.Add(versificationMismatch);
197-
}
198185
_currentBook = state.VerseRef.BookNum;
199186
_currentChapter = 0;
200187
_currentVerse = new VerseRef();

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

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,92 @@ public void GetUsfmVersificationMismatches_ExtraVerse_ExcludedInCustomVrs()
291291
Assert.That(mismatches[0].Type, Is.EqualTo(UsfmVersificationMismatchType.ExtraVerse));
292292
}
293293

294+
[Test]
295+
public void GetUsfmVersificationMismatches_MultipleBooks()
296+
{
297+
var env = new TestEnvironment(
298+
files: new Dictionary<string, string>()
299+
{
300+
{
301+
"642JNTest.SFM",
302+
@"\id 2JN
303+
\c 1
304+
\v 1
305+
\v 2
306+
\v 3
307+
\v 4
308+
\v 5
309+
\v 6
310+
\v 7
311+
\v 8
312+
\v 9
313+
\v 10
314+
\v 11
315+
\v 12
316+
"
317+
},
318+
{
319+
"653JNTest.SFM",
320+
@"\id 3JN
321+
\c 1
322+
\v 1
323+
\v 2
324+
\v 3
325+
\v 4
326+
\v 5
327+
\v 6
328+
\v 7
329+
\v 8
330+
\v 9
331+
\v 10
332+
\v 11
333+
\v 12
334+
\v 13
335+
\v 14
336+
\v 15
337+
"
338+
}
339+
}
340+
);
341+
IReadOnlyList<UsfmVersificationMismatch> mismatches = env.GetUsfmVersificationMismatches();
342+
Assert.That(mismatches, Has.Count.EqualTo(1), JsonSerializer.Serialize(mismatches));
343+
Assert.That(mismatches[0].Type, Is.EqualTo(UsfmVersificationMismatchType.MissingVerse));
344+
}
345+
346+
[Test]
347+
public void GetUsfmVersificationMismatches_MultipleChapters()
348+
{
349+
var env = new TestEnvironment(
350+
files: new Dictionary<string, string>()
351+
{
352+
{
353+
"642JNTest.SFM",
354+
@"\id 2JN
355+
\c 1
356+
\v 1
357+
\v 2
358+
\v 3
359+
\v 4
360+
\v 5
361+
\v 6
362+
\v 7
363+
\v 8
364+
\v 9
365+
\v 10
366+
\v 11
367+
\v 12
368+
\c 2
369+
\v 1
370+
"
371+
}
372+
}
373+
);
374+
IReadOnlyList<UsfmVersificationMismatch> mismatches = env.GetUsfmVersificationMismatches();
375+
Assert.That(mismatches, Has.Count.EqualTo(2), JsonSerializer.Serialize(mismatches));
376+
Assert.That(mismatches[0].Type, Is.EqualTo(UsfmVersificationMismatchType.MissingVerse));
377+
Assert.That(mismatches[1].Type, Is.EqualTo(UsfmVersificationMismatchType.ExtraVerse));
378+
}
379+
294380
private class TestEnvironment(ParatextProjectSettings? settings = null, Dictionary<string, string>? files = null)
295381
{
296382
public ParatextProjectVersificationMismatchDetector Detector { get; } =

tests/SIL.Machine.Tests/PunctuationAnalysis/MemoryParatextProjectQuoteConvetionDetector.cs renamed to tests/SIL.Machine.Tests/PunctuationAnalysis/MemoryParatextProjectQuoteConventionDetector.cs

File renamed without changes.

tests/SIL.Machine.Tests/PunctuationAnalysis/ParatextProjectQuoteConvetionDetectorTests.cs renamed to tests/SIL.Machine.Tests/PunctuationAnalysis/ParatextProjectQuoteConventionDetectorTests.cs

File renamed without changes.

0 commit comments

Comments
 (0)