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}"); }
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); }
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; }
public void InvalidArgNameCharacters() { var p = new PathMatcher("{.}"); }
public void EmptyArgName() { var p = new PathMatcher("{}"); }
public void MissingClosingArgBrace2() { var p = new PathMatcher("{x}y{z"); }
public void MissingClosingArgBrace() { var p = new PathMatcher("{"); }
public void EmptyPath() { var p = new PathMatcher(""); }
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); }
//[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); }