public void ShouldRemoveQuantifierQuestionMark()
        {
            // Arrange
            var quantifierNode = new QuantifierQuestionMarkNode(new CharacterNode('X'));
            var childNodes     = new List <RegexNode>
            {
                new CharacterNode('a'),
                new CharacterNode('b'),
                new CharacterNode('c'),
                quantifierNode
            };
            var rootNode = new ConcatenationNode(childNodes);
            var target   = new QuantifierRemovalMutator();

            // Act
            var result = target.ApplyMutations(quantifierNode, rootNode);

            // Assert
            var mutation = result.ShouldHaveSingleItem();

            mutation.OriginalNode.ShouldBe(quantifierNode);
            mutation.ReplacementNode.ToString().ShouldBe("X");
            mutation.ReplacementPattern.ShouldBe("abcX");
            mutation.DisplayName.ShouldBe("Regex quantifier removal mutation");
            mutation.Description.ShouldBe("Quantifier \"?\" was removed at offset 4.");
        }
Esempio n. 2
0
        public void ToStringShouldReturnQuantifierQuestionMarkOnChildNodeToString()
        {
            // Arrange
            var characterNode = new CharacterNode('a');
            var target        = new QuantifierQuestionMarkNode(characterNode);

            // Act
            var result = target.ToString();

            // Assert
            result.ShouldBe("a?");
        }
Esempio n. 3
0
        public void SpanShouldStartAfterChildNodes()
        {
            // Arrange
            var childNode = new CharacterNode('a');
            var target    = new QuantifierQuestionMarkNode(childNode);

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

            // Assert
            Start.ShouldBe(childNode.ToString().Length);
            Length.ShouldBe(1);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public void ToStringOnQuantifierWithPrefixShouldReturnPrefixBeforeOriginalQuantifierAndAfterQuantifiersChildNode()
        {
            // Arrange
            var comment       = new CommentGroupNode("This is a comment.");
            var characterNode = new CharacterNode('a');
            var target        = new QuantifierQuestionMarkNode(characterNode)
            {
                Prefix = comment
            };

            // Act
            var result = target.ToString();

            // Assert
            result.ShouldBe("a(?#This is a comment.)?");
        }
Esempio n. 6
0
        public void SpanShouldStartAfterPrefix()
        {
            // Arrange
            var childNode = new CharacterNode('a');
            var prefix    = new CommentGroupNode("X");
            var target    = new QuantifierQuestionMarkNode(childNode)
            {
                Prefix = prefix
            };

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

            // Assert
            Start.ShouldBe(6);
            Length.ShouldBe(1);
        }
Esempio n. 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);
        }