示例#1
0
 public void consumeTestFalseOnNoLabelMatch()
 {
     ArgDef testDef = new ArgDef();
     testDef.argLabels.Add("-test");
     testDef.parseInit(ArgTypeParser.basicParsers);
     VirtualArray<string> vArgs = new VirtualArray<string>(new string[] {"-nottest"}, 0, 1);
     ParsedArgs pArgs = new ParsedArgs();
     bool result = testDef.consume(vArgs, pArgs);
     Assert.IsFalse(result, "[ArgDef][consume] consume should return false when no label matches the input");
 }
示例#2
0
 public void consumeTestFlag()
 {
     ArgDef testDef = new ArgDef();
     testDef.argLabels.Add("-t");
     testDef.parseInit(ArgTypeParser.basicParsers);
     VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-t" });
     ParsedArgs pArgs = new ParsedArgs();
     testDef.consume(vArgs, pArgs);
     Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given");
     Assert.IsTrue(pArgs.getValue<bool>("t"), "[ArgDef][consume] consume should set the appropriate value for the given arg name when encountered.");
 }
示例#3
0
 public void consumeTestLabeledBoolAsArray()
 {
     ArgDef testDef = new ArgDef();
     testDef.argLabels.Add("-t");
     testDef.type = typeof(bool);
     testDef.argCount = 1;
     testDef.createArrayForArgCount1 = true;
     testDef.parseInit(ArgTypeParser.basicParsers);
     VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-t", "false" });
     ParsedArgs pArgs = new ParsedArgs();
     testDef.consume(vArgs, pArgs);
     Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given");
     bool[] result = pArgs.getArray<bool>("t");
     Assert.AreEqual<int>(1, result.Length, "[ArgDef][consume] consume should create an array of size 1 when argCount is 1 and createArrayForArgCount1 is true");
     Assert.IsFalse(result[0], "[ArgDef][consume] consume should set the appropriate value for the given arg name when encountered.");
 }
示例#4
0
 public void consumeTestLabeledDouble()
 {
     ArgDef testDef = new ArgDef();
     testDef.argLabels.Add("-t");
     testDef.type = typeof(double);
     testDef.argCount = 1;
     testDef.parseInit(ArgTypeParser.basicParsers);
     VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-t", "33.3" });
     ParsedArgs pArgs = new ParsedArgs();
     testDef.consume(vArgs, pArgs);
     Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given");
     Assert.AreEqual(33.3, pArgs.getValue<double>("t"), 0.01, "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given");
 }
示例#5
0
 public void consumeTestWrongNumberOfFollowingArgs()
 {
     ArgDef testDef = new ArgDef();
     testDef.argLabels.Add("-test");
     testDef.argCount = 2;
     testDef.parseInit(ArgTypeParser.basicParsers);
     VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-test", "a" }, 0, 2);
     ParsedArgs pArgs = new ParsedArgs();
     bool result = testDef.consume(vArgs, pArgs);
     bool errors = testDef.errorOccured();
     Assert.IsFalse(result, "[ArgDef][consume] consume should return false when there are less remaining args than argCount.");
     Assert.IsTrue(errors, "[ArgDef][consume] consume should generate an error message when there are less remaining args than argCount.");
 }
示例#6
0
 public void consumeTestRemainingString()
 {
     ArgDef testDef = new ArgDef();
     testDef.name = "t";
     testDef.argCountIsRemainderOfArgs = true;
     testDef.parseInit(ArgTypeParser.basicParsers);
     string[] testVals = new string[] { "what", "the", "french toast" };
     VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { testVals[0].ToString(), testVals[1].ToString(), testVals[2].ToString() });
     ParsedArgs pArgs = new ParsedArgs();
     testDef.consume(vArgs, pArgs);
     Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given");
     string[] result = pArgs.getArray<string>("t");
     int i = 0;
     foreach (string val in result)
     {
         Assert.AreEqual<string>(testVals[i], val, "[ArgDef][consume] consume resulted in an array with unexpected values.");
         i++;
     }
 }
示例#7
0
 public void consumeTestOrderedInt()
 {
     ArgDef testDef = new ArgDef();
     testDef.name = "test";
     testDef.type = typeof(int);
     testDef.parseInit(ArgTypeParser.basicParsers);
     VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "33" });
     ParsedArgs pArgs = new ParsedArgs();
     testDef.consume(vArgs, pArgs);
     Assert.IsTrue(pArgs.containsKey("test"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given");
     Assert.AreEqual<int>(33, pArgs.getValue<int>("test"), "[ArgDef][consume] consume should set the appropriate value for the given arg name when encountered.");
 }
示例#8
0
 public void consumeTestOrderedEncounteredWrongType()
 {
     ArgDef testDef = new ArgDef();
     testDef.name = "test";
     testDef.type = typeof(int);
     testDef.parseInit(ArgTypeParser.basicParsers);
     VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "a" }, 0, 1);
     ParsedArgs pArgs = new ParsedArgs();
     bool result = testDef.consume(vArgs, pArgs);
     bool errors = testDef.errorOccured();
     Assert.IsFalse(result, "[ArgDef][consume] consume should return false when the args provided don't match the arg def's type.");
     Assert.IsTrue(errors, "[ArgDef][consume] consume should generate an error when the args provided don't match the arg def's type.");
 }
示例#9
0
 public void consumeTestNoVArgs()
 {
     ArgDef testDef = new ArgDef();
     testDef.name = "test";
     testDef.parseInit(ArgTypeParser.basicParsers);
     VirtualArray<string> vArgs = new VirtualArray<string>(new string[]{}, 0, 0);
     ParsedArgs pArgs = new ParsedArgs();
     testDef.consume(vArgs, pArgs);
 }
示例#10
0
 public void consumeTestMultipleOptionEncounters()
 {
     ArgDef testDef = new ArgDef();
     testDef.argLabels.AddRange(new string[]{"-test", "-t"});
     testDef.parseInit(ArgTypeParser.basicParsers);
     VirtualArray<string> vArgs = new VirtualArray<string>(new string[] {"-test", "-t"}, 0, 2);
     ParsedArgs pArgs = new ParsedArgs();
     testDef.consume(vArgs, pArgs);
     bool result2 = testDef.consume(vArgs, pArgs);
     bool errors = testDef.errorOccured();
     Assert.IsFalse(result2, "[ArgDef][consume] consume should return false when a label is encountered twice.");
     Assert.IsTrue(errors, "[ArgDef][consume] consume should generate an error message when a label is encountered twice.");
 }
示例#11
0
 public void consumeTestListOfString()
 {
     ArgDef testDef = new ArgDef();
     testDef.argLabels.Add("-t");
     testDef.argCount = 5;
     testDef.parseInit(ArgTypeParser.basicParsers);
     string[] testVals = new string[] { "ok", "", "what ", "yeyeah", "turn down" };
     VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-t", testVals[0].ToString(), testVals[1].ToString(), testVals[2].ToString(), testVals[3].ToString(), testVals[4].ToString() });
     ParsedArgs pArgs = new ParsedArgs();
     testDef.consume(vArgs, pArgs);
     Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given");
     string[] result = pArgs.getArray<string>("t");
     int i = 0;
     foreach (string val in result)
     {
         Assert.AreEqual<string>(testVals[i], val, "[ArgDef][consume] consume resulted in an array with unexpected values.");
         i++;
     }
 }
示例#12
0
 public void consumeTestListOfDouble()
 {
     ArgDef testDef = new ArgDef();
     testDef.argLabels.Add("-t");
     testDef.type = typeof(double);
     testDef.argCount = 3;
     testDef.parseInit(ArgTypeParser.basicParsers);
     double[] testVals = new double[] { -234.556, 0, 234234.234 };
     VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-t", testVals[0].ToString(), testVals[1].ToString(), testVals[2].ToString() });
     ParsedArgs pArgs = new ParsedArgs();
     testDef.consume(vArgs, pArgs);
     Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given");
     double[] result = pArgs.getArray<double>("t");
     int i = 0;
     foreach (double val in result)
     {
         Assert.AreEqual<double>(testVals[i], val, "[ArgDef][consume] consume resulted in an array with unexpected values.");
         i++;
     }
 }