Skip to content

Commit

Permalink
Tuple missing types (#65)
Browse files Browse the repository at this point in the history
* Test cases covers tuple issue

* Proposed solution to track extra parentheses

Instead of treat additional parentheses as an error in place, ensure that they are balanced (e.g., two closed and two open)

* Add more complex tuple test cases

Refers to comment here - #65 (comment)

* Add more test cases for non-parsable inputs

* Closing parenthesis should be treated as error only when it is not part of tuple argument

* Treat backslashes as errors only if they not inside parenthesis block
  • Loading branch information
KonH authored Oct 10, 2020
1 parent 70f258f commit 50565c1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/NUnit.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,23 @@ public static ParsedName Parse(string fullyQualifedName)
}
else if (state == NameParseState.Default)
{
if (thisChar == '(' || thisChar == '"' || thisChar == '\\')
if (thisChar == '(')
{
parenthesisCount--;
}

// Backslashes allowed only inside parenthesis block
if ((thisChar == '\\') && (parenthesisCount == 0))
{
throw new Exception("Found invalid characters");
}
else if (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 @@ -125,7 +136,7 @@ public static ParsedName Parse(string fullyQualifedName)
{
if (thisChar == ')')
{
throw new Exception("Found invalid characters");
parenthesisCount++;
}

if (thisChar == '(')
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
10 changes: 10 additions & 0 deletions test/NUnit.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_WithConsoleOutput(stri
[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 50565c1

Please sign in to comment.