public void BasicSwitchArguments() { CommandLineParser parser = new CommandLineParser(); parser.Parse(new string[] { @"/ foo", @"-BAR" }); parser.Target.Should().BeNull("only switch arguments should have null target"); parser.Targets.Should().NotBeNull("only switch arguments should not have null targets"); parser.Targets.Should().HaveCount(0, "only switch arguments should have no targets"); parser.GetOption<bool>("foo").Should().BeTrue("foo switch should be true, even though it has a space"); parser.GetOption<bool>("bar").Should().BeTrue("bar switch was set"); parser.GetOption<bool>("Bar").Should().BeTrue("foo switch should be true, irrespective of case"); }
public void StringArgument() { CommandLineParser parser = new CommandLineParser(null); parser.Parse(new string[] { @"/foo:bar" }); parser.Target.Should().BeNull("only switch arguments should have null target"); parser.Targets.Should().NotBeNull("only switch arguments should not have null targets"); parser.Targets.Should().HaveCount(0, "only switch arguments should have no targets"); parser.GetOption<string>("foo").Should().Be("bar", "foo's value was specified as bar"); parser.GetOption<bool>("foo").Should().BeFalse("foo switch doesn't translate to bool"); parser.GetOption<bool?>("foo").Should().NotHaveValue("foo switch doesn't translate to bool"); }
public void MultipartArgument() { CommandLineParser parser = new CommandLineParser(null); parser.Parse(new string[] { @"/foo:bar", @"/foo:foo" }); parser.Target.Should().BeNull("only switch arguments should have null target"); parser.Targets.Should().NotBeNull("only switch arguments should not have null targets"); parser.Targets.Should().HaveCount(0, "only switch arguments should have no targets"); parser.GetOption<string>("foo").Should().Be("bar;foo", "foo's value was specified via two switches"); }
public void FileArgument() { string path; IFileService fileService = TestFileServices.CreateSubstituteForFile(out path, "a\nb\nc\n@ @ @"); CommandLineParser parser = new CommandLineParser(fileService); parser.Parse(new string[] { "Command", @"/foo:@" + path }); parser.GetOption<string>("foo").Should().Be("a;b;c", "specified in file as a, b, c"); }
public void BooleanSwitches() { CommandLineParser parser = new CommandLineParser(); parser.Parse(new string[] { @"/foo", @"/bar:1", @"/foofoo:0", @"/barbar:false", @"/foobar:true" }); parser.Target.Should().BeNull("only switch arguments should have null target"); parser.Targets.Should().NotBeNull("only switch arguments should not have null targets"); parser.Targets.Should().HaveCount(0, "only switch arguments should have no targets"); parser.GetOption<bool>("foo").Should().BeTrue("foo switch should be true"); parser.GetOption<int>("foo").Should().Be(1, "foo switch should be also be 1"); parser.GetOption<bool>("bar").Should().BeTrue("far switch should be true"); parser.GetOption<int>("bar").Should().Be(1, "bar switch should be also be 1"); parser.GetOption<bool>("foofoo").Should().BeFalse("foofoo switch should be false"); parser.GetOption<int>("foofoo").Should().Be(0, "foofoo switch should be also be 0"); parser.GetOption<bool>("barbar").Should().BeFalse("barbar switch should be false"); parser.GetOption<int>("barbar").Should().Be(0, "barbar switch should be also be 0"); parser.GetOption<bool>("foobar").Should().BeTrue("explicit foobar switch should be true"); // TODO: Need to handle the float/double case // parser.GetOption<double>("foobar").Should().Be(1.0, "explicit foobar switch should be 1.0"); }