From 6bc3ffa61779b545a1a62a992e5608a054f085b1 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Fri, 21 Apr 2023 20:36:19 -0700 Subject: [PATCH] chore: add test for anonymous system --- test/BUILD.bazel | 16 ++++++++++++++++ test/anonymous_system.cc | 32 ++++++++++++++++++++++++++++++++ test/anonymous_system.ecsact | 7 +++++++ 3 files changed, 55 insertions(+) create mode 100644 test/anonymous_system.cc create mode 100644 test/anonymous_system.ecsact diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 4a1d559..cdf82f6 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -57,3 +57,19 @@ cc_test( "@com_google_googletest//:gtest_main", ], ) + +cc_test( + name = "anonymous_system", + srcs = ["anonymous_system.cc"], + copts = copts, + data = [ + "anonymous_system.ecsact", + ], + deps = [ + ":test_lib", + "//:ecsact_interpret", + "@bazel_sundry//bazel_sundry:runfiles", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/test/anonymous_system.cc b/test/anonymous_system.cc new file mode 100644 index 0000000..39facf9 --- /dev/null +++ b/test/anonymous_system.cc @@ -0,0 +1,32 @@ +#include "gtest/gtest.h" +#include "ecsact/interpret/eval.h" +#include "ecsact/runtime/meta.hh" + +#include "test/test_lib.hh" + +TEST(EcsactInterpret, AllowAnonymousSystem) { + auto errs = ecsact_interpret_test_files({"anonymous_system.ecsact"}); + ASSERT_EQ(errs.size(), 0) // + << "Expected no errors. Instead got: " << errs[0].error_message << "\n"; + + auto package_ids = ecsact::meta::get_package_ids(); + ASSERT_EQ(package_ids.size(), 1); + + auto sys_ids = ecsact::meta::get_system_ids(package_ids[0]); + ASSERT_EQ(sys_ids.size(), 1); + + auto sys_name = ecsact::meta::system_name(sys_ids[0]); + ASSERT_TRUE(sys_name.empty()); + + auto sys_caps = ecsact::meta::system_capabilities(sys_ids[0]); + ASSERT_EQ(sys_caps.size(), 1); + + auto comp_ids = ecsact::meta::get_component_ids(package_ids[0]); + ASSERT_EQ(comp_ids.size(), 1); + + ASSERT_EQ(sys_caps.begin()->second, ECSACT_SYS_CAP_REMOVES); + ASSERT_EQ( + sys_caps.begin()->first, + ecsact_id_cast(comp_ids[0]) + ); +} diff --git a/test/anonymous_system.ecsact b/test/anonymous_system.ecsact new file mode 100644 index 0000000..2beb39e --- /dev/null +++ b/test/anonymous_system.ecsact @@ -0,0 +1,7 @@ +package example.anonymous_sys; + +component MyComponent; + +// Trival anonymous system that always removes MyComponent +system { removes MyComponent; } +