Skip to content
This repository has been archived by the owner on Dec 24, 2020. It is now read-only.

Commit

Permalink
Fix line ending in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mafiesto4 committed Aug 10, 2018
1 parent f20491b commit d4403d6
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions FlaxEngine.Tests/TestSerialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public void TestConvertID()
Assert.AreEqual(id1, id1Tmp);
}

public static string FilterLineBreak(string str)
{
return str.Replace("\r", "");
}

/// <summary>
/// Test object serialization to JSON.
/// </summary>
Expand All @@ -42,15 +47,15 @@ public void TestSerialize()
{
ObjectOne obj = new ObjectOne();

Assert.AreEqual("{\r\n\t\"MyValue\": 0.0,\r\n\t\"MyVector\": {\r\n\t\t\"X\": 0.0,\r\n\t\t\"Y\": 0.0\r\n\t}\r\n}", JsonSerializer.Serialize(obj));
Assert.AreEqual("{\n\t\"MyValue\": 0.0,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 0.0\n\t}\n}", FilterLineBreak(JsonSerializer.Serialize(obj)));

obj.MyValue = 1.2f;

Assert.AreEqual("{\r\n\t\"MyValue\": 1.2,\r\n\t\"MyVector\": {\r\n\t\t\"X\": 0.0,\r\n\t\t\"Y\": 0.0\r\n\t}\r\n}", JsonSerializer.Serialize(obj));
Assert.AreEqual("{\n\t\"MyValue\": 1.2,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 0.0\n\t}\n}", FilterLineBreak(JsonSerializer.Serialize(obj)));

obj.MyVector.Y = 2.0f;

Assert.AreEqual("{\r\n\t\"MyValue\": 1.2,\r\n\t\"MyVector\": {\r\n\t\t\"X\": 0.0,\r\n\t\t\"Y\": 2.0\r\n\t}\r\n}", JsonSerializer.Serialize(obj));
Assert.AreEqual("{\n\t\"MyValue\": 1.2,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 2.0\n\t}\n}", FilterLineBreak(JsonSerializer.Serialize(obj)));

obj.MyArray = new[]
{
Expand All @@ -60,7 +65,7 @@ public void TestSerialize()
4
};

Assert.AreEqual("{\r\n\t\"MyValue\": 1.2,\r\n\t\"MyVector\": {\r\n\t\t\"X\": 0.0,\r\n\t\t\"Y\": 2.0\r\n\t},\r\n\t\"MyArray\": [\r\n\t\t1,\r\n\t\t2,\r\n\t\t3,\r\n\t\t4\r\n\t]\r\n}", JsonSerializer.Serialize(obj));
Assert.AreEqual("{\n\t\"MyValue\": 1.2,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 2.0\n\t},\n\t\"MyArray\": [\n\t\t1,\n\t\t2,\n\t\t3,\n\t\t4\n\t]\n}", FilterLineBreak(JsonSerializer.Serialize(obj)));
}

/// <summary>
Expand All @@ -71,25 +76,25 @@ public void TestDeserialize()
{
ObjectOne obj = new ObjectOne();

JsonSerializer.Deserialize(obj, "{\r\n\t\"MyValue\": 0.0,\r\n\t\"MyVector\": {\r\n\t\t\"X\": 0.0,\r\n\t\t\"Y\": 0.0\r\n\t}\r\n}");
JsonSerializer.Deserialize(obj, "{\n\t\"MyValue\": 0.0,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 0.0\n\t}\n}");

Assert.AreEqual(0.0f, obj.MyValue);
Assert.AreEqual(Vector2.Zero, obj.MyVector);
Assert.IsNull(obj.MyArray);

JsonSerializer.Deserialize(obj, "{\r\n\t\"MyValue\": 1.2,\r\n\t\"MyVector\": {\r\n\t\t\"X\": 0.0,\r\n\t\t\"Y\": 0.0\r\n\t}\r\n}");
JsonSerializer.Deserialize(obj, "{\n\t\"MyValue\": 1.2,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 0.0\n\t}\n}");

Assert.AreEqual(1.2f, obj.MyValue);
Assert.AreEqual(Vector2.Zero, obj.MyVector);
Assert.IsNull(obj.MyArray);

JsonSerializer.Deserialize(obj, "{\r\n\t\"MyValue\": 1.2,\r\n\t\"MyVector\": {\r\n\t\t\"X\": 0.0,\r\n\t\t\"Y\": 2.0\r\n\t}\r\n}");
JsonSerializer.Deserialize(obj, "{\n\t\"MyValue\": 1.2,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 2.0\n\t}\n}");

Assert.AreEqual(1.2f, obj.MyValue);
Assert.AreEqual(new Vector2(0.0f, 2.0f), obj.MyVector);
Assert.IsNull(obj.MyArray);

JsonSerializer.Deserialize(obj, "{\r\n\t\"MyValue\": 1.2,\r\n\t\"MyVector\": {\r\n\t\t\"X\": 0.0,\r\n\t\t\"Y\": 2.0\r\n\t},\r\n\t\"MyArray\": [\r\n\t\t1,\r\n\t\t2,\r\n\t\t3,\r\n\t\t4\r\n\t]\r\n}");
JsonSerializer.Deserialize(obj, "{\n\t\"MyValue\": 1.2,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 2.0\n\t},\n\t\"MyArray\": [\n\t\t1,\n\t\t2,\n\t\t3,\n\t\t4\n\t]\n}");

Assert.AreEqual(1.2f, obj.MyValue);
Assert.AreEqual(new Vector2(0.0f, 2.0f), obj.MyVector);
Expand All @@ -116,7 +121,7 @@ public void TestSerializeDiff()

obj.MyValue = 2.0f;

Assert.AreEqual("{\r\n\t\"MyValue\": 2.0\r\n}", JsonSerializer.SerializeDiff(obj, other));
Assert.AreEqual("{\n\t\"MyValue\": 2.0\n}", FilterLineBreak(JsonSerializer.SerializeDiff(obj, other)));

obj.MyValue = 2.0f;
other.MyValue = 2.0f;
Expand All @@ -125,7 +130,7 @@ public void TestSerializeDiff()

other.MyArray = new[] { 1 };

Assert.AreEqual("{\r\n\t\"MyArray\": null\r\n}", JsonSerializer.SerializeDiff(obj, other));
Assert.AreEqual("{\n\t\"MyArray\": null\n}", FilterLineBreak(JsonSerializer.SerializeDiff(obj, other)));

obj.MyArray = other.MyArray;

Expand All @@ -137,11 +142,11 @@ public void TestSerializeDiff()

obj.MyArray = new[] { 2 };

Assert.AreEqual("{\r\n\t\"MyArray\": [\r\n\t\t2\r\n\t]\r\n}", JsonSerializer.SerializeDiff(obj, other));
Assert.AreEqual("{\n\t\"MyArray\": [\n\t\t2\n\t]\n}", FilterLineBreak(JsonSerializer.SerializeDiff(obj, other)));

other.MyArray = null;

Assert.AreEqual("{\r\n\t\"MyArray\": [\r\n\t\t2\r\n\t]\r\n}", JsonSerializer.SerializeDiff(obj, other));
Assert.AreEqual("{\n\t\"MyArray\": [\n\t\t2\n\t]\n}", FilterLineBreak(JsonSerializer.SerializeDiff(obj, other)));
}
}
}

0 comments on commit d4403d6

Please sign in to comment.