mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-10 06:45:40 +00:00
132 lines
4.4 KiB
C#
132 lines
4.4 KiB
C#
using System.Globalization;
|
|
using System.Text;
|
|
using NUnit.Framework;
|
|
using X10D.IO;
|
|
|
|
namespace X10D.Tests.IO;
|
|
|
|
public partial class TextWriterTests
|
|
{
|
|
[Test]
|
|
public void WriteNoAlloc_ShouldThrowArgumentNullException_GivenSingle_AndNullWriter()
|
|
{
|
|
TextWriter writer = null!;
|
|
Assert.Throws<ArgumentNullException>(() => writer.WriteNoAlloc(420.0f));
|
|
Assert.Throws<ArgumentNullException>(() => writer.WriteNoAlloc(420.0f, "N0"));
|
|
Assert.Throws<ArgumentNullException>(() => writer.WriteNoAlloc(420.0f, "N0", null));
|
|
}
|
|
|
|
[Test]
|
|
public void WriteNoAlloc_ShouldThrowObjectDisposedException_GivenSingle_AndDisposedStream()
|
|
{
|
|
var stream = new MemoryStream();
|
|
var writer = new StreamWriter(stream, Encoding.UTF8);
|
|
writer.Dispose();
|
|
stream.Dispose();
|
|
|
|
Assert.Throws<ObjectDisposedException>(() => writer.WriteNoAlloc(420.0f));
|
|
Assert.Throws<ObjectDisposedException>(() => writer.WriteNoAlloc(420.0f, "N0"));
|
|
Assert.Throws<ObjectDisposedException>(() => writer.WriteNoAlloc(420.0f, "N0", null));
|
|
}
|
|
|
|
[Test]
|
|
public void WriteLineNoAlloc_ShouldThrowArgumentNullException_GivenSingle_AndNullWriter()
|
|
{
|
|
TextWriter writer = null!;
|
|
Assert.Throws<ArgumentNullException>(() => writer.WriteLineNoAlloc(420.0f));
|
|
Assert.Throws<ArgumentNullException>(() => writer.WriteLineNoAlloc(420.0f, "N0"));
|
|
Assert.Throws<ArgumentNullException>(() => writer.WriteLineNoAlloc(420.0f, "N0", null));
|
|
}
|
|
|
|
[Test]
|
|
public void WriteLineNoAlloc_ShouldThrowObjectDisposedException_GivenSingle_AndDisposedStream()
|
|
{
|
|
var stream = new MemoryStream();
|
|
var writer = new StreamWriter(stream, Encoding.UTF8);
|
|
writer.Dispose();
|
|
stream.Dispose();
|
|
|
|
Assert.Throws<ObjectDisposedException>(() => writer.WriteLineNoAlloc(420.0f));
|
|
Assert.Throws<ObjectDisposedException>(() => writer.WriteLineNoAlloc(420.0f, "N0"));
|
|
Assert.Throws<ObjectDisposedException>(() => writer.WriteLineNoAlloc(420.0f, "N0", null));
|
|
}
|
|
|
|
[Test]
|
|
public void WriteNoAlloc_ShouldWriteTextValue_GivenSingle()
|
|
{
|
|
Assert.That(_stream.Length, Is.Zero);
|
|
_writer.WriteNoAlloc(420.0f);
|
|
_writer.Flush();
|
|
|
|
string actual = Encoding.UTF8.GetString(_stream.ToArray());
|
|
const string expected = "420";
|
|
|
|
Assert.That(actual, Is.EqualTo(expected));
|
|
}
|
|
|
|
[Test]
|
|
public void WriteNoAlloc_ShouldWriteTextValue_GivenSingle_AndFormatString()
|
|
{
|
|
Assert.That(_stream.Length, Is.Zero);
|
|
_writer.WriteNoAlloc(420.0f, "N0");
|
|
_writer.Flush();
|
|
|
|
string actual = Encoding.UTF8.GetString(_stream.ToArray());
|
|
const string expected = "420";
|
|
|
|
Assert.That(actual, Is.EqualTo(expected));
|
|
}
|
|
|
|
[Test]
|
|
public void WriteNoAlloc_ShouldWriteTextValue_GivenSingle_AndFormatString_AndCultureInfo()
|
|
{
|
|
Assert.That(_stream.Length, Is.Zero);
|
|
_writer.WriteNoAlloc(420.0f, "N0", CultureInfo.CurrentCulture);
|
|
_writer.Flush();
|
|
|
|
string actual = Encoding.UTF8.GetString(_stream.ToArray());
|
|
const string expected = "420";
|
|
|
|
Assert.That(actual, Is.EqualTo(expected));
|
|
}
|
|
|
|
[Test]
|
|
public void WriteLineNoAlloc_ShouldWriteTextValue_GivenSingle()
|
|
{
|
|
Assert.That(_stream.Length, Is.Zero);
|
|
_writer.WriteLineNoAlloc(420.0f);
|
|
_writer.Flush();
|
|
|
|
string actual = Encoding.UTF8.GetString(_stream.ToArray());
|
|
var expected = $"420{Environment.NewLine}";
|
|
|
|
Assert.That(actual, Is.EqualTo(expected));
|
|
}
|
|
|
|
[Test]
|
|
public void WriteLineNoAlloc_ShouldWriteTextValue_GivenSingle_AndFormatString()
|
|
{
|
|
Assert.That(_stream.Length, Is.Zero);
|
|
_writer.WriteLineNoAlloc(420.0f, "N0");
|
|
_writer.Flush();
|
|
|
|
string actual = Encoding.UTF8.GetString(_stream.ToArray());
|
|
var expected = $"420{Environment.NewLine}";
|
|
|
|
Assert.That(actual, Is.EqualTo(expected));
|
|
}
|
|
|
|
[Test]
|
|
public void WriteLineNoAlloc_ShouldWriteTextValue_GivenSingle_AndFormatString_AndCultureInfo()
|
|
{
|
|
Assert.That(_stream.Length, Is.Zero);
|
|
_writer.WriteLineNoAlloc(420.0f, "N0", CultureInfo.CurrentCulture);
|
|
_writer.Flush();
|
|
|
|
string actual = Encoding.UTF8.GetString(_stream.ToArray());
|
|
var expected = $"420{Environment.NewLine}";
|
|
|
|
Assert.That(actual, Is.EqualTo(expected));
|
|
}
|
|
}
|