Skip to content

Commit

Permalink
fix: add missing out capabilities count assignment (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy authored Jun 19, 2024
1 parent 79a94ec commit e81cead
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 2 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module(
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "magic_enum", version = "0.9.3")
bazel_dep(name = "ecsact_runtime", version = "0.6.5")
bazel_dep(name = "ecsact_runtime", version = "0.6.6")
bazel_dep(name = "ecsact_parse", version = "0.5.1")

bazel_dep(name = "toolchains_llvm", version = "1.0.0", dev_dependency = True)
Expand Down
4 changes: 4 additions & 0 deletions parse-resolver-runtime/assoc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ void ecsact_meta_system_assoc_capabilities(
return;
}

if(out_capabilities_count) {
*out_capabilities_count = static_cast<int32_t>(info->caps.size());
}

for(int32_t i = 0; max_capabilities_count > i; ++i) {
if(i >= info->caps.size()) {
break;
Expand Down
16 changes: 16 additions & 0 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ cc_test(
],
)

cc_test(
name = "assoc_capabilities",
srcs = ["assoc_capabilities.cc"],
copts = copts,
data = [
"assoc_capabilities.ecsact",
],
deps = [
":test_lib",
"@ecsact_interpret",
"@bazel_sundry//bazel_sundry:runfiles",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)

cc_test(
name = "field_indexing",
srcs = ["field_indexing.cc"],
Expand Down
2 changes: 1 addition & 1 deletion test/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "googletest", version = "1.14.0")
bazel_dep(name = "ecsact_parse", version = "0.5.1")
bazel_dep(name = "ecsact_runtime", version = "0.6.5")
bazel_dep(name = "ecsact_runtime", version = "0.6.6")

bazel_dep(name = "toolchains_llvm", version = "1.0.0", dev_dependency = True)
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
Expand Down
76 changes: 76 additions & 0 deletions test/assoc_capabilities.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

#include "gtest/gtest.h"

#include "ecsact/runtime/meta.hh"
#include "ecsact/runtime/dynamic.h"
#include "test_lib.hh"

using ecsact::meta::get_field_type;

class AssocCapabilities : public testing::Test {
public:
ecsact_package_id pkg_id;

protected:
void SetUp() override {
auto errs = ecsact_interpret_test_files({"assoc_capabilities.ecsact"});
ASSERT_EQ(errs.size(), 0) //
<< "Expected no errors. Instead got: " << errs[0].error_message << "\n";
pkg_id = ecsact::meta::get_package_ids().at(0);
}

void TearDown() override {
// ecsact_destroy_package(pkg_id);
}
};

TEST_F(AssocCapabilities, GeneralReads) {
auto example_comp = get_component_by_name(pkg_id, "Example");
ASSERT_TRUE(example_comp);

auto comp = get_component_by_name(pkg_id, "AssocComp");
ASSERT_TRUE(comp);

auto sys = get_system_by_name(pkg_id, "ReadwriteSystem");
auto assoc_ids = ecsact::meta::system_assoc_ids(*sys);
ASSERT_EQ(assoc_ids.size(), 1);

auto caps = ecsact::meta::system_assoc_capabilities(*sys, assoc_ids.at(0));
ASSERT_EQ(caps.size(), 1);

ASSERT_EQ(
caps.at(0).first,
ecsact_id_cast<ecsact_component_like_id>(*example_comp)
);
ASSERT_EQ(caps.at(0).second, ECSACT_SYS_CAP_READWRITE);
}

TEST_F(AssocCapabilities, RemovesExists) {
auto example_comp = get_component_by_name(pkg_id, "Example");
ASSERT_TRUE(example_comp);

auto tag_comp = get_component_by_name(pkg_id, "MyTag");
ASSERT_TRUE(tag_comp);

auto comp = get_component_by_name(pkg_id, "AssocComp");
ASSERT_TRUE(comp);

auto sys = get_system_by_name(pkg_id, "RemovesSystem");
auto assoc_ids = ecsact::meta::system_assoc_ids(*sys);
ASSERT_EQ(assoc_ids.size(), 1);

auto assoc_caps =
ecsact::meta::system_assoc_capabilities(*sys, assoc_ids.at(0));

// order isn't guaranteed
for(auto&& [comp_id, caps] : assoc_caps) {
if(comp_id == ecsact_id_cast<ecsact_component_like_id>(*tag_comp)) {
ASSERT_EQ(caps, ECSACT_SYS_CAP_INCLUDE);
} else if(comp_id ==
ecsact_id_cast<ecsact_component_like_id>(*example_comp)) {
ASSERT_EQ(caps, ECSACT_SYS_CAP_REMOVES);
} else {
ASSERT_TRUE(false) << "unknown comp id";
}
}
}
19 changes: 19 additions & 0 deletions test/assoc_capabilities.ecsact
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package eval.assoc_capabilities;

component MyTag;
component Example { i32 num; }
component AssocComp { Example.num hello; }

system ReadwriteSystem {
readwrite AssocComp with hello {
readwrite Example;
}
}

system RemovesSystem {
readwrite AssocComp with hello {
include MyTag;
removes Example;
}
}

0 comments on commit e81cead

Please # to comment.