DimonSmart.RegexUnitTester.TestAdapter 1.0.0.2

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package DimonSmart.RegexUnitTester.TestAdapter --version 1.0.0.2
NuGet\Install-Package DimonSmart.RegexUnitTester.TestAdapter -Version 1.0.0.2
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.TestAdapter" Version="1.0.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DimonSmart.RegexUnitTester.TestAdapter --version 1.0.0.2
#r "nuget: DimonSmart.RegexUnitTester.TestAdapter, 1.0.0.2"
#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.TestAdapter as a Cake Addin
#addin nuget:?package=DimonSmart.RegexUnitTester.TestAdapter&version=1.0.0.2

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

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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 68 5/14/2024
1.0.0.2 75 5/9/2024
1.0.0 106 5/5/2024