Skip to content

Commit 1ffd84c

Browse files
committed
options should be case sensitive
1 parent fe63e41 commit 1ffd84c

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

FluentCommandLineParser.Tests/FluentCommandLineParser/when_a_new_instance_is_created.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class when_a_new_instance_is_created : FluentCommandLineParserTestContext
3434
{
3535
It should_create_a_default_parser_engine = () => sut.ParserEngine.ShouldBeOfType(typeof(Fclp.Internals.CommandLineParserEngineMark2));
3636
It should_create_a_default_option_factory = () => sut.OptionFactory.ShouldBeOfType(typeof(CommandLineOptionFactory));
37-
It should_set_IsCaseSensitive_to_default_value_of_false = () => sut.StringComparison.ShouldEqual(System.StringComparison.CurrentCultureIgnoreCase);
37+
It should_set_the_string_comparison_to_current_culture = () => sut.StringComparison.ShouldEqual(System.StringComparison.CurrentCulture);
3838
It should_have_setup_no_options_internally = () => sut.Options.ShouldBeEmpty();
3939
It should_have_a_default_option_formatter = () => sut.OptionFormatter.ShouldBeOfType(typeof(CommandLineOptionFormatter));
4040
}

FluentCommandLineParser.Tests/FluentCommandLineParserTests.cs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ public void Ensure_Defaults_Are_Called_When_Empty_Args_Specified()
570570
bool actualBool = false;
571571

572572
parser.Setup<int>('i').Callback(i => actualInt = i).SetDefault(expectedInt);
573-
parser.Setup<string>('s').Callback(s=> actualString = s).SetDefault(expectedString);
573+
parser.Setup<string>('s').Callback(s => actualString = s).SetDefault(expectedString);
574574
parser.Setup<bool>('b').Callback(b => actualBool = b).SetDefault(expectedBool);
575575
parser.Setup<double>('d').Callback(d => actualDouble = d).SetDefault(expectedDouble);
576576

@@ -660,7 +660,7 @@ public void Setup_Help_And_Ensure_It_Is_Called_With_Custom_Formatter()
660660

661661
var formatter = new Mock<ICommandLineOptionFormatter>();
662662

663-
var args = new[] {"/help", "i", "s"};
663+
var args = new[] { "/help", "i", "s" };
664664
const string expectedCallbackResult = "blah";
665665
string callbackResult = null;
666666

@@ -708,6 +708,49 @@ public void Setup_Help_And_Ensure_It_Is_Called()
708708

709709
#endregion
710710

711+
#region Case Sensitive
712+
713+
[Test]
714+
public void Ensure_Short_Options_Are_Case_Sensitive()
715+
{
716+
var parser = CreateFluentParser();
717+
718+
const string expectedSValue = "my expected value";
719+
string SValue;
720+
bool sValue = false;
721+
722+
parser.Setup<string>('S').Callback(str => SValue = str).Required();
723+
parser.Setup<bool>('s').Callback(b => sValue = b).Required();
724+
725+
var result = parser.Parse(new[] { "-S", expectedSValue, "-s" });
726+
727+
Assert.IsFalse(result.HasErrors);
728+
Assert.AreEqual(expectedSValue, expectedSValue);
729+
Assert.IsTrue(sValue);
730+
}
731+
732+
733+
[Test]
734+
public void Ensure_Long_Options_Are_Case_Sensitive()
735+
{
736+
var parser = CreateFluentParser();
737+
738+
const string expectedSValue = "my expected value";
739+
string SValue;
740+
bool sValue = false;
741+
742+
parser.Setup<string>("LONGOPTION").Callback(str => SValue = str).Required();
743+
parser.Setup<bool>("longoption").Callback(b => sValue = b).Required();
744+
745+
var result = parser.Parse(new[] { "--LONGOPTION", expectedSValue, "--longoption" });
746+
747+
Assert.IsFalse(result.HasErrors);
748+
Assert.AreEqual(expectedSValue, expectedSValue);
749+
Assert.IsTrue(sValue);
750+
}
751+
752+
#endregion
753+
711754
#endregion Top Level Tests
712755

713756
#region Duplicate Options Tests

FluentCommandLineParser/FluentCommandLineParser.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,12 @@ public class FluentCommandLineParser : IFluentCommandLineParser
4747
ICommandLineParserErrorFormatter _errorFormatter;
4848
ICommandLineOptionValidator _optionValidator;
4949

50-
///// <summary>
51-
///// Gets or sets whether the parser is case-sensitive. E.g. If <c>true</c> then <c>/a</c> will be treated as identical to <c>/A</c>.
52-
///// </summary>
53-
//public bool IsCaseSensitive { get; set; }
54-
5550
/// <summary>
5651
/// Gets the <see cref="StringComparison"/> to use when matching values.
5752
/// </summary>
5853
internal StringComparison StringComparison
5954
{
60-
//get { return this.IsCaseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase; }
61-
get { return StringComparison.CurrentCultureIgnoreCase; }
55+
get { return StringComparison.CurrentCulture; }
6256
}
6357

6458
/// <summary>

0 commit comments

Comments
 (0)