Skip to content

Commit

Permalink
Engine - ECS: support generic components / tags - coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
friflo committed Jun 19, 2024
1 parent c8c488c commit a1b490b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Engine/src/ECS/Base/SchemaTypeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal static int GetScriptIndex(Type type)
return schema.ScriptTypeByType[type].ScriptIndex;
}

private static InvalidOperationException ComponentTypeException(Type type, string typeBase)
internal static InvalidOperationException ComponentTypeException(Type type, string typeBase)
{
if (!type.IsGenericType) {
return new InvalidOperationException($"{typeBase} type not found: {type}");
Expand Down
4 changes: 2 additions & 2 deletions Engine/src/ECS/Base/SchemaUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ internal static GenericInstanceType[] GetGenericInstanceTypes(Type type)
return list.ToArray();
}

private static string GetGenericComponentKey(Type type)
internal static string GetGenericComponentKey(Type type)
{
var genericInstanceTypes = GetGenericInstanceTypes(type);
var findTypes = type.GenericTypeArguments;
Expand All @@ -155,7 +155,7 @@ private static string GetGenericComponentKey(Type type)
return genericType.key;
}
}
return null;
return null; // cannot be reached - only in internal tests
}

internal static void GetComponentSymbol(Type type, out string name, out SymbolColor? color)
Expand Down
10 changes: 10 additions & 0 deletions Engine/src/Tests-internal/ECS/Test_ComponentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ public static void Test_ComponentType_Tags_DebugView()
AreEqual(typeof(TestTag), types[0].Type);
AreEqual(typeof(TestTag2), types[1].Type);
}

[Test]
public static void Test_ComponentType_not_found()
{
var e = SchemaTypeUtils.ComponentTypeException(typeof(int), nameof(IComponent));
AreEqual("IComponent type not found: System.Int32", e.Message);

IsNull(SchemaUtils.GetGenericComponentKey(typeof(int)));
}

}

}
8 changes: 8 additions & 0 deletions Engine/src/Tests/ECS/Base/Test_Components.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ public static void Test_Generic_Component_exceptions()
inner = e!.InnerException as InvalidOperationException;
AreEqual("Missing attribute [GenericInstanceType(\"<key>\", typeof(Int32), typeof(String))] for generic ITag type: Tests.ECS.GenericTag2`2[System.Int32,System.String]", inner!.Message);
}

[Test]
public static void Test_Generic_Component_coverage()
{
_ = new GenericInstanceTypeAttribute("abc", typeof(int));
_ = new GenericInstanceTypeAttribute("abc", typeof(int), typeof(int));
_ = new GenericInstanceTypeAttribute("abc", typeof(int), typeof(int), typeof(int));
}
}

}
1 change: 1 addition & 0 deletions Engine/src/Tests/ECS/GenericComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public struct GenericTag<T> : ITag { }
[GenericInstanceType("generic-tag2", typeof(int), typeof(bool))]
public struct GenericTag2<T1, T2> : ITag { }

[CodeCoverageTest]
[GenericInstanceType("generic-tag3", typeof(int), typeof(int), typeof(int))]
public struct GenericTag3<T1, T2, T3> : ITag { }

Expand Down

0 comments on commit a1b490b

Please sign in to comment.