Skip to content

Commit ce14242

Browse files
committed
Added failing test for the argument parser not properly handling multiple quoted values. Added documentation to group regex field.
1 parent 976df6a commit ce14242

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Utility.CommandLine.Arguments.Tests/Arguments.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,20 @@ public void ParseStringOfLongs()
199199
Assert.Equal("5 5", test["five"]);
200200
}
201201

202+
/// <summary>
203+
/// Tests the <see cref="Utility.CommandLine.Arguments.Parse(string)"/> method with an explicit command line string containing multiple pairs of arguments containing quoted values.
204+
/// </summary>
205+
[Fact]
206+
public void ParseMultipleQuotes()
207+
{
208+
Dictionary<string, string> test = CommandLine.Arguments.Parse("--test1 \"1\" --test2 \"2\" --test3 \'3\' --test4 \'4\'");
209+
210+
Assert.Equal("1", test["test1"]);
211+
Assert.Equal("2", test["test2"]);
212+
Assert.Equal("3", test["test3"]);
213+
Assert.Equal("4", test["test4"]);
214+
}
215+
202216
/// <summary>
203217
/// Tests the <see cref="Utility.CommandLine.Arguments.Populate(string)"/> method with the default values.
204218
/// </summary>

Utility.CommandLine.Arguments/Arguments.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ public static class Arguments
6868
/// </summary>
6969
private const string ArgumentRegEx = "(?:[-]{1,2}|\\/)([\\w-]+)[=|:| ]?(\\w\\S*|\\\".*\\\"|\\\'.*\\\')?";
7070

71+
/// <summary>
72+
/// The regular expression with which to parse argument-value groups.
73+
/// </summary>
7174
private const string GroupRegEx = "^-[^-]+";
7275

7376
#endregion Private Fields

0 commit comments

Comments
 (0)