mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-19 00:27:04 +01:00
* Fix some nullability warnings for WireMockOpenApiParser * . * . * . * opt * FromText * ab * . * private const string AdminOpenApi = "/__admin/openapi"; * fix test * rnd * . * urldetails * 0 * , * . * tests * . * CompressionUtilsTests * ut * .
59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Text.RegularExpressions;
|
|
using FluentAssertions;
|
|
using WireMock.Util;
|
|
using Xunit;
|
|
|
|
namespace WireMock.Net.Tests.Util;
|
|
|
|
public class RegexUtilsTests
|
|
{
|
|
[Fact]
|
|
public void GetNamedGroups_ValidRegexWithNamedGroups_ReturnsNamedGroupsDictionary()
|
|
{
|
|
// Arrange
|
|
var pattern = @"^(?<street>\w+)\s(?<number>\d+)$";
|
|
var input = "MainStreet 123";
|
|
var regex = new Regex(pattern);
|
|
|
|
// Act
|
|
var namedGroupsDictionary = RegexUtils.GetNamedGroups(regex, input);
|
|
|
|
// Assert
|
|
namedGroupsDictionary.Should().NotBeEmpty()
|
|
.And.Contain(new KeyValuePair<string, string>("street", "MainStreet"))
|
|
.And.Contain(new KeyValuePair<string, string>("number", "123"));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("", "test", false, false)]
|
|
[InlineData(null, "test", false, false)]
|
|
[InlineData(".*", "test", true, true)]
|
|
[InlineData("invalid[", "test", false, false)]
|
|
public void MatchRegex_WithVariousPatterns_ReturnsExpectedResults(
|
|
string? pattern, string input, bool expectedIsValid, bool expectedResult)
|
|
{
|
|
// Act
|
|
var (isValidResult, matchResult) = RegexUtils.MatchRegex(pattern, input);
|
|
|
|
// Assert
|
|
isValidResult.Should().Be(expectedIsValid);
|
|
matchResult.Should().Be(expectedResult);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("", "test", false, false)]
|
|
[InlineData(null, "test", false, false)]
|
|
[InlineData(".*", "test", true, true)]
|
|
[InlineData("invalid[", "test", false, false)]
|
|
public void MatchRegex_WithVariousPatternsAndExtendedRegex_ReturnsExpectedResults(
|
|
string? pattern, string input, bool expectedIsValid, bool expectedResult)
|
|
{
|
|
// Act
|
|
var (isValidResult, matchResult) = RegexUtils.MatchRegex(pattern, input, useRegexExtended: true);
|
|
|
|
// Assert
|
|
isValidResult.Should().Be(expectedIsValid);
|
|
matchResult.Should().Be(expectedResult);
|
|
}
|
|
} |