Skip to content

Commit da959b7

Browse files
committed
Adding failing test for new feature (Issue #68)
1 parent be62ab9 commit da959b7

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

src/CommandLine.Tests/CommandLine.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<Compile Include="Fakes\FakeOptionsWithDouble.cs" />
6363
<Compile Include="Fakes\FakeOptionsWithEnum.cs" />
6464
<Compile Include="Fakes\FakeOptionsWithMetaValue.cs" />
65+
<Compile Include="Fakes\FakeOptionsWithSequenceAndSeparator.cs" />
6566
<Compile Include="Fakes\FakeOptionsWithSequenceWithoutRange.cs" />
6667
<Compile Include="Fakes\FakeOptionsWithSets.cs" />
6768
<Compile Include="Fakes\FakeOptionsWithValues.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace CommandLine.Tests.Fakes
7+
{
8+
class FakeOptionsWithSequenceAndSeparator
9+
{
10+
[Option("string-seq", Separator=";")]
11+
public IEnumerable<string> StringSequence { get; set; }
12+
}
13+
}

src/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs

+25-3
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ public void Parse_sequence_value_without_range_constraints()
162162
{
163163
// Fixture setup
164164
var expectedResult = new FakeOptionsWithSequenceWithoutRange
165-
{
166-
LongSequence = new[] { 1L, 2L, 3L, 4L, 5L, 6L }
167-
};
165+
{
166+
LongSequence = new[] { 1L, 2L, 3L, 4L, 5L, 6L }
167+
};
168168

169169
// Exercize system
170170
var result = InstanceBuilder.Build(
@@ -179,6 +179,28 @@ public void Parse_sequence_value_without_range_constraints()
179179
// Teardown
180180
}
181181

182+
[Fact]
183+
public void Parse_string_sequence_with_separator()
184+
{
185+
// Fixture setup
186+
var expectedResult = new FakeOptionsWithSequenceAndSeparator
187+
{
188+
StringSequence = new[] { "abc","1234","[email protected]" }
189+
};
190+
191+
// Exercize system
192+
var result = InstanceBuilder.Build(
193+
() => new FakeOptionsWithSequenceAndSeparator(),
194+
new[] { "abc;1234;[email protected]" },
195+
StringComparer.Ordinal,
196+
CultureInfo.InvariantCulture);
197+
198+
// Verify outcome
199+
expectedResult.ShouldHave().AllProperties().EqualTo(result.Value);
200+
201+
// Teardown
202+
}
203+
182204
/// <summary>
183205
/// https://github.com/gsscoder/commandline/issues/31
184206
/// </summary>

src/CommandLine/OptionAttribute.cs

+15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public sealed class OptionAttribute : Attribute
1616
private string setName;
1717
private int min;
1818
private int max;
19+
private string separator;
1920
private object defaultValue;
2021
private string helpText;
2122
private string metaValue;
@@ -147,6 +148,20 @@ public int Max
147148
}
148149
}
149150

151+
public string Separator
152+
{
153+
get { return this.separator; }
154+
set
155+
{
156+
if (value == null)
157+
{
158+
throw new ArgumentNullException("value");
159+
}
160+
161+
this.setName = value;
162+
}
163+
}
164+
150165
/// <summary>
151166
/// Gets or sets mapped property default value.
152167
/// </summary>

0 commit comments

Comments
 (0)