-
-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solves issue #5
- Loading branch information
Showing
8 changed files
with
214 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace WireMock.Matchers | ||
{ | ||
/// <summary> | ||
/// IMatcher | ||
/// </summary> | ||
public interface IMatcher | ||
{ | ||
/// <summary> | ||
/// Determines whether the specified input is match. | ||
/// </summary> | ||
/// <param name="input">The input.</param> | ||
/// <returns> | ||
/// <c>true</c> if the specified input is match; otherwise, <c>false</c>. | ||
/// </returns> | ||
bool IsMatch(string input); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Text.RegularExpressions; | ||
using JetBrains.Annotations; | ||
using WireMock.Validation; | ||
|
||
namespace WireMock.Matchers | ||
{ | ||
/// <summary> | ||
/// Regular Expression Matcher | ||
/// </summary> | ||
/// <seealso cref="WireMock.Matchers.IMatcher" /> | ||
public class RegexMatcher : IMatcher | ||
{ | ||
private readonly Regex _expression; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RegexMatcher"/> class. | ||
/// </summary> | ||
/// <param name="pattern">The pattern.</param> | ||
public RegexMatcher([NotNull] string pattern) | ||
{ | ||
Check.NotNull(pattern, nameof(pattern)); | ||
|
||
_expression = new Regex(pattern, RegexOptions.Compiled); | ||
} | ||
|
||
/// <summary> | ||
/// Determines whether the specified input is match. | ||
/// </summary> | ||
/// <param name="input">The input.</param> | ||
/// <returns> | ||
/// <c>true</c> if the specified input is match; otherwise, <c>false</c>. | ||
/// </returns> | ||
public bool IsMatch(string input) | ||
{ | ||
return input != null && _expression.IsMatch(input); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Xml; | ||
using JetBrains.Annotations; | ||
using WireMock.Validation; | ||
using Wmhelp.XPath2; | ||
|
||
namespace WireMock.Matchers | ||
{ | ||
/// <summary> | ||
/// XPath2Matcher | ||
/// </summary> | ||
/// <seealso cref="WireMock.Matchers.IMatcher" /> | ||
public class XPathMatcher : IMatcher | ||
{ | ||
private readonly string _pattern; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="XPathMatcher"/> class. | ||
/// </summary> | ||
/// <param name="pattern">The pattern.</param> | ||
public XPathMatcher([NotNull] string pattern) | ||
{ | ||
Check.NotNull(pattern, nameof(pattern)); | ||
|
||
_pattern = pattern; | ||
} | ||
|
||
/// <summary> | ||
/// Determines whether the specified input is match. | ||
/// </summary> | ||
/// <param name="input">The input.</param> | ||
/// <returns> | ||
/// <c>true</c> if the specified input is match; otherwise, <c>false</c>. | ||
/// </returns> | ||
public bool IsMatch(string input) | ||
{ | ||
var nav = new XmlDocument { InnerXml = input }.CreateNavigator(); | ||
object result = nav.XPath2Evaluate($"boolean({_pattern})"); | ||
|
||
return true.Equals(result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters