// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
+using System.Linq;
using Xunit;
namespace System.Text.Tests
{
- public partial class ASCIIEncodingDecode
+ public class ASCIIEncodingDecode
{
public static IEnumerable<object[]> Decode_TestData()
{
}
return new string(chars);
}
+
+ [Theory]
+ [InlineData("hello!", 6)]
+ [InlineData("hello\u1234there!", 16)]
+ [InlineData("\ud800\udc00", 10)]
+ public void GetByteCount_WithReplacementFallback(string input, int expectedByteCount)
+ {
+ Encoding encoding = Encoding.GetEncoding("ascii", new EncoderReplacementFallback("abcde"), DecoderFallback.ExceptionFallback);
+ Assert.Equal(expectedByteCount, encoding.GetByteCount(input));
+ }
+
+ [Fact]
+ public void GetByteCount_WithSingleCharNonAsciiReplacementFallback_ValidatesAscii()
+ {
+ // Tests trying to replace one non-ASCII character with another, which should cause
+ // fallback logic to identify the invalid data and abort the operation.
+
+ Encoding encoding = Encoding.GetEncoding("ascii", new EncoderReplacementFallback("\u1234"), DecoderFallback.ExceptionFallback);
+ Assert.Throws<ArgumentException>("chars", () => encoding.GetByteCount("\u0080"));
+ }
+
+ [Theory]
+ [InlineData("hello!", "hello!")]
+ [InlineData("hello\u1234there!", "helloabcdethere!")]
+ [InlineData("\ud800\udc00", "abcdeabcde")]
+ public void GetBytes_WithReplacementFallback(string input, string expectedResult)
+ {
+ Encoding encoding = Encoding.GetEncoding("ascii", new EncoderReplacementFallback("abcde"), DecoderFallback.ExceptionFallback);
+ Assert.Equal(WideToAsciiStr(expectedResult), encoding.GetBytes(input));
+ }
+
+ [Fact]
+ public void GetBytes_WithNonAsciiInput_AndSingleCharNonAsciiReplacementFallback_Throws()
+ {
+ // Tests trying to replace one non-ASCII character with another, which should cause
+ // fallback logic to identify the invalid data and abort the operation.
+
+ Encoding encoding = Encoding.GetEncoding("ascii", new EncoderReplacementFallback("\u1234"), DecoderFallback.ExceptionFallback);
+ Assert.Throws<ArgumentException>("chars", () => encoding.GetBytes("\u0080"));
+ }
+
+ private static byte[] WideToAsciiStr(string input)
+ {
+ return input.Select(ch => (byte)checked((sbyte)ch)).ToArray(); // makes sure each char is 00..7F
+ }
}
}
+++ /dev/null
-// 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.Linq;
-using Xunit;
-
-namespace System.Text.Tests
-{
- public partial class ASCIIEncodingDecode
- {
- [Theory]
- [InlineData("hello!", 6)]
- [InlineData("hello\u1234there!", 16)]
- [InlineData("\ud800\udc00", 10)]
- public void GetByteCount_WithReplacementFallback(string input, int expectedByteCount)
- {
- Encoding encoding = Encoding.GetEncoding("ascii", new EncoderReplacementFallback("abcde"), DecoderFallback.ExceptionFallback);
- Assert.Equal(expectedByteCount, encoding.GetByteCount(input));
- }
-
- [Fact]
- public void GetByteCount_WithSingleCharNonAsciiReplacementFallback_ValidatesAscii()
- {
- // Tests trying to replace one non-ASCII character with another, which should cause
- // fallback logic to identify the invalid data and abort the operation.
-
- Encoding encoding = Encoding.GetEncoding("ascii", new EncoderReplacementFallback("\u1234"), DecoderFallback.ExceptionFallback);
- Assert.Throws<ArgumentException>("chars", () => encoding.GetByteCount("\u0080"));
- }
-
- [Theory]
- [InlineData("hello!", "hello!")]
- [InlineData("hello\u1234there!", "helloabcdethere!")]
- [InlineData("\ud800\udc00", "abcdeabcde")]
- public void GetBytes_WithReplacementFallback(string input, string expectedResult)
- {
- Encoding encoding = Encoding.GetEncoding("ascii", new EncoderReplacementFallback("abcde"), DecoderFallback.ExceptionFallback);
- Assert.Equal(WideToAsciiStr(expectedResult), encoding.GetBytes(input));
- }
-
- [Fact]
- public void GetBytes_WithNonAsciiInput_AndSingleCharNonAsciiReplacementFallback_Throws()
- {
- // Tests trying to replace one non-ASCII character with another, which should cause
- // fallback logic to identify the invalid data and abort the operation.
-
- Encoding encoding = Encoding.GetEncoding("ascii", new EncoderReplacementFallback("\u1234"), DecoderFallback.ExceptionFallback);
- Assert.Throws<ArgumentException>("chars", () => encoding.GetBytes("\u0080"));
- }
-
- private static byte[] WideToAsciiStr(string input)
- {
- return input.Select(ch => (byte)checked((sbyte)ch)).ToArray(); // makes sure each char is 00..7F
- }
- }
-}
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
+using System.Linq;
using Xunit;
namespace System.Text.Tests
{
- public partial class ASCIIEncodingEncode
+ public class ASCIIEncodingEncode
{
public static IEnumerable<object[]> Encode_TestData()
{
}
return bytes;
}
+
+ [Theory]
+ [InlineData("hello!", 6)]
+ [InlineData("hello\u0080there!", 16)]
+ [InlineData("\u00ff\u00ff", 10)]
+ public void GetCharCount_WithReplacementFallback(string input, int expectedCharCount)
+ {
+ Encoding encoding = Encoding.GetEncoding("ascii", EncoderFallback.ExceptionFallback, new DecoderReplacementFallback("abcde"));
+ Assert.Equal(expectedCharCount, encoding.GetCharCount(WideToNarrowStr(input)));
+ }
+
+ [Fact]
+ public void GetCharCount_WithInvalidFallbackBuffer_ValidatesAscii()
+ {
+ // Internal fallback logic should notice that we're about to write out a standalone
+ // surrogate character and should abort the operation.
+
+ Encoding encoding = Encoding.GetEncoding("ascii", EncoderFallback.ExceptionFallback, new StandaloneLowSurrogateDecoderFallback());
+ Assert.Throws<ArgumentException>(() => encoding.GetCharCount(new byte[] { 0x80 }));
+ }
+
+ [Theory]
+ [InlineData("hello!", "hello!")]
+ [InlineData("hello\u0080there!", "helloabcdethere!")]
+ [InlineData("\u00ff\u00ff", "abcdeabcde")]
+ public void GetChars_WithReplacementFallback(string input, string expectedResult)
+ {
+ Encoding encoding = Encoding.GetEncoding("ascii", EncoderFallback.ExceptionFallback, new DecoderReplacementFallback("abcde"));
+ Assert.Equal(expectedResult, encoding.GetChars(WideToNarrowStr(input)));
+ }
+
+ [Fact]
+ public void GetChars_WithNonAsciiInput_AndSingleCharNonAsciiReplacementFallback_Throws()
+ {
+ // Internal fallback logic should notice that we're about to write out a standalone
+ // surrogate character and should abort the operation.
+
+ Encoding encoding = Encoding.GetEncoding("ascii", EncoderFallback.ExceptionFallback, new StandaloneLowSurrogateDecoderFallback());
+ Assert.Throws<ArgumentException>(() => encoding.GetChars(new byte[] { 0x80 }));
+ }
+
+ private static byte[] WideToNarrowStr(string input)
+ {
+ return input.Select(ch => checked((byte)ch)).ToArray(); // makes sure each char is 00..FF
+ }
+
+ private class StandaloneLowSurrogateDecoderFallback : DecoderFallback
+ {
+ public override int MaxCharCount => 1;
+
+ public override DecoderFallbackBuffer CreateFallbackBuffer()
+ {
+ return new InnerFallbackBuffer();
+ }
+
+ private class InnerFallbackBuffer : DecoderFallbackBuffer
+ {
+ private int _remaining;
+
+ public override int Remaining => _remaining;
+
+ public override bool Fallback(byte[] bytesUnknown, int index)
+ {
+ _remaining = 1;
+ return true;
+ }
+
+ public override char GetNextChar()
+ {
+ // Return a standalone low surrogate
+ return (--_remaining >= 0) ? '\udc00' : default;
+ }
+
+ public override bool MovePrevious()
+ {
+ throw new NotImplementedException();
+ }
+ }
+ }
}
}
+++ /dev/null
-// 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.Linq;
-using Xunit;
-
-namespace System.Text.Tests
-{
- public partial class ASCIIEncodingEncode
- {
- [Theory]
- [InlineData("hello!", 6)]
- [InlineData("hello\u0080there!", 16)]
- [InlineData("\u00ff\u00ff", 10)]
- public void GetCharCount_WithReplacementFallback(string input, int expectedCharCount)
- {
- Encoding encoding = Encoding.GetEncoding("ascii", EncoderFallback.ExceptionFallback, new DecoderReplacementFallback("abcde"));
- Assert.Equal(expectedCharCount, encoding.GetCharCount(WideToNarrowStr(input)));
- }
-
- [Fact]
- public void GetCharCount_WithInvalidFallbackBuffer_ValidatesAscii()
- {
- // Internal fallback logic should notice that we're about to write out a standalone
- // surrogate character and should abort the operation.
-
- Encoding encoding = Encoding.GetEncoding("ascii", EncoderFallback.ExceptionFallback, new StandaloneLowSurrogateDecoderFallback());
- Assert.Throws<ArgumentException>(() => encoding.GetCharCount(new byte[] { 0x80 }));
- }
-
- [Theory]
- [InlineData("hello!", "hello!")]
- [InlineData("hello\u0080there!", "helloabcdethere!")]
- [InlineData("\u00ff\u00ff", "abcdeabcde")]
- public void GetChars_WithReplacementFallback(string input, string expectedResult)
- {
- Encoding encoding = Encoding.GetEncoding("ascii", EncoderFallback.ExceptionFallback, new DecoderReplacementFallback("abcde"));
- Assert.Equal(expectedResult, encoding.GetChars(WideToNarrowStr(input)));
- }
-
- [Fact]
- public void GetChars_WithNonAsciiInput_AndSingleCharNonAsciiReplacementFallback_Throws()
- {
- // Internal fallback logic should notice that we're about to write out a standalone
- // surrogate character and should abort the operation.
-
- Encoding encoding = Encoding.GetEncoding("ascii", EncoderFallback.ExceptionFallback, new StandaloneLowSurrogateDecoderFallback());
- Assert.Throws<ArgumentException>(() => encoding.GetChars(new byte[] { 0x80 }));
- }
-
- private static byte[] WideToNarrowStr(string input)
- {
- return input.Select(ch => checked((byte)ch)).ToArray(); // makes sure each char is 00..FF
- }
-
- private class StandaloneLowSurrogateDecoderFallback : DecoderFallback
- {
- public override int MaxCharCount => 1;
-
- public override DecoderFallbackBuffer CreateFallbackBuffer()
- {
- return new InnerFallbackBuffer();
- }
-
- private class InnerFallbackBuffer : DecoderFallbackBuffer
- {
- private int _remaining;
-
- public override int Remaining => _remaining;
-
- public override bool Fallback(byte[] bytesUnknown, int index)
- {
- _remaining = 1;
- return true;
- }
-
- public override char GetNextChar()
- {
- // Return a standalone low surrogate
- return (--_remaining >= 0) ? '\udc00' : default;
- }
-
- public override bool MovePrevious()
- {
- throw new NotImplementedException();
- }
- }
- }
- }
-}
namespace System.Text.Encodings.Tests
{
- public partial class DecoderTests
+ public class DecoderTests
{
[Fact]
public static void GetCharCount_Span_MatchesEncodingCharCount()
namespace System.Text.Encodings.Tests
{
- public partial class EncoderTests
+ public class EncoderTests
{
[Fact]
public static void GetByteCount_Span_MatchesEncodingByteCount()
namespace System.Text.Tests
{
- public static partial class EncodingHelpers
+ public static class EncodingHelpers
{
public static void Encode(Encoding encoding, string chars, int index, int count, byte[] expected)
{
Assert.Equal(expected, encoding.GetString(bytes, index, count));
}
- // 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);
+ static 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.AsSpan(index, count)));
+
+ if (count == 0)
+ Assert.Equal(expected, encoding.GetByteCount(ReadOnlySpan<char>.Empty));
+ }
+
+ static 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.AsSpan(index, count), (Span<byte>)stringResultAdvanced));
+ VerifyGetBytes(stringResultAdvanced, 0, stringResultAdvanced.Length, new byte[expected.Length], expected);
+
+ if (count == 0)
+ Assert.Equal(expected.Length, encoding.GetBytes(ReadOnlySpan<char>.Empty, (Span<byte>)stringResultAdvanced));
+ }
+
+ static 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)));
+
+ if (count == 0)
+ Assert.Equal(expected, encoding.GetCharCount(ReadOnlySpan<byte>.Empty));
+ }
+
+ static 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);
+
+ if (byteCount == 0)
+ {
+ charCount = encoding.GetChars(ReadOnlySpan<byte>.Empty, new Span<char>(byteChars).Slice(charIndex));
+ Assert.Equal(expectedChars.Length, charCount);
+ }
+ }
+
+ static 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)));
+
+ if (count == 0)
+ Assert.Equal(expected, encoding.GetString(ReadOnlySpan<byte>.Empty));
+ }
}
}
+++ /dev/null
-// 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.Tests
-{
- public static partial class EncodingHelpers
- {
- 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.AsSpan(index, count)));
-
- if (count == 0)
- Assert.Equal(expected, encoding.GetByteCount(ReadOnlySpan<char>.Empty));
- }
-
- 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.AsSpan(index, count), (Span<byte>)stringResultAdvanced));
- VerifyGetBytes(stringResultAdvanced, 0, stringResultAdvanced.Length, new byte[expected.Length], expected);
-
- if (count == 0)
- Assert.Equal(expected.Length, encoding.GetBytes(ReadOnlySpan<char>.Empty, (Span<byte>)stringResultAdvanced));
- }
-
- 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)));
-
- if (count == 0)
- Assert.Equal(expected, encoding.GetCharCount(ReadOnlySpan<byte>.Empty));
- }
-
- 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);
-
- if (byteCount == 0)
- {
- charCount = encoding.GetChars(ReadOnlySpan<byte>.Empty, new Span<char>(byteChars).Slice(charIndex));
- 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)));
-
- if (count == 0)
- Assert.Equal(expected, encoding.GetString(ReadOnlySpan<byte>.Empty));
- }
- }
-}
// 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;
using System.Collections.Generic;
using Xunit;
namespace System.Text.Tests
{
- public static partial class NegativeEncodingTests
+ public static class NegativeEncodingTests
{
public static IEnumerable<object[]> Encodings_TestData()
{
AssertExtensions.Throws<ArgumentException>("chars", () => decoder.Convert(new byte[4], 0, 4, new char[0], 0, 0, flush, out charsUsed, out bytesUsed, out completed));
VerifyOutParams();
}
+
+ [Theory]
+ [MemberData(nameof(Encodings_TestData))]
+ public static unsafe void GetByteCount_Invalid_NetCoreApp(Encoding encoding)
+ {
+ // Chars is null
+ AssertExtensions.Throws<ArgumentNullException>("s", () => encoding.GetByteCount((string)null, 0, 0));
+
+ // Index < 0
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetByteCount("abc", -1, 0));
+
+ // Count < 0
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => encoding.GetByteCount("abc", 0, -1));
+
+ // Index + count > chars.Length
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetByteCount("abc", 0, 4));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetByteCount("abc", 1, 3));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetByteCount("abc", 2, 2));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetByteCount("abc", 3, 1));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetByteCount("abc", 4, 0));
+ }
+
+ [Theory]
+ [MemberData(nameof(Encodings_TestData))]
+ public static unsafe void GetBytes_Invalid_NetCoreApp(Encoding encoding)
+ {
+ // Source is null
+ AssertExtensions.Throws<ArgumentNullException>("s", () => encoding.GetBytes((string)null, 0, 0));
+
+ // CharIndex < 0
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetBytes("a", -1, 0));
+
+ // CharCount < 0
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => encoding.GetBytes("a", 0, -1));
+
+ // CharIndex + charCount > source.Length
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetBytes("a", 2, 0));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetBytes("a", 1, 1));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetBytes("a", 0, 2));
+ }
}
public class HighMaxCharCountEncoderFallback : EncoderFallback
+++ /dev/null
-// 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;
-using System.Collections.Generic;
-using Xunit;
-
-namespace System.Text.Tests
-{
- public static partial class NegativeEncodingTests
- {
- [Theory]
- [MemberData(nameof(Encodings_TestData))]
- public static unsafe void GetByteCount_Invalid_NetCoreApp(Encoding encoding)
- {
- // Chars is null
- AssertExtensions.Throws<ArgumentNullException>("s", () => encoding.GetByteCount((string)null, 0, 0));
-
- // Index < 0
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetByteCount("abc", -1, 0));
-
- // Count < 0
- AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => encoding.GetByteCount("abc", 0, -1));
-
- // Index + count > chars.Length
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetByteCount("abc", 0, 4));
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetByteCount("abc", 1, 3));
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetByteCount("abc", 2, 2));
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetByteCount("abc", 3, 1));
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetByteCount("abc", 4, 0));
- }
-
- [Theory]
- [MemberData(nameof(Encodings_TestData))]
- public static unsafe void GetBytes_Invalid_NetCoreApp(Encoding encoding)
- {
- // Source is null
- AssertExtensions.Throws<ArgumentNullException>("s", () => encoding.GetBytes((string)null, 0, 0));
-
- // CharIndex < 0
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetBytes("a", -1, 0));
-
- // CharCount < 0
- AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => encoding.GetBytes("a", 0, -1));
-
- // CharIndex + charCount > source.Length
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetBytes("a", 2, 0));
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetBytes("a", 1, 1));
- AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetBytes("a", 0, 2));
- }
- }
-}
<ItemGroup>
<Compile Include="ASCIIEncoding\ASCIIEncodingEncode.cs" />
<Compile Include="ASCIIEncoding\ASCIIEncodingDecode.cs" />
- <Compile Include="ASCIIEncoding\ASCIIEncodingEncode.netcoreapp.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
- <Compile Include="ASCIIEncoding\ASCIIEncodingDecode.netcoreapp.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
<Compile Include="ASCIIEncoding\ASCIIEncodingGetDecoder.cs" />
<Compile Include="ASCIIEncoding\ASCIIEncodingGetEncoder.cs" />
<Compile Include="ASCIIEncoding\ASCIIEncodingGetMaxByteCount.cs" />
<Compile Include="ASCIIEncoding\ASCIIEncodingGetMaxCharCount.cs" />
<Compile Include="ASCIIEncoding\ASCIIEncodingTests.cs" />
- <Compile Include="Decoder\DecoderSpanTests.netcoreapp.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
+ <Compile Include="Decoder\DecoderSpanTests.cs" />
<Compile Include="Decoder\DecoderConvert2.cs" />
<Compile Include="Decoder\DecoderCtor.cs" />
<Compile Include="Decoder\DecoderGetCharCount2.cs" />
<Compile Include="DecoderFallback\DecoderFallbackTests.cs" />
<Compile Include="DecoderFallbackException\DecoderFallbackExceptionTests.cs" />
<Compile Include="EncoderFallbackException\EncoderFallbackExceptionTests.cs" />
- <Compile Include="Encoder\EncoderSpanTests.netcoreapp.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
+ <Compile Include="Encoder\EncoderSpanTests.cs" />
<Compile Include="Encoder\EncoderConvert2.cs" />
<Compile Include="Encoder\EncoderCtor.cs" />
<Compile Include="Encoder\EncoderGetByteCount2.cs" />
<Compile Include="Fallback\EncoderExceptionFallbackTests.cs" />
<Compile Include="Fallback\DecoderExceptionFallbackTests.cs" />
<Compile Include="NegativeEncodingTests.cs" />
- <Compile Include="NegativeEncodingTests.netcoreapp.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
<Compile Include="EncodingTestHelpers.cs" />
- <Compile Include="EncodingTestHelpers.netcoreapp.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
<Compile Include="Latin1Encoding\Latin1EncodingEncode.cs" />
<Compile Include="Latin1Encoding\Latin1EncodingDecode.cs" />
<Compile Include="Latin1Encoding\Latin1EncodingGetMaxByteCount.cs" />