Skip to content

Commit 3eba330

Browse files
Again adjust for culture name normalization in AssemblyNameInfoFuzzer (#114531)
* Again adjust for culture name normalization in AssemblyNameInfoFuzzer * Don't run the test on Nano --------- Co-authored-by: Miha Zupan <[email protected]>
1 parent bdfb872 commit 3eba330

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/libraries/Fuzzing/DotnetFuzzing/Fuzzers/AssemblyNameInfoFuzzer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ private static void Test(Span<char> span)
6868
// When converting to AssemblyName, the culture name is lower-cased
6969
// by the CultureInfo ctor that calls CultureData.GetCultureData
7070
// which lowers the name for caching and normalization purposes.
71+
// It lowers only the part before the `-` character, but we lower
72+
// the whole string for the sake of simplicity of this test.
7173

7274
string lowerCase = fromTryParse.CultureName.ToLower();
7375
if (lowerCase != "c")
7476
{
75-
Assert.Equal(lowerCase, fromParse.ToAssemblyName().CultureName);
77+
Assert.Equal(lowerCase, fromParse.ToAssemblyName().CultureName!.ToLower());
7678
}
7779
else
7880
{

src/libraries/System.Reflection.Metadata/tests/Metadata/AssemblyNameInfoTests.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Collections.Generic;
45
using System.Globalization;
56
using Xunit;
67

@@ -106,15 +107,24 @@ public void EmptyInputIsInvalid()
106107
Assert.Throws<ArgumentException>(() => AssemblyNameInfo.Parse("".AsSpan()));
107108
}
108109

109-
[Fact]
110-
public void CultureNameGetLoweredByToAssemblyName()
110+
111+
public static IEnumerable<object[]> CultureNameGetLoweredByToAssemblyName_Arguments()
112+
{
113+
yield return new object[] { "aA", "aa" };
114+
yield return new object[] { "B-BB", PlatformDetection.IsNetFramework ? "B-BB" : "b-BB" };
115+
}
116+
117+
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
118+
[MemberData(nameof(CultureNameGetLoweredByToAssemblyName_Arguments))]
119+
public void CultureNameGetLoweredByToAssemblyName(string input, string expected)
111120
{
112-
AssemblyNameInfo assemblyNameInfo = AssemblyNameInfo.Parse("test,culture=aA".AsSpan());
113-
Assert.Equal("aA", assemblyNameInfo.CultureName);
121+
AssemblyNameInfo assemblyNameInfo = AssemblyNameInfo.Parse($"test,culture={input}".AsSpan());
122+
Assert.Equal(input, assemblyNameInfo.CultureName);
114123
// When converting to AssemblyName, the culture name is lower-cased
115124
// by the CultureInfo ctor that calls CultureData.GetCultureData
116125
// which lowers the name for caching and normalization purposes.
117-
Assert.Equal("aa", assemblyNameInfo.ToAssemblyName().CultureName);
126+
// It lowers only the part before the `-` character.
127+
Assert.Equal(expected, assemblyNameInfo.ToAssemblyName().CultureName);
118128
}
119129

120130
[Theory]

0 commit comments

Comments
 (0)