1+ using System . Text ;
12using System . Text . Json ;
23using NUnit . Framework ;
4+ using SIL . Scripture ;
35
46namespace SIL . Machine . Corpora ;
57
@@ -196,6 +198,99 @@ public void GetUsfmVersificationMismatches_ExtraVerseSegment()
196198 Assert . That ( mismatches [ 0 ] . Type , Is . EqualTo ( UsfmVersificationMismatchType . ExtraVerseSegment ) ) ;
197199 }
198200
201+ [ Test ]
202+ public void GetUsfmVersificationMismatches_MissingVerseSegment ( )
203+ {
204+ var env = new TestEnvironment (
205+ settings : new MemoryParatextProjectFileHandler . DefaultParatextProjectSettings (
206+ versification : GetCustomVersification ( @"*3JN 1:13,a,b" )
207+ ) ,
208+ files : new Dictionary < string , string > ( )
209+ {
210+ {
211+ "653JNTest.SFM" ,
212+ @"\id 3JN
213+ \c 1
214+ \v 1
215+ \v 2
216+ \v 3
217+ \v 4
218+ \v 5
219+ \v 6
220+ \v 7
221+ \v 8
222+ \v 9
223+ \v 10
224+ \v 11
225+ \v 12
226+ \v 13
227+ \v 14
228+ \v 15
229+ "
230+ }
231+ }
232+ ) ;
233+ IReadOnlyList < UsfmVersificationMismatch > mismatches = env . GetUsfmVersificationMismatches ( ) ;
234+ Assert . That ( mismatches , Has . Count . EqualTo ( 1 ) , JsonSerializer . Serialize ( mismatches ) ) ;
235+ Assert . That ( mismatches [ 0 ] . Type , Is . EqualTo ( UsfmVersificationMismatchType . MissingVerseSegment ) ) ;
236+ }
237+
238+ [ Test ]
239+ public void GetUsfmVersificationMismatches_IgnoreNonCanonicals ( )
240+ {
241+ var env = new TestEnvironment (
242+ files : new Dictionary < string , string > ( )
243+ {
244+ {
245+ "98XXETest.SFM" ,
246+ @"\id XXE
247+ \c 1
248+ \v 3-2
249+ "
250+ }
251+ }
252+ ) ;
253+ IReadOnlyList < UsfmVersificationMismatch > mismatches = env . GetUsfmVersificationMismatches ( ) ;
254+ Assert . That ( mismatches , Has . Count . EqualTo ( 0 ) , JsonSerializer . Serialize ( mismatches ) ) ;
255+ }
256+
257+ [ Test ]
258+ public void GetUsfmVersificationMismatches_ExtraVerse_ExcludedInCustomVrs ( )
259+ {
260+ var env = new TestEnvironment (
261+ settings : new MemoryParatextProjectFileHandler . DefaultParatextProjectSettings (
262+ versification : GetCustomVersification ( @"-3JN 1:13" )
263+ ) ,
264+ files : new Dictionary < string , string > ( )
265+ {
266+ {
267+ "653JNTest.SFM" ,
268+ @"\id 3JN
269+ \c 1
270+ \v 1
271+ \v 2
272+ \v 3
273+ \v 4
274+ \v 5
275+ \v 6
276+ \v 7
277+ \v 8
278+ \v 9
279+ \v 10
280+ \v 11
281+ \v 12
282+ \v 13
283+ \v 14
284+ \v 15
285+ "
286+ }
287+ }
288+ ) ;
289+ IReadOnlyList < UsfmVersificationMismatch > mismatches = env . GetUsfmVersificationMismatches ( ) ;
290+ Assert . That ( mismatches , Has . Count . EqualTo ( 1 ) , JsonSerializer . Serialize ( mismatches ) ) ;
291+ Assert . That ( mismatches [ 0 ] . Type , Is . EqualTo ( UsfmVersificationMismatchType . ExtraVerse ) ) ;
292+ }
293+
199294 private class TestEnvironment ( ParatextProjectSettings ? settings = null , Dictionary < string , string > ? files = null )
200295 {
201296 public ParatextProjectVersificationMismatchDetector Detector { get ; } =
@@ -206,4 +301,21 @@ public IReadOnlyList<UsfmVersificationMismatch> GetUsfmVersificationMismatches()
206301 return Detector . GetUsfmVersificationMismatches ( ) ;
207302 }
208303 }
304+
305+ private static ScrVers GetCustomVersification ( string customVrsContents , ScrVers ? baseVersification = null )
306+ {
307+ baseVersification ??= ScrVers . English ;
308+ ScrVers customVersification = baseVersification ;
309+ using ( var reader = new StreamReader ( new MemoryStream ( Encoding . UTF8 . GetBytes ( customVrsContents ) ) ) )
310+ {
311+ customVersification = Versification . Table . Implementation . Load (
312+ reader ,
313+ "custom.vrs" ,
314+ baseVersification ,
315+ baseVersification . ToString ( ) + "-" + customVrsContents . GetHashCode ( )
316+ ) ;
317+ }
318+ Versification . Table . Implementation . RemoveAllUnknownVersifications ( ) ;
319+ return customVersification ;
320+ }
209321}
0 commit comments