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

Add letter number among valid identifiers in class name #13868

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -563,15 +563,17 @@ private static bool NeedsEscaping(char c, int pos)
}

if (c == '_'
|| char.IsLetterOrDigit(c) // Lu, Ll, Lt, Lm, Lo, or Nl
// 'Digit' does not include letter numbers, which are valid identifiers as per docs https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/identifier-names'.
|| char.IsLetterOrDigit(c) // Lu, Ll, Lt, Lm, Lo, or Nd
)
{
return false;
}

var category = CharUnicodeInfo.GetUnicodeCategory(c);
return category
is not UnicodeCategory.NonSpacingMark // Mn
is not UnicodeCategory.LetterNumber // Nl
and not UnicodeCategory.NonSpacingMark // Mn
and not UnicodeCategory.SpacingCombiningMark // Mc
and not UnicodeCategory.ConnectorPunctuation // Pc
and not UnicodeCategory.Format; // Cf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using Microsoft.VisualStudio.TestTools.UnitTesting;

using TestClasses;

namespace Microsoft.TestPlatform.AdapterUtilities.ManagedNameUtilities.UnitTests;

[TestClass]
Expand Down Expand Up @@ -123,4 +125,18 @@ public void Namespaceless_InnerRecordMembers_ShouldNotReportANamespace_InHierarc
Assert.AreEqual("Method0", managedMethodName);
Assert.IsNull(hierarchyValues[HierarchyConstants.Levels.NamespaceIndex]);
}

[TestMethod]
public void SpecialCharacters_HierarchyShouldNotWrapMembersWithSpecialCharactersInSingleQuotes()
{
var methodBase = typeof(Class狧麱狵錋狾龍龪啊阿埃挨哎唉0u㐀㐁㐂㐃㐄㐅㐆㐇6ⅶ0ǒoU1U2U38丂丄丅丆丏丒丟).GetMethod("Method0")!;

// Act
ManagedNameHelper.GetManagedName(methodBase, out var managedTypeName, out var managedMethodName, out var _);

// Assert
Assert.AreEqual("TestClasses.Class狧麱狵錋狾龍龪啊阿埃挨哎唉0u㐀㐁㐂㐃㐄㐅㐆㐇6ⅶ0ǒoU1U2U38丂丄丅丆丏丒丟", managedTypeName);
Assert.AreEqual("Method0", managedMethodName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,17 @@ public void Overload0(Tuple<Tuple<string[,], int>> t0) { }
public void Overload0(Tuple<Tuple<string>, Tuple<int>> t) { }
public void Overload0<U>(Tuple<Tuple<Outer<U>.Inner<U>>> t) { }
}

public class Class狧麱狵錋狾龍龪啊阿埃挨哎唉0u㐀㐁㐂㐃㐄㐅㐆㐇6ⅶ0ǒoU1U2U38丂丄丅丆丏丒丟
{
public void Method0()
{

}
}
}


#pragma warning restore IDE0161 // Convert to file-scoped namespace
#pragma warning restore IDE0060 // Remove unused parameter
#pragma warning restore CA1822 // Mark members as static