Skip to content

Commit

Permalink
Feat: Import parser fixes from spekt/nunit.testlogger#65
Browse files Browse the repository at this point in the history
  • Loading branch information
Siphonophora committed Sep 25, 2020
1 parent a2e6f84 commit c367d13
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/JUnit.Xml.TestLogger/TestCaseNameParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static ParsedName Parse(string fullyQualifedName)

var step = NameParseStep.FindMethod;
var state = NameParseState.Default;
var parenthesisCount = 0;

var output = new List<char>();

Expand All @@ -71,13 +72,18 @@ public static ParsedName Parse(string fullyQualifedName)
}
else if (state == NameParseState.Default)
{
if (thisChar == '(' || thisChar == '"' || thisChar == '\\')
if (thisChar == '(')
{
parenthesisCount--;
}

if (thisChar == '"' || thisChar == '\\')
{
throw new Exception("Found invalid characters");
}
else if (thisChar == ')')
{
if (output.Count > 0)
if ((output.Count > 0) && (parenthesisCount == 0))
{
throw new Exception("The closing parenthesis we detected wouldn't be the last character in the output string. This isn't acceptable because we aren't in a string");
}
Expand Down Expand Up @@ -124,6 +130,11 @@ public static ParsedName Parse(string fullyQualifedName)
else if (state == NameParseState.Parenthesis)
{
if (thisChar == ')')
{
parenthesisCount++;
}

if (thisChar == '\\')
{
throw new Exception("Found invalid characters");
}
Expand Down Expand Up @@ -157,6 +168,11 @@ public static ParsedName Parse(string fullyQualifedName)
}
}

if (parenthesisCount != 0)
{
throw new Exception($"Unbalanced count of parentheses found ({parenthesisCount})");
}

// We are done. If we are finding type, set that variable.
// Otherwise, ther was some issue, so leave the type blank.
if (step == NameParseStep.FindNamespace)
Expand Down Expand Up @@ -211,4 +227,4 @@ public ParsedName(string namespaceName, string typeName, string methodName)
public string MethodName { get; }
}
}
}
}
10 changes: 10 additions & 0 deletions test/JUnit.Xml.TestLogger.UnitTests/TestCaseNameParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public class TestCaseNameParserTests

// See nunit.testlogger #66.
[DataRow("z.y.x.ape.bar(a\\b)", "z.y.x", "ape", "bar(a\\b)")]

// Test with tuple arguments
[DataRow("z.a.b((0,1))", "z", "a", "b((0,1))")]
[DataRow("z.a.b((\"arg\",1))", "z", "a", "b((\"arg\",1))")]
[DataRow("z.a.b((0,1),(2,3))", "z", "a", "b((0,1),(2,3))")]
[DataRow("z.a.b((0,(0,1)),(0,1))", "z", "a", "b((0,(0,1)),(0,1))")]
public void Parse_ParsesAllParsableInputs_WithoutConsoleOutput(string testCaseName, string expectedNamespace, string expectedType, string expectedMethod)
{
var expected = new Tuple<string, string>(expectedType, expectedMethod);
Expand Down Expand Up @@ -94,6 +100,10 @@ public void Parse_ParsesAllParsableInputsWithoutNamespace_WithoutConsoleOutput(s
[DataRow("z.y.x.")]
[DataRow("z.y.x.)")]
[DataRow("z.y.x.\"\")")]
[DataRow("z.a.b((0,1)")]
[DataRow("z.a.b((0,1)))")]
[DataRow("z.a.b((0,(0,1))")]
[DataRow("z.a.b((0,(0,1))))")]
public void Parse_FailsGracefullyOnNonParsableInputs_WithConsoleOutput(string testCaseName)
{
var expectedConsole = string.Format(
Expand Down

0 comments on commit c367d13

Please sign in to comment.