11using NUnit . Framework ;
22
3+ using System ;
4+
35using UnityEditor ;
46using UnityEngine ;
57
68namespace Toolbox . Editor . Tests
79{
810 public class PropertyUtilitesTest
911 {
10- private SerializedObject scriptableObject ;
11-
12+ private SerializedObject serializedObject ;
1213
1314 [ OneTimeSetUp ]
1415 public void SetUp ( )
1516 {
1617 var target = ScriptableObject . CreateInstance < TestObject2 > ( ) ;
17- scriptableObject = new SerializedObject ( target ) ;
18- var array = scriptableObject . FindProperty ( "var2.var3" ) ;
19- array . InsertArrayElementAtIndex ( 0 ) ;
18+ serializedObject = new SerializedObject ( target ) ;
19+
20+ var var2var3Property = serializedObject . FindProperty ( "var2.var3" ) ;
21+ var2var3Property . InsertArrayElementAtIndex ( 0 ) ;
22+
23+ #if UNITY_2019_3_OR_NEWER
24+ var var3Property = serializedObject . FindProperty ( "var3" ) ;
25+ var3Property . managedReferenceValue = new TestObject2 . TestNestedObject3 ( )
26+ {
27+ var1 = 3.0f
28+ } ;
29+ #endif
2030 }
2131
2232 [ TestCase ( "var1" , null ) ]
2333 [ TestCase ( "var2.var1" , "var2" ) ]
2434 [ TestCase ( "var2.var2.var1" , "var2" ) ]
2535 public void TestGetParentPass ( string propertyPath , string parentName )
2636 {
27- var property = scriptableObject . FindProperty ( propertyPath ) ;
37+ var property = serializedObject . FindProperty ( propertyPath ) ;
2838 var parent = property ? . GetParent ( ) ;
2939 Assert . AreEqual ( parent ? . name , parentName ) ;
3040 }
@@ -35,7 +45,7 @@ public void TestGetParentPass(string propertyPath, string parentName)
3545 [ TestCase ( "var2.var3.Array.data[0]" , 1 ) ]
3646 public void TestGetValuePass ( string propertyPath , object value )
3747 {
38- var property = scriptableObject . FindProperty ( propertyPath ) ;
48+ var property = serializedObject . FindProperty ( propertyPath ) ;
3949 var fieldInfo = property . GetFieldInfo ( out _ ) ;
4050 property . SetProperValue ( fieldInfo , value ) ;
4151 var newValue = property . GetProperValue ( fieldInfo ) ;
@@ -47,7 +57,7 @@ public void TestGetValuePass(string propertyPath, object value)
4757 [ TestCase ( "var2.var3.Array.data[0]" , true ) ]
4858 public void TestIsArrayElementPass ( string propertyPath , bool expected )
4959 {
50- var property = scriptableObject . FindProperty ( propertyPath ) ;
60+ var property = serializedObject . FindProperty ( propertyPath ) ;
5161 var actual = PropertyUtility . IsSerializableArrayElement ( property ) ;
5262 Assert . AreEqual ( expected , actual ) ;
5363 }
@@ -59,7 +69,7 @@ public void TestIsArrayElementPass(string propertyPath, bool expected)
5969 [ TestCase ( "var2.var3.Array.data[0]" , "var2.var3.[0]" ) ]
6070 public void TestGetPathTreePass ( string propertyPath , string path )
6171 {
62- var property = scriptableObject . FindProperty ( propertyPath ) ;
72+ var property = serializedObject . FindProperty ( propertyPath ) ;
6373 var pathTree = PropertyUtility . GetPropertyFieldTree ( property ) ;
6474 var actual = string . Join ( "." , pathTree ) ;
6575 Assert . AreEqual ( path , actual ) ;
@@ -69,9 +79,23 @@ public void TestGetPathTreePass(string propertyPath, string path)
6979 [ TestCase ( "var2.var1" , false ) ]
7080 public void TestIsMonoScriptPass ( string propertyPath , bool expected )
7181 {
72- var property = scriptableObject . FindProperty ( propertyPath ) ;
82+ var property = serializedObject . FindProperty ( propertyPath ) ;
7383 var actual = PropertyUtility . IsDefaultScriptProperty ( property ) ;
7484 Assert . AreEqual ( expected , actual ) ;
7585 }
86+
87+ [ TestCase ( "var1" , typeof ( int ) ) ]
88+ [ TestCase ( "var2.var1" , typeof ( string ) ) ]
89+ #if UNITY_2019_3_OR_NEWER
90+ [ TestCase ( "var3" , typeof ( TestObject2 . TestNestedObject3 ) ) ]
91+ [ TestCase ( "var3.var1" , typeof ( float ) ) ]
92+ #endif
93+ public void TestGetFieldInfoPass ( string propertyPath , Type expected )
94+ {
95+ var property = serializedObject . FindProperty ( propertyPath ) ;
96+ var fieldInfo = PropertyUtility . GetFieldInfo ( property , out var propertyType ) ;
97+ Assert . IsNotNull ( fieldInfo ) ;
98+ Assert . AreEqual ( expected , propertyType ) ;
99+ }
76100 }
77101}
0 commit comments