Summary

Class:WireMock.Matchers.RegexMatcher
Assembly:WireMock.Net
File(s):C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Matchers\RegexMatcher.cs
Covered lines:17
Uncovered lines:10
Coverable lines:27
Total lines:85
Line coverage:62.9%
Branch coverage:75%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)10100100
.ctor(...)22100100
IsMatch(...)2255.5666.67
GetPatterns()1000
GetName()1000

File(s)

C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Matchers\RegexMatcher.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using System.Text.RegularExpressions;
 4using JetBrains.Annotations;
 5using WireMock.Validation;
 6
 7namespace WireMock.Matchers
 8{
 9    /// <summary>
 10    /// Regular Expression Matcher
 11    /// </summary>
 12    /// <seealso cref="IMatcher" />
 13    public class RegexMatcher : IMatcher
 14    {
 15        private readonly string[] _patterns;
 16        private readonly Regex[] _expressions;
 17
 18        /// <summary>
 19        /// Initializes a new instance of the <see cref="RegexMatcher"/> class.
 20        /// </summary>
 21        /// <param name="pattern">The pattern.</param>
 22        /// <param name="ignoreCase">IgnoreCase</param>
 3923        public RegexMatcher([NotNull, RegexPattern] string pattern, bool ignoreCase = false) : this(new [] { pattern }, 
 3924        {
 3925        }
 26
 27        /// <summary>
 28        /// Initializes a new instance of the <see cref="RegexMatcher"/> class.
 29        /// </summary>
 30        /// <param name="patterns">The patterns.</param>
 31        /// <param name="ignoreCase">IgnoreCase</param>
 9832        public RegexMatcher([NotNull, RegexPattern] string[] patterns, bool ignoreCase = false)
 9833        {
 9834            Check.NotNull(patterns, nameof(patterns));
 35
 9836            _patterns = patterns;
 37
 9838            RegexOptions options = RegexOptions.Compiled;
 9839             if (ignoreCase)
 440                options |= RegexOptions.IgnoreCase;
 41
 19642            _expressions = patterns.Select(p => new Regex(p, options)).ToArray();
 9843        }
 44
 45        /// <summary>
 46        /// Determines whether the specified input is match.
 47        /// </summary>
 48        /// <param name="input">The input string</param>
 49        /// <returns>A value between 0.0 - 1.0 of the similarity.</returns>
 50        public double IsMatch(string input)
 6051        {
 6052             if (input == null)
 053                return MatchScores.Mismatch;
 54
 55            try
 6056            {
 12057                return MatchScores.ToScore(_expressions.Select(e => e.IsMatch(input)));
 58            }
 059            catch (Exception)
 060            {
 061                return MatchScores.Mismatch;
 62            }
 6063        }
 64
 65        /// <summary>
 66        /// Gets the patterns.
 67        /// </summary>
 68        /// <returns>Pattern</returns>
 69        public virtual string[] GetPatterns()
 070        {
 071            return _patterns;
 072        }
 73
 74        /// <summary>
 75        /// Gets the name.
 76        /// </summary>
 77        /// <returns>
 78        /// Name
 79        /// </returns>
 80        public virtual string GetName()
 081        {
 082            return "RegexMatcher";
 083        }
 84    }
 85}