Skip to content

Commit

Permalink
Merge pull request #120 from AndyTWF/sid-star-empty-route
Browse files Browse the repository at this point in the history
fix(parser): allow empty SID or STAR routes
  • Loading branch information
AndyTWF authored Jan 29, 2021
2 parents 3d8ebe3 + f0eb5d9 commit e3e8cb5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Compiler/Parser/SidStarParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using Compiler.Model;
using Compiler.Error;
using Compiler.Event;
Expand Down Expand Up @@ -45,7 +45,7 @@ public void ParseData(AbstractSectorDataFile data)
line.dataSegments[1],
line.dataSegments[2],
line.dataSegments[3],
new List<string>(line.dataSegments[4].Split(' ')),
line.dataSegments[4].Split(' ').Where(s => !string.IsNullOrEmpty(s)).ToList(),
line.definition,
line.docblock,
line.inlineComment
Expand Down
26 changes: 20 additions & 6 deletions tests/CompilerTest/Parser/SidStarParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,38 @@ public class SidStarParserTest: AbstractParserTestCase
[MemberData(nameof(BadData))]
public void ItRaisesSyntaxErrorsOnBadData(List<string> lines)
{
this.RunParserOnLines(lines);
RunParserOnLines(lines);

Assert.Empty(this.sectorElementCollection.Runways);
this.logger.Verify(foo => foo.AddEvent(It.IsAny<SyntaxError>()), Times.Once);
Assert.Empty(sectorElementCollection.Runways);
logger.Verify(foo => foo.AddEvent(It.IsAny<SyntaxError>()), Times.Once);
}

[Fact]
public void TestItAddsSidStarData()
{
this.RunParserOnLines(new List<string>(new[] { "SID:EGKK:26L:ADMAG2X:FIX1 FIX2 ;comment" }));
RunParserOnLines(new List<string>(new[] { "SID:EGKK:26L:ADMAG2X:FIX1 FIX2 ;comment" }));

SidStar result = this.sectorElementCollection.SidStars[0];
SidStar result = sectorElementCollection.SidStars[0];
Assert.Equal("SID", result.Type);
Assert.Equal("EGKK", result.Airport);
Assert.Equal("26L", result.Runway);
Assert.Equal("ADMAG2X", result.Identifier);
Assert.Equal(new List<string>(new[] { "FIX1", "FIX2" }), result.Route);
this.AssertExpectedMetadata(result);
AssertExpectedMetadata(result);
}

[Fact]
public void TestItAddsSidStarWithNoRoute()
{
RunParserOnLines(new List<string>(new[] { "SID:EGKK:26L:ADMAG2X: ;comment" }));

SidStar result = sectorElementCollection.SidStars[0];
Assert.Equal("SID", result.Type);
Assert.Equal("EGKK", result.Airport);
Assert.Equal("26L", result.Runway);
Assert.Equal("ADMAG2X", result.Identifier);
Assert.Empty(result.Route);
AssertExpectedMetadata(result);
}

protected override InputDataType GetInputDataType()
Expand Down

0 comments on commit e3e8cb5

Please sign in to comment.