コード例 #1
0
        public void SpanOnCommentGroupShouldStartAfter()
        {
            // Arrange
            var comment = new CommentGroupNode("This is a comment.");
            var a       = new CharacterNode('a');
            var b       = new CharacterNode('b')
            {
                Prefix = comment
            };
            var concat = new ConcatenationNode(new List <RegexNode> {
                a, b
            });

            // Act
            var(commentStart, commentLength) = comment.GetSpan();
            var(aStart, aLength)             = a.GetSpan();
            var(bStart, bLength)             = b.GetSpan();
            var(concatStart, concatLength)   = concat.GetSpan();

            // Assert
            concatStart.ShouldBe(0);
            concatLength.ShouldBe(a.ToString().Length + b.ToString().Length);
            aStart.ShouldBe(0);
            aLength.ShouldBe(1);
            commentStart.ShouldBe(1);
            commentLength.ShouldBe(comment.ToString().Length);
            bStart.ShouldBe(commentStart + commentLength);
            bLength.ShouldBe(1);
        }
コード例 #2
0
        public void GetSpanShouldReturnTupleWithStart0AndLenght1()
        {
            // Arrange
            var target = new CharacterNode('a');

            // Act
            var(Start, Length) = target.GetSpan();

            // Assert
            Start.ShouldBe(0);
            Length.ShouldBe(1);
        }
コード例 #3
0
        public void ChildNodeShouldStartBeforeQuantifier()
        {
            // Arrange
            var target = new CharacterNode('a');

            _ = new QuantifierQuestionMarkNode(target);

            // Act
            var(Start, Length) = target.GetSpan();

            // Assert
            Start.ShouldBe(0);
            Length.ShouldBe(1);
        }
コード例 #4
0
        public void EndSpanShouldStartAfterStartAndDash()
        {
            // Arrange
            var start = new CharacterNode('a');
            var end   = new CharacterNode('z');

            _ = new CharacterClassRangeNode(start, end);

            // Act
            var(Start, Length) = end.GetSpan();

            // Assert
            Start.ShouldBe(2);
            Length.ShouldBe(1);
        }
コード例 #5
0
        public void StartSpanShouldStartBe0()
        {
            // Arrange
            var start = new CharacterNode('a');
            var end   = new CharacterNode('z');

            _ = new CharacterClassRangeNode(start, end);

            // Act
            var(Start, Length) = start.GetSpan();

            // Assert
            Start.ShouldBe(0);
            Length.ShouldBe(1);
        }
コード例 #6
0
        public void GetSpanShouldReturnTupleWithStartEqualToPrefixLengthAndLength1()
        {
            // Arrange
            var comment = new CommentGroupNode("X");
            var target  = new CharacterNode('a')
            {
                Prefix = comment
            };

            // Act
            var(Start, Length) = target.GetSpan();

            // Assert
            Start.ShouldBe(5);
            Length.ShouldBe(1);
        }
コード例 #7
0
        public void ChildNodeShouldStartBeforeQuantifiersPrefix()
        {
            // Arrange
            var target = new CharacterNode('a');
            var prefix = new CommentGroupNode("X");

            _ = new QuantifierQuestionMarkNode(target)
            {
                Prefix = prefix
            };

            // Act
            var(Start, Length) = target.GetSpan();

            // Assert
            Start.ShouldBe(0);
            Length.ShouldBe(1);
        }
コード例 #8
0
        public void FirstAlternateSpanShouldStartBe0()
        {
            // Arrange
            var firstChild  = new CharacterNode('a');
            var secondChild = new CharacterNode('b');
            var thirdChild  = new CharacterNode('c');
            var childNodes  = new List <RegexNode> {
                firstChild, secondChild, thirdChild
            };

            _ = new AlternationNode(childNodes);

            // Act
            var(Start, Length) = firstChild.GetSpan();

            // Assert
            Start.ShouldBe(0);
            Length.ShouldBe(1);
        }
コード例 #9
0
        public void NonFirstAlternateSpanShouldStartAfterPreviousAlternateAndPipe()
        {
            // Arrange
            var firstChild  = new CharacterNode('a');
            var secondChild = new CharacterNode('b');
            var thirdChild  = new CharacterNode('c');
            var childNodes  = new List <RegexNode> {
                firstChild, secondChild, thirdChild
            };

            _ = new AlternationNode(childNodes);

            // Act
            var(secondChildStart, secondChildLength) = secondChild.GetSpan();
            var(thirdChildStart, thirdChildLength)   = thirdChild.GetSpan();

            // Assert
            secondChildStart.ShouldBe(2);
            secondChildLength.ShouldBe(1);
            thirdChildStart.ShouldBe(4);
            thirdChildLength.ShouldBe(1);
        }