Skip to content

Commit

Permalink
added types to json catalog, added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThoSe1990 committed Nov 11, 2024
1 parent 7e37288 commit daf5cdd
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if(GTest_FOUND)

add_executable(${target}
${CMAKE_CURRENT_SOURCE_DIR}/ast.cc
${CMAKE_CURRENT_SOURCE_DIR}/any.cc
${CMAKE_CURRENT_SOURCE_DIR}/ast_visitor.cc
${CMAKE_CURRENT_SOURCE_DIR}/catalog.cc
${CMAKE_CURRENT_SOURCE_DIR}/context.cc
Expand Down
32 changes: 32 additions & 0 deletions gtest/any.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

#include <gtest/gtest.h>

#include "../src/any.hpp"

using namespace cuke::internal;

TEST(any, init_obj) { any a(234); }
TEST(any, init_int)
{
any a(234);
int i = a;
EXPECT_EQ(i, 234);
}
TEST(any, assign_int)
{
any a(234);
int i = 99;
i = a;
EXPECT_EQ(i, 234);
}

struct foo
{
std::string value;
};
TEST(any, init_string_in_struct)
{
any a(std::string("hello"));
foo f{a};
EXPECT_EQ(f.value, std::string("hello"));
}
13 changes: 13 additions & 0 deletions src/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ std::string as_json(std::size_t indents /* = 2 */)

steps_catalog["steps_catalog"].push_back(step_entry);
}
for (auto& [key, value] : cuke::registry().custom_expressions())
{
json field_type = {{"type", key}};
json field_pattern = {{"pattern", value.pattern}};
json field_comment = {{"comment", value.type_info}};

json type_entry = {
{"type", field_type["type"]},
{"pattern", field_pattern["pattern"]},
{"comment", field_comment["comment"]},
};
steps_catalog["types"].push_back(type_entry);
}

return steps_catalog.dump(indents);
#endif // WITH_JSON
Expand Down
5 changes: 5 additions & 0 deletions src/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class registry
m_expressions.custom.clear();
}

[[nodiscard]] std::unordered_map<std::string, expression> custom_expressions()
const noexcept
{
return m_expressions.custom;
}
void push_expression(std::string_view key,
const expression& custom_expression)
{
Expand Down

0 comments on commit daf5cdd

Please sign in to comment.