f916cfad6b
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.
167 lines
4.0 KiB
C#
167 lines
4.0 KiB
C#
using Core.Parsers.EventOccurrence;
|
|
using NUnit.Framework;
|
|
|
|
namespace Tests.Parsers.EventOccurrence;
|
|
|
|
[TestFixture]
|
|
public class LocationPatternMatcher_Tests
|
|
{
|
|
[Test]
|
|
public void Match_ExactMatch_ReturnsLocation()
|
|
{
|
|
// Arrange
|
|
var patterns = new List<string> { "Room A", "Room B", "Hall C" };
|
|
|
|
// Act
|
|
var result = LocationPatternMatcher.Match("Room A", patterns);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.EqualTo("Room A"));
|
|
}
|
|
|
|
[Test]
|
|
public void Match_ExactMatch_CaseInsensitive_ReturnsLocation()
|
|
{
|
|
// Arrange
|
|
var patterns = new List<string> { "Room A" };
|
|
|
|
// Act
|
|
var result = LocationPatternMatcher.Match("room a", patterns);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.EqualTo("room a"));
|
|
}
|
|
|
|
[Test]
|
|
public void Match_WildcardPattern_Matches_ReturnsLocation()
|
|
{
|
|
// Arrange
|
|
var patterns = new List<string> { "Room *", "Hall *" };
|
|
|
|
// Act
|
|
var result = LocationPatternMatcher.Match("Room 101", patterns);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.EqualTo("Room 101"));
|
|
}
|
|
|
|
[Test]
|
|
public void Match_WildcardPattern_MultipleMatches_ReturnsFirstMatch()
|
|
{
|
|
// Arrange
|
|
var patterns = new List<string> { "Room *", "Exhibit Hall *" };
|
|
|
|
// Act
|
|
var result = LocationPatternMatcher.Match("Room 202", patterns);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.EqualTo("Room 202"));
|
|
}
|
|
|
|
[Test]
|
|
public void Match_WildcardPattern_ExhibitHall_Matches()
|
|
{
|
|
// Arrange
|
|
var patterns = new List<string> { "Exhibit Hall *" };
|
|
|
|
// Act
|
|
var result = LocationPatternMatcher.Match("Exhibit Hall C", patterns);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.EqualTo("Exhibit Hall C"));
|
|
}
|
|
|
|
[Test]
|
|
public void Match_WildcardPattern_MtgRoom_Matches()
|
|
{
|
|
// Arrange
|
|
var patterns = new List<string> { "Mtg. Room *" };
|
|
|
|
// Act
|
|
var result = LocationPatternMatcher.Match("Mtg. Room 14", patterns);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.EqualTo("Mtg. Room 14"));
|
|
}
|
|
|
|
[Test]
|
|
public void Match_NoMatch_ReturnsEmpty()
|
|
{
|
|
// Arrange
|
|
var patterns = new List<string> { "Room *", "Hall *" };
|
|
|
|
// Act
|
|
var result = LocationPatternMatcher.Match("Unknown Location", patterns);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public void Match_EmptyLocation_ReturnsEmpty()
|
|
{
|
|
// Arrange
|
|
var patterns = new List<string> { "Room *" };
|
|
|
|
// Act
|
|
var result = LocationPatternMatcher.Match("", patterns);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public void Match_WhitespaceLocation_ReturnsEmpty()
|
|
{
|
|
// Arrange
|
|
var patterns = new List<string> { "Room *" };
|
|
|
|
// Act
|
|
var result = LocationPatternMatcher.Match(" ", patterns);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public void Match_EmptyPatterns_ReturnsEmpty()
|
|
{
|
|
// Arrange
|
|
var patterns = new List<string>();
|
|
|
|
// Act
|
|
var result = LocationPatternMatcher.Match("Room A", patterns);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public void Match_PatternWithSpecialCharacters_EscapesCorrectly()
|
|
{
|
|
// Arrange
|
|
var patterns = new List<string> { "Room (A)" };
|
|
|
|
// Act
|
|
var result = LocationPatternMatcher.Match("Room (A)", patterns);
|
|
|
|
// Assert
|
|
Assert.That(result, Is.EqualTo("Room (A)"));
|
|
}
|
|
|
|
[Test]
|
|
public void Match_LocationWithWhitespace_Trims_ReturnsLocation()
|
|
{
|
|
// Arrange
|
|
var patterns = new List<string> { "Room *" };
|
|
|
|
// Act
|
|
var result = LocationPatternMatcher.Match(" Room 101 ", patterns);
|
|
|
|
// Assert
|
|
// LocationPatternMatcher returns the matched location after normalization (trim)
|
|
Assert.That(result, Is.EqualTo("Room 101"));
|
|
}
|
|
}
|
|
|