Beispiel #1
0
        public void ShouldRemoveContiguousMatchNode()
        {
            // Arrange
            var contiguousMatchNode = new ContiguousMatchNode();
            var childNodes          = new List <RegexNode>
            {
                contiguousMatchNode,
                new CharacterNode('a'),
                new CharacterNode('b'),
                new CharacterNode('c')
            };
            var rootNode = new ConcatenationNode(childNodes);
            var target   = new AnchorRemovalMutator();

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

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

            mutation.OriginalNode.ShouldBe(contiguousMatchNode);
            mutation.ReplacementNode.ShouldBeNull();
            mutation.ReplacementPattern.ShouldBe("abc");
            mutation.DisplayName.ShouldBe("Regex anchor removal mutation");
            mutation.Description.ShouldBe("Anchor \"\\G\" was removed at offset 0.");
        }
        public void ToStringShouldReturnBackslashUppercaseG()
        {
            // Arrange
            var target = new ContiguousMatchNode();

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

            // Assert
            result.ShouldBe(@"\G");
        }
        public void ToStringOnContiguousMatchNodeWithPrefixShouldReturnCommentBeforeBackslashUppercaseG()
        {
            // Arrange
            var comment = new CommentGroupNode("This is a comment.");
            var target  = new ContiguousMatchNode()
            {
                Prefix = comment
            };

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

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

            Start.ShouldBe(22);
            Length.ShouldBe(2);

            // Assert
            result.ShouldBe(@"(?#This is a comment.)\G");
        }