Skip to content

Commit

Permalink
#1027 Add test for world::scope(const char*)
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Aug 20, 2023
1 parent 1665302 commit c32c426
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ extern "C" {

/**
* @file table_graph.h
* @brief Table graph types.
* @brief Table graph types and functions.
*/

#ifndef FLECS_TABLE_GRAPH_H
Expand Down
6 changes: 6 additions & 0 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19784,6 +19784,8 @@ struct world {
template <typename T>
flecs::scoped_world scope() const;

flecs::scoped_world scope(const char* name) const;

/** Delete all entities with specified id. */
void delete_with(id_t the_id) const {
ecs_delete_with(m_world, the_id);
Expand Down Expand Up @@ -30178,6 +30180,10 @@ inline flecs::scoped_world world::scope() const {
return scoped_world(m_world, parent);
}

inline flecs::scoped_world world::scope(const char* name) const {
return scope(entity(name));
}

} // namespace flecs


Expand Down
2 changes: 1 addition & 1 deletion src/storage/table_graph.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file table_graph.h
* @brief Table graph types.
* @brief Table graph types and functions.
*/

#ifndef FLECS_TABLE_GRAPH_H
Expand Down
3 changes: 2 additions & 1 deletion test/cpp_api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,8 @@
"component_w_low_id",
"get_set_log_level",
"reset_world",
"id_from_pair_type"
"id_from_pair_type",
"scope_w_name"
]
}, {
"id": "Singleton",
Expand Down
9 changes: 9 additions & 0 deletions test/cpp_api/src/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1715,3 +1715,12 @@ void World_id_from_pair_type(void) {
test_assert(id.second() == ecs.id<Velocity>());
}


void World_scope_w_name(void) {
flecs::world ecs;

flecs::entity parent = ecs.entity("parent");
flecs::entity child = ecs.scope("parent").entity();

test_assert(child.has(flecs::ChildOf, parent));
}
7 changes: 6 additions & 1 deletion test/cpp_api/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ void World_component_w_low_id(void);
void World_get_set_log_level(void);
void World_reset_world(void);
void World_id_from_pair_type(void);
void World_scope_w_name(void);

// Testsuite 'Singleton'
void Singleton_set_get_singleton(void);
Expand Down Expand Up @@ -5500,6 +5501,10 @@ bake_test_case World_testcases[] = {
{
"id_from_pair_type",
World_id_from_pair_type
},
{
"scope_w_name",
World_scope_w_name
}
};

Expand Down Expand Up @@ -6273,7 +6278,7 @@ static bake_test_suite suites[] = {
"World",
NULL,
NULL,
97,
98,
World_testcases
},
{
Expand Down

0 comments on commit c32c426

Please sign in to comment.