Skip to content

Commit

Permalink
fix: Fix issue parsing methods with char args (#27)
Browse files Browse the repository at this point in the history
* Add failing test cases per nunit issue 90. Plus other control character chars

* Fix: Parse chars like strings

* Fix reduction in test coverage.
  • Loading branch information
Siphonophora committed Nov 27, 2021
1 parent f710cec commit b5078d1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
29 changes: 23 additions & 6 deletions src/TestLogger/Core/TestCaseNameParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ private enum NameParseState
{
Default,
Parenthesis,
String
String,
Char,
}

/// <summary>
Expand Down Expand Up @@ -85,6 +86,10 @@ public static ParsedName Parse(string fullyQualifiedName)
{
throw new Exception("Found invalid characters");
}
else if (thisChar == '\'')
{
throw new Exception("Found invalid characters");
}
else if (thisChar == ')')
{
if ((output.Count > 0) && (parenthesisCount == 0))
Expand Down Expand Up @@ -137,8 +142,7 @@ public static ParsedName Parse(string fullyQualifiedName)
{
parenthesisCount++;
}

if (thisChar == '(')
else if (thisChar == '(')
{
// If we found the beginning of the parenthesis block, we are back in
// default state
Expand All @@ -150,12 +154,14 @@ public static ParsedName Parse(string fullyQualifiedName)
// an issue, so we are 'entering' string state, because of the reverse parsing.
state = NameParseState.String;
}
else if (thisChar == '\'')
{
state |= NameParseState.Char;
}

output.Insert(0, thisChar);
}

// state == NameParseState.String
else
else if (state == NameParseState.String)
{
if (thisChar == '"' && fullyQualifiedName.ElementAtOrDefault(i - 1) != '\\')
{
Expand All @@ -164,6 +170,17 @@ public static ParsedName Parse(string fullyQualifiedName)
state = NameParseState.Parenthesis;
}

output.Insert(0, thisChar);
}
else if (state == NameParseState.Char)
{
if (thisChar == '\'' && fullyQualifiedName.ElementAtOrDefault(i - 1) != '\\')
{
// If this is a single quote that has not been escaped, switch the state. If it
// had been escaped, we would still be in a char.
state = NameParseState.Parenthesis;
}

output.Insert(0, thisChar);
}
}
Expand Down
13 changes: 12 additions & 1 deletion test/TestLogger.UnitTests/TestCaseNameParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public class TestCaseNameParserTests
[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))")]

// See nunit.testlogger #90
[DataRow("z.y.x.ape.bar('A',False)", "z.y.x", "ape", "bar('A',False)")]
[DataRow("z.y.x.ape.bar('\"',False)", "z.y.x", "ape", "bar('\"',False)")]
[DataRow("z.y.x.ape.bar('(',False)", "z.y.x", "ape", "bar('(',False)")]
[DataRow("z.y.x.ape.bar(')',False)", "z.y.x", "ape", "bar(')',False)")]
[DataRow("z.y.x.ape.bar('.',False)", "z.y.x", "ape", "bar('.',False)")]
[DataRow("z.y.x.ape.bar('\\'',False)", "z.y.x", "ape", "bar('\\'',False)")]
[DataRow("z.y.x.ape.bar('\\\\',False)", "z.y.x", "ape", "bar('\\\\',False)")]
public void Parse_ParsesAllParseableInputs_WithoutConsoleOutput(string testCaseName, string expectedNamespace, string expectedType, string expectedMethod)
{
using (var sw = new StringWriter())
Expand Down Expand Up @@ -94,6 +103,8 @@ public void Parse_ParsesAllParseableInputsWithoutNamespace_WithConsoleOutput(str
[DataRow("z.y.X\\x")]
[DataRow("z.y.x\\")]
[DataRow("z.y.X\\)")]
[DataRow("z.y.X\')")]
[DataRow("z.y.\'x")]
[DataRow("z.y.x))")]
[DataRow("z.y.x()x")]
[DataRow("z.y.x.")]
Expand Down Expand Up @@ -126,4 +137,4 @@ public void Parse_FailsGracefullyOnNonParseableInputs_WithConsoleOutput(string t
}
}
}
}
}

0 comments on commit b5078d1

Please sign in to comment.