DimonSmart.RegexUnitTester.Attributes
1.24607.2005
Prefix Reserved
dotnet add package DimonSmart.RegexUnitTester.Attributes --version 1.24607.2005
NuGet\Install-Package DimonSmart.RegexUnitTester.Attributes -Version 1.24607.2005
<PackageReference Include="DimonSmart.RegexUnitTester.Attributes" Version="1.24607.2005" />
paket add DimonSmart.RegexUnitTester.Attributes --version 1.24607.2005
#r "nuget: DimonSmart.RegexUnitTester.Attributes, 1.24607.2005"
// Install DimonSmart.RegexUnitTester.Attributes as a Cake Addin #addin nuget:?package=DimonSmart.RegexUnitTester.Attributes&version=1.24607.2005 // Install DimonSmart.RegexUnitTester.Attributes as a Cake Tool #tool nuget:?package=DimonSmart.RegexUnitTester.Attributes&version=1.24607.2005
DimonSmart.RegexUnitTester.Attributes
⚠ - This package is for attributes only! for TestAdapter please check TestAdapter package
Overview
The DimonSmart.RegexUnitTester.Attributes
NuGet package enhances regex testing by using custom attributes to specify test cases and document regex behaviors. This package focuses solely on providing attribute tools for marking test cases directly in your code, improving code readability and documentation.
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.
Related Packages
For automated testing integration, consider using the DimonSmart.RegexUnitTester.TestAdapter
package. This adapter works seamlessly with the attributes provided here to facilitate automated unit testing.
Install-Package DimonSmart.RegexUnitTester.TestAdapter
Find out more about the TestAdapter package here
License
This project is licensed under the 0BSD License, which is one of the most permissive licenses available. This means that the DimonSmart.RegexUnitTester.Attributes
are completely free for both personal and commercial use. You are allowed to use, modify, and distribute the software without any restrictions.
For more details on the license, you can review it here.
Product | Versions 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. |
-
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 |