Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Add DateTime ParseExact test with 'Allow White' styles#27678

Merged
ahsonkhan merged 1 commit intodotnet:masterfrom
ahsonkhan:AddDateTimeParseTest
Mar 3, 2018
Merged

Add DateTime ParseExact test with 'Allow White' styles#27678
ahsonkhan merged 1 commit intodotnet:masterfrom
ahsonkhan:AddDateTimeParseTest

Conversation

@ahsonkhan
Copy link

@ahsonkhan ahsonkhan commented Mar 3, 2018

See dotnet/coreclr#16718 (comment) for context.

cc @jkotas, @stephentoub

Added some test to cover code paths leading to RemoveLeadingInQuoteSpaces / RemoveTrailingInQuoteSpaces. There are other DateTimeStyles that are still not well covered. Filed issue - https://github.com/dotnet/corefx/issues/27679

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc: @tarekgh



yield return new object[] { "9", "\" \"%d", CultureInfo.InvariantCulture, DateTimeStyles.AllowLeadingWhite, new DateTime(DateTime.Now.Year, 1, 9, 0, 0, 0) };
yield return new object[] { "15", "\' \'dd", CultureInfo.InvariantCulture, DateTimeStyles.AllowLeadingWhite, new DateTime(DateTime.Now.Year, 1, 15, 0, 0, 0) };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm misunderstanding, but doesn't AllowLeadingWhitespace primarily apply to ignoring whitespace in the input string, not the pattern?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That isn't what the implementation suggests. Quoted white space within the format string is allowed. Although, I couldn't really find good documentation on it to show it is supported. MSDN only talks about the input string.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://msdn.microsoft.com/en-us/library/ms131038(v=vs.110).aspx

AllowLeadingWhite - Specifies that white space not defined by format can appear at the beginning of s.

https://referencesource.microsoft.com/#mscorlib/system/globalization/datetimeparse.cs,4038

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifies that white space not defined by format can appear at the beginning of s.

Right... that's not what your tests are testing... the input strings you added have no whitespace... what am I missing?

Copy link
Author

@ahsonkhan ahsonkhan Mar 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You wanted me to add tests to cover all the code paths in RemoveLeadingInQuoteSpaces() / RemoveTrailingInQuoteSpaces(). Those methods are only ever called when removing white space from the format string (not from the input string). The tests I added improve branch coverage of those two internal methods.

I understand that the tests I added do not verify the correctness of the whitespace in the input string (and we should definitely add those too).

If there is a bug in the implementation of TryParseExact, we should address that, but I am not sure what the expected behavior should be based on the docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those methods are only ever called when removing white space from the format string (not from the input string).

Ah, that's what I was missing, thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants