Skip to content
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
91 changes: 64 additions & 27 deletions src/Workspaces/CSharpTest/OrganizeImports/OrganizeUsingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.CodeAnalysis.OrganizeImports;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.UnitTests;
using Roslyn.Test.Utilities;
using Xunit;

Expand Down Expand Up @@ -120,7 +121,7 @@ namespace N2
{
using H;
using G;
}
}
}

namespace N3
Expand All @@ -138,7 +139,7 @@ namespace N5
{
using N;
using M;
}
}
}";

var final =
Expand All @@ -160,7 +161,7 @@ namespace N2
{
using G;
using H;
}
}
}

namespace N3
Expand All @@ -178,7 +179,7 @@ namespace N5
{
using M;
using N;
}
}
}";
await CheckAsync(initial, final);
}
Expand Down Expand Up @@ -1038,13 +1039,44 @@ public async Task CaseSensitivity1()
using Bbb;
using cc;
using cC;
using CC;
using CC;";

// If Kana is sensitive あ != ア, if Kana is insensitive あ == ア.
// If Width is sensitiveア != ア, if Width is insensitive ア == ア.";
string sortedKana;
if (GlobalizationUtilities.ICUMode())
{
sortedKana =
@"using あ;
using ア;
using ああ;
using あア;
using アあ;
using アア;
using あア;
using アア;
using ア;
using アあ;
using アア;
using アア;";
}
else
{
sortedKana =
@"using ア;
using ア;
using あ;
using アア;
using アア;
using アア;
using アア;
using アあ;
using アあ;
using あア;
using あア;
using ああ;";
}

var final =
@"using a;
@$"using a;
using A;
using aa;
using aA;
Expand All @@ -1071,21 +1103,8 @@ public async Task CaseSensitivity1()
using cC;
using Cc;
using CC;
using ア;
using ア;
using あ;
using アア;
using アア;
using アア;
using アア;
using アあ;
using アあ;
using あア;
using あア;
using ああ;

// If Kana is sensitive あ != ア, if Kana is insensitive あ == ア.
// If Width is sensitiveア != ア, if Width is insensitive ア == ア.";
{sortedKana}
";
await CheckAsync(initial, final);
}

Expand All @@ -1106,7 +1125,26 @@ public async Task CaseSensitivity2()
using アア;
using アア;";

var final =
if (GlobalizationUtilities.ICUMode())
{
await CheckAsync(initial,
@"using あ;
using ア;
using ああ;
using あア;
using アあ;
using アア;
using あア;
using アア;
using ア;
using アあ;
using アア;
using アア;
");
}
else
{
await CheckAsync(initial,
@"using ア;
using ア;
using あ;
Expand All @@ -1119,9 +1157,8 @@ public async Task CaseSensitivity2()
using あア;
using あア;
using ああ;
";

await CheckAsync(initial, final);
");
}
}

[WorkItem(20988, "https://github.com/dotnet/roslyn/issues/20988")]
Expand Down
26 changes: 26 additions & 0 deletions src/Workspaces/CoreTestUtilities/GlobalizationUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Globalization;

namespace Microsoft.CodeAnalysis.UnitTests;
internal class GlobalizationUtilities
{
/// <summary>
/// The final ordering of kana depends on what globalization mode is being used.
/// On .net framework it is NLS, but on .net core + newer versions of windows, it defers to ICU
/// See https://docs.microsoft.com/en-us/dotnet/core/extensions/globalization-icu
/// and https://github.com/dotnet/runtime/blob/78065413b2d1b4f0ed26343567379e992a3e26ee/src/libraries/System.Globalization/tests/CompareInfo/CompareInfoTests.cs#L100
///
/// This helper allows us to figure out at runtime which mode is being used so tests can behave accordingly.
/// </summary>
public static bool ICUMode()
{
// Copied from https://docs.microsoft.com/en-us/dotnet/core/extensions/globalization-icu#determine-if-your-app-is-using-icu
var sortVersion = CultureInfo.InvariantCulture.CompareInfo.Version;
var bytes = sortVersion.SortId.ToByteArray();
var version = bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0];
return version != 0 && version == sortVersion.FullVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Imports Roslyn.Test.Utilities
Imports Xunit
Imports Microsoft.CodeAnalysis.[Shared].Extensions
Imports Microsoft.CodeAnalysis.OrganizeImports
Imports Microsoft.CodeAnalysis.UnitTests

Namespace Microsoft.CodeAnalysis.VisualBasic.Workspaces.UnitTests.OrganizeImports
<[UseExportProvider]>
Expand Down Expand Up @@ -673,11 +674,53 @@ Imports Bbb
Imports cc
Imports cC
Imports CC
</content>

// If Kana is sensitive あ != ア, if Kana is insensitive あ == ア.
// If Width is sensitiveア != ア, if Width is insensitive ア == ア.</content>

Dim final =
Dim final As XElement
If GlobalizationUtilities.ICUMode() Then
final =
<content>Imports a
Imports A
Imports aa
Imports aA
Imports Aa
Imports AA
Imports b
Imports B
Imports bb
Imports bB
Imports Bb
Imports BB
Imports bbb
Imports bbB
Imports bBb
Imports bBB
Imports Bbb
Imports BbB
Imports BBb
Imports BBB
Imports c
Imports C
Imports cc
Imports cC
Imports cC
Imports Cc
Imports CC
Imports あ
Imports ア
Imports ああ
Imports あア
Imports アあ
Imports アア
Imports あア
Imports アア
Imports ア
Imports アあ
Imports アア
Imports アア
</content>
Else
final =
<content>Imports a
Imports A
Imports aa
Expand Down Expand Up @@ -717,9 +760,9 @@ Imports アあ
Imports あア
Imports あア
Imports ああ
</content>
End If

// If Kana is sensitive あ != ア, if Kana is insensitive あ == ア.
// If Width is sensitiveア != ア, if Width is insensitive ア == ア.</content>
Await CheckAsync(initial, final)
End Function

Expand All @@ -739,7 +782,24 @@ Imports アあ
Imports アア
Imports アア</content>

Dim final =
Dim final As XElement
If GlobalizationUtilities.ICUMode() Then
final =
<content>Imports あ
Imports ア
Imports ああ
Imports あア
Imports アあ
Imports アア
Imports あア
Imports アア
Imports ア
Imports アあ
Imports アア
Imports アア
</content>
Else
final =
<content>Imports ア
Imports ア
Imports あ
Expand All @@ -753,6 +813,7 @@ Imports あア
Imports あア
Imports ああ
</content>
End If

Await CheckAsync(initial, final)
End Function
Expand Down