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

Sign up
Appearance settings

Commit f2c7ab9

Browse files
committed
Addressed code review + remote merge
2 parents be80664 + 1cca1ac commit f2c7ab9

File tree

6 files changed

+37
-3
lines changed

6 files changed

+37
-3
lines changed

‎src/CommandLine/Core/InstanceBuilder.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static ParserResult<T> Build<T>(
6767

6868
var valueSpecPropsResult =
6969
ValueMapper.MapValues(
70-
(from pt in specProps where pt.Specification.IsValue() select pt),
70+
(from pt in specProps where pt.Specification.IsValue() orderby ((ValueSpecification)pt.Specification).Indexselect pt),
7171
valuesPartition,
7272
(vals, type, isScalar) => TypeConverter.ChangeType(vals, type, isScalar, parsingCulture, ignoreValueCase));
7373

‎src/CommandLine/Core/TokenPartitioner.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static
2828
.Where(t => !scalars.Contains(t, ReferenceEqualityComparer.Default))
2929
.Where(t => !sequences.Contains(t, ReferenceEqualityComparer.Default)).Memorize();
3030
var values = nonOptions.Where(v => v.IsValue()).Memorize();
31-
var errors = nonOptions.Except(values, ReferenceEqualityComparer.Default).Cast<Token>().Memorize();
31+
var errors = nonOptions.Except(values, (IEqualityComparer<Token>)ReferenceEqualityComparer.Default).Memorize();
3232

3333
return Tuple.Create(
3434
KeyValuePairHelper.ForSwitch(switches)

‎src/CommandLine/Infrastructure/ReferenceEqualityComparer.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal sealed class ReferenceEqualityComparer : IEqualityComparer, IEqualityCo
1313

1414
public new bool Equals(object x, object y)
1515
{
16-
return x==y;// reference equality because operator== is static and resolved at compile-time
16+
return ReferenceEquals(x,y);
1717
}
1818

1919
public int GetHashCode(object obj)

‎tests/CommandLine.Tests/CommandLine.Tests.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<Compile Include="Fakes\Options_With_Guid.cs" />
6363
<Compile Include="Fakes\Options_With_Option_And_Value_Of_String_Type.cs" />
6464
<Compile Include="Fakes\Options_With_SetName_That_Ends_With_Previous_SetName.cs" />
65+
<Compile Include="Fakes\Options_With_Shuffled_Index_Values.cs" />
6566
<Compile Include="Fakes\Options_With_Uri_And_SimpleType.cs" />
6667
<Compile Include="Fakes\Options_With_Switches.cs" />
6768
<Compile Include="Fakes\Options_With_Two_Option_Required_Set_To_True_And_Two_Sets.cs" />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
2+
3+
using System;
4+
using System.Linq;
5+
6+
namespace CommandLine.Tests.Fakes
7+
{
8+
class Options_With_Shuffled_Index_Values
9+
{
10+
[Value(1)]
11+
public string Arg1 { get; set; }
12+
13+
[Value(2)]
14+
public string Arg2 { get; set; }
15+
16+
[Value(0)]
17+
public string Arg0 { get; set; }
18+
}
19+
}

‎tests/CommandLine.Tests/Unit/ParserTests.cs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,5 +833,19 @@ public void Parse_verb_with_same_option_and_value_args()
833833
Assert.Equal("arg", args.PosValue);
834834
});
835835
}
836+
837+
public void Parse_options_with_shuffled_index_values()
838+
{
839+
var parser = Parser.Default;
840+
parser.ParseArguments<Options_With_Shuffled_Index_Values>(
841+
new[] { "zero", "one", "two" })
842+
.WithNotParsed(errors => { throw new InvalidOperationException("Must be parsed."); })
843+
.WithParsed(args =>
844+
{
845+
Assert.Equal("zero", args.Arg0);
846+
Assert.Equal("one", args.Arg1);
847+
Assert.Equal("two", args.Arg2);
848+
});
849+
}
836850
}
837851
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /