From b1041cf5f781e3d0aac0199672c83a5228a21ae5 Mon Sep 17 00:00:00 2001 From: "Alecio Furanze (Ale)" Date: Mon, 8 Jul 2024 17:00:54 +0200 Subject: [PATCH] add primitive skipping null/empty test #29 #30 add primitive skipping null/empty test #29 #30 --- test/primitive/Primitive.Null.cs | 142 +++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 test/primitive/Primitive.Null.cs diff --git a/test/primitive/Primitive.Null.cs b/test/primitive/Primitive.Null.cs new file mode 100644 index 0000000..629ec30 --- /dev/null +++ b/test/primitive/Primitive.Null.cs @@ -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(); // empty + _ = primitive.Get.Array(); // null + + _ = primitive.Get.List(); // empty + _ = primitive.Get.List(); // null + + _ = primitive.Get.Class(); // empty + _ = primitive.Get.Class(); // null + + _ = primitive.Get.Struct(); // empty + _ = primitive.Get.Struct(); // null + + _ = primitive.Get.Enum(); // empty + _ = primitive.Get.Enum(); // 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; + + public static List EmptyList = []; + public static List NullList = null; + + public static NonEmptyClass TheEmptyClass = new(); + public static NonEmptyClass TheNullClass = null; + + 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 + { + } + } +} \ No newline at end of file