-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Allow digit separator after base specifier #20449
Changes from 1 commit
8d7fb2b
75365a4
ee697a5
b268dc1
4bad4d7
2726b4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2612,6 +2612,31 @@ public void TestNumericWithUnderscoresWithoutFeatureFlag() | |
Assert.Equal(text, token.Text); | ||
} | ||
|
||
[Fact] | ||
[Trait("Feature", "Literals")] | ||
public void TestNumericWithLeadingUnderscores() | ||
{ | ||
var text = "0x_A"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please test with multiple underscores. @gafter can confirm expected language/spec behavior. #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
var token = LexToken(text, _underscoreOptions); | ||
|
||
Assert.NotNull(token); | ||
Assert.Equal(SyntaxKind.NumericLiteralToken, token.Kind()); | ||
Assert.Equal(0, token.Errors().Length); | ||
Assert.Equal(0xA, token.Value); | ||
Assert.Equal(text, token.Text); | ||
|
||
text = "0b_1"; | ||
token = LexToken(text, _binaryUnderscoreOptions); | ||
|
||
Assert.NotNull(token); | ||
Assert.Equal(SyntaxKind.NumericLiteralToken, token.Kind()); | ||
Assert.Equal(0, token.Errors().Length); | ||
Assert.Equal(1, token.Value); | ||
Assert.Equal(text, token.Text); | ||
|
||
// TODO(leading-digit-separator): test feature flag | ||
} | ||
|
||
[Fact] | ||
[Trait("Feature", "Literals")] | ||
public void TestNumericWithBadUnderscores() | ||
|
@@ -2693,17 +2718,6 @@ public void TestNumericWithBadUnderscores() | |
Assert.Equal("error CS1013: Invalid number", errors[0].ToString(EnsureEnglishUICulture.PreferredOrNull)); | ||
Assert.Equal(text, token.Text); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add tests for |
||
|
||
text = "0x_A"; | ||
token = LexToken(text, _underscoreOptions); | ||
|
||
Assert.NotNull(token); | ||
Assert.Equal(SyntaxKind.NumericLiteralToken, token.Kind()); | ||
errors = token.Errors(); | ||
Assert.Equal(1, errors.Length); | ||
Assert.Equal((int)ErrorCode.ERR_InvalidNumber, errors[0].Code); | ||
Assert.Equal("error CS1013: Invalid number", errors[0].ToString(EnsureEnglishUICulture.PreferredOrNull)); | ||
Assert.Equal(text, token.Text); | ||
|
||
text = "0xA_"; | ||
token = LexToken(text, _underscoreOptions); | ||
|
||
|
@@ -2715,17 +2729,6 @@ public void TestNumericWithBadUnderscores() | |
Assert.Equal("error CS1013: Invalid number", errors[0].ToString(EnsureEnglishUICulture.PreferredOrNull)); | ||
Assert.Equal(text, token.Text); | ||
|
||
text = "0b_1"; | ||
token = LexToken(text, _binaryUnderscoreOptions); | ||
|
||
Assert.NotNull(token); | ||
Assert.Equal(SyntaxKind.NumericLiteralToken, token.Kind()); | ||
errors = token.Errors(); | ||
Assert.Equal(1, errors.Length); | ||
Assert.Equal((int)ErrorCode.ERR_InvalidNumber, errors[0].Code); | ||
Assert.Equal("error CS1013: Invalid number", errors[0].ToString(EnsureEnglishUICulture.PreferredOrNull)); | ||
Assert.Equal(text, token.Text); | ||
|
||
text = "0b1_"; | ||
token = LexToken(text, _binaryUnderscoreOptions); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1694,7 +1694,10 @@ FullWidthRepeat: | |
IntegerLiteralStart = Here | ||
Base = LiteralBase.Hexadecimal | ||
|
||
UnderscoreInWrongPlace = (CanGet(Here) AndAlso Peek(Here) = "_"c) | ||
If (CanGet(Here) AndAlso Peek(Here) = "_"c) Then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary parentheses around entire Boolean expression, here and below. |
||
' TODO(leading-digit-separator): check feature flag | ||
End If | ||
|
||
While CanGet(Here) | ||
ch = Peek(Here) | ||
If Not IsHexDigit(ch) AndAlso ch <> "_"c Then | ||
|
@@ -1712,7 +1715,10 @@ FullWidthRepeat: | |
IntegerLiteralStart = Here | ||
Base = LiteralBase.Binary | ||
|
||
UnderscoreInWrongPlace = (CanGet(Here) AndAlso Peek(Here) = "_"c) | ||
If (CanGet(Here) AndAlso Peek(Here) = "_"c) Then | ||
' TODO(leading-digit-separator): check feature flag | ||
End If | ||
|
||
While CanGet(Here) | ||
ch = Peek(Here) | ||
If Not IsBinaryDigit(ch) AndAlso ch <> "_"c Then | ||
|
@@ -1730,7 +1736,10 @@ FullWidthRepeat: | |
IntegerLiteralStart = Here | ||
Base = LiteralBase.Octal | ||
|
||
UnderscoreInWrongPlace = (CanGet(Here) AndAlso Peek(Here) = "_"c) | ||
If (CanGet(Here) AndAlso Peek(Here) = "_"c) Then | ||
' TODO(leading-digit-separator): check feature flag | ||
End If | ||
|
||
While CanGet(Here) | ||
ch = Peek(Here) | ||
If Not IsOctalDigit(ch) AndAlso ch <> "_"c Then | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't let new TODOs into the master branch.
Blockers should be addressed. Non-blockers should be tracked with a github issue.