Skip to content

Commit

Permalink
add primitive skipping null/empty test #29 #30
Browse files Browse the repository at this point in the history
add primitive skipping null/empty test #29 #30
  • Loading branch information
alec1o committed Jul 8, 2024
1 parent 3bb9005 commit b1041cf
Showing 1 changed file with 142 additions and 0 deletions.
142 changes: 142 additions & 0 deletions test/primitive/Primitive.Null.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
using System.Collections.Generic;
using Byter;
using Xunit;

namespace Test.Primitives;

public partial class Primitives
{
[Fact]
public void Null()
{
Primitive primitive = new();

primitive.Add.Bytes(null);
primitive.Add.Bytes([]);

primitive.Add.String(NullConfig.EmptyString);
primitive.Add.String(NullConfig.NullString);

primitive.Add.Array(NullConfig.EmptyArray);
primitive.Add.Array(NullConfig.NullArray);

primitive.Add.List(NullConfig.EmptyList);
primitive.Add.List(NullConfig.NullList);

primitive.Add.Class(NullConfig.TheEmptyClass);
primitive.Add.Class(NullConfig.TheNullClass);

primitive.Add.Struct(NullConfig.TheEmptyStruct);
primitive.Add.Struct(NullConfig.TheNullStruct);

primitive.Add.Enum(NullConfig.TheEmptyEnum);
primitive.Add.Enum(NullConfig.TheNullEnum);

primitive.Add.Bool(default);
primitive.Add.Byte(default);
primitive.Add.SByte(default);
primitive.Add.Char(default);
primitive.Add.Short(default);
primitive.Add.UShort(default);
primitive.Add.Int(default);
primitive.Add.UInt(default);
primitive.Add.Float(default);
primitive.Add.Long(default);
primitive.Add.ULong(default);
primitive.Add.Double(default);
primitive.Add.DateTime(default);
primitive.Add.Decimal(default);
primitive.Add.String(default);
primitive.Add.BigInteger(default);

// read

_ = primitive.Get.Bytes(); // empty bytes
_ = primitive.Get.Bytes(); // null bytes

_ = primitive.Get.String(); // empty
_ = primitive.Get.String(); // null

_ = primitive.Get.Array<byte>(); // empty
_ = primitive.Get.Array<byte>(); // null

_ = primitive.Get.List<byte>(); // empty
_ = primitive.Get.List<byte>(); // null

_ = primitive.Get.Class<NullConfig.EmptyClass>(); // empty
_ = primitive.Get.Class<NullConfig.NonEmptyClass>(); // null

_ = primitive.Get.Struct<NullConfig.EmptyStruct>(); // empty
_ = primitive.Get.Struct<NullConfig.NonEmptyStruct>(); // null

_ = primitive.Get.Enum<NullConfig.EmptyEnum>(); // empty
_ = primitive.Get.Enum<NullConfig.NonEmptyEnum>(); // null

_ = primitive.Get.Bool();
_ = primitive.Get.Byte();
_ = primitive.Get.SByte();
_ = primitive.Get.Char();
_ = primitive.Get.Short();
_ = primitive.Get.UShort();
_ = primitive.Get.Int();
_ = primitive.Get.UInt();
_ = primitive.Get.Float();
_ = primitive.Get.Long();
_ = primitive.Get.ULong();
_ = primitive.Get.Double();
_ = primitive.Get.DateTime();
_ = primitive.Get.Decimal();
_ = primitive.Get.String();
_ = primitive.Get.BigInteger();

Assert.True(primitive.IsValid);
}

public static class NullConfig
{
public static string EmptyString = "";
public static string NullString = "";

public static byte[] EmptyArray = [];
public static byte[] NullArray = null;

Check warning on line 101 in test/primitive/Primitive.Null.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

public static List<byte> EmptyList = [];
public static List<byte> NullList = null;

Check warning on line 104 in test/primitive/Primitive.Null.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

public static NonEmptyClass TheEmptyClass = new();
public static NonEmptyClass TheNullClass = null;

Check warning on line 107 in test/primitive/Primitive.Null.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

public static EmptyStruct TheEmptyStruct = new();
public static NonEmptyStruct TheNullStruct = default;

public static EmptyEnum TheEmptyEnum = new();
public static NonEmptyEnum TheNullEnum = default;

public class EmptyClass
{
}

public struct EmptyStruct
{
}

public class NonEmptyClass
{
public byte Byte { get; set; }
}

public struct NonEmptyStruct
{
public byte Byte { get; set; }
}

public enum NonEmptyEnum
{
Byter
}

public enum EmptyEnum
{
}
}
}

0 comments on commit b1041cf

Please sign in to comment.