Beispiel #1
0
        private RegexMutation QuantifierRemoval(QuantifierNode node, RegexNode root)
        {
            var       replacementNode = node.ChildNodes.FirstOrDefault();
            var       span            = node.GetSpan();
            int       length;
            RegexNode target;

            if (node.Parent is LazyNode)
            {
                target = node.Parent;
                length = span.Length + 1;
            }
            else
            {
                target = node;
                length = span.Length;
            }

            return(new RegexMutation
            {
                OriginalNode = target,
                ReplacementNode = replacementNode,
                DisplayName = "Regex quantifier removal mutation",
                Description = $"Quantifier \"{root.ToString().Substring(span.Start, length)}\" was removed at offset {span.Start}.",
                ReplacementPattern = root.ReplaceNode(target, replacementNode).ToString()
            });
        }
        private RegexMutation AnchorRemoval(AnchorNode node, RegexNode root)
        {
            var span = node.GetSpan();

            return(new RegexMutation
            {
                OriginalNode = node,
                DisplayName = "Regex anchor removal mutation",
                Description = $"Anchor \"{root.ToString().Substring(span.Start, span.Length)}\" was removed at offset {span.Start}.",
                ReplacementPattern = root.RemoveNode(node).ToString()
            });
        }
Beispiel #3
0
        public string Dump()
        {
            var sb = new StringBuilder();

            RegexNode node = this;

            for (var i = 0; node != null; i++)
            {
                node = FindNodeById(i);
                if (node != null)
                {
                    sb.AppendLine(node.ToString());
                }
            }

            return(sb.ToString());
        }