Skip to content

More tests for double-dash scenarios #683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.

using System.Collections.Generic;

namespace CommandLine.Tests.Fakes
{
class Options_With_Value_Sequence_And_Subsequent_Value
{
[Value(0)]
public IEnumerable<string> StringSequence { get; set; }

[Value(1)]
public string NeverReachedValue { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.

using System.Collections.Generic;

namespace CommandLine.Tests.Fakes
{
class Options_With_Value_Sequence_With_Max_And_Subsequent_Value
{
[Value(0, Max=2)]
public IEnumerable<string> StringSequence { get; set; }

[Value(1)]
public string NeverReachedValue { get; set; }
}
}
71 changes: 71 additions & 0 deletions tests/CommandLine.Tests/Unit/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,77 @@ public void Parse_options_with_double_dash_and_option_sequence()
((Parsed<Options_With_Option_Sequence_And_Value_Sequence>)result).Value.Should().BeEquivalentTo(expectedOptions);
}

[Theory]
[InlineData("value1", "value2", "value3")]
[InlineData("--", "value1", "value2", "value3")]
[InlineData("value1", "--", "value2", "value3")]
[InlineData("value1", "value2", "--", "value3")]
[InlineData("value1", "value2", "value3", "--")]
public void Parse_options_with_double_dash_in_various_positions(params string[] args)
{
var expectedOptions = new Options_With_Sequence_And_Only_Max_Constraint_For_Value
{
StringSequence = new[] { "value1", "value2", "value3" }
};

var sut = new Parser(with => with.EnableDashDash = true);

// Exercize system
var result =
sut.ParseArguments<Options_With_Sequence_And_Only_Max_Constraint_For_Value>(args);

// Verify outcome
((Parsed<Options_With_Sequence_And_Only_Max_Constraint_For_Value>)result).Value.Should().BeEquivalentTo(expectedOptions);
}

[Theory]
[InlineData("value1", "value2", "value3")]
[InlineData("--", "value1", "value2", "value3")]
[InlineData("value1", "--", "value2", "value3")]
[InlineData("value1", "value2", "--", "value3")]
[InlineData("value1", "value2", "value3", "--")]
public void Parse_options_with_double_dash_and_all_consuming_sequence_leaves_nothing_for_later_values(params string[] args)
{
var expectedOptions = new Options_With_Value_Sequence_And_Subsequent_Value
{
StringSequence = new[] { "value1", "value2", "value3" },
NeverReachedValue = null
};

var sut = new Parser(with => with.EnableDashDash = true);

// Exercize system
var result =
sut.ParseArguments<Options_With_Value_Sequence_And_Subsequent_Value>(args);

// Verify outcome
((Parsed<Options_With_Value_Sequence_And_Subsequent_Value>)result).Value.Should().BeEquivalentTo(expectedOptions);
}

[Theory]
[InlineData("value1", "value2", "value3")]
[InlineData("--", "value1", "value2", "value3")]
[InlineData("value1", "--", "value2", "value3")]
[InlineData("value1", "value2", "--", "value3")]
[InlineData("value1", "value2", "value3", "--")]
public void Parse_options_with_double_dash_and_limited_sequence_leaves_something_for_later_values(params string[] args)
{
var expectedOptions = new Options_With_Value_Sequence_With_Max_And_Subsequent_Value
{
StringSequence = new[] { "value1", "value2" },
NeverReachedValue = "value3"
};

var sut = new Parser(with => with.EnableDashDash = true);

// Exercize system
var result =
sut.ParseArguments<Options_With_Value_Sequence_With_Max_And_Subsequent_Value>(args);

// Verify outcome
((Parsed<Options_With_Value_Sequence_With_Max_And_Subsequent_Value>)result).Value.Should().BeEquivalentTo(expectedOptions);
}

[Fact]
public void Parse_options_with_double_dash_in_verbs_scenario()
{
Expand Down