public void GetDescendantsShouldReturnAllDescendants() { // Arrange // a+bc* var charNodeA = new CharacterNode('a'); var charNodeB = new CharacterNode('b'); var charNodeC = new CharacterNode('c'); var quantifierPlus = new QuantifierPlusNode(charNodeA); var quantifierStar = new QuantifierStarNode(charNodeC); var grandchildren = new List <RegexNode> { quantifierPlus, charNodeB, quantifierStar }; var concatenationNode = new ConcatenationNode(grandchildren); var target = new TestRegexNode(concatenationNode); // Act IEnumerable <RegexNode> result = target.GetDescendantNodes(); // Assert result.Count().ShouldBe(6); result.First().ShouldBe(charNodeA); result.ElementAt(1).ShouldBe(quantifierPlus); result.ElementAt(2).ShouldBe(charNodeB); result.ElementAt(3).ShouldBe(charNodeC); result.ElementAt(4).ShouldBe(quantifierStar); result.Last().ShouldBe(concatenationNode); }
public void ToStringShouldAppendQuestionMarkToChildToString() { // Arrange var characterNode = new CharacterNode('a'); var quantifierNode = new QuantifierStarNode(characterNode); var target = new LazyNode(quantifierNode); // Act var result = target.ToString(); // Assert result.ShouldBe("a*?"); }
public void SpanShouldStartAfterQuantifier() { // Arrange var childNode = new CharacterNode('a'); var quantifier = new QuantifierStarNode(childNode); var target = new LazyNode(quantifier); // Act var(Start, Length) = target.GetSpan(); // Assert Start.ShouldBe(2); Length.ShouldBe(1); }
public void QuantifierShouldStartBeforeLazyToken() { // Arrange var childNode = new CharacterNode('a'); var target = new QuantifierStarNode(childNode); _ = new LazyNode(target); // Act var(Start, Length) = target.GetSpan(); // Assert Start.ShouldBe(1); Length.ShouldBe(1); }
public void ToStringOnLazyNodeWithPrefixShouldReturnPrefixBeforeLazyNodeAndAfterQuantifier() { // Arrange var comment = new CommentGroupNode("This is a comment."); var characterNode = new CharacterNode('a'); var quantifierNode = new QuantifierStarNode(characterNode); var target = new LazyNode(quantifierNode) { Prefix = comment }; // Act var result = target.ToString(); // Assert result.ShouldBe("a*(?#This is a comment.)?"); }