You've already forked linux-packaging-mono
Imported Upstream version 5.10.0.47
Former-commit-id: d0813289fa2d35e1f8ed77530acb4fb1df441bc0
This commit is contained in:
parent
88ff76fe28
commit
e46a49ecf1
@@ -37,7 +37,7 @@ namespace System.Text.Tests
|
||||
private const int c_SIZE_OF_ARRAY = 127;
|
||||
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
|
||||
|
||||
// PosTest1: Call Convert to convert a arbitrary byte array to character array by using ASCII decoder
|
||||
// PosTest1: Call Convert to convert an arbitrary byte array to character array by using ASCII decoder
|
||||
[Fact]
|
||||
public void PosTest1()
|
||||
{
|
||||
@@ -59,7 +59,7 @@ namespace System.Text.Tests
|
||||
decoder.Reset();
|
||||
}
|
||||
|
||||
// PosTest2: Call Convert to convert a arbitrary byte array to character array by using Unicode decoder"
|
||||
// PosTest2: Call Convert to convert an arbitrary byte array to character array by using Unicode decoder"
|
||||
[Fact]
|
||||
public void PosTest2()
|
||||
{
|
||||
|
||||
57
external/corefx/src/System.Text.Encoding/tests/Decoder/DecoderSpanTests.netcoreapp.cs
vendored
Normal file
57
external/corefx/src/System.Text.Encoding/tests/Decoder/DecoderSpanTests.netcoreapp.cs
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
// 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 Xunit;
|
||||
|
||||
namespace System.Text.Encodings.Tests
|
||||
{
|
||||
public partial class DecoderTests
|
||||
{
|
||||
[Fact]
|
||||
public static void GetCharCount_Span_MatchesEncodingCharCount()
|
||||
{
|
||||
const string TextString = "hello world";
|
||||
Encoding e = Encoding.UTF8;
|
||||
byte[] textBytes = e.GetBytes(TextString);
|
||||
|
||||
Assert.Equal(TextString.Length, e.GetDecoder().GetCharCount(textBytes.AsSpan(), flush: true));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void GetChars_Span_MatchesEncodingGetChars()
|
||||
{
|
||||
const string TextString = "hello world";
|
||||
Encoding e = Encoding.UTF8;
|
||||
byte[] textBytes = e.GetBytes(TextString);
|
||||
|
||||
char[] chars = new char[TextString.Length];
|
||||
Assert.Equal(chars.Length, e.GetDecoder().GetChars(textBytes.AsReadOnlySpan(), chars.AsSpan(), flush: true));
|
||||
Assert.Equal(TextString, new string(chars));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void Convert_Span_MatchesGetChars()
|
||||
{
|
||||
const string TextString = "hello world";
|
||||
Encoding e = Encoding.UTF8;
|
||||
Decoder decoder = e.GetDecoder();
|
||||
byte[] textBytes = e.GetBytes(TextString);
|
||||
char[] chars;
|
||||
|
||||
chars = new char[TextString.Length];
|
||||
decoder.Convert(textBytes.AsSpan(), chars.AsSpan().Slice(0, 2), true, out int bytesUsed, out int charsUsed, out bool completed);
|
||||
Assert.Equal("he", new string(chars, 0, 2));
|
||||
Assert.Equal(2, bytesUsed);
|
||||
Assert.Equal(2, charsUsed);
|
||||
Assert.False(completed);
|
||||
|
||||
chars = new char[TextString.Length];
|
||||
decoder.Convert(textBytes.AsSpan(), chars.AsSpan(), true, out bytesUsed, out charsUsed, out completed);
|
||||
Assert.Equal(TextString, new string(chars));
|
||||
Assert.Equal(textBytes.Length, bytesUsed);
|
||||
Assert.Equal(TextString.Length, charsUsed);
|
||||
Assert.True(completed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ namespace System.Text.Tests
|
||||
yield return new object[] { Encoding.Unicode.GetEncoder(), 2 };
|
||||
}
|
||||
|
||||
// Call Convert to convert a arbitrary character array encoders
|
||||
// Call Convert to convert an arbitrary character array encoders
|
||||
[Theory]
|
||||
[MemberData(nameof(Encoders_RandomInput))]
|
||||
public void EncoderConvertRandomCharArray(Encoder encoder)
|
||||
|
||||
53
external/corefx/src/System.Text.Encoding/tests/Encoder/EncoderSpanTests.netcoreapp.cs
vendored
Normal file
53
external/corefx/src/System.Text.Encoding/tests/Encoder/EncoderSpanTests.netcoreapp.cs
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
// 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 Xunit;
|
||||
|
||||
namespace System.Text.Encodings.Tests
|
||||
{
|
||||
public partial class EncoderTests
|
||||
{
|
||||
[Fact]
|
||||
public static void GetByteCount_Span_MatchesEncodingByteCount()
|
||||
{
|
||||
const string TextString = "hello world";
|
||||
Encoding e = Encoding.UTF8;
|
||||
Assert.Equal(e.GetByteCount(TextString), e.GetEncoder().GetByteCount(TextString.AsReadOnlySpan(), flush: true));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void GetBytes_Span_MatchesEncodingGetBytes()
|
||||
{
|
||||
const string TextString = "hello world";
|
||||
Encoding e = Encoding.UTF8;
|
||||
|
||||
byte[] bytes = new byte[e.GetByteCount(TextString)];
|
||||
Assert.Equal(bytes.Length, e.GetEncoder().GetBytes(TextString.AsReadOnlySpan(), bytes, flush: true));
|
||||
Assert.Equal(e.GetBytes(TextString), bytes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void Convert_Span_MatchesGetBytes()
|
||||
{
|
||||
const string TextString = "hello world";
|
||||
Encoding encoding = Encoding.UTF8;
|
||||
Encoder encoder = encoding.GetEncoder();
|
||||
byte[] bytes;
|
||||
|
||||
bytes = new byte[encoding.GetByteCount(TextString)];
|
||||
encoder.Convert(TextString.AsReadOnlySpan(), bytes.AsSpan().Slice(0, 2), true, out int charsUsed, out int bytesUsed, out bool completed);
|
||||
Assert.Equal(encoding.GetBytes(TextString).AsSpan().Slice(0, 2).ToArray(), bytes.AsSpan().Slice(0, 2).ToArray());
|
||||
Assert.Equal(2, charsUsed);
|
||||
Assert.Equal(2, bytesUsed);
|
||||
Assert.False(completed);
|
||||
|
||||
bytes = new byte[encoding.GetByteCount(TextString)];
|
||||
encoder.Convert(TextString.AsReadOnlySpan(), bytes, true, out charsUsed, out bytesUsed, out completed);
|
||||
Assert.Equal(encoding.GetBytes(TextString), bytes);
|
||||
Assert.Equal(TextString.Length, charsUsed);
|
||||
Assert.Equal(bytes.Length, bytesUsed);
|
||||
Assert.True(completed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace System.Text.Encodings.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Full framework uses system ACP and not UTF8")]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework | TargetFrameworkMonikers.Mono, "Full framework uses system ACP and not UTF8")]
|
||||
public static void DefaultEncodingBOMTest()
|
||||
{
|
||||
UTF8Encoding defaultEncoding = Encoding.Default as UTF8Encoding;
|
||||
@@ -61,7 +61,9 @@ namespace System.Text.Encodings.Tests
|
||||
{
|
||||
Encoding encoding = Encoding.GetEncoding(info.CodePage);
|
||||
Assert.Equal(encoding, info.GetEncoding());
|
||||
#if !MONO // https://bugzilla.xamarin.com/show_bug.cgi?id=60202
|
||||
Assert.Equal(encoding.WebName, info.Name);
|
||||
#endif
|
||||
Assert.False(String.IsNullOrEmpty(info.DisplayName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +123,9 @@ namespace System.Text.Tests
|
||||
GetCharCount(encoding, bytes, index, count, expected.Length);
|
||||
GetChars(encoding, bytes, index, count, expected.ToCharArray());
|
||||
GetString(encoding, bytes, index, count, expected);
|
||||
|
||||
GetCharCount_NetCoreApp(encoding, bytes, index, count, expected.Length);
|
||||
GetString_NetCoreApp(encoding, bytes, index, count, expected);
|
||||
}
|
||||
|
||||
private static unsafe void GetCharCount(Encoding encoding, byte[] bytes, int index, int count, int expected)
|
||||
@@ -145,8 +148,7 @@ namespace System.Text.Tests
|
||||
}
|
||||
}
|
||||
|
||||
private static void GetChars(Encoding encoding, byte[] bytes, int index, int count, char[]
|
||||
expectedChars)
|
||||
private static void GetChars(Encoding encoding, byte[] bytes, int index, int count, char[] expectedChars)
|
||||
{
|
||||
char[] fullArray = new char[expectedChars.Length + 4];
|
||||
for (int i = 0; i < fullArray.Length; i++)
|
||||
@@ -197,6 +199,8 @@ namespace System.Text.Tests
|
||||
}
|
||||
VerifyGetChars(bytePointerChars, charIndex, charCount, originalChars, expectedChars);
|
||||
}
|
||||
|
||||
VerifyGetChars_NetCoreApp(encoding, bytes, byteIndex, byteCount, chars, charIndex, expectedChars);
|
||||
}
|
||||
|
||||
private static void VerifyGetChars(char[] chars, int charIndex, int charCount, char[] originalChars, char[] expectedChars)
|
||||
@@ -228,12 +232,11 @@ namespace System.Text.Tests
|
||||
Assert.Equal(expected, encoding.GetString(bytes, index, count));
|
||||
}
|
||||
|
||||
#if !netcoreapp
|
||||
// Netcoreapp adds GetByteCount(string, int, int) and GetBytes(string, int, int) APIs.
|
||||
// To use the common data from the Encode(...) entry point to these tests, we can define stubs that
|
||||
// do nothing with netfx or netstandard. However, these are defined (they test the new APIs) with netcoreapp.
|
||||
private static void GetByteCount_NetCoreApp(Encoding encoding, string chars, int index, int count, int expected) {}
|
||||
private static void GetBytes_NetCoreApp(Encoding encoding, string chars, int index, int count, byte[] expected) {}
|
||||
#endif
|
||||
// Netcoreapp adds several Encoding members.
|
||||
static partial void GetByteCount_NetCoreApp(Encoding encoding, string chars, int index, int count, int expected);
|
||||
static partial void GetBytes_NetCoreApp(Encoding encoding, string chars, int index, int count, byte[] expected);
|
||||
static partial void GetCharCount_NetCoreApp(Encoding encoding, byte[] bytes, int index, int count, int expected);
|
||||
static partial void VerifyGetChars_NetCoreApp(Encoding encoding, byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, char[] expectedChars);
|
||||
static partial void GetString_NetCoreApp(Encoding encoding, byte[] bytes, int index, int count, string expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,46 @@ namespace System.Text.Tests
|
||||
{
|
||||
public static partial class EncodingHelpers
|
||||
{
|
||||
private static void GetByteCount_NetCoreApp(Encoding encoding, string chars, int index, int count, int expected)
|
||||
static partial void GetByteCount_NetCoreApp(Encoding encoding, string chars, int index, int count, int expected)
|
||||
{
|
||||
// Use GetByteCount(string, int, int)
|
||||
Assert.Equal(expected, encoding.GetByteCount(chars, index, count));
|
||||
|
||||
// Use GetByteCount(ReadOnlySpan<char> chars)
|
||||
Assert.Equal(expected, encoding.GetByteCount(chars.AsReadOnlySpan().Slice(index, count)));
|
||||
}
|
||||
|
||||
private static void GetBytes_NetCoreApp(Encoding encoding, string chars, int index, int count, byte[] expected)
|
||||
static partial void GetBytes_NetCoreApp(Encoding encoding, string chars, int index, int count, byte[] expected)
|
||||
{
|
||||
// Use GetBytes(string, int, int)
|
||||
byte[] stringResultAdvanced = encoding.GetBytes(chars, index, count);
|
||||
VerifyGetBytes(stringResultAdvanced, 0, stringResultAdvanced.Length, new byte[expected.Length], expected);
|
||||
|
||||
// Use GetBytes(ReadOnlySpan<char>, Span<byte>)
|
||||
Array.Clear(stringResultAdvanced, 0, stringResultAdvanced.Length);
|
||||
Assert.Equal(expected.Length, encoding.GetBytes(chars.AsReadOnlySpan().Slice(index, count), (Span<byte>)stringResultAdvanced));
|
||||
VerifyGetBytes(stringResultAdvanced, 0, stringResultAdvanced.Length, new byte[expected.Length], expected);
|
||||
}
|
||||
|
||||
static partial void GetCharCount_NetCoreApp(Encoding encoding, byte[] bytes, int index, int count, int expected)
|
||||
{
|
||||
// Use GetCharCount(ReadOnlySpan<byte>)
|
||||
Assert.Equal(expected, encoding.GetCharCount(new ReadOnlySpan<byte>(bytes, index, count)));
|
||||
}
|
||||
|
||||
static partial void VerifyGetChars_NetCoreApp(Encoding encoding, byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, char[] expectedChars)
|
||||
{
|
||||
// Use GetChars(ReadOnlySpan<byte>, Span<char>)
|
||||
char[] byteChars = (char[])chars.Clone();
|
||||
int charCount = encoding.GetChars(new ReadOnlySpan<byte>(bytes, byteIndex, byteCount), new Span<char>(byteChars).Slice(charIndex));
|
||||
VerifyGetChars(byteChars, charIndex, charCount, (char[])chars.Clone(), expectedChars);
|
||||
Assert.Equal(expectedChars.Length, charCount);
|
||||
}
|
||||
|
||||
static partial void GetString_NetCoreApp(Encoding encoding, byte[] bytes, int index, int count, string expected)
|
||||
{
|
||||
// Use GetString(ReadOnlySpan<byte>)
|
||||
Assert.Equal(expected, encoding.GetString(new ReadOnlySpan<byte>(bytes, index, count)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
8
external/corefx/src/System.Text.Encoding/tests/Performance/Configurations.props
vendored
Normal file
8
external/corefx/src/System.Text.Encoding/tests/Performance/Configurations.props
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
netcoreapp;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -19,6 +19,7 @@
|
||||
<Compile Include="ASCIIEncoding\ASCIIEncodingGetMaxByteCount.cs" />
|
||||
<Compile Include="ASCIIEncoding\ASCIIEncodingGetMaxCharCount.cs" />
|
||||
<Compile Include="ASCIIEncoding\ASCIIEncodingTests.cs" />
|
||||
<Compile Include="Decoder\DecoderSpanTests.netcoreapp.cs" Condition="'$(TargetGroup)'=='netcoreapp'" />
|
||||
<Compile Include="Decoder\DecoderConvert2.cs" />
|
||||
<Compile Include="Decoder\DecoderCtor.cs" />
|
||||
<Compile Include="Decoder\DecoderGetCharCount2.cs" />
|
||||
@@ -28,6 +29,7 @@
|
||||
<Compile Include="Decoder\DecoderReset.cs" />
|
||||
<Compile Include="DecoderFallbackException\DecoderFallbackExceptionTests.cs" />
|
||||
<Compile Include="EncoderFallbackException\EncoderFallbackExceptionTests.cs" />
|
||||
<Compile Include="Encoder\EncoderSpanTests.netcoreapp.cs" Condition="'$(TargetGroup)'=='netcoreapp'" />
|
||||
<Compile Include="Encoder\EncoderConvert2.cs" />
|
||||
<Compile Include="Encoder\EncoderCtor.cs" />
|
||||
<Compile Include="Encoder\EncoderGetByteCount2.cs" />
|
||||
|
||||
@@ -99,7 +99,9 @@ namespace System.Text.Tests
|
||||
yield return new object[] { new byte[] { 84, 0, 101, 0, 115, 0, 116, 0, 84, 0, 101, 0, 115, 0, 116, 0, 3, 216 }, 0, 17, "TestTest\uFFFD" };
|
||||
|
||||
yield return new object[] { new byte[] { 84, 0, 0, 0, 84, 0, 101, 0, 10, 0, 115, 0, 116, 0, 0, 0, 9, 0, 0, 0, 84, 0, 15, 0, 101, 0, 115, 0, 116, 0, 0, 0, 0 }, 0, 33, "T\0Te\nst\0\t\0T\u000Fest\0\uFFFD" };
|
||||
|
||||
|
||||
yield return new object[] { new byte[] { 0, 0, 84, 0, 101, 0, 10, 0, 115, 0, 116, 0, 0, 0, 9, 0, 0, 0, 84, 0, 15, 0, 101, 0, 115, 0, 116, 0, 0, 0, 0 }, 0, 31, "\0Te\nst\0\t\0T\u000Fest\0\uFFFD" };
|
||||
|
||||
yield return new object[] { new byte[] { 3, 216, 84 }, 0, 3, "\uFFFD\uFFFD" };
|
||||
|
||||
// Invalid surrogate bytes
|
||||
|
||||
Reference in New Issue
Block a user