Skip to content

Commit

Permalink
Update Primitive.Class.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
alec1o committed May 31, 2024
1 parent 6e3bf03 commit 2a60dcd
Showing 1 changed file with 154 additions and 0 deletions.
154 changes: 154 additions & 0 deletions test/primitive/Primitive.Class.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#define ARRAY_IGNORE
using System;
using System.Collections.Generic;
using Byter;
using Xunit;

namespace Test.Primitives;
Expand All @@ -7,5 +11,155 @@ public partial class Primitives
[Fact]
public void _Class()
{
Primitive primitive = new();

var real = new MyComplexClass()
{
Number = int.MinValue,
String = Guid.NewGuid().ToString(),
Bool = true,
ByteArray = Guid.NewGuid().ToString().GetBytes(),
StringList =
[
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
],
SubStructList =
[
MyComplexClass.MySubStruct.Random(),
MyComplexClass.MySubStruct.Random(),
MyComplexClass.MySubStruct.Random(),
],
SubClassList =
[
MyComplexClass.MySubClass.Random(),
MyComplexClass.MySubClass.Random(),
MyComplexClass.MySubClass.Random(),
],
#if !ARRAY_IGNORE
StringArray =
[
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
],
SubStructArray =
[
MyComplexClass.MySubStruct.Random(),
MyComplexClass.MySubStruct.Random(),
MyComplexClass.MySubStruct.Random(),
],
SubClassArray =
[
MyComplexClass.MySubClass.Random(),
MyComplexClass.MySubClass.Random(),
MyComplexClass.MySubClass.Random(),
],
#endif
SubClass = MyComplexClass.MySubClass.Random(),
SubStruct = MyComplexClass.MySubStruct.Random()
};

primitive.Add.Class(real);

var clone = primitive.Get.Class<MyComplexClass>();

Assert.Equal(real.Number, clone.Number);
Assert.Equal(real.String, clone.String);
Assert.Equal(real.Bool, clone.Bool);
Assert.Equal(real.ByteArray, clone.ByteArray);

for (int i = 0; i < real.StringList.Count; i++)
{
Assert.Equal(real.StringList[i], clone.StringList[i]);
}

for (int i = 0; i < real.SubClassList.Count; i++)
{
Assert.Equal(real.SubClassList[i].Number, clone.SubClassList[i].Number);
Assert.Equal(real.SubClassList[i].String, clone.SubClassList[i].String);
}

for (int i = 0; i < real.SubStructList.Count; i++)
{
Assert.Equal(real.SubStructList[i].Number, clone.SubStructList[i].Number);
Assert.Equal(real.SubStructList[i].String, clone.SubStructList[i].String);
}
#if !ARRAY_IGNORE
for (int i = 0; i < real.StringArray.Length; i++)
{
Assert.Equal(real.StringArray[i], clone.StringArray[i]);
}

for (int i = 0; i < real.SubClassArray.Length; i++)
{
Assert.Equal(real.SubClassArray[i].Number, clone.SubClassArray[i].Number);
Assert.Equal(real.SubClassArray[i].String, clone.SubClassArray[i].String);
}

for (int i = 0; i < real.SubStructArray.Length; i++)
{
Assert.Equal(real.SubStructArray[i].Number, clone.SubStructArray[i].Number);
Assert.Equal(real.SubStructArray[i].String, clone.SubStructArray[i].String);
}
#endif
{
Assert.Equal(real.SubClass.Number, clone.SubClass.Number);
Assert.Equal(real.SubClass.String, clone.SubClass.String);
}
{
Assert.Equal(real.SubStruct.Number, clone.SubStruct.Number);
Assert.Equal(real.SubStruct.String, clone.SubStruct.String);
}
Assert.True(primitive.IsValid);
}

private class MyComplexClass
{
public int Number { get; set; }
public string String { get; set; }

Check warning on line 121 in test/primitive/Primitive.Class.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'String' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public bool Bool { get; set; }
public byte[] ByteArray { get; set; }

Check warning on line 123 in test/primitive/Primitive.Class.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'ByteArray' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public List<string> StringList { get; set; }

Check warning on line 124 in test/primitive/Primitive.Class.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'StringList' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public List<MySubClass> SubClassList { get; set; }

Check warning on line 125 in test/primitive/Primitive.Class.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'SubClassList' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public List<MySubStruct> SubStructList { get; set; }

Check warning on line 126 in test/primitive/Primitive.Class.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'SubStructList' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
#if !ARRAY_IGNORE
public string[] StringArray { get; set; }
public MySubClass[] SubClassArray { get; set; }
public MySubStruct[] SubStructArray { get; set; }
#endif
public MySubClass SubClass { get; set; }

Check warning on line 132 in test/primitive/Primitive.Class.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'SubClass' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public MySubStruct SubStruct { get; set; }

public struct MySubStruct
{
public long Number { get; set; }
public string String { get; set; }

public static MySubStruct Random()
{
return new()
{
Number = new Random().Next(int.MinValue, int.MaxValue),
String = Guid.NewGuid().ToString()
};
}
}

public class MySubClass
{
public long Number { get; set; }
public string String { get; set; }

Check warning on line 153 in test/primitive/Primitive.Class.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'String' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public static MySubClass Random()
{
return new()
{
Number = new Random().Next(int.MinValue, int.MaxValue),
String = Guid.NewGuid().ToString()
};
}
}
}
}

0 comments on commit 2a60dcd

Please sign in to comment.