Skip to content

Commit 7bce97e

Browse files
Port C++ tests
1 parent fb8e1d4 commit 7bce97e

File tree

8 files changed

+421
-14
lines changed

8 files changed

+421
-14
lines changed

src/Flecs.NET.Tests/Cpp/EntityTests.cs

+16
Original file line numberDiff line numberDiff line change
@@ -4021,6 +4021,22 @@ private void EntityWithType()
40214021
Assert.True(e == e2);
40224022
}
40234023

4024+
[Fact]
4025+
private void PrefabWithType()
4026+
{
4027+
using World world = World.Create();
4028+
4029+
Entity e = world.Prefab<EntityType>();
4030+
4031+
Assert.Equal("EntityType", e.Name());
4032+
Assert.Equal(".EntityType", e.Path());
4033+
Assert.True(e.Has<EcsComponent>());
4034+
Assert.True(e.Has(Ecs.Prefab));
4035+
4036+
Entity e2 = world.Entity<EntityType>();
4037+
Assert.True(e == e2);
4038+
}
4039+
40244040
[Fact]
40254041
private void PrefabHierarchyWithTypes()
40264042
{

src/Flecs.NET.Tests/Cpp/ObserverTests.cs

+62
Original file line numberDiff line numberDiff line change
@@ -1646,4 +1646,66 @@ private void TriggerOnSetInOnAddImplicitRegistrationNamespaced()
16461646
Assert.Equal(1, v->X);
16471647
Assert.Equal(2, v->Y);
16481648
}
1649+
1650+
[Fact]
1651+
private void FixedSrcWithEach()
1652+
{
1653+
using World world = World.Create();
1654+
1655+
Entity matched = default;
1656+
Entity e = world.Entity();
1657+
1658+
world.Observer()
1659+
.With<Tag>().Src(e)
1660+
.Event(Ecs.OnAdd)
1661+
.Each((Iter it, int _) =>
1662+
{
1663+
matched = it.Src(0);
1664+
});
1665+
1666+
Assert.True(matched == 0);
1667+
1668+
e.Add<Tag>();
1669+
1670+
Assert.True(matched == e);
1671+
1672+
matched = default;
1673+
1674+
world.Entity().Add<Tag>();
1675+
1676+
Assert.True(matched == 0);
1677+
}
1678+
1679+
[Fact]
1680+
private void FixedSrcWithRun()
1681+
{
1682+
using World world = World.Create();
1683+
1684+
Entity matched = default;
1685+
Entity e = world.Entity();
1686+
1687+
world.Observer()
1688+
.With<Tag>().Src(e)
1689+
.Event(Ecs.OnAdd)
1690+
.Run((Iter it) =>
1691+
{
1692+
while (it.Next())
1693+
{
1694+
Assert.Equal(0, it.Count());
1695+
matched = it.Src(0);
1696+
}
1697+
});
1698+
1699+
Assert.True(matched == 0);
1700+
1701+
e.Add<Tag>();
1702+
1703+
Assert.True(matched == e);
1704+
1705+
matched = default;
1706+
1707+
world.Entity().Add<Tag>();
1708+
1709+
Assert.True(matched == 0);
1710+
}
16491711
}

src/Flecs.NET.Tests/Cpp/QueryBuilderTests.cs

+34-4
Original file line numberDiff line numberDiff line change
@@ -5480,7 +5480,7 @@ private void EachWithFieldWithFixedSrc(ecs_query_cache_kind_t cacheKind)
54805480
Entity e2 = world.Entity()
54815481
.Set(new Position(20, 30));
54825482

5483-
Query q = world.QueryBuilder()
5483+
using Query q = world.QueryBuilder()
54845484
.With<Position>()
54855485
.With<Velocity>().Src(e1)
54865486
.CacheKind(cacheKind)
@@ -5527,7 +5527,7 @@ private void EachWithFieldAtWithFixedSrc(ecs_query_cache_kind_t cacheKind)
55275527
Entity e2 = world.Entity()
55285528
.Set(new Position(20, 30));
55295529

5530-
Query q = world.QueryBuilder()
5530+
using Query q = world.QueryBuilder()
55315531
.With<Position>()
55325532
.With<Velocity>().Src(e1)
55335533
.CacheKind(cacheKind)
@@ -5574,7 +5574,7 @@ private void EachWithUntypedFieldWithFixedSrc(ecs_query_cache_kind_t cacheKind)
55745574
Entity e2 = world.Entity()
55755575
.Set(new Position(20, 30));
55765576

5577-
Query q = world.QueryBuilder()
5577+
using Query q = world.QueryBuilder()
55785578
.With<Position>()
55795579
.With<Velocity>().Src(e1)
55805580
.CacheKind(cacheKind)
@@ -5622,7 +5622,7 @@ private void EachWithUntypedFieldAtWithFixedSrc(ecs_query_cache_kind_t cacheKind
56225622
Entity e2 = world.Entity()
56235623
.Set(new Position(20, 30));
56245624

5625-
Query q = world.QueryBuilder()
5625+
using Query q = world.QueryBuilder()
56265626
.With<Position>()
56275627
.With<Velocity>().Src(e1)
56285628
.CacheKind(cacheKind)
@@ -5656,4 +5656,34 @@ private void EachWithUntypedFieldAtWithFixedSrc(ecs_query_cache_kind_t cacheKind
56565656

56575657
Assert.Equal(2, count);
56585658
}
5659+
5660+
[Theory]
5661+
[MemberData(nameof(CacheKinds))]
5662+
private void SingletonPair(ecs_query_cache_kind_t cacheKind)
5663+
{
5664+
using World world = World.Create();
5665+
5666+
Entity rel = world.Component<Position>();
5667+
Entity tgt = world.Entity();
5668+
5669+
world.Set(tgt, new Position(10, 20));
5670+
5671+
int count = 0;
5672+
5673+
using Query<Position> q = world.QueryBuilder<Position>()
5674+
.TermAt(0).Second(tgt).Singleton()
5675+
.CacheKind(cacheKind)
5676+
.Build();
5677+
5678+
q.Each((Iter it, int _, ref Position p) =>
5679+
{
5680+
Assert.True(it.Src(0) == rel);
5681+
Assert.True(it.Pair(0) == world.Pair<Position>(tgt));
5682+
Assert.Equal(10, p.X);
5683+
Assert.Equal(20, p.Y);
5684+
count++;
5685+
});
5686+
5687+
Assert.Equal(1, count);
5688+
}
56595689
}

0 commit comments

Comments
 (0)