Git Product home page Git Product logo

Comments (10)

moodmosaic avatar moodmosaic commented on May 12, 2024

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.

moodmosaic avatar moodmosaic commented on May 12, 2024

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.

ploeh avatar ploeh commented on May 12, 2024

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.

moodmosaic avatar moodmosaic commented on May 12, 2024

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.

ploeh avatar ploeh commented on May 12, 2024

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.

moodmosaic avatar moodmosaic commented on May 12, 2024

Yes, exactly that..

from autofixture.

ploeh avatar ploeh commented on May 12, 2024

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.

moodmosaic avatar moodmosaic commented on May 12, 2024

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.

moodmosaic avatar moodmosaic commented on May 12, 2024

I have just added the commits to a Pull Request.

from autofixture.

moodmosaic avatar moodmosaic commented on May 12, 2024

Resolved (changesets f41ffc3 and 7eb4613)

from autofixture.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.