コード例 #1
0
 public void ConsecutiveArgs()
 {
   Assert.IsNotNull(new PathMatcher("{a}"));
   Assert.IsNotNull(new PathMatcher("{b}"));
   Assert.IsNotNull(new PathMatcher("{a} {b}"));
   var p = new PathMatcher("{a}{b}");
 }
コード例 #2
0
 public void AllLiteral()
 {
   var p1 = new PathMatcher("x");
   Assert.AreEqual(0, p1.ArgumentCount);
   Assert.IsTrue(p1.Match("x").Success);
   Assert.AreEqual(0, p1.Match("x").Parameters.Length);
   Assert.IsFalse(p1.Match("X").Success);
 }
コード例 #3
0
    private void SetHandledBy(Delegate handler, int argCount, HandlerContextParam contextParam)
    {
      if (handler == null)
        throw new ArgumentException("Handler cannot be null");

      _handler = handler;
      _contextParam = contextParam;

      _pathMatcher = new PathMatcher(Path);
      if (_pathMatcher.ArgumentCount != argCount)
        throw new ArgumentException("Mismatch arg count: handler expect " + argCount + " but found " + _pathMatcher.ArgumentCount + " in path " + Path);

      if (argCount > MaxArgCount)
        throw new ArgumentException("Max " + MaxArgCount + " allowed, not " + argCount);
      ArgNames = _pathMatcher.ArgumentNames;
    }
コード例 #4
0
 public void InvalidArgNameCharacters()
 {
   var p = new PathMatcher("{.}");
 }
コード例 #5
0
 public void EmptyArgName()
 {
   var p = new PathMatcher("{}");
 }
コード例 #6
0
 public void MissingClosingArgBrace2()
 {
   var p = new PathMatcher("{x}y{z");
 }
コード例 #7
0
 public void MissingClosingArgBrace()
 {
   var p = new PathMatcher("{");
 }
コード例 #8
0
 public void EmptyPath()
 {
   var p = new PathMatcher("");
 }
コード例 #9
0
 private void VerifyMatchNo(string expr, string path)
 {
   var what = string.Format("Match {0} with {1}", expr, path);
   var p = new PathMatcher(expr);
   var match = p.Match(path);
   Assert.IsFalse(match.Success, what);
 }
コード例 #10
0
    //[TestMethod()]
    //public void ValidManyMatches()
    //{
    //  string literal = "abcdefg";
    //  for (int parts = 1; parts < 5; parts++)
    //  {
    //    for (int prefixLength = 0; prefixLength < 3; prefixLength++)
    //    {
    //      for (int postfixLength = 0; postfixLength < 3; postfixLength++)
    //      {
    //        StringBuilder sb = new StringBuilder();
    //        for (int i = 0; i < parts; i++)
    //        {
    //          var prefix = literal.Substring(0, prefixLength);
    //          var postfix = literal.Substring(0, postfixLength);
    //          var name = literal.Substring(i, 1);
    //          if (sb.Length > 0 && sb[sb.Length - 1] == '}')
    //            sb.Append("x");
    //          sb.AppendFormat("{0}{{{1}}}{2}", prefix, name, postfix);
    //        }
    //        var expr = sb.ToString();
            
    //      }
    //    }
    //  }
    //}

    private void VerifyMatchDo(string expr, string path, params string[] expect)
    {
      var what = string.Format("Match {0} with {1}", expr, path);
      var p = new PathMatcher(expr);
      Assert.AreEqual(expect.Length, p.ArgumentCount, what);
      var match = p.Match(path);
      Assert.IsTrue(match.Success, what);
      Assert.AreEqual(expect.Length, match.Parameters.Length, what);
      //Assert.IsTrue(expect.SequenceEqual(match.Parameters), what);
    }