Skip to content
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