1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-09 23:25:43 +00:00

[ci skip] docs: add comment explaining my absolute pain

This commit is contained in:
Oliver Booth 2023-04-06 19:18:20 +01:00
parent 9d26f3da60
commit 57ff32ee94
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025

View File

@ -15,6 +15,17 @@ public partial class TextWriterTests
{ {
_stream = new MemoryStream(); _stream = new MemoryStream();
_writer = new StreamWriter(_stream, Encoding.UTF8); _writer = new StreamWriter(_stream, Encoding.UTF8);
// When StreamWriter flushes for the first time, an encoding preamble is written to the stream,
// which is correctly mirrored by the behaviour of StreamReader.
// however, we're not using StreamReader, we read the contents of the stream
// using MemoryStream.ToArray(). This was causing one test to fail, as the first test
// that runs would cause the preamble to be written and not be accounted for when reading.
// Subsequent tests would pass since the preamble would not be written again.
// The following 4 lines ensure that the preamble is written by manually flushing the
// writer after writing a single space character. We then clear the stream, and allow
// unit tests to do their thing. This took me an HOUR AND A HALF to narrow down.
// I want to fucking die.
_writer.Write(' '); _writer.Write(' ');
_writer.Flush(); _writer.Flush();
_stream.SetLength(0); _stream.SetLength(0);