Refactor event occurrence parsing by introducing modular components for improved maintainability
This commit restructures the EventOccurrenceParser by breaking down its functionality into modular components, including EventDefinitionResolver, LineClassifier, LocationPatternMatcher, SectionHeaderMatcher, TimeLocationParser, and TimeParser. This refactoring enhances code readability and maintainability, allowing for easier updates and testing. Additionally, the TextUtil class has been updated to include input sanitization methods. Comprehensive unit tests have been added to ensure the correctness of the new parsing logic and to validate the handling of various event occurrence scenarios.
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
using Core.Parsers.EventOccurrence;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Tests.Parsers.EventOccurrence;
|
||||
|
||||
[TestFixture]
|
||||
public class LineClassifier_Tests
|
||||
{
|
||||
[Test]
|
||||
public void IsEmptyLine_EmptyString_ReturnsTrue()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsEmptyLine(""), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsEmptyLine_WhitespaceOnly_ReturnsTrue()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsEmptyLine(" "), Is.True);
|
||||
Assert.That(LineClassifier.IsEmptyLine("\t\n"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsEmptyLine_NonEmpty_ReturnsFalse()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsEmptyLine("Some text"), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsCommentLine_StartsWithHash_ReturnsTrue()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsCommentLine("# This is a comment"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsCommentLine_NoHash_ReturnsFalse()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsCommentLine("Not a comment"), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsContinuationLine_ParentheticalNote_ReturnsTrue()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsContinuationLine("(Semifinalists only)"), Is.True);
|
||||
Assert.That(LineClassifier.IsContinuationLine("(Note: Some information)"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsContinuationLine_StartsWithLowercaseContinuationWord_ReturnsTrue()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsContinuationLine("the event will be held"), Is.True);
|
||||
Assert.That(LineClassifier.IsContinuationLine("and participants should arrive"), Is.True);
|
||||
Assert.That(LineClassifier.IsContinuationLine("be sure to register"), Is.True);
|
||||
Assert.That(LineClassifier.IsContinuationLine("or contact the coordinator"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsContinuationLine_StartsWithLowercase_NonContinuationWord_ReturnsFalse()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsContinuationLine("important: bring materials"), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsContinuationLine_StartsWithUppercase_ReturnsFalse()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsContinuationLine("Important Event March 15"), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsContinuationLine_ContainsSchedulePosted_ReturnsTrue()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsContinuationLine("Schedule Posted on website"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsContinuationLine_ContainsNote_ReturnsTrue()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsContinuationLine("Note: Additional information"), Is.True);
|
||||
Assert.That(LineClassifier.IsContinuationLine("*Note: Important details"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsContinuationLine_RegularEventLine_ReturnsFalse()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsContinuationLine("Test Event March 15 3:00 p.m. Room A"), Is.False);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user