Skip to content

Commit 9cddc6e

Browse files
committed
Create tests for generic classes
1 parent e7fa268 commit 9cddc6e

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Tests/Editor/TypeCandidateService_GenericVarianceTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using MackySoft.SerializeReferenceExtensions.Editor;
44
using NUnit.Framework;
5+
using UnityEngine;
56

67
namespace MackySoft.SerializeReferenceExtensions.Tests
78
{
@@ -39,6 +40,33 @@ public void Invariance_RemainsStrict ()
3940
Assert.That(set, Does.Contain(typeof(Invariant_Actor)));
4041
Assert.That(set, !Does.Contain(typeof(Invariant_NetworkActor)));
4142
}
43+
44+
[Test]
45+
public void GenericClass_ParticleSystem_IsSupported ()
46+
{
47+
var set = TypeSearchService.TypeCandiateService.GetDisplayableTypes(typeof(IObjectHolder<ParticleSystem>)).ToHashSet();
48+
49+
Assert.That(set, Does.Contain(typeof(ObjectHolder<ParticleSystem>)));
50+
Assert.That(set, Does.Contain(typeof(ParticleSystemHolder)));
51+
}
52+
53+
[Test]
54+
public void GenericClass_GameObject_IsSupported ()
55+
{
56+
var set = TypeSearchService.TypeCandiateService.GetDisplayableTypes(typeof(IObjectHolder<GameObject>)).ToHashSet();
57+
58+
Assert.That(set, Does.Contain(typeof(ObjectHolder<GameObject>)));
59+
Assert.That(set, !Does.Contain(typeof(ParticleSystemHolder)));
60+
}
61+
62+
[Test]
63+
public void GenericClass_Integer_IsSupported ()
64+
{
65+
var set = TypeSearchService.TypeCandiateService.GetDisplayableTypes(typeof(IObjectHolder<int>)).ToHashSet();
66+
67+
Assert.That(set, Does.Contain(typeof(ObjectHolder<int>)));
68+
Assert.That(set, !Does.Contain(typeof(ParticleSystemHolder)));
69+
}
4270
}
4371
}
4472
#endif

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Tests/Editor/TypeCandidateTestTypes.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public interface IContravariant<in T> { }
6161
public interface ICovariant<out T> { T Create (); }
6262
public interface IInvariant<T> { }
6363

64+
public interface IObjectHolder<T> { }
65+
6466
[Serializable]
6567
public sealed class Contravariant_Actor : IContravariant<IActor> { }
6668

@@ -93,4 +95,10 @@ public sealed class Invariant_Actor : IInvariant<IActor> { }
9395

9496
[Serializable]
9597
public sealed class Invariant_NetworkActor : IInvariant<INetworkActor> { }
98+
99+
[Serializable]
100+
public sealed class ObjectHolder<T> : IObjectHolder<T> { }
101+
102+
[Serializable]
103+
public sealed class ParticleSystemHolder : IObjectHolder<ParticleSystem> { }
96104
}

0 commit comments

Comments
 (0)