Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Sentry/StringOrRegex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public class StringOrRegex
internal readonly Regex? _regex;
internal readonly string? _string;

/// <summary>
/// Whether this instance contains a regular expression.
/// </summary>
public bool IsRegex => _regex is Regex;

/// <summary>
/// Constructs a <see cref="StringOrRegex"/> instance.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,7 @@ namespace Sentry
{
public StringOrRegex(System.Text.RegularExpressions.Regex regex) { }
public StringOrRegex(string stringOrRegex) { }
public bool IsRegex { get; }
public override bool Equals(object? obj) { }
public override int GetHashCode() { }
public override string ToString() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,7 @@ namespace Sentry
{
public StringOrRegex(System.Text.RegularExpressions.Regex regex) { }
public StringOrRegex(string stringOrRegex) { }
public bool IsRegex { get; }
public override bool Equals(object? obj) { }
public override int GetHashCode() { }
public override string ToString() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,7 @@ namespace Sentry
{
public StringOrRegex(System.Text.RegularExpressions.Regex regex) { }
public StringOrRegex(string stringOrRegex) { }
public bool IsRegex { get; }
public override bool Equals(object? obj) { }
public override int GetHashCode() { }
public override string ToString() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,7 @@ namespace Sentry
{
public StringOrRegex(System.Text.RegularExpressions.Regex regex) { }
public StringOrRegex(string stringOrRegex) { }
public bool IsRegex { get; }
public override bool Equals(object? obj) { }
public override int GetHashCode() { }
public override string ToString() { }
Expand Down Expand Up @@ -2065,4 +2066,4 @@ public static class SentryExceptionExtensions
public static void AddSentryContext(this System.Exception ex, string name, System.Collections.Generic.IReadOnlyDictionary<string, object> data) { }
public static void AddSentryTag(this System.Exception ex, string name, string value) { }
public static void SetSentryMechanism(this System.Exception ex, string type, string? description = null, bool? handled = default, bool? terminal = default) { }
}
}
28 changes: 26 additions & 2 deletions test/Sentry.Tests/StringOrRegexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,41 @@ namespace Sentry.Tests;
public class StringOrRegexTests
{
[Fact]
public void StringOrRegex_ImplicitlyConvertsFromString()
public void Constructor_String_IsRegexFalse()
{
var target = new StringOrRegex("abc");
target.IsRegex.Should().BeFalse();
}

[Fact]
public void Constructor_Regex_IsRegexTrue()
{
var target = new StringOrRegex(new Regex("^abc.*ghi$"));
target.IsRegex.Should().BeTrue();
}

[Fact]
public void Constructor_NullRegex_IsRegexFalse()
{
var target = new StringOrRegex((Regex)null!);
target.IsRegex.Should().BeFalse();
target.ToString().Should().BeEmpty();
}

[Fact]
public void ImplicitConversion_String_PreservesValueAndType()
{
StringOrRegex target = "abc";
target.IsRegex.Should().BeFalse();
target._string.Should().Be("abc");
target._regex.Should().BeNull();
}

[Fact]
public void StringOrRegex_ImplicitlyConvertsFromRegex()
public void ImplicitConversion_Regex_PreservesValueAndType()
{
StringOrRegex target = new Regex("^abc.*ghi$");
target.IsRegex.Should().BeTrue();
target._string.Should().BeNull();
target._regex.Should().NotBeNull();
target._regex?.ToString().Should().Be("^abc.*ghi$");
Expand Down
Loading