Skip to content

Commit

Permalink
Add letter number among valid identifiers in class name (#13868)
Browse files Browse the repository at this point in the history
* Add letter number among valid identifiers in class name

* Update src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs

Co-authored-by: Amaury Levé <[email protected]>

* Update test/Microsoft.TestPlatform.AdapterUtilities.UnitTests/TestClasses.cs

Co-authored-by: Amaury Levé <[email protected]>

* Update test/Microsoft.TestPlatform.AdapterUtilities.UnitTests/ManagedNameUtilities/ManagedNameGeneratorTests.cs

Co-authored-by: Amaury Levé <[email protected]>

---------

Co-authored-by: Amaury Levé <[email protected]>
  • Loading branch information
nohwnd and Evangelink authored Jan 6, 2025
1 parent d8aa584 commit 778c004
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
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

0 comments on commit 778c004

Please sign in to comment.