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

Made char.IsAscii public #41396

Merged
merged 2 commits into from
Aug 31, 2020
Merged

Conversation

gfoidl
Copy link
Member

@gfoidl gfoidl commented Aug 26, 2020

Fixes #40936

Also normalized parameters of other method to c (instead of ch, only two others).

/cc: @GrabYourPitchforks

@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

Assert.True(char.IsAscii(char.MinValue));
Assert.True(char.IsAscii('\x007f'));
Assert.False(char.IsAscii('\x0080'));
Assert.False(char.IsAscii(char.MaxValue));
Copy link
Member Author

Choose a reason for hiding this comment

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

Is this enough for testing, or should be use the "whole range" ala

public static IEnumerable<object[]> UnicodeInfoTestData_Latin1AndSelectOthers()

?

Copy link
Member

Choose a reason for hiding this comment

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

The whole range. There is probably a similar test for Rune.IsAscii

Copy link
Member Author

@gfoidl gfoidl Aug 26, 2020

Choose a reason for hiding this comment

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

Just scanned again through the repo, looking for IsAscii-tests. Haven't found one.

I've seen that all IsAscii implementations, like

public bool IsAscii => UnicodeUtility.IsAsciiCodePoint(_value);
delegate to
public static bool IsAsciiCodePoint(uint value) => value <= 0x7Fu;

It's a trivial method (just one compare), but maybe it's better to delegate char.IsAscii also to this method and add tests over there (as I didn't find some for IsAsciiCodePoint -- maybe because it's defined in an internal type)?

Copy link
Member

Choose a reason for hiding this comment

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

Search the file https://github.com/dotnet/runtime/blob/master/src/libraries/System.Runtime/tests/System/Text/RuneTests.cs for the substring "IsAscii". You'll see how we perform tests against the Rune APIs.

Though to be honest those tests are basically just testing specific values like '\u0000', '\u007f', etc., as you had here. :)

I have no problem with you leaving the test as you have it here.

@danmoseley
Copy link
Member

This needs to be also exposed in the /ref/ file where Char surface is defined.
https://github.com/dotnet/runtime/blob/2a4284b9f3eb2ad95fdf324f0249d372abff96df/docs/coding-guidelines/updating-ref-source.md

@gfoidl
Copy link
Member Author

gfoidl commented Aug 26, 2020

Ahhh, ref-assembly -- thanks for the hint / info.
Will update when the test-question is resolved.

Copy link
Member

@GrabYourPitchforks GrabYourPitchforks left a comment

Choose a reason for hiding this comment

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

Remember to update the ref asms! Send a ping once that's ready. Otherwise LGTM.

Assert.True(char.IsAscii(char.MinValue));
Assert.True(char.IsAscii('\x007f'));
Assert.False(char.IsAscii('\x0080'));
Assert.False(char.IsAscii(char.MaxValue));
Copy link
Member

Choose a reason for hiding this comment

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

Search the file https://github.com/dotnet/runtime/blob/master/src/libraries/System.Runtime/tests/System/Text/RuneTests.cs for the substring "IsAscii". You'll see how we perform tests against the Rune APIs.

Though to be honest those tests are basically just testing specific values like '\u0000', '\u007f', etc., as you had here. :)

I have no problem with you leaving the test as you have it here.

@gfoidl
Copy link
Member Author

gfoidl commented Aug 27, 2020

@GrabYourPitchforks I pushed the commit with the ref-assembly update.

I have no problem with you leaving the test as you have it here.

I left the test as they are.

@GrabYourPitchforks GrabYourPitchforks merged commit 4921dbb into dotnet:master Aug 31, 2020
@gfoidl gfoidl deleted the char_isascii branch September 1, 2020 07:17
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API Proposal: Make char.IsAscii public
4 participants