int charsUsedTotal = 0;
foreach (ReadOnlyMemory<char> chunk in _readLineSB.GetChunks())
{
+ Debug.Assert(!buffer.IsEmpty);
+
encoder.Convert(chunk.Span, buffer, flush: false, out int charsUsed, out int bytesUsed, out bool completed);
buffer = buffer.Slice(bytesUsed);
bytesUsedTotal += bytesUsed;
charsUsedTotal += charsUsed;
- if (charsUsed == 0)
+ if (!completed || buffer.IsEmpty)
{
break;
}
using System.Diagnostics;
using System.Threading.Tasks;
using System.IO;
+using System.Text;
using Xunit;
namespace System
}
[ConditionalFact(nameof(ManualTestsEnabled))]
+ public static void ReadFromOpenStandardInput()
+ {
+ // The implementation in StdInReader uses a StringBuilder for caching. We want this builder to use
+ // multiple chunks. So the expectedLine is longer than 16 characters (StringBuilder.DefaultCapacity).
+ string expectedLine = $"This is a test for ReadFromOpenStandardInput.";
+ Assert.True(expectedLine.Length > new StringBuilder().Capacity);
+ Console.WriteLine($"Please type the sentence (without the quotes): \"{expectedLine}\"");
+ using Stream inputStream = Console.OpenStandardInput();
+ for (int i = 0; i < expectedLine.Length; i++)
+ {
+ Assert.Equal((byte)expectedLine[i], inputStream.ReadByte());
+ }
+ Assert.Equal((byte)'\n', inputStream.ReadByte());
+ AssertUserExpectedResults("the characters you typed properly echoed as you typed");
+ }
+
+ [ConditionalFact(nameof(ManualTestsEnabled))]
public static void ConsoleReadSupportsBackspace()
{
const string expectedLine = "aab\r";