DimonSmart.RegexUnitTester.Attributes 1.24605.2215

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package DimonSmart.RegexUnitTester.Attributes --version 1.24605.2215                
NuGet\Install-Package DimonSmart.RegexUnitTester.Attributes -Version 1.24605.2215                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DimonSmart.RegexUnitTester.Attributes" Version="1.24605.2215" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DimonSmart.RegexUnitTester.Attributes --version 1.24605.2215                
#r "nuget: DimonSmart.RegexUnitTester.Attributes, 1.24605.2215"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DimonSmart.RegexUnitTester.Attributes as a Cake Addin
#addin nuget:?package=DimonSmart.RegexUnitTester.Attributes&version=1.24605.2215

// Install DimonSmart.RegexUnitTester.Attributes as a Cake Tool
#tool nuget:?package=DimonSmart.RegexUnitTester.Attributes&version=1.24605.2215                

DimonSmart.RegexUnitTester.Attributes

Overview

The DimonSmart.RegexUnitTester.Attributes NuGet package enhances regex testing by using custom attributes to specify test cases and document regex behaviors, improving code readability and facilitating automated testing via the DimonSmart.RegexUnitTester.TestAdapter.

Features

  • ShouldMatchAttribute: Asserts that a regex should match the provided test data.
  • ShouldNotMatchAttribute: Asserts that a regex should not match the provided test data, useful for patterns intended to exclude certain formats.
  • InfoMatchAttribute: Captures cases that fall into a gray area, neither strictly matching nor non-matching, for logging and informational purposes without triggering errors.

Installation

To install DimonSmart.RegexUnitTester.Attributes, run:

Install-Package DimonSmart.RegexUnitTester.Attributes

Comparison Example

Traditional Comments

// Regex "10001" matches, "ABCDE" does not match, "123 45" is logged.
public const string USZipCodeRegex = @"^\d{5}$";

Attribute Usage

[ShouldMatch("10001"), ShouldNotMatch("ABCDE"), InfoMatch("123 45")]
public const string USZipCodeRegex = @"^\d{5}$";

Detailed Attribute Usage Example

using System.Text.RegularExpressions;
using DimonSmart.RegexUnitTester.Attributes;

namespace PostalCodeValidation
{
    public class PostalCodeRegexTests
    {
        [ShouldMatch("10001"), ShouldNotMatch("ABCDE"), InfoMatch("123 45")]
        public const string USZipCodeRegex = @"^\d{5}$";

        [ShouldMatch("A1A 1A1"), ShouldNotMatch("12345"), InfoMatch("A1A-1A1")]
        public const string CanadaPostalCodeRegex = @"^[A-Z]\d[A-Z] \d[A-Z]\d$";
    }
}

Key Scenarios

  • ShouldMatch: "10001" correctly matches the US postal code format.
  • ShouldNotMatch: "ABCDE" fails to match as it's not a valid postal code format.
  • InfoMatch: "123 45" represents a borderline case which is logged for potential reevaluation but does not trigger a test failure.

Integration with DimonSmart.RegexUnitTester.TestAdapter

For automated testing, pair this package with DimonSmart.RegexUnitTester.TestAdapter:

Install-Package DimonSmart.RegexUnitTester.TestAdapter

This streamlined approach using attributes not only facilitates easier unit testing but also improves documentation directly within the code, maintaining clarity and efficiency.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DimonSmart.RegexUnitTester.Attributes:

Package Downloads
DimonSmart.RegexUnitTester.TestAdapter

Attribute based Regex unit test adapter

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.24607.2005 119 6/7/2024
1.24605.2215 147 6/5/2024
1.24602.2213 129 6/2/2024
1.0.3 114 5/14/2024
1.0.0 151 5/4/2024