Skip to content

Commit 73d76f2

Browse files
committed
Update reflection-related tests
1 parent 91499a4 commit 73d76f2

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

Assets/Editor Toolbox/Tests/Editor/ExtractionTest.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void SetUp()
2121
[TestCase("var2", "var1", 3)]
2222
[TestCase("var2.var3", "var1", "TestValue")]
2323
[TestCase("var2.var2.var2", "var1", true)]
24-
public void TestExtractionPass(string propertyPath, string source, object expected)
24+
public void TestFieldsExtractionPass(string propertyPath, string source, object expected)
2525
{
2626
var property = scriptableObject.FindProperty(propertyPath);
2727
var sibling = property.GetSibling(source);
@@ -31,5 +31,31 @@ public void TestExtractionPass(string propertyPath, string source, object expect
3131
Assert.IsFalse(hasMixedValues);
3232
Assert.AreEqual(expected, actual);
3333
}
34+
35+
[TestCase("var2", "BoolValue", true)]
36+
[TestCase("var2.var3", "GetFloatValue", 1.6f)]
37+
[TestCase("var2.var2.var2", "IntValue", 3)]
38+
public void TestPropertiesExtractionPass(string propertyPath, string source, object expected)
39+
{
40+
var property = scriptableObject.FindProperty(propertyPath);
41+
ValueExtractionHelper.TryGetValue(source, property, out var actual, out _);
42+
Assert.AreEqual(expected, actual);
43+
}
44+
45+
[TestCase("var2", "GetStringValue", "Text", true)]
46+
[TestCase("var2", "GetDoubleValue", null, false)]
47+
[TestCase("var2.var3", "GetFloatValue", 1.6f, true)]
48+
[TestCase("var2.var2.var2", "GetIntValue", null, false)]
49+
[TestCase("var2.var2.var2", "DoSomething", null, true)]
50+
public void TestMethodsExtractionPass(string propertyPath, string source, object expected, bool success)
51+
{
52+
var property = scriptableObject.FindProperty(propertyPath);
53+
var isFound = ValueExtractionHelper.TryGetValue(source, property, out var actual, out _);
54+
Assert.AreEqual(success, isFound);
55+
if (isFound)
56+
{
57+
Assert.AreEqual(expected, actual);
58+
}
59+
}
3460
}
3561
}

Assets/Editor Toolbox/Tests/Editor/TestObject2.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,47 @@ internal class TestObject2 : ScriptableObject
88
public int var1;
99
public TestNestedObject1 var2;
1010

11+
public bool BoolValue
12+
{
13+
get => true;
14+
}
15+
16+
public string GetStringValue()
17+
{
18+
return "Text";
19+
}
20+
21+
public double GetDoubleValue(int arg)
22+
{
23+
return arg + 2.0005;
24+
}
25+
1126
[Serializable]
1227
public class TestNestedObject1
1328
{
1429
public string var1;
1530
public TestNestedObject2 var2;
1631
public float[] var3;
32+
33+
public float GetFloatValue()
34+
{
35+
return 1.6f;
36+
}
1737
}
1838

1939
[Serializable]
2040
public class TestNestedObject2
2141
{
2242
public bool var1;
2343
public int var2;
44+
45+
public int IntValue
46+
{
47+
get => 3;
48+
}
49+
50+
public void DoSomething()
51+
{ }
2452
}
2553
}
2654
}

0 commit comments

Comments
 (0)