public void PatternMatchTest14()
 {
     // Typed parameter: int, optional and absent
      IOrderPattern cmdPat = new OrderPattern("order par1 [<int:number>] par2");
      Dictionary<string, object> parameters = null;
      bool shouldMatch = cmdPat.Match("order par1 par2", out parameters);
      Assert.IsTrue(shouldMatch);
      Assert.AreEqual(0, parameters.Count);
 }
 public void PatternMatchTest1()
 {
     IOrderPattern cmdPat = new OrderPattern("order par1 [par2] par3");
      Dictionary<string, object> parameters;
      // Match without optionals
      parameters = null;
      bool shouldMatch = cmdPat.Match("order par1 par3", out parameters);
      Assert.IsTrue(shouldMatch);
      Assert.AreEqual(0, parameters.Count);
 }
 public void PatternMatchTest13()
 {
     // Typed parameter: int, optional and present
      IOrderPattern cmdPat = new OrderPattern("order par1 [<int:number>] par2");
      Dictionary<string, object> parameters = null;
      bool shouldMatch = cmdPat.Match("order par1 5 par2", out parameters);
      Assert.IsTrue(shouldMatch);
      Assert.AreEqual(1, parameters.Count);
      Assert.IsTrue(parameters.ContainsKey("number"));
      Assert.AreEqual(5, parameters["number"]);
 }
 public void PatternMatchTest15()
 {
     // Typed parameter: string, non-optional, one word and non-quoted
      IOrderPattern cmdPat = new OrderPattern("order <string:bar>");
      Dictionary<string, object> parameters = null;
      bool shouldMatch = cmdPat.Match("order foo", out parameters);
      Assert.IsTrue(shouldMatch);
      Assert.AreEqual(1, parameters.Count);
      Assert.IsTrue(parameters.ContainsKey("bar"));
      Assert.AreEqual("foo", parameters["bar"]);
 }
 public void PatternMatchTest8()
 {
     // No match, too few parameters, optionals missing
      IOrderPattern cmdPat = new OrderPattern("order par1 [par2] par3");
      Dictionary<string, object> parameters = null;
      bool shouldNotMatch = cmdPat.Match("order2 par1", out parameters);
      Assert.IsFalse(shouldNotMatch);
      Assert.IsNull(parameters);
 }
 public void PatternMatchTest62()
 {
     // Typed parameter: string, two consequtive string types: <string> <string>
      //  should take first param as the first <string> and the rest as the second one
      IOrderPattern cmdPat = new OrderPattern("order [<string:foo>] <string:bar>");
      Dictionary<string, object> parameters = null;
      bool shouldMatch = cmdPat.Match("order foo", out parameters);
      Assert.IsTrue(shouldMatch);
      Assert.AreEqual(1, parameters.Count);
      Assert.IsTrue(parameters.ContainsKey("bar"));
      Assert.AreEqual("foo", parameters["bar"]);
 }
 public void PatternMatchTest60()
 {
     // Choice parameter: string, non-optional, three choices (wrong match)
      IOrderPattern cmdPat = new OrderPattern("order {foo|bar|foo2:par1}");
      Dictionary<string, object> parameters = null;
      bool shouldNotMatch = cmdPat.Match("order bar2", out parameters);
      Assert.IsFalse(shouldNotMatch);
      Assert.IsNull(parameters);
 }
 public void PatternMatchTest59()
 {
     // Choice parameter: string, non-optional, three choices
      IOrderPattern cmdPat = new OrderPattern("order {foo|bar|foo2:par1}");
      Dictionary<string, object> parameters = null;
      bool shouldMatch = cmdPat.Match("order foo2", out parameters);
      Assert.IsTrue(shouldMatch);
      Assert.AreEqual(1, parameters.Count);
      Assert.IsTrue(parameters.ContainsKey("par1"));
      Assert.AreEqual("foo2", parameters["par1"]);
 }
 public void PatternMatchTest52()
 {
     // Choice parameter: string, non-optional, one choice
      IOrderPattern cmdPat = new OrderPattern("order {foo:bar}");
      Dictionary<string, object> parameters = null;
      bool shouldMatch = cmdPat.Match("order foo", out parameters);
      Assert.IsTrue(shouldMatch);
      Assert.AreEqual(1, parameters.Count);
      Assert.IsTrue(parameters.ContainsKey("bar"));
      Assert.AreEqual("foo", parameters["bar"]);
 }
示例#10
0
 public void PatternMatchTest51()
 {
     // Typed parameter: string, non-optional, two words and quoted, preceeded by an int
      IOrderPattern cmdPat = new OrderPattern("order [<int:foo>] <string:bar>");
      Dictionary<string, object> parameters = null;
      bool shouldMatch = cmdPat.Match("order 7 \"foo bar\"", out parameters);
      Assert.IsTrue(shouldMatch);
      Assert.AreEqual(2, parameters.Count);
      Assert.IsTrue(parameters.ContainsKey("foo"));
      Assert.AreEqual(7, parameters["foo"]);
      Assert.IsTrue(parameters.ContainsKey("bar"));
      Assert.AreEqual("foo bar", parameters["bar"]);
 }
示例#11
0
 public void PatternMatchTest42()
 {
     // Typed parameter: string, complex: <string> par1 par2 <string>
      IOrderPattern cmdPat = new OrderPattern("order <string:foo> par1 par2 <string:bar>");
      Dictionary<string, object> parameters = null;
      bool shouldMatch = cmdPat.Match("order foo1 bar1 par1 par2 foo2 bar2", out parameters);
      Assert.IsTrue(shouldMatch);
      Assert.AreEqual(2, parameters.Count);
      Assert.IsTrue(parameters.ContainsKey("foo"));
      Assert.AreEqual("foo1 bar1", parameters["foo"]);
      Assert.IsTrue(parameters.ContainsKey("bar"));
      Assert.AreEqual("foo2 bar2", parameters["bar"]);
 }
示例#12
0
 public void PatternMatchTest40()
 {
     // Typed parameter: string, several consequtive string types: <string> <string> <string>
      //  should take first param as the first <string> and second as the second one, etc, until it gets to the last <string>
      //  which should take the rest of the params
      IOrderPattern cmdPat = new OrderPattern("order <string:foo> <string:bar> <string:fubar>");
      Dictionary<string, object> parameters = null;
      bool shouldMatch = cmdPat.Match("order par1 par2 foo bar", out parameters);
      Assert.IsTrue(shouldMatch);
      Assert.AreEqual(3, parameters.Count);
      Assert.IsTrue(parameters.ContainsKey("foo"));
      Assert.AreEqual("par1", parameters["foo"]);
      Assert.IsTrue(parameters.ContainsKey("bar"));
      Assert.AreEqual("par2", parameters["bar"]);
      Assert.IsTrue(parameters.ContainsKey("fubar"));
      Assert.AreEqual("foo bar", parameters["fubar"]);
 }
示例#13
0
 public void PatternMatchTest4()
 {
     // No match, wrong order
      IOrderPattern cmdPat = new OrderPattern("order par1 [par2] par3");
      Dictionary<string, object> parameters = null;
      bool shouldNotMatch = cmdPat.Match("order2 par1 par2 par3", out parameters);
      Assert.IsFalse(shouldNotMatch);
      Assert.IsNull(parameters);
 }
示例#14
0
 public void PatternMatchTest38()
 {
     // Typed parameter: string, non-optional, two words and quoted, followed by 1 optional parameter
      IOrderPattern cmdPat = new OrderPattern("order <string:bar> [par1]");
      Dictionary<string, object> parameters = null;
      bool shouldMatch = cmdPat.Match("order \"foo bar\"", out parameters);
      Assert.IsTrue(shouldMatch);
      Assert.AreEqual(1, parameters.Count);
      Assert.IsTrue(parameters.ContainsKey("bar"));
      Assert.AreEqual("foo bar", parameters["bar"]);
 }
示例#15
0
 public void PatternMatchTest21()
 {
     // Typed parameter: string, non-optional, two words and non-quoted, preceeded by 1 parameter
      IOrderPattern cmdPat = new OrderPattern("order par1 <string:bar>");
      Dictionary<string, object> parameters = null;
      bool shouldMatch = cmdPat.Match("order par1 foo bar", out parameters);
      Assert.IsTrue(shouldMatch);
      Assert.AreEqual(1, parameters.Count);
      Assert.IsTrue(parameters.ContainsKey("bar"));
      Assert.AreEqual("foo bar", parameters["bar"]);
 }
示例#16
0
 public void PatternMatchTest2()
 {
     // Perfect match, including optionals
      IOrderPattern cmdPat = new OrderPattern("order par1 [par2] par3");
      Dictionary<string, object> parameters = null;
      bool shouldMatch = cmdPat.Match("order par1 par2 par3", out parameters);
      Assert.IsTrue(shouldMatch);
      Assert.AreEqual(0, parameters.Count);
 }