Comments (10)
Very tricky.. It fails when the generated regular expression is "(\nl"
.
\n
is treated as a line break so the result becomes:
// Output from Text Visualizer:
(
l
from autofixture.
In the unit test, the assertion has been (implicitly) setup to match any character except \n
:
if (Regex.IsMatch(regex, pattern))
{
}
We need to pass RegexOptions.Singleline in order to match every character (instead of every character except \n):
if (Regex.IsMatch(regex, pattern, RegexOptions.Singleline))
{
}
Testing it using an infinite loop β The assertion never fails now.
from autofixture.
Pretty awesome detective work :)
What is the cost of using RegexOptions.Singleline
? By adding that, are there now regular expressions we can't deal with? Were there regular expressions before that we couldn't deal with, that we can deal with now?
What does the [RegularExpression] attribute use when it validates input? RegexOptions.Singleline
or one or more of the other flags?
I'm just trying to figure out if this is innocuous or really a breaking change...
from autofixture.
Good suggestion!..
There is no way to pass RegexOptions to the [RegularExpression] attribute.. I also had a look with Reflector and the options seem to be hardcoded.
As it seems, the [RegularExpression] attribute uses the default options:
string input = "(\nl";
string pattern = @"\(.*l";
bool result = Regex.IsMatch(input, pattern);
// Prints -> false
var attribute = new RegularExpressionAttribute(pattern);
bool result = attribute.IsValid(input);
// Prints -> false
However, it is now easier for us β We could remove the test case with the @"\(.*l"
pattern as it makes the test to behave erratically.
Optionally we could also validate the result using the attribute's built-in RegularExpressionAttribute.IsValid instance method (instead of using the Regex.IsMatch static method).
How does that sound?
from autofixture.
I think those suggestions sound good - I think the most important thing here is to stay in sync with what the [RegularExpression] attribute expects. After all, we should rather not produce a value that can't be validated by the attribute itself.
from autofixture.
Yes, exactly that..
from autofixture.
Here's another error that occasionally pops up:
Test 'Ploeh.AutoFixtureUnitTest.RegularExpressionGeneratorTest.CreateWithRegularExpressionRequestReturnsCorrectResult(".gr")' failed:
result: Ploeh.AutoFixture.Kernel.NoSpecimen
RegularExpressionGeneratorTest.cs(62,0): at Ploeh.AutoFixtureUnitTest.RegularExpressionGeneratorTest.CreateWithRegularExpressionRequestReturnsCorrectResult(String pattern)
from autofixture.
I have just checked it and it fails when the value is '\ngr' (similar to the above). It should also be removed since we can't pass RegexOptions to the [RegularExpression] attribute..
from autofixture.
I have just added the commits to a Pull Request.
from autofixture.
Resolved (changesets f41ffc3 and 7eb4613)
from autofixture.
Related Issues (20)
- Generator<T> hangs when used to generate a sample from limited range HOT 2
- π¨ GDPR compliance issue HOT 1
- β¨ Repeatable random numbers
- π [AutoFixture.Xunit2] MemberAutoDataAttribute generates fixtures for test method parameters provided from MemberData HOT 3
- π Enum data type is not applied when a member has both `[StringLength]` and `[EnumDataType]` annotations HOT 4
- π Unexpected ObjectCreationExceptionWithPath or if not a bug at least a confusing description HOT 3
- β¨ Support FakeItEasy 8 HOT 1
- β¨ Support for NUnit 4 HOT 16
- π FromFactory doesn't honor the Range attribute HOT 6
- β¨ Accept `ISpecimentBuilder` as value generator for `With` HOT 1
- β¨ DataAnnotations support for specimen factories
- π Auto properties on large record types causes severe performance degradation HOT 4
- ICustomization for DateOnly causes a hang. HOT 1
- π RandomNumericSequenceGenerator with limits, can create values outside of these limits in certain scenarios HOT 1
- autofixture is missing NuGet package README file HOT 2
- autofixture.automoq is missing NuGet package README file HOT 1
- `IAsyncEnumerable` generates an infinite sequence π HOT 2
- π SourceLink doesn't work because of incorrect casing in GitHub URLs HOT 4
- π¨ Vulnerability in packages System.Net.Http and System.Text.RegularExpressions HOT 3
- Builder.WithVariations⨠HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autofixture.