Skip to content

Commit 0f0d8ff

Browse files
author
Jake Shadle
authored
Merge pull request #3 from electronicarts/fix-parse-error
Fix parse error
2 parents 037c5dc + 8033ff7 commit 0f0d8ff

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ The headings should be in this order:
1212

1313
# UNRELEASED
1414

15+
## Fixed
16+
- Parsing error that could occur if yaml content contained "..." or "---" which resulted in the parser getting confused.
17+
1518
# 1.2.0 - [2017-10-27]
1619

1720
## Changed

src/NetTAP/Parser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public class TAPParser
7777
new Regex(
7878
@"(?<status>^(not )?ok\b)\s*(?<index>[0-9]*)\s*-?\s*(?<description>[\S\s-[#]]*)\s*#?\s*(?<directive>[\S\s]*)?");
7979

80-
private static readonly Regex s_yamlStartBlock = new Regex(@"(^\s)?---");
81-
private static readonly Regex s_yamlEndBlock = new Regex(@"(^\s)?\.\.\.");
80+
private static readonly Regex s_yamlStartBlock = new Regex(@"^\s+(---)$");
81+
private static readonly Regex s_yamlEndBlock = new Regex(@"^\s+(\.\.\.)$");
8282
private static readonly Regex s_tapVersion = new Regex(@"TAP\s+version\s+(?<version>\d*)");
8383

8484
private static readonly Regex s_testPlan =

test/NetTAP.Tests/Tests.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,5 +634,52 @@ public void RecievesParsedStreamCopy()
634634

635635
Assert.Equal(tapContent, resultTAPContent);
636636
}
637+
638+
[Fact]
639+
public void ParseYamlContentWithDotsAndDashes()
640+
{
641+
var tapContent = "TAP version 13\r\n" +
642+
"1..4\r\n" +
643+
"ok 1 - Input file opened\r\n" +
644+
"not ok 2 - First line of the input valid\r\n" +
645+
" ---\r\n" +
646+
" got: \'some unexpected dots ...\'\r\n" +
647+
" expect: \'some unexpected dashes\'\r\n" +
648+
" ...\r\n" +
649+
"ok 3 - Read the rest of the file\r\n" +
650+
"not ok 4 - Summarized correctly # TODO Not written yet\r\n" +
651+
" ---\r\n" +
652+
" message: \"Can\'t make --- yet\"\r\n" +
653+
" severity: ...\r\n" +
654+
" ...";
655+
656+
var errored = false;
657+
var bailedOut = false;
658+
var parser = new TAPParser();
659+
660+
parser.OnError += exception =>
661+
{
662+
errored = true;
663+
};
664+
665+
parser.OnBailout += message =>
666+
{
667+
bailedOut = true;
668+
};
669+
670+
var results = parser.Parse(CreateMemoryStream(tapContent)).Tests.ToList();
671+
672+
Assert.False(errored, "Expected nettap to successfully parse content.");
673+
Assert.False(bailedOut, "Expected nettap to successfully parse content.");
674+
675+
Assert.True(results.Count == 4, "Expected count is 4");
676+
677+
var secondResult = results[1];
678+
Assert.Equal(secondResult.YAML["got"], "some unexpected dots ...");
679+
680+
var fourthResult = results[3];
681+
Assert.Equal(fourthResult.YAML["message"], "Can\'t make --- yet");
682+
Assert.Equal(fourthResult.YAML["severity"], "...");
683+
}
637684
}
638685
}

0 commit comments

Comments
 (0)