public void Parses_ULong_Argument() { var app = new Application("Test") .Argument(new ValueArgument(typeof(ulong)) .SetShort("-n") .SetName("number")); var result = app.Parse(new[] { "-n", "6" }); Assert.IsTrue(result.number == 6UL); Assert.IsTrue(result.number.GetType() == typeof(ulong)); }
public void Parses_String_Argument() { var app = new Application("Test") .Argument(new ValueArgument(typeof(string)) .SetShort("-s") .SetName("str")); var result = app.Parse(new[] { "-s", "test" }); Assert.IsTrue(result.str == "test"); Assert.IsTrue(result.str.GetType() == typeof(string)); }
public void Parses_Guid_Argument() { var app = new Application("Test") .Argument(new ValueArgument(typeof(Guid)) .SetShort("-g") .SetName("guid")); var result = app.Parse(new[] { "-g", "25e5a2c8-a0ea-452c-809c-df288a4c444c" }); Assert.IsTrue(result.guid == new Guid("25e5a2c8-a0ea-452c-809c-df288a4c444c")); Assert.IsTrue(result.guid.GetType() == typeof(Guid)); }
public void Parses_Switch() { var app = new Application("Test") .Argument(new Switch() .SetShort("-k") .SetName("kay")); var result = app.Parse(new[] { "-k" }); Assert.IsTrue(result.kay == true); Assert.IsTrue(result.kay.GetType() == typeof(bool)); }
public void Parses_SByte_Argument() { var app = new Application("Test") .Argument(new ValueArgument(typeof(sbyte)) .SetShort("-b") .SetName("byt")); var result = app.Parse(new[] { "-b", "6" }); Assert.IsTrue(result.byt == (sbyte)6); Assert.IsTrue(result.byt.GetType() == typeof(sbyte)); }
public void Parses_Char_Argument() { var app = new Application("Test") .Argument(new ValueArgument(typeof(char)) .SetShort("-c") .SetName("ch")); var result = app.Parse(new[] { "-c", "t" }); Assert.IsTrue(result.ch == 't'); Assert.IsTrue(result.ch.GetType() == typeof(char)); }
public void Parses_Bool_Argument() { // I don't know why you would do this instead of a switch, but it should probably be handled. var app = new Application("Test") .Argument(new ValueArgument(typeof(bool)) .SetShort("-b") .SetName("boolean")); var result = app.Parse(new[] { "-b", "true" }); Assert.IsTrue(result.boolean == true); Assert.IsTrue(result.boolean.GetType() == typeof(bool)); }
public void Parses_DateTime_Argument() { // Uses the .NET DateTime.Parse method. Does not give a particular culture, so it should use the machine's culture. // This will probably go into the configuration object at some point so that it can be injected, so the test can pass in other cultures. var app = new Application("Test") .Argument(new ValueArgument(typeof(DateTime)) .SetShort("-d") .SetName("date")); var result = app.Parse(new[] { "-d", "11/9/2018" }); Assert.IsTrue(result.date == new DateTime(2018, 11, 9)); Assert.IsTrue(result.date.GetType() == typeof(DateTime)); }
public void Parses_Multiple_Arguments_In_Order() { var app = new Application("Test") .Argument(new ValueArgument(typeof(int)) .SetShort("-n") .SetName("number")) .Argument(new ValueArgument(typeof(double)) .SetShort("-d") .SetName("dub")); var result = app.Parse(new[] { "-n", "6", "-d", "2.0" }); Assert.IsTrue(result.number == 6); Assert.IsTrue(result.dub == 2.0); }
public void Parses_Two_Switches_With_One_Not_Passed() { var app = new Application("Test") .Argument(new Switch() .SetShort("-k") .SetName("kay")) .Argument(new Switch() .SetShort("-t") .SetName("tee")); var result = app.Parse(new[] { "-k" }); Assert.IsTrue(result.kay == true); Assert.IsTrue(result.tee == false); }
public void Parses_Multiple_Arguments_With_Only_One_Passed() { var app = new Application("Test") .Argument(new ValueArgument(typeof(int)) .SetShort("-n") .SetName("number")) .Argument(new ValueArgument(typeof(double)) .SetShort("-d") .SetName("dub")); var result = app.Parse(new[] { "-n", "6" }); Assert.IsTrue(result.number == 6); Assert.IsTrue(result.dub == default(double)); }