Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions 6 src/CommandLine/Core/Tokenizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ private static IEnumerable<Token> TokenizeShortName(
string value,
Func<string, NameLookupResult> nameLookup)
{
//Allow single dash as a value
if (value.Length == 1 && value[0] == '-')
{
yield return Token.Value(value);
yield break;
}
if (value.Length > 1 && value[0] == '-' && value[1] != '-')
{
var text = value.Substring(1);
Expand Down
20 changes: 20 additions & 0 deletions 20 tests/CommandLine.Tests/Unit/Core/TokenizerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ public void Should_return_error_if_option_format_with_equals_is_not_correct()
Assert.Equal(ErrorType.BadFormatTokenError, tokens.First().Tag);
Assert.Equal(ErrorType.BadFormatTokenError, tokens.Last().Tag);
}


[Theory]
[InlineData(new[] { "-a", "-" }, 2,"a","-")]
[InlineData(new[] { "--file", "-" }, 2,"file","-")]
[InlineData(new[] { "-f-" }, 2,"f", "-")]
[InlineData(new[] { "--file=-" }, 2, "file", "-")]
[InlineData(new[] { "-a", "--" }, 1, "a", "a")]
public void single_dash_as_a_value(string[] args, int countExcepted,string first,string last)
{
//Arrange
//Act
var result = Tokenizer.Tokenize(args, name => NameLookupResult.OtherOptionFound, token => token);
var tokens = result.SucceededWith().ToList();
//Assert
tokens.Should().NotBeNull();
tokens.Count.Should().Be(countExcepted);
tokens.First().Text.Should().Be(first);
tokens.Last().Text.Should().Be(last);
}
}

}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.