Esempio n. 1
0
		public void ParseSwitchWithArguments()
		{
			const string Name1 = "name1";
			const string Name2 = "name2";
			const string Value1 = "value1";
			const string Value2 = "value2";

			string[] arguments = new string[]
			{
				Switch.GetPrefixedName(Name1),
				Value1,
				Value2,
				Switch.GetPrefixedName(Name2)
			};

			string[] argumentNames = new string[] { "arg1", "arg2" };

			string[] values = new string[] { Value1, Value2 };

			SwitchCollection switches = new SwitchCollection();

			switches.Add(Name1, NoLongName, NoDescription, IsRequired, argumentNames);
			switches.Add(Name2);

			ArgumentParser parser = new ArgumentParser(arguments, switches);

			Assert.IsFalse(parser.IsParsed(Name1));
			Assert.IsFalse(parser.IsParsed(Name2));

			parser.Parse();

			Assert.AreEqual(values, parser.GetValues(Name1));

			Assert.IsTrue(parser.IsParsed(Name1));
			Assert.IsTrue(parser.IsParsed(Name2));
		}
Esempio n. 2
0
		public void ParseSwitchWithExcessArguments()
		{
			const string Name1 = "name1";
			const string Name2 = "name2";
			const string Value1 = "value1";
			const string Value2 = "value2";
			const string Value3 = "value3";

			string[] arguments = new string[]
			{
				Switch.GetPrefixedName(Name1),
				Value1,
				Value2,
				Switch.GetPrefixedName(Name2)
			};

			string[] argumentNames = new string[] { "arg1", "arg2" };

			string[] enoughValues = new string[] { Value1, Value2 };

			string[] excessValues = new string[] { Value1, Value2, Value3 };

			SwitchCollection switches = new SwitchCollection();

			switches.Add(Name1, NoLongName, NoDescription, IsRequired, argumentNames);
			switches.Add(Name2);

			ArgumentParser parser = new ArgumentParser(arguments, switches);

			Assert.IsFalse(parser.IsParsed(Name1));
			Assert.IsFalse(parser.IsParsed(Name2));

			// No exceptions should be thrown. Excess arguments should be ignored.
			Assert.DoesNotThrow(delegate { parser.Parse(); });

			Assert.AreEqual(enoughValues, parser.GetValues(Name1));

			Assert.AreNotEqual(excessValues, parser.GetValues(Name1));

			Assert.IsTrue(parser.IsParsed(Name1));
			Assert.IsTrue(parser.IsParsed(Name2));
		}
Esempio n. 3
0
		public void GetValues()
		{
			const string Name1 = "name1";
			const string Name2 = "name2";
			const int NumberArguments = 2;
			const string Value1 = "value1";
			const string Value2 = "value2";
			const string Value3 = "value3";
			const string Value4 = "value4";

			string[] arguments = new string[]
			{
				Switch.GetPrefixedName(Name1),
				Value1, Value2,
				Switch.GetPrefixedName(Name2),
				Value3, Value4
			};

			SwitchCollection switches = new SwitchCollection();

			switches.Add(Name1, NoLongName, NoDescription, NumberArguments, IsRequired);
			switches.Add(Name2, NoLongName, NoDescription, NumberArguments, IsRequired);

			ArgumentParser parser = new ArgumentParser(arguments, switches);

			Assert.IsNull(parser.GetValues(EmptyName));
			Assert.IsNull(parser.GetValues(Name1));
			Assert.IsNull(parser.GetValues(Name2));
			Assert.IsNull(parser.GetValues(NoName));
			Assert.IsNull(m_emptyParser.GetValues(EmptyName));
			Assert.IsNull(m_emptyParser.GetValues(Name1));
			Assert.IsNull(m_emptyParser.GetValues(Name2));
			Assert.IsNull(m_emptyParser.GetValues(NoName));

			parser.Parse();

			Assert.AreEqual(new string[] { Value1, Value2 }, parser.GetValues(Name1));
			Assert.AreEqual(new string[] { Value3, Value4 }, parser.GetValues(Name2));

			Assert.IsNull(parser.GetValues(EmptyName));
			Assert.IsNull(parser.GetValues(NoName));
		}