mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-14 22:33:35 +01:00
* Add TIOBE + include SonarAnalyzer.CSharp * . * cp * Copyright © WireMock.Net * more fixes * fix * xpath * if (Matchers == null || !Matchers.Any()) * if (Matchers != null) * ? * . * .
59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
// Copyright © WireMock.Net
|
|
|
|
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);
|
|
}
|
|
} |