public void should_be_ok_if_transforming_empty_option_value() { ArgsParser parser = new ArgsParserBuilder() .BeginDefaultCommand() .AddOptionWithValue("integer", 'i', string.Empty, false, IntegerTransformer.Instance) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new string[0]); result.AssertSuccess(); Assert.Empty(result.GetOptionValue <int>("--integer")); }
public void should_transform_multiple_integer_values() { ArgsParser parser = new ArgsParserBuilder() .BeginDefaultCommand() .AddOptionWithValue("integer", 'i', string.Empty, true, IntegerTransformer.Instance) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new [] { "-i", "12", "--integer", "13" }); result.AssertSuccess(); Assert.Equal(new [] { 12, 13 }, result.GetOptionValue <int>("-i")); }
public void should_throw_if_option_is_not_defined() { ArgsParser parser = new ArgsParserBuilder() .BeginCommand("command", string.Empty) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new [] { "command" }); Assert.Throws <ArgumentException>(() => result.GetOptionValue <string>("--not_existed_option")); Assert.Throws <ArgumentException>(() => result.GetFirstOptionValue <string>("--not_existed_option")); Assert.Throws <ArgumentException>(() => result.GetFreeValue <string>("not_existed_free_value")); Assert.Throws <ArgumentException>(() => result.GetFirstFreeValue <string>("not_existed_free_value")); }
public void should_throw_if_option_is_null() { ArgsParser parser = new ArgsParserBuilder() .BeginCommand("command", string.Empty) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new [] { "command" }); Assert.Throws <ArgumentNullException>(() => result.GetOptionValue <object>(null)); Assert.Throws <ArgumentNullException>(() => result.GetFirstOptionValue <object>(null)); Assert.Throws <ArgumentNullException>(() => result.GetFreeValue <object>(null)); Assert.Throws <ArgumentNullException>(() => result.GetFirstFreeValue <object>(null)); }
public void should_throw_if_option_has_no_value() { ArgsParser parser = new ArgsParserBuilder() .BeginCommand("command", string.Empty) .AddOptionWithValue("option", 'o', string.Empty) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new [] { "command" }); IList <string> values = result.GetOptionValue <string>("--option"); Assert.Empty(values); Assert.Throws <InvalidOperationException>(() => result.GetFirstOptionValue <string>("--option")); }
public void should_throw_if_getting_option_from_a_failure_result() { ArgsParser parser = new ArgsParserBuilder() .BeginDefaultCommand() .AddOptionWithValue("option", 'o', string.Empty, true) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new string[0]); Assert.False(result.IsSuccess); Assert.Throws <InvalidOperationException>(() => result.GetOptionRawValue("-o")); Assert.Throws <InvalidOperationException>(() => result.GetOptionValue("-o")); }
public void should_throw_if_option_is_not_defined_when_getting_option_value() { ArgsParser parser = new ArgsParserBuilder() .BeginDefaultCommand() .AddOptionWithValue("option", 'o', string.Empty, true) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new[] { "-o", "value" }); result.AssertSuccess(); Assert.Throws <ArgumentException>(() => result.GetOptionRawValue("--not-defined")); Assert.Throws <ArgumentException>(() => result.GetOptionValue("--not-defined")); }
public void should_throw_if_result_is_not_a_successful_one() { ArgsParser parser = new ArgsParserBuilder() .BeginCommand("command", string.Empty) .AddFreeValue("name", string.Empty) .AddOptionWithValue("option", 'o', string.Empty, true) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new [] { "command", "-f" }); Assert.False(result.IsSuccess); Assert.Throws <InvalidOperationException>(() => result.GetOptionValue <bool>("-o")); Assert.Throws <InvalidOperationException>(() => result.GetFirstOptionValue <bool>("-o")); Assert.Throws <InvalidOperationException>(() => result.GetFreeValue <bool>("name")); Assert.Throws <InvalidOperationException>(() => result.GetFirstFreeValue <bool>("name")); }