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
1 change: 0 additions & 1 deletion src/libraries/Common/Common.Tests.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
</Folder>
<Folder Name="/tests/">
<Project Path="tests/Common.Tests.csproj" />
<Project Path="tests/ComplianceTests/Compliance.Tests.csproj" />
<Project Path="tests/StreamConformanceTests/StreamConformanceTests.csproj" />
<Project Path="tests/TestUtilities/TestUtilities.csproj" />
</Folder>
Expand Down
56 changes: 0 additions & 56 deletions src/libraries/Common/tests/ComplianceTests/Compliance.Tests.csproj

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)TestHelper.cs">
<Link>Common\ComplianceTests\GB18030\TestHelper.cs</Link>
</Compile>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Level3+Amendment_Test_Data_for_Mid_to_High_Volume_cases.txt">
<LogicalName>Level3+Amendment_Test_Data_for_Mid_to_High_Volume_cases.txt</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Globalization.Tests;
using System.Linq;
using Xunit;

namespace GB18030.Tests;

// Requires CharUnicodeInfoTestData.cs and the UnicodeData.txt embedded resource, so it is compiled
// only into the projects whose GB18030 tests are driven by the Unicode character database.
public static partial class TestHelper
{
private static IEnumerable<CharUnicodeInfoTestCase> GB18030CharUnicodeInfo { get; } = GetGB18030CharUnicodeInfo();

private static IEnumerable<CharUnicodeInfoTestCase> GetGB18030CharUnicodeInfo()
{
const int CodePointsTotal = 9793; // Make sure a Unicode version downgrade doesn't make us lose coverage.

var ret = CharUnicodeInfoTestData.TestCases.Where(tc => IsInGB18030Range(tc.CodePoint)).ToArray();
Assert.Equal(CodePointsTotal, ret.Length);
return ret;

static bool IsInGB18030Range(int codePoint)
=> (codePoint >= 0x9FF0 && codePoint <= 0x9FFF) ||
(codePoint >= 0x4DB6 && codePoint <= 0x4DBF) ||
(codePoint >= 0x2A6D7 && codePoint <= 0x2A6DF) ||
(codePoint >= 0x2B735 && codePoint <= 0x2B739) ||
(codePoint >= 0x30000 && codePoint <= 0x3134A) ||
(codePoint >= 0x31350 && codePoint <= 0x323AF) ||
(codePoint >= 0x2EBF0 && codePoint <= 0x2EE5D);
}

public static IEnumerable<object[]> GB18030CharUnicodeInfoMemberData { get; } = GB18030CharUnicodeInfo.Select(data => new object[] { data }).ToArray();
}
31 changes: 6 additions & 25 deletions src/libraries/Common/tests/ComplianceTests/GB18030/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Globalization.Tests;
using System.IO;
using System.Linq;
using System.Text;
using Xunit;

namespace GB18030.Tests;

public static class TestHelper
// The CharUnicodeInfo-derived test data lives in TestHelper.CharUnicodeInfo.cs so that only the
// projects exercising it have to take on CharUnicodeInfoTestData.cs and the UnicodeData.txt resource.
public static partial class TestHelper
{
// New Code Points in existing ranges
internal static IEnumerable<int> CjkNewCodePoints { get; } = CreateRange(0x9FF0, 0x9FFF);
Expand All @@ -27,25 +27,6 @@ public static class TestHelper

private static IEnumerable<int> CreateRange(int first, int last) => Enumerable.Range(first, last - first + 1);

private static IEnumerable<CharUnicodeInfoTestCase> s_gb18030CharUnicodeInfo { get; } = GetGB18030CharUnicodeInfo();
private static IEnumerable<CharUnicodeInfoTestCase> GetGB18030CharUnicodeInfo()
{
const int CodePointsTotal = 9793; // Make sure a Unicode version downgrade doesn't make us lose coverage.

var ret = CharUnicodeInfoTestData.TestCases.Where(tc => IsInGB18030Range(tc.CodePoint)).ToArray();
Assert.Equal(CodePointsTotal, ret.Length);
return ret;

static bool IsInGB18030Range(int codePoint)
=> (codePoint >= 0x9FF0 && codePoint <= 0x9FFF) ||
(codePoint >= 0x4DB6 && codePoint <= 0x4DBF) ||
(codePoint >= 0x2A6D7 && codePoint <= 0x2A6DF) ||
(codePoint >= 0x2B735 && codePoint <= 0x2B739) ||
(codePoint >= 0x30000 && codePoint <= 0x3134A) ||
(codePoint >= 0x31350 && codePoint <= 0x323AF) ||
(codePoint >= 0x2EBF0 && codePoint <= 0x2EE5D);
}

internal static CultureInfo[] Cultures { get; } = [
CultureInfo.CurrentCulture,
CultureInfo.InvariantCulture,
Expand Down Expand Up @@ -107,9 +88,10 @@ internal static Encoding GB18030Encoding
if (s_gb18030Encoding is null)
{
#if !NETFRAMEWORK
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
#endif
s_gb18030Encoding = CodePagesEncodingProvider.Instance.GetEncoding("gb18030");
#else
s_gb18030Encoding = Encoding.GetEncoding("gb18030");
#endif
}

return s_gb18030Encoding;
Expand Down Expand Up @@ -151,7 +133,6 @@ internal static Encoding GB18030Encoding
public static IEnumerable<object[]> EncodedMemberData { get; } = s_encodedTestData.Select(data => new object[] { data }).ToArray();
public static IEnumerable<object[]> DecodedMemberData { get; } = DecodedTestData.Select(data => new object[] { data }).ToArray();
public static IEnumerable<object[]> NonExceedingPathNameMaxDecodedMemberData { get; } = NonExceedingPathNameMaxDecodedTestData.Select(data => new object[] { data }).ToArray();
public static IEnumerable<object[]> GB18030CharUnicodeInfoMemberData { get; } = s_gb18030CharUnicodeInfo.Select(data => new object[] { data }).ToArray();

private static IEnumerable<byte[]> GetTestData()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;
using System.Text;
using Microsoft.DotNet.RemoteExecutor;
using Xunit;

Expand All @@ -11,9 +13,33 @@ public class ConsoleTests
{
protected static readonly int WaitInMS = 30 * 1000 * PlatformDetection.SlowRuntimeTimeoutModifier;

// GB18030 console tests require a platform whose console subsystem supports the GB18030
// code page. Older platforms (e.g. Windows Nano Server) don't, so gate on GB18030 support.
public static bool IsSupported => RemoteExecutor.IsSupported && TestHelper.IsGB18030Supported;
public static bool IsSupported { get; } =
RemoteExecutor.IsSupported &&
TestHelper.IsGB18030Supported &&
(!PlatformDetection.IsWindows || IsConsoleInputEncodingSupported());

private static bool IsConsoleInputEncodingSupported()
{
Encoding? originalEncoding = null;

try
{
originalEncoding = Console.InputEncoding;
Console.InputEncoding = TestHelper.GB18030Encoding;
return Console.InputEncoding.CodePage == TestHelper.GB18030Encoding.CodePage;
}
catch (IOException)
{
return false;
}
finally
{
if (originalEncoding is not null)
{
Console.InputEncoding = originalEncoding;
}
}
}

[ConditionalTheory(typeof(ConsoleTests), nameof(IsSupported))]
[MemberData(nameof(TestHelper.DecodedMemberData), MemberType = typeof(TestHelper))]
Expand Down Expand Up @@ -42,9 +68,7 @@ public void StandardInput(string decodedText)
{
var remoteOptions = new RemoteInvokeOptions();
remoteOptions.StartInfo.RedirectStandardInput = true;
#if !NETFRAMEWORK
remoteOptions.StartInfo.StandardInputEncoding = TestHelper.GB18030Encoding;
#endif

using RemoteInvokeHandle remoteHandle = RemoteExecutor.Invoke(line =>
{
Expand All @@ -54,18 +78,8 @@ public void StandardInput(string decodedText)
return 42;
}, decodedText, remoteOptions);

if (PlatformDetection.IsNetFramework)
{
// there's no StandardInputEncoding in .NET Framework, re-encode and write.
byte[] encoded = TestHelper.GB18030Encoding.GetBytes(decodedText);
remoteHandle.Process.StandardInput.BaseStream.Write(encoded, 0, encoded.Length);
remoteHandle.Process.StandardInput.Close();
}
else
{
remoteHandle.Process.StandardInput.Write(decodedText);
remoteHandle.Process.StandardInput.Close();
}
remoteHandle.Process.StandardInput.Write(decodedText);
remoteHandle.Process.StandardInput.Close();

Assert.True(remoteHandle.Process.WaitForExit(WaitInMS));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<Compile Include="ConsoleKeyInfoTests.cs" />
<Compile Include="ConsoleHandles.cs" />
<Compile Include="ConsoleStream.cs" />
<Compile Include="GB18030\ConsoleTests.cs" />
<Compile Include="SetError.cs" />
<Compile Include="SetIn.cs" />
<Compile Include="Color.cs" />
Expand Down Expand Up @@ -81,4 +82,5 @@
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetPwUid.cs"
Link="Common\Interop\Unix\Interop.GetPwUid.cs" />
</ItemGroup>
<Import Project="$(CommonTestPath)ComplianceTests\GB18030\GB18030.Shared.projitems" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace GB18030.Tests;

[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
public class CharTests
{
[Theory]
Expand Down Expand Up @@ -102,7 +101,6 @@ public void IsNonLetter_False(CharUnicodeInfoTestCase testCase)
if (utf32String.Length < 2)
{
char c = utf32String[0];
#if !NETFRAMEWORK
Assert.False(char.IsAscii(c));
Assert.False(char.IsAsciiDigit(c));
Assert.False(char.IsAsciiHexDigit(c));
Expand All @@ -112,7 +110,6 @@ public void IsNonLetter_False(CharUnicodeInfoTestCase testCase)
Assert.False(char.IsAsciiLetterOrDigit(c));
Assert.False(char.IsAsciiLetterLower(c));
Assert.False(char.IsAsciiLetterUpper(c));
#endif
Assert.False(char.IsControl(c));
Assert.False(char.IsDigit(c));
Assert.False(char.IsLower(c));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,21 @@

namespace GB18030.Tests;

[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
public class CharUnicodeInfoTests
{
[Theory]
[MemberData(nameof(TestHelper.GB18030CharUnicodeInfoMemberData), MemberType = typeof(TestHelper))]
public void GetUnicodeCategory(CharUnicodeInfoTestCase testCase)
{
UnicodeCategory expected = PlatformDetection.IsNetFramework ? UnicodeCategory.OtherNotAssigned : UnicodeCategory.OtherLetter;
const UnicodeCategory expected = UnicodeCategory.OtherLetter;

if (testCase.Utf32CodeValue.Length == 1)
{
Assert.Equal(expected, CharUnicodeInfo.GetUnicodeCategory(testCase.Utf32CodeValue[0]));
}

Assert.Equal(expected, CharUnicodeInfo.GetUnicodeCategory(testCase.Utf32CodeValue, 0));
#if !NETFRAMEWORK
Assert.Equal(expected, CharUnicodeInfo.GetUnicodeCategory(testCase.CodePoint));
#endif
Assert.True(PlatformDetection.IsNetFramework || testCase.GeneralCategory == expected);
Assert.Equal(expected, testCase.GeneralCategory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="GB18030\CharTests.cs" />
<Compile Include="GB18030\CharUnicodeInfoTests.cs" />
<Compile Include="IcuTests.cs" />
<Compile Include="CompareInfo\CompareInfoTests.cs" />
<Compile Include="CompareInfo\CompareInfoTestsBase.cs" />
Expand Down Expand Up @@ -127,6 +129,8 @@
<Compile Include="System\Globalization\TextElementEnumeratorTests.cs" />
<Compile Include="System\Globalization\UnicodeCategoryTests.cs" />
<!-- Helpers -->
<Compile Include="$(CommonTestPath)ComplianceTests\GB18030\TestHelper.CharUnicodeInfo.cs"
Link="Common\ComplianceTests\GB18030\TestHelper.CharUnicodeInfo.cs" />
<Compile Include="$(CommonTestPath)System\RandomDataGenerator.cs"
Link="Common\System\RandomDataGenerator.cs" />
</ItemGroup>
Expand All @@ -144,4 +148,5 @@
<ItemGroup>
<ProjectReference Include="$(CommonTestPath)TestUtilities.Unicode\TestUtilities.Unicode.csproj" />
</ItemGroup>
<Import Project="$(CommonTestPath)ComplianceTests\GB18030\GB18030.Shared.projitems" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
<Compile Include="$(CommonTestPath)System\IO\CallTrackingStream.cs" Link="Common\System\IO\CallTrackingStream.cs" />
<Compile Include="$(CommonTestPath)System\IO\DelegateStream.cs" Link="Common\System\IO\DelegateStream.cs" />
<Compile Include="$(CommonTestPath)System\IO\WrappedMemoryStream.cs" Link="Common\System\IO\WrappedMemoryStream.cs" />
<Compile Include="GB18030\DirectoryInfoTests.cs" />
<Compile Include="GB18030\DirectoryTestBase.cs" />
<Compile Include="GB18030\DirectoryTests.cs" />
<Compile Include="GB18030\FileInfoTests.cs" />
<Compile Include="GB18030\FileTestBase.cs" />
<Compile Include="GB18030\FileTests.cs" />
<Compile Include="TestDataProvider\TestDataProvider.cs" />
<Compile Include="TextReader\CharArrayTextReader.cs" />
<Compile Include="TextReader\TextReaderTests.cs" />
Expand All @@ -79,4 +85,5 @@
<ItemGroup>
<ProjectReference Include="$(CommonTestPath)StreamConformanceTests\StreamConformanceTests.csproj" />
</ItemGroup>
<Import Project="$(CommonTestPath)ComplianceTests\GB18030\GB18030.Shared.projitems" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public static IEnumerable<object[]> Contains_MemberData() =>
TestHelper.NonOrdinalStringComparisons.Select(comparison => new object[] { testData, comparison }));

[Theory]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
[MemberData(nameof(Contains_MemberData))]
public void Contains(string decoded, StringComparison comparison)
{
Expand Down Expand Up @@ -270,9 +269,9 @@ public void Replace_CultureInfo(string decoded, CultureInfo culture)
string replaced = decoded.Replace(textElement, Dummy, ignoreCase: false, culture);

// '0' (U+0030) and '〇' (U+3007) collate as equal under most cultures. zh-CN normally keeps
// them distinct, but the browser's ICU collation shard treats them as equal there too, so
// them distinct, but the WebAssembly ICU collation shard treats them as equal there too, so
// tolerate the resulting count mismatch wherever that equivalence applies.
bool zeroIdeographicZeroEquivalence = culture.Name != "zh-CN" || PlatformDetection.IsBrowser;
bool zeroIdeographicZeroEquivalence = culture.Name != "zh-CN" || PlatformDetection.IsWasm;
Assert.True(expected == SplitHelper(replaced, Dummy).Length ||
(zeroIdeographicZeroEquivalence && textElement == "\u3007" && decoded.Contains('0')) ||
(zeroIdeographicZeroEquivalence && textElement == "0" && decoded.Contains('\u3007')),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@

<ItemGroup>
<Compile Include="$(CommonTestPath)System\Collections\IEnumerable.Generic.Serialization.Tests.cs" Link="Common\System\Collections\IEnumerable.Generic.Serialization.Tests.cs" />
<Compile Include="GB18030\StringTests.cs" />
<EmbeddedResource Include="System\Reflection\EmbeddedImage.png">
<LogicalName>System.Reflection.Tests.EmbeddedImage.png</LogicalName>
</EmbeddedResource>
Expand Down Expand Up @@ -388,4 +389,5 @@
Private="true"
SetTargetFramework="TargetFramework=$(NetCoreAppMinimum)" />
</ItemGroup>
<Import Project="$(CommonTestPath)ComplianceTests\GB18030\GB18030.Shared.projitems" />
</Project>
Loading
Loading