public void ConsumeTest() { var eater = new PathIterator("foo/bar/baz"); Assert.AreEqual("foo", eater.Next()); Assert.IsFalse(eater.IsAtEnd); Assert.AreEqual("bar", eater.Next()); Assert.AreEqual("baz", eater.Next()); Assert.IsTrue(eater.IsAtEnd); }
/// <summary> /// Given a path, attempts to match the next part of it to the current segment. /// </summary> /// <param name="route">The route.</param> /// <param name="path">The path.</param> /// <returns> /// An object that indicates whether the path was successfully matched. /// </returns> public override SegmentPathMatch MatchPath(IRoute route, PathIterator path) { var next = path.Next(); return String.Equals(next, literal, StringComparison.InvariantCultureIgnoreCase) ? SegmentPathMatch.Successful() : SegmentPathMatch.Failure(string.Format("Expected segment '{0}'; got '{1}'", literal, next)); }
/// <summary> /// Given a path, attempts to match the next part of it to the current segment. /// </summary> /// <param name="route">The route.</param> /// <param name="path">The path.</param> /// <returns> /// An object that indicates whether the path was successfully matched. /// </returns> public override SegmentPathMatch MatchPath(IRoute route, PathIterator path) { var values = new RouteValueDictionary(); var next = path.Next(); if (next.Length == 0) { if (defaultValue != UrlParameter.NotSpecified) { values[parameterName] = defaultValue; } else { return SegmentPathMatch.Failure(string.Format("The path does not contain a segment for parameter '{0}'", parameterName)); } } else { values[parameterName] = next; if (constraint != null && !constraint.IsValid(route, next, parameterName)) { return SegmentPathMatch.Failure(string.Format("Segment '{0}' did not match the constraint on parameter '{1}'", next, parameterName)); } } return SegmentPathMatch.Successful(values); }
/// <summary> /// Given a path, attempts to match the next part of it to the current segment. /// </summary> /// <param name="route">The route.</param> /// <param name="path">The path.</param> /// <returns> /// An object that indicates whether the path was successfully matched. /// </returns> public override SegmentPathMatch MatchPath(IRoute route, PathIterator path) { var values = new RouteValueDictionary(); var next = path.Next(); if (next.Length == 0) { if (defaultValue != UrlParameter.NotSpecified) { values[parameterName] = defaultValue; } else { return(SegmentPathMatch.Failure(string.Format("The path does not contain a segment for parameter '{0}'", parameterName))); } } else { values[parameterName] = next; if (constraint != null && !constraint.IsValid(route, next, parameterName)) { return(SegmentPathMatch.Failure(string.Format("Segment '{0}' did not match the constraint on parameter '{1}'", next, parameterName))); } } return(SegmentPathMatch.Successful(values)); }
/// <summary> /// Given a path, attempts to match the next part of it to the current segment. /// </summary> /// <param name="route">The route.</param> /// <param name="path">The path.</param> /// <returns> /// An object that indicates whether the path was successfully matched. /// </returns> public override SegmentPathMatch MatchPath(IRoute route, PathIterator path) { var next = path.Next(); return(String.Equals(next, literal, StringComparison.InvariantCultureIgnoreCase) ? SegmentPathMatch.Successful() : SegmentPathMatch.Failure(string.Format("Expected segment '{0}'; got '{1}'", literal, next))); }
public void ConsumeEmptyTest() { var eater = new PathIterator(""); Assert.AreEqual("", eater.Next()); Assert.IsTrue(eater.IsAtEnd); }