public void MultipleOptionShouldThrow() { Option[] options = new Option[] { new Option("a", null, "TestA", "Nothing", false, multipleTimes: false) }; OptionParser parser = new OptionParser(new OptionParser.Configuration(options)); string testLine = "-a -a"; Assert.ThrowsException <ParserException>(() => parser.ParseAll(testLine).ToList()); }
public void OptionWithArgumentAtEndShouldNotThrow() { Option[] options = new Option[] { new Option("a", null, "TestA", "Nothing", false) }; OptionParser parser = new OptionParser(new OptionParser.Configuration(options)); string testLine = "-a argument"; parser.ParseAll(testLine).ToList(); }
public void OptionWithoutArgumentShouldFail() { Option[] options = new Option[] { new Option("a", null, "TestA", "Nothing", true) }; OptionParser parser = new OptionParser(new OptionParser.Configuration(options)); string testLine = "-a"; Assert.ThrowsException <ParserException>(() => parser.ParseAll(testLine).ToList()); }
public void SingleSimpleLongOption() { Option[] options = new Option[] { new Option("a", "longoption", "TestA", "Nothing", false) }; OptionParser parser = new OptionParser(new OptionParser.Configuration(options)); string testLine = "--longoption"; var result = parser.ParseAll(testLine); Assert.IsTrue(result.Count() == 1); Assert.IsTrue(result.First().Option == options[0]); }
public void ArgumentBetweenOptionsShouldThrow() { Option[] options = new Option[] { new Option("a", null, "TestA", "Nothing", false) }; OptionParser parser = new OptionParser(new OptionParser.Configuration(options) { AllowArgumentsBetweenOptions = false }); string testLine = "-a hola -a"; Assert.ThrowsException <ParserException>(() => parser.ParseAll(testLine).ToList()); }
public void SingleShortOption() { Option[] options = new Option[] { new Option("a", null, "TestA", "Nothing", true) }; OptionParser parser = new OptionParser(new OptionParser.Configuration(options)); string testLine = "-a 'test'"; var result = parser.ParseAll(testLine); Assert.IsTrue(result.Count() == 1); Assert.IsTrue(result.First().Option == options[0]); Assert.AreEqual("test", result.First().Argument); }
public void MultipleSimpleShortOptions() { Option[] options = new Option[] { new Option("a", null, "TestA", "Nothing"), new Option("b", null, "TestB", "Nothing") }; OptionParser parser = new OptionParser(new OptionParser.Configuration(options)); string testLine = "-a -b"; var result = parser.ParseAll(testLine).ToArray(); Assert.IsTrue(result.Count() == 2); Assert.AreEqual(options[0], result[0].Option); Assert.AreEqual(options[1], result[1].Option); }
public void MultipleLongOptions() { Option[] options = new Option[] { new Option("a", "longa", "TestA", "Nothing", true), new Option("b", "longb", "TestB", "Nothing", true) }; OptionParser parser = new OptionParser(new OptionParser.Configuration(options)); string testLine = "--longa 'testa' --longb testb"; var result = parser.ParseAll(testLine).ToArray(); Assert.IsTrue(result.Count() == 2); Assert.AreEqual(options[0], result[0].Option); Assert.AreEqual(options[1], result[1].Option); Assert.AreEqual("testa", result[0].Argument); Assert.AreEqual("testb", result[1].Argument); }