mirror of
https://github.com/SabreTools/SabreTools.IO.git
synced 2026-02-04 05:36:05 +00:00
Clean up test classes
This commit is contained in:
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using SabreTools.IO.Compression.Quantum;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable CA1822 // Mark members as static
|
||||
namespace SabreTools.IO.Test.Compression
|
||||
{
|
||||
public class QuantumTests
|
||||
|
||||
@@ -622,35 +622,35 @@ namespace SabreTools.IO.Test.Extensions
|
||||
// Guid
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
var bw = new BinaryWriter(stream);
|
||||
bool actual = bw.WriteType<Guid>(new Guid(_bytes));
|
||||
bool actual = bw.WriteType(new Guid(_bytes));
|
||||
Assert.True(actual);
|
||||
ValidateBytes(_bytes, stream.GetBuffer());
|
||||
|
||||
// Half
|
||||
stream = new MemoryStream(new byte[2], 0, 2, true, true);
|
||||
bw = new BinaryWriter(stream);
|
||||
actual = bw.WriteType<Half>(BitConverter.Int16BitsToHalf(0x0100));
|
||||
actual = bw.WriteType(BitConverter.Int16BitsToHalf(0x0100));
|
||||
Assert.True(actual);
|
||||
ValidateBytes([.. _bytes.Take(2)], stream.GetBuffer());
|
||||
|
||||
// Int128
|
||||
stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
bw = new BinaryWriter(stream);
|
||||
actual = bw.WriteType<Int128>((Int128)new BigInteger(_bytes));
|
||||
actual = bw.WriteType((Int128)new BigInteger(_bytes));
|
||||
Assert.True(actual);
|
||||
ValidateBytes(_bytes, stream.GetBuffer());
|
||||
|
||||
// UInt128
|
||||
stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
bw = new BinaryWriter(stream);
|
||||
actual = bw.WriteType<UInt128>((UInt128)new BigInteger(_bytes));
|
||||
actual = bw.WriteType((UInt128)new BigInteger(_bytes));
|
||||
Assert.True(actual);
|
||||
ValidateBytes(_bytes, stream.GetBuffer());
|
||||
|
||||
// Enum
|
||||
stream = new MemoryStream(new byte[4], 0, 4, true, true);
|
||||
bw = new BinaryWriter(stream);
|
||||
actual = bw.WriteType<TestEnum>((TestEnum)0x03020100);
|
||||
actual = bw.WriteType((TestEnum)0x03020100);
|
||||
Assert.True(actual);
|
||||
ValidateBytes([.. _bytes.Take(4)], stream.GetBuffer());
|
||||
}
|
||||
|
||||
@@ -641,35 +641,35 @@ namespace SabreTools.IO.Test.Extensions
|
||||
// Guid
|
||||
int offset = 0;
|
||||
byte[] buffer = new byte[16];
|
||||
bool actual = buffer.WriteType<Guid>(ref offset, new Guid(_bytes));
|
||||
bool actual = buffer.WriteType(ref offset, new Guid(_bytes));
|
||||
Assert.True(actual);
|
||||
ValidateBytes(_bytes, buffer);
|
||||
|
||||
// Half
|
||||
offset = 0;
|
||||
buffer = new byte[2];
|
||||
actual = buffer.WriteType<Half>(ref offset, BitConverter.Int16BitsToHalf(0x0100));
|
||||
actual = buffer.WriteType(ref offset, BitConverter.Int16BitsToHalf(0x0100));
|
||||
Assert.True(actual);
|
||||
ValidateBytes([.. _bytes.Take(2)], buffer);
|
||||
|
||||
// Int128
|
||||
offset = 0;
|
||||
buffer = new byte[16];
|
||||
actual = buffer.WriteType<Int128>(ref offset, (Int128)new BigInteger(_bytes));
|
||||
actual = buffer.WriteType(ref offset, (Int128)new BigInteger(_bytes));
|
||||
Assert.True(actual);
|
||||
ValidateBytes(_bytes, buffer);
|
||||
|
||||
// UInt128
|
||||
offset = 0;
|
||||
buffer = new byte[16];
|
||||
actual = buffer.WriteType<UInt128>(ref offset, (UInt128)new BigInteger(_bytes));
|
||||
actual = buffer.WriteType(ref offset, (UInt128)new BigInteger(_bytes));
|
||||
Assert.True(actual);
|
||||
ValidateBytes(_bytes, buffer);
|
||||
|
||||
// Enum
|
||||
offset = 0;
|
||||
buffer = new byte[4];
|
||||
actual = buffer.WriteType<TestEnum>(ref offset, (TestEnum)0x03020100);
|
||||
actual = buffer.WriteType(ref offset, (TestEnum)0x03020100);
|
||||
Assert.True(actual);
|
||||
ValidateBytes([.. _bytes.Take(4)], buffer);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ using System.Threading;
|
||||
using SabreTools.IO.Extensions;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable IDE0060 // Remove unused parameter
|
||||
#pragma warning disable IDE0290 // Use primary constructor
|
||||
namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
public class EnumerableExtensionsTests
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Text;
|
||||
using SabreTools.IO.Extensions;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable IDE0017 // Object initialization can be simplified
|
||||
namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
public class StreamExtensionsTests
|
||||
|
||||
@@ -585,31 +585,31 @@ namespace SabreTools.IO.Test.Extensions
|
||||
{
|
||||
// Guid
|
||||
var stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
bool actual = stream.WriteType<Guid>(new Guid(_bytes));
|
||||
bool actual = stream.WriteType(new Guid(_bytes));
|
||||
Assert.True(actual);
|
||||
ValidateBytes(_bytes, stream.GetBuffer());
|
||||
|
||||
// Half
|
||||
stream = new MemoryStream(new byte[2], 0, 2, true, true);
|
||||
actual = stream.WriteType<Half>(BitConverter.Int16BitsToHalf(0x0100));
|
||||
actual = stream.WriteType(BitConverter.Int16BitsToHalf(0x0100));
|
||||
Assert.True(actual);
|
||||
ValidateBytes([.. _bytes.Take(2)], stream.GetBuffer());
|
||||
|
||||
// Int128
|
||||
stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
actual = stream.WriteType<Int128>((Int128)new BigInteger(_bytes));
|
||||
actual = stream.WriteType((Int128)new BigInteger(_bytes));
|
||||
Assert.True(actual);
|
||||
ValidateBytes(_bytes, stream.GetBuffer());
|
||||
|
||||
// UInt128
|
||||
stream = new MemoryStream(new byte[16], 0, 16, true, true);
|
||||
actual = stream.WriteType<UInt128>((UInt128)new BigInteger(_bytes));
|
||||
actual = stream.WriteType((UInt128)new BigInteger(_bytes));
|
||||
Assert.True(actual);
|
||||
ValidateBytes(_bytes, stream.GetBuffer());
|
||||
|
||||
// Enum
|
||||
stream = new MemoryStream(new byte[4], 0, 4, true, true);
|
||||
actual = stream.WriteType<TestEnum>((TestEnum)0x03020100);
|
||||
actual = stream.WriteType((TestEnum)0x03020100);
|
||||
Assert.True(actual);
|
||||
ValidateBytes([.. _bytes.Take(4)], stream.GetBuffer());
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using SabreTools.IO.Matching;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable CA1861 // Prefer 'static readonly' fields
|
||||
namespace SabreTools.IO.Test.Matching
|
||||
{
|
||||
public class PathMatchSetTests
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace SabreTools.IO.Test.Numerics
|
||||
[Fact]
|
||||
public void GetTypeCodeTest()
|
||||
{
|
||||
TypeCode expected = ((int)1).GetTypeCode();
|
||||
TypeCode expected = 1.GetTypeCode();
|
||||
|
||||
var val = new BothInt32(1, 1);
|
||||
Assert.Equal(expected, val.GetTypeCode());
|
||||
@@ -59,51 +59,51 @@ namespace SabreTools.IO.Test.Numerics
|
||||
{
|
||||
var val = new BothInt32(1, 1);
|
||||
|
||||
bool expectedBool = Convert.ToBoolean((int)1);
|
||||
bool expectedBool = Convert.ToBoolean(1);
|
||||
Assert.Equal(expectedBool, val.ToBoolean(null));
|
||||
|
||||
char expectedChar = Convert.ToChar((int)1);
|
||||
char expectedChar = Convert.ToChar(1);
|
||||
Assert.Equal(expectedChar, val.ToChar(null));
|
||||
|
||||
sbyte expectedSByte = Convert.ToSByte((int)1);
|
||||
sbyte expectedSByte = Convert.ToSByte(1);
|
||||
Assert.Equal(expectedSByte, val.ToSByte(null));
|
||||
|
||||
byte expectedByte = Convert.ToByte((int)1);
|
||||
byte expectedByte = Convert.ToByte(1);
|
||||
Assert.Equal(expectedByte, val.ToByte(null));
|
||||
|
||||
short expectedInt16 = Convert.ToInt16((int)1);
|
||||
short expectedInt16 = Convert.ToInt16(1);
|
||||
Assert.Equal(expectedInt16, val.ToInt16(null));
|
||||
|
||||
ushort expectedUInt16 = Convert.ToUInt16((int)1);
|
||||
ushort expectedUInt16 = Convert.ToUInt16(1);
|
||||
Assert.Equal(expectedUInt16, val.ToUInt16(null));
|
||||
|
||||
int expectedInt32 = Convert.ToInt32((int)1);
|
||||
int expectedInt32 = Convert.ToInt32(1);
|
||||
Assert.Equal(expectedInt32, val.ToInt32(null));
|
||||
|
||||
uint expectedUInt32 = Convert.ToUInt32((int)1);
|
||||
uint expectedUInt32 = Convert.ToUInt32(1);
|
||||
Assert.Equal(expectedUInt32, val.ToUInt32(null));
|
||||
|
||||
long expectedInt64 = Convert.ToInt64((int)1);
|
||||
long expectedInt64 = Convert.ToInt64(1);
|
||||
Assert.Equal(expectedInt64, val.ToInt64(null));
|
||||
|
||||
ulong expectedUInt64 = Convert.ToUInt64((int)1);
|
||||
ulong expectedUInt64 = Convert.ToUInt64(1);
|
||||
Assert.Equal(expectedUInt64, val.ToUInt64(null));
|
||||
|
||||
float expectedSingle = Convert.ToSingle((int)1);
|
||||
float expectedSingle = Convert.ToSingle(1);
|
||||
Assert.Equal(expectedSingle, val.ToSingle(null));
|
||||
|
||||
double expectedDouble = Convert.ToDouble((int)1);
|
||||
double expectedDouble = Convert.ToDouble(1);
|
||||
Assert.Equal(expectedDouble, val.ToDouble(null));
|
||||
|
||||
decimal expectedDecimal = Convert.ToDecimal((int)1);
|
||||
decimal expectedDecimal = Convert.ToDecimal(1);
|
||||
Assert.Equal(expectedDecimal, val.ToDecimal(null));
|
||||
|
||||
Assert.Throws<InvalidCastException>(() => val.ToDateTime(null));
|
||||
|
||||
string expectedString = Convert.ToString((int)1);
|
||||
string expectedString = Convert.ToString(1);
|
||||
Assert.Equal(expectedString, val.ToString(null));
|
||||
|
||||
ulong expectedObject = Convert.ToUInt64((int)1);
|
||||
ulong expectedObject = Convert.ToUInt64(1);
|
||||
Assert.Equal(expectedObject, val.ToType(typeof(ulong), null));
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace SabreTools.IO.Test.Numerics
|
||||
public void BitwiseUnaryOperatorsTest()
|
||||
{
|
||||
var valA = new BothUInt32(2, 2);
|
||||
uint expected = ~((uint)2);
|
||||
uint expected = ~(uint)2;
|
||||
BothUInt32 actual = ~valA;
|
||||
Assert.Equal(expected, actual.LittleEndian);
|
||||
Assert.Equal(expected, actual.BigEndian);
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace SabreTools.IO.Test.Numerics
|
||||
public void BitwiseUnaryOperatorsTest()
|
||||
{
|
||||
var valA = new BothUInt64(2, 2);
|
||||
ulong expected = ~((ulong)2);
|
||||
ulong expected = ~(ulong)2;
|
||||
BothUInt64 actual = ~valA;
|
||||
Assert.Equal(expected, actual.LittleEndian);
|
||||
Assert.Equal(expected, actual.BigEndian);
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using SabreTools.IO.Streams;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable IDE0017 // Object initialization can be simplified
|
||||
namespace SabreTools.IO.Test.Streams
|
||||
{
|
||||
public class ViewStreamTests
|
||||
|
||||
@@ -4,6 +4,7 @@ using SabreTools.IO.Extensions;
|
||||
using SabreTools.IO.Transform;
|
||||
using Xunit;
|
||||
|
||||
#pragma warning disable IDE0230 // Use UTF-8 string literal
|
||||
namespace SabreTools.IO.Test.Transform
|
||||
{
|
||||
public class SwapTests
|
||||
|
||||
Reference in New Issue
Block a user