public void should_support_mandatory_free_values_for_default_command() { ArgsParser parser = new ArgsParserBuilder() .BeginDefaultCommand() .AddFreeValue("name", string.Empty, true, DefaultTransformer.Instance) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new [] { "free_value" }); result.AssertSuccess(); Assert.Equal("free_value", result.GetFirstFreeValue <string>("name")); }
public void should_support_transformer_on_free_values() { ArgsParser parser = new ArgsParserBuilder() .BeginCommand("command", string.Empty) .AddFreeValue("name", string.Empty, false, IntegerTransformer.Instance) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new [] { "command", "123" }); result.AssertSuccess(); Assert.Equal(123, result.GetFreeValue <int>("name").Single()); Assert.Equal(123, result.GetFirstFreeValue <int>("name")); }
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_free_value_name_has_no_value() { ArgsParser parser = new ArgsParserBuilder() .BeginCommand("command", string.Empty) .AddFreeValue("name", string.Empty) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new [] { "command" }); IList <string> values = result.GetFreeValue <string>("name"); Assert.Empty(values); Assert.Throws <InvalidOperationException>(() => result.GetFirstFreeValue <string>("name")); }
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")); }