19e5ef0675
This commit introduces a new property to track skipped high school section headers in the EventOccurrenceParseResult and EventOccurrenceParserResult classes. The EventOccurrenceParser has been updated to gracefully skip HS section headers that do not match any event definitions, improving the parsing logic. Additionally, the LocationParsingConfiguration has been removed from the EventOccurrenceParser, simplifying its constructor. Unit tests have been updated to reflect these changes and ensure correct behavior during parsing.
164 lines
4.1 KiB
C#
164 lines
4.1 KiB
C#
using Core.Parsers.EventOccurrence;
|
|
using NUnit.Framework;
|
|
|
|
namespace Tests.Parsers.EventOccurrence;
|
|
|
|
[TestFixture]
|
|
public class TimeLocationParser_Tests
|
|
{
|
|
[Test]
|
|
public void Parse_TimeAndLocation_ExtractsBoth()
|
|
{
|
|
// Act
|
|
TimeLocationParser.Parse("10:30 a.m. Room 101",
|
|
out string time, out string location);
|
|
|
|
// Assert
|
|
Assert.That(time, Is.EqualTo("10:30 a.m."));
|
|
Assert.That(location, Is.EqualTo("Room 101"));
|
|
}
|
|
|
|
[Test]
|
|
public void Parse_TimeRangeAndLocation_ExtractsTimeRangeAndLocation()
|
|
{
|
|
// Act
|
|
TimeLocationParser.Parse("10:00 a.m. - 12:00 p.m. Room 202",
|
|
out string time, out string location);
|
|
|
|
// Assert
|
|
Assert.That(time, Is.EqualTo("10:00 a.m. - 12:00 p.m."));
|
|
Assert.That(location, Is.EqualTo("Room 202"));
|
|
}
|
|
|
|
[Test]
|
|
public void Parse_NOONAndLocation_ExtractsBoth()
|
|
{
|
|
// Act
|
|
TimeLocationParser.Parse("NOON Hall C",
|
|
out string time, out string location);
|
|
|
|
// Assert
|
|
Assert.That(time, Is.EqualTo("NOON"));
|
|
Assert.That(location, Is.EqualTo("Hall C"));
|
|
}
|
|
|
|
[Test]
|
|
public void Parse_TimeOnly_NoLocation()
|
|
{
|
|
// Act
|
|
TimeLocationParser.Parse("3:00 p.m.",
|
|
out string time, out string location);
|
|
|
|
// Assert
|
|
Assert.That(time, Is.EqualTo("3:00 p.m."));
|
|
Assert.That(location, Is.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public void Parse_AnyLocation_ExtractsLocationWithoutValidation()
|
|
{
|
|
// Act
|
|
TimeLocationParser.Parse("10:00 a.m. Unknown Location",
|
|
out string time, out string location);
|
|
|
|
// Assert
|
|
Assert.That(time, Is.EqualTo("10:00 a.m."));
|
|
Assert.That(location, Is.EqualTo("Unknown Location"));
|
|
}
|
|
|
|
[Test]
|
|
public void Parse_LocationWithTimeComponent_CleansTimeComponent()
|
|
{
|
|
// Act
|
|
TimeLocationParser.Parse("10:00 a.m. - 12:15 p.m. Exhibit Hall C",
|
|
out string time, out string location);
|
|
|
|
// Assert
|
|
Assert.That(time, Is.EqualTo("10:00 a.m. - 12:15 p.m."));
|
|
Assert.That(location, Is.EqualTo("Exhibit Hall C"));
|
|
}
|
|
|
|
[Test]
|
|
public void Parse_AnyLocation_ExtractsAsIs()
|
|
{
|
|
// Act
|
|
TimeLocationParser.Parse("3:00 p.m. Room A",
|
|
out string time, out string location);
|
|
|
|
// Assert
|
|
Assert.That(time, Is.EqualTo("3:00 p.m."));
|
|
Assert.That(location, Is.EqualTo("Room A"));
|
|
}
|
|
|
|
[Test]
|
|
public void CleanLocationText_RemovesTimeAtStart()
|
|
{
|
|
// Act
|
|
var result = TimeLocationParser.CleanLocationText("- 12:15 p.m. Exhibit Hall C");
|
|
|
|
// Assert
|
|
Assert.That(result, Is.EqualTo("Exhibit Hall C"));
|
|
}
|
|
|
|
[Test]
|
|
public void CleanLocationText_RemovesTimeWithoutDash()
|
|
{
|
|
// Act
|
|
var result = TimeLocationParser.CleanLocationText("12:15 p.m. Exhibit Hall C");
|
|
|
|
// Assert
|
|
Assert.That(result, Is.EqualTo("Exhibit Hall C"));
|
|
}
|
|
|
|
[Test]
|
|
public void CleanLocationText_RemovesNOONAtStart()
|
|
{
|
|
// Act
|
|
var result = TimeLocationParser.CleanLocationText("- NOON Exhibit Hall C");
|
|
|
|
// Assert
|
|
Assert.That(result, Is.EqualTo("Exhibit Hall C"));
|
|
}
|
|
|
|
[Test]
|
|
public void CleanLocationText_OnlyTime_ReturnsEmpty()
|
|
{
|
|
// Act
|
|
var result = TimeLocationParser.CleanLocationText("12:15 p.m.");
|
|
|
|
// Assert
|
|
Assert.That(result, Is.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public void CleanLocationText_EmptyString_ReturnsEmpty()
|
|
{
|
|
// Act
|
|
var result = TimeLocationParser.CleanLocationText("");
|
|
|
|
// Assert
|
|
Assert.That(result, Is.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public void CleanLocationText_WhitespaceOnly_ReturnsEmpty()
|
|
{
|
|
// Act
|
|
var result = TimeLocationParser.CleanLocationText(" ");
|
|
|
|
// Assert
|
|
Assert.That(result, Is.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public void CleanLocationText_NoTimeComponent_ReturnsOriginal()
|
|
{
|
|
// Act
|
|
var result = TimeLocationParser.CleanLocationText("Exhibit Hall C");
|
|
|
|
// Assert
|
|
Assert.That(result, Is.EqualTo("Exhibit Hall C"));
|
|
}
|
|
}
|
|
|