public static void TestWriteOptionDescriptionsWithValueArguments() { string value = null; OptionSetCollection options = new OptionSetCollection() { { "a=", s => value = s }, { "b:|c:", s => value = s }, { "d={=>}", (s, v) => value = s + v }, { "e={}", (s, v) => value = s + v }, { "f", s => value = s }, }; string expectedDescription = " -a=VALUE " + Environment.NewLine + " -b, -c[=VALUE] " + Environment.NewLine + " -d=VALUE1=>VALUE2 " + Environment.NewLine + " -e=VALUE1 VALUE2 " + Environment.NewLine + " -f " + Environment.NewLine; using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture)) { options.WriteOptionDescriptions(writer); string s = writer.ToString(); Assert.That(s, Is.EqualTo(expectedDescription)); } Assert.That(value, Is.Null); }
public static void TestAddNullOptionToCollectionThrows() { OptionSetCollection options = new OptionSetCollection(); OptionBase nullOb = null; Assert.Throws <ArgumentNullException>(() => options.Add(nullOb)); }
private static OptionContext CreateOptionContext() { OptionSetCollection optionSet = new OptionSetCollection() { { "x=", (k, v) => {} }, }; OptionContext oc = new OptionContext(optionSet); return(oc); }
public static void TestTooManyOptionValuesThrows() { IDictionary <string, string> dictionary = new Dictionary <string, string>(); OptionSetCollection options = new OptionSetCollection() { { "a={=>}", (key, value) => dictionary.Add(key, value) }, }; Assert.Throws <OptionException>(() => options.Parse(new string[] { "-a", "b=>c=>d" })); }
public static void TestParsingNullElementThrows() { int i = 0; OptionSetCollection options = new OptionSetCollection() { { "x", var => ++ i }, }; Assert.Throws <ArgumentNullException>(() => options.Parse(new string[] { "-x", null })); }
public static void TestBadlyFormedTypedValueThrows() { int i = 0; OptionSetCollection options = new OptionSetCollection() { { "name=", (int value) => i = value }, }; Assert.Throws <OptionException>(() => options.Parse(new string[] { "-name=Three" })); Assert.That(i, Is.EqualTo(0)); }
public static void TestMissingTrailingRequiredValueThrows() { string value = null; OptionSetCollection options = new OptionSetCollection() { { "name=", v => value = v } }; Assert.Throws <OptionException>(() => options.Parse(new string[] { "-name" })); Assert.That(value, Is.Null); }
public static void TestOptionBaseToString() { int i = 0; OptionSetCollection options = new OptionSetCollection() { { "x|y", v => ++ i }, }; OptionBase ob = options["x"]; Assert.That(ob.ToString(), Is.EqualTo("x|y")); }
public static void TestOptionBaseGetDescription() { int i = 0; OptionSetCollection options = new OptionSetCollection() { { "x|y", "X or Y", v => ++ i }, }; OptionBase ob = options["x"]; Assert.That(ob.Description, Is.EqualTo("X or Y")); }
public static void TestForcedDisabledOption() { bool x = true; OptionSetCollection options = new OptionSetCollection() { { "x", value => x = value != null }, }; options.Parse(new string[] { "-x-" }); Assert.That(x, Is.False); }
public static void TestTypedValue() { int i = 0; OptionSetCollection options = new OptionSetCollection() { { "name=", (int value) => i = value }, }; options.Parse(new string[] { "-name=3" }); Assert.That(i, Is.EqualTo(3)); }
public static void TestOptionBaseGetPrototype() { int i = 0; OptionSetCollection options = new OptionSetCollection() { { "x|y", v => ++ i }, }; OptionBase ob = options["x"]; Assert.That(ob.Prototype, Is.EqualTo("x|y")); }
public static void TestMultipleValuesWithNoSeparator() { IDictionary <string, string> dictionary = new Dictionary <string, string>(); OptionSetCollection options = new OptionSetCollection() { { "name={}", (key, value) => dictionary.Add(key, value) }, }; options.Parse(new string[] { "-name=A", "a", "-name=B", "b" }); Assert.That(dictionary["A"], Is.EqualTo("a")); Assert.That(dictionary["B"], Is.EqualTo("b")); }
public static void TestStronglyTypedKeyValuePair() { int k = 0, v = 0; OptionSetCollection options = new OptionSetCollection() { { "D=", (int key, int value) => { k = key; v = value; } }, }; options.Parse(new string[] { "-D1=2" }); Assert.That(k, Is.EqualTo(1)); Assert.That(v, Is.EqualTo(2)); }
public static void TestOptionBaseGetValueSeparatorsWhenNone() { IDictionary <string, string> dictionary = new Dictionary <string, string>(); OptionSetCollection options = new OptionSetCollection() { { "a={}", (key, value) => dictionary.Add(key, value) }, }; OptionBase ob = options["a"]; string[] separators = ob.GetValueSeparators(); Assert.That(separators.Length, Is.EqualTo(0)); }
public static void TestOptionWithValue() { string v = null; OptionSetCollection options = new OptionSetCollection() { { "y=", value => v = value }, }; options.Parse(new string[] { "-y=s" }); Assert.That(v, Is.EqualTo("s")); }
public static void TestOptionBaseGetValueSeparators() { IDictionary <string, string> dictionary = new Dictionary <string, string>(); OptionSetCollection options = new OptionSetCollection() { { "a=-+", (key, value) => dictionary.Add(key, value) }, }; OptionBase ob = options["a"]; string[] separators = ob.GetValueSeparators(); Assert.That(separators[0], Is.EqualTo("-")); Assert.That(separators[1], Is.EqualTo("+")); }
public static void TestStopProcessingMarker() { int verbose = 0; OptionSetCollection options = new OptionSetCollection() { { "v", v => ++ verbose } }; IList <string> extra = options.Parse(new string[] { "-v", "--v", "/v", "--", "-v" }); Assert.That(verbose, Is.EqualTo(3)); Assert.That(extra[0], Is.EqualTo("-v")); }
public static void TestOptionBaseGetNames() { int i = 0; OptionSetCollection options = new OptionSetCollection() { { "x|y", v => ++ i }, }; OptionBase ob = options["x"]; string[] names = ob.GetNames(); Assert.That(names[0], Is.EqualTo("x")); Assert.That(names[1], Is.EqualTo("y")); }
public static void TestBundledOptionWithUnknownOptionThrows() { bool x = false; bool y = false; OptionSetCollection options = new OptionSetCollection() { { "x", value => x = value != null }, { "y", value => y = value != null }, }; Assert.Throws <OptionException>(() => options.Parse(new string[] { "-xyz" })); Assert.That(x, Is.True); Assert.That(y, Is.True); }
public static void TestBundledOption() { bool x = false; bool y = false; OptionSetCollection options = new OptionSetCollection() { { "x", value => x = value != null }, { "y", value => y = value != null }, }; options.Parse(new string[] { "-xy" }); Assert.That(x, Is.True); Assert.That(y, Is.True); }
public static void TestSimpleOption() { bool x = false; OptionSetCollection options = new OptionSetCollection() { { "x", var => x = true }, }; options.Parse(new string[] { "-y" }); Assert.That(x, Is.False); options.Parse(new string[] { "-x" }); Assert.That(x, Is.True); }
public static void TestWriteOptionDescriptionsWithUnterminatedRightCurlyBraceEscape() { int i = 0; OptionSetCollection options = new OptionSetCollection() { { "name=", "A Description }", (int value) => i = value }, }; using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture)) { Assert.Throws <InvalidOperationException>(() => options.WriteOptionDescriptions(writer)); } Assert.That(i, Is.EqualTo(0)); }
public static void TestExampleFromDocumentation() { int verbose = 0; List <string> names = new List <string>(); OptionSetCollection options = new OptionSetCollection() .Add("v", v => ++ verbose) .Add("name=|value=", v => names.Add(v)); IList <string> extra = options.Parse(new string[] { "-v", "--v", "/v", "-name=A", "/name", "B", "extra" }); Assert.That(verbose, Is.EqualTo(3)); Assert.That(names[0], Is.EqualTo("A")); Assert.That(names[1], Is.EqualTo("B")); Assert.That(extra[0], Is.EqualTo("extra")); }
public static void TestOptionContext() { OptionSetCollection optionSet = new OptionSetCollection(); OptionContext oc = new OptionContext(optionSet); Assert.That(oc.OptionSet, Is.EqualTo(oc.OptionSet)); Assert.That(oc.OptionValues.Count(), Is.EqualTo(0)); oc.OptionIndex = 3; Assert.That(oc.OptionIndex, Is.EqualTo(3)); oc.OptionName = "option"; Assert.That(oc.OptionName, Is.EqualTo("option")); }
public static void TestBundledOptionWithValue() { bool x = false; string v = null; OptionSetCollection options = new OptionSetCollection() { { "x", value => x = value != null }, { "y=", value => v = value }, }; options.Parse(new string[] { "-xyoption" }); Assert.That(x, Is.True); Assert.That(v, Is.EqualTo("option")); }
public static void TestBundledOptionWithNonMinusSwitchWhichApparentlyIsNotSupported() { bool x = false; bool y = false; OptionSetCollection options = new OptionSetCollection() { { "x", value => x = value != null }, { "y", value => y = value != null }, }; IList <string> extra = options.Parse(new string[] { "/xy" }); Assert.That(extra[0], Is.EqualTo("/xy")); Assert.That(x, Is.False); Assert.That(y, Is.False); }
public static void TestWriteOptionDescriptionsWithInsertedValueNamesForSingleArgument() { int i = 0; OptionSetCollection options = new OptionSetCollection() { { "name=", "Description {Key} and {1:Value}", (int value) => { i = value; } }, }; string description = " --name=Key Description Key and Value" + Environment.NewLine; using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture)) { options.WriteOptionDescriptions(writer); string s = writer.ToString(); Assert.That(s, Is.EqualTo(description)); } Assert.That(i, Is.EqualTo(0)); }
public static void TestWriteOptionDescriptionsWithInsertedValueNamesIgnoredBecauseOfUnterminatedPlaceholderMarkerAndDescriptionBug() { int i = 0; OptionSetCollection options = new OptionSetCollection() { { "name=", "Description {Key and value", (int value) => { i = value; } }, }; string description = " --name=VALUE Description " + Environment.NewLine; using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture)) { options.WriteOptionDescriptions(writer); string s = writer.ToString(); Assert.That(s, Is.EqualTo(description)); } Assert.That(i, Is.EqualTo(0)); }
public static void TestWriteOptionDescriptionsWithRightCurlyBraceEscape() { int i = 0; OptionSetCollection options = new OptionSetCollection() { { "name=", "A }} Description", (int value) => i = value }, }; string description = " --name=VALUE A } Description" + Environment.NewLine; using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture)) { options.WriteOptionDescriptions(writer); string s = writer.ToString(); Assert.That(s, Is.EqualTo(description)); } Assert.That(i, Is.EqualTo(0)); }