-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide the ability to run ParatextChecks and cleanup JSON serializing (
- Loading branch information
Showing
36 changed files
with
1,084 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Paranext.DataProvider.Checks; | ||
using SIL.Scripture; | ||
|
||
namespace TestParanextDataProvider.Checks; | ||
|
||
public class CheckInputRangeTests | ||
{ | ||
[TestCase("pid1", "GEN 1:1", "GEN 10:1", "pid1", 1, 4, true)] // In range (single book) | ||
[TestCase("pid1", "GEN 1:1", "EXO 10:1", "pid1", 1, 4, true)] // In range (multiple books) | ||
[TestCase("pid1", "GEN 1:1", "GEN 10:1", "pid2", 1, 4, false)] // Different project | ||
[TestCase("pid1", "GEN 1:1", "GEN 10:1", "pid1", 2, 4, false)] // Book outside range (single book) | ||
[TestCase("pid1", "GEN 1:1", "GEN 10:1", "pid1", 1, 11, false)] // Chapter after range | ||
[TestCase("pid1", "GEN 2:1", "GEN 10:1", "pid1", 1, 1, false)] // Chapter before range | ||
[TestCase("pid1", "GEN 1:1", null, "pid1", 1, 11, true)] // No end, normal in range | ||
[TestCase("pid1", "GEN 1:1", null, "pid1", 2, 11, false)] // No end, different book | ||
[TestCase("pid1", "GEN 1:1", "LEV 10:1", "pid1", 5, 1, false)] // Book after range (multiple books) | ||
[TestCase("pid1", "EXO 1:1", "LEV 10:1", "pid1", 1, 1, false)] // Book before range (multiple books) | ||
[TestCase("pid1", "GEN 1:1", "GEN 10:1", "pid1", 0, 4, true)] // Book 0, chapter in range | ||
[TestCase("pid1", "GEN 1:1", "GEN 10:1", "pid1", 0, 20, true)] // Book 0, chapter outside of range | ||
[TestCase("pid1", "GEN 1:1", "GEN 10:1", "pid1", 1, 0, true)] // Book in range, Chapter 0 | ||
public void IsWithinRange_IdentifiesOutOfRange( | ||
string verseRefProjectId, | ||
string verseRefStart, | ||
string? verseRefEnd, | ||
string projectId, | ||
int bookNum, | ||
int chapterNum, | ||
bool expectedResult | ||
) | ||
{ | ||
VerseRef vrefStart = new(verseRefStart); | ||
VerseRef? vrefEnd = string.IsNullOrEmpty(verseRefEnd) ? null : new VerseRef(verseRefEnd); | ||
CheckInputRange checkInputRange = new(verseRefProjectId, vrefStart, vrefEnd); | ||
Assert.That( | ||
checkInputRange.IsWithinRange(projectId, bookNum, chapterNum), | ||
Is.EqualTo(expectedResult) | ||
); | ||
} | ||
|
||
[TestCase(null, 1, 1, 1, 1, "projectId")] | ||
[TestCase("", 1, 1, 1, 1, "empty string")] | ||
[TestCase("projectId", 1, 0, 1, 10, "start.ChapterNum must be > 0")] | ||
[TestCase("projectId", 1, 1, 1, 0, "end.ChapterNum must be > 0")] | ||
[TestCase("projectId", 3, 1, 1, 1, "end must come after start")] | ||
public void CheckInputRange_Constructor_ThrowsWithBadInputs( | ||
string? projectId, | ||
int bookNumStart, | ||
int chapterNumStart, | ||
int? bookNumEnd, | ||
int? chapterNumEnd, | ||
string expectedPartialMessage | ||
) | ||
{ | ||
string exceptionMessage = string.Empty; | ||
try | ||
{ | ||
var checkInputRange = new CheckInputRange( | ||
projectId!, | ||
new VerseRef(bookNumStart, chapterNumStart, 1), | ||
bookNumEnd.HasValue && chapterNumEnd.HasValue | ||
? new VerseRef(bookNumEnd.Value, chapterNumEnd.Value, 1) | ||
: null | ||
); | ||
|
||
// This line is to just get linters to not complain about unused variables | ||
checkInputRange.ToString(); | ||
} | ||
catch (ArgumentException ex) | ||
{ | ||
exceptionMessage = ex.Message; | ||
} | ||
|
||
Assert.That(exceptionMessage, Does.Contain(expectedPartialMessage)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Paranext.DataProvider.Checks; | ||
using SIL.Scripture; | ||
|
||
namespace TestParanextDataProvider.Checks; | ||
|
||
public class CheckLocationTests | ||
{ | ||
[TestCase("GEN 1:1", 2, "GEN 1:1", 2, true)] | ||
[TestCase("GEN 1:1", 2, "NUM 1:1", 2, false)] | ||
[TestCase("GEN 1:1", 1, "GEN 1:1", 2, false)] | ||
public void Equality_Objects_ComparedByValue( | ||
string verseRef1, | ||
int offset1, | ||
string verseRef2, | ||
int offset2, | ||
bool expectedResult | ||
) | ||
{ | ||
VerseRef vref1 = new(verseRef1); | ||
CheckLocation item1 = new(vref1, offset1); | ||
VerseRef vref2 = new(verseRef2); | ||
CheckLocation item2 = new(vref2, offset2); | ||
Assert.That(item1 == item2, Is.EqualTo(expectedResult)); | ||
Assert.That(item1.Equals(item2), Is.EqualTo(expectedResult)); | ||
Assert.That(item1.GetHashCode() == item2.GetHashCode(), Is.EqualTo(expectedResult)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Paranext.DataProvider.Checks; | ||
using SIL.Scripture; | ||
|
||
namespace TestParanextDataProvider.Checks; | ||
|
||
public class CheckRunResultTests | ||
{ | ||
[TestCase("checkId", "projectId", "message", "GEN 1:1", 1, "GEN 1:2", 5, true)] | ||
[TestCase("ABC", "projectId", "message", "GEN 1:1", 1, "GEN 1:2", 5, false)] | ||
[TestCase("checkId", "ABC", "message", "GEN 1:1", 1, "GEN 1:2", 5, false)] | ||
[TestCase("checkId", "projectId", "ABC", "GEN 1:1", 1, "GEN 1:2", 5, false)] | ||
[TestCase("checkId", "projectId", "message", "GEN 1:2", 1, "GEN 1:2", 5, false)] | ||
[TestCase("checkId", "projectId", "message", "GEN 1:1", 2, "GEN 1:2", 5, false)] | ||
[TestCase("checkId", "projectId", "message", "GEN 1:1", 1, "GEN 1:3", 5, false)] | ||
[TestCase("checkId", "projectId", "message", "GEN 1:1", 1, "GEN 1:2", 7, false)] | ||
public void Equality_Objects_ComparedByValue( | ||
string checkId2, | ||
string projectId2, | ||
string message2, | ||
string verseRefStart2, | ||
int offsetStart2, | ||
string verseRefEnd2, | ||
int offsetEnd2, | ||
bool expectedResult | ||
) | ||
{ | ||
VerseRef vrefStart1 = new("GEN 1:1"); | ||
CheckLocation start1 = new(vrefStart1, 1); | ||
VerseRef vrefEnd1 = new("GEN 1:2"); | ||
CheckLocation end1 = new(vrefEnd1, 5); | ||
CheckRunResult checkRunResult1 = new("checkId", "projectId", "message", start1, end1); | ||
|
||
VerseRef vrefStart2 = new(verseRefStart2); | ||
CheckLocation start2 = new(vrefStart2, offsetStart2); | ||
VerseRef vrefEnd2 = new(verseRefEnd2); | ||
CheckLocation end2 = new(vrefEnd2, offsetEnd2); | ||
CheckRunResult checkRunResult2 = new(checkId2, projectId2, message2, start2, end2); | ||
|
||
Assert.That(checkRunResult1 == checkRunResult2, Is.EqualTo(expectedResult)); | ||
Assert.That(checkRunResult1.Equals(checkRunResult2), Is.EqualTo(expectedResult)); | ||
Assert.That( | ||
checkRunResult1.GetHashCode() == checkRunResult2.GetHashCode(), | ||
Is.EqualTo(expectedResult) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Paranext.DataProvider.Checks; | ||
using Paranext.DataProvider.JsonUtils; | ||
using Paratext.Data.Checking; | ||
|
||
namespace TestParanextDataProvider.Checks; | ||
|
||
public class ParatextCheckDetailsTests | ||
{ | ||
[Test] | ||
public void Serialization_Json_MatchesExpectations() | ||
{ | ||
var checkDetails = new ParatextCheckDetails(CheckType.Capitalization); | ||
checkDetails.EnabledProjectIds.Add("testProjectId"); | ||
Assert.That( | ||
checkDetails.SerializeToJson(), | ||
Is.EqualTo( | ||
"""{"checkName":"Capitalization","checkDescription":"Capitalization","checkId":"Capitalization","enabledProjectIds":["testProjectId"]}""" | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.