Make test EntitySpecifiers ignore entities with null prototypes (#22174)
This commit is contained in:
@@ -112,17 +112,19 @@ public abstract partial class InteractionTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert an entity-uid to a matching entity specifier. Usefull when doing entity lookups & checking that the
|
/// Convert an entity-uid to a matching entity specifier. Useful when doing entity lookups & checking that the
|
||||||
/// right quantity of entities/materials werre produced.
|
/// right quantity of entities/materials werre produced. Returns null if passed an entity with a null prototype.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected EntitySpecifier ToEntitySpecifier(EntityUid uid)
|
protected EntitySpecifier? ToEntitySpecifier(EntityUid uid)
|
||||||
{
|
{
|
||||||
if (SEntMan.TryGetComponent(uid, out StackComponent? stack))
|
if (SEntMan.TryGetComponent(uid, out StackComponent? stack))
|
||||||
return new EntitySpecifier(stack.StackTypeId, stack.Count) { Converted = true };
|
return new EntitySpecifier(stack.StackTypeId, stack.Count) { Converted = true };
|
||||||
|
|
||||||
var meta = SEntMan.GetComponent<MetaDataComponent>(uid);
|
var meta = SEntMan.GetComponent<MetaDataComponent>(uid);
|
||||||
Assert.That(meta.EntityPrototype, Is.Not.Null);
|
|
||||||
|
|
||||||
return new(meta.EntityPrototype!.ID, 1) { Converted = true };
|
if (meta.EntityPrototype is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new(meta.EntityPrototype.ID, 1) { Converted = true };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,7 +156,9 @@ public abstract partial class InteractionTest
|
|||||||
|
|
||||||
protected EntitySpecifierCollection ToEntityCollection(IEnumerable<EntityUid> entities)
|
protected EntitySpecifierCollection ToEntityCollection(IEnumerable<EntityUid> entities)
|
||||||
{
|
{
|
||||||
var collection = new EntitySpecifierCollection(entities.Select(uid => ToEntitySpecifier(uid)));
|
var collection = new EntitySpecifierCollection(entities
|
||||||
|
.Select(ToEntitySpecifier)
|
||||||
|
.OfType<EntitySpecifier>());
|
||||||
Assert.That(collection.Converted);
|
Assert.That(collection.Converted);
|
||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -598,7 +598,7 @@ public abstract partial class InteractionTest
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Performs an entity lookup and asserts that only the listed entities exist and that they are all present.
|
/// Performs an entity lookup and asserts that only the listed entities exist and that they are all present.
|
||||||
/// Ignores the grid, map, player, target and contained entities.
|
/// Ignores the grid, map, player, target, contained entities, and entities with null prototypes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected async Task AssertEntityLookup(
|
protected async Task AssertEntityLookup(
|
||||||
EntitySpecifierCollection collection,
|
EntitySpecifierCollection collection,
|
||||||
@@ -652,6 +652,9 @@ public abstract partial class InteractionTest
|
|||||||
foreach (var uid in entities)
|
foreach (var uid in entities)
|
||||||
{
|
{
|
||||||
var found = ToEntitySpecifier(uid);
|
var found = ToEntitySpecifier(uid);
|
||||||
|
if (found is null)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (spec.Prototype != found.Prototype)
|
if (spec.Prototype != found.Prototype)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user