Skip to content

Commit f122bf6

Browse files
committed
Add tests for default parsing
1 parent 81b300b commit f122bf6

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

SabreTools.CommandLine.Test/CommandSetTests.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,71 @@ public void GetUInt64_NestedExists_Returns()
759759

760760
#endregion
761761

762+
#region ProcessArgs
763+
764+
[Fact]
765+
public void ProcessArgs_EmptyArgs_Success()
766+
{
767+
CommandSet commandSet = new CommandSet();
768+
769+
string[] args = [];
770+
771+
bool actual = commandSet.ProcessArgs(args);
772+
Assert.True(actual);
773+
}
774+
775+
[Fact]
776+
public void ProcessArgs_ValidArgs_Success()
777+
{
778+
CommandSet commandSet = new CommandSet();
779+
Feature feature = new MockFeature("a", "a", "a");
780+
feature.Add(new FlagInput("b", "b", "b"));
781+
feature.Add(new FlagInput("c", "c", "c"));
782+
commandSet.Add(feature);
783+
784+
string[] args = ["a", "b", "c"];
785+
786+
bool actual = commandSet.ProcessArgs(args);
787+
Assert.True(actual);
788+
Assert.Empty(feature.Inputs);
789+
}
790+
791+
[Fact]
792+
public void ProcessArgs_InvalidArg_AddedAsGeneric()
793+
{
794+
CommandSet commandSet = new CommandSet();
795+
Feature feature = new MockFeature("a", "a", "a");
796+
feature.Add(new FlagInput("b", "b", "b"));
797+
feature.Add(new FlagInput("d", "d", "d"));
798+
commandSet.Add(feature);
799+
800+
string[] args = ["a", "b", "c"];
801+
802+
bool actual = commandSet.ProcessArgs(args);
803+
Assert.True(actual);
804+
string input = Assert.Single(feature.Inputs);
805+
Assert.Equal("c", input);
806+
}
807+
808+
[Fact]
809+
public void ProcessArgs_NestedArgs_Success()
810+
{
811+
CommandSet commandSet = new CommandSet();
812+
Feature feature = new MockFeature("a", "a", "a");
813+
var sub = new FlagInput("b", "b", "b");
814+
sub.Add(new FlagInput("c", "c", "c"));
815+
feature.Add(sub);
816+
commandSet.Add(feature);
817+
818+
string[] args = ["a", "b", "c"];
819+
820+
bool actual = commandSet.ProcessArgs(args);
821+
Assert.True(actual);
822+
Assert.Empty(feature.Inputs);
823+
}
824+
825+
#endregion
826+
762827
/// <summary>
763828
/// Mock Feature implementation for testing
764829
/// </summary>

0 commit comments

Comments
 (0)