Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match verification method fails for regex with curly brackets #112

Closed
DimaDubyk opened this issue Nov 9, 2017 · 1 comment
Closed

Match verification method fails for regex with curly brackets #112

DimaDubyk opened this issue Nov 9, 2017 · 1 comment
Assignees
Labels
Milestone

Comments

@DimaDubyk
Copy link

DimaDubyk commented Nov 9, 2017

STR:
for element:
public Text<_> Text { get; private set; }

assert element with text 123456-1234 using regex:
1:
Text.Should.Match("\\d{{6}}-\\d{{4}}");
or
2:
Text.Should.Match("\\d{6}-\\d{4}");

Expected behavior:
one of the regex works

Actual behavior:
1:
Text.Should.Match("\\d{{6}}-\\d{{4}}");
throws not equal exception
Atata.AssertionException : ---
Expected: should match pattern "\d{6}-\d{4}"
Actual: "123456-1234"

2:
Text.Should.Match("\\d{6}-\\d{4}");
System.FormatException : Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.Format(String format, Object[] args)
at Atata.IDataVerificationProviderExtensions.BuildVerificationConstraintMessage[TData,TOwner](IDataVerificationProvider2 should, String message, TData[] args) at Atata.IDataVerificationProviderExtensions.Satisfy[TData,TOwner](IDataVerificationProvider2 should, Predicate1 predicate, String message, TData[] args) at Atata.IDataVerificationProviderExtensions.Match[TOwner](IDataVerificationProvider2 should, String pattern)

@YevgeniyShunevych
Copy link
Member

The second regex is correct. But I would write it this way: @"^\d{6}-\d{4}$".

However, it is a bug. Match method fails when regex contains "{*}". Exception occurs when the log message is formatting. I will fix it within the next v0.16.0 release of Atata.

For now, you can bypass this issue using common Satisfy method:

page.Text.Should.Satisfy(actual => actual != null && Regex.IsMatch(actual, @"^\d{6}-\d{4}$"), "match pattern")

@YevgeniyShunevych YevgeniyShunevych changed the title match method fails for regex with curly brackets Match verification method fails for regex with curly brackets Nov 16, 2017
@YevgeniyShunevych YevgeniyShunevych self-assigned this Nov 16, 2017
@YevgeniyShunevych YevgeniyShunevych added this to the 0.16.0 milestone Nov 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants