-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPopJson_Test.cs
More file actions
74 lines (59 loc) · 1.56 KB
/
PopJson_Test.cs
File metadata and controls
74 lines (59 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NUnit.Framework;
namespace PopX
{
public class Json_UnitTest
{
[System.Serializable]
public class StructHello
{
public string Hello;
public StructHello(string _HelloValue)
{
Hello = _HelloValue;
}
};
[System.Serializable]
public class StructHelloCat : StructHello
{
public string Cat;
public StructHelloCat(string _HelloValue,string _CatValue) : base(_HelloValue)
{
Cat = _CatValue;
}
};
[Test]
public void Replace_Test()
{
// use a struct to avoid whitespace hassle. We just need to know if it de/serialises
var Struct = new StructHello ("World");
var NewValue = "Universe";
var Json = JsonUtility.ToJson (Struct);
PopX.Json.Replace (ref Json, "Hello", NewValue);
JsonUtility.FromJsonOverwrite (Json, Struct);
Assert.AreEqual ( NewValue,Struct.Hello);
}
[Test]
public void Append_ToEmptyJson()
{
var Json = "{}";
var Value = "World";
PopX.Json.Append (ref Json, "Hello",Value);
// read new json (will throw json syntax errors for us)
var Struct = JsonUtility.FromJson<StructHello>(Json);
Assert.AreEqual (Value,Struct.Hello);
}
[Test]
public void Append_ToShallowJson()
{
var Json = JsonUtility.ToJson (new StructHello ("World"));
var CatValue = "Dog";
PopX.Json.Append (ref Json, "Cat", CatValue );
// read new json (will throw json syntax errors for us)
var Struct = JsonUtility.FromJson<StructHelloCat>(Json);
Assert.AreEqual (CatValue,Struct.Cat);
}
}
}