Skip to content

Commit

Permalink
fix catch2 include error
Browse files Browse the repository at this point in the history
  • Loading branch information
injae committed Dec 31, 2023
1 parent bd02d0b commit df400d6
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 55 deletions.
6 changes: 2 additions & 4 deletions tests/catch_main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#define CATCH_CONFIG_MAIN

#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>

TEST_CASE("1: test (pass)", "[multi-file:1]") {
REQUIRE(1==1);
}
TEST_CASE("1: test (pass)", "[multi-file:1]") { REQUIRE(1 == 1); }
10 changes: 3 additions & 7 deletions tests/nlohmann_json.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

#include <catch2/catch.hpp>
#include "test_struct.hpp"
#include <catch2/catch_all.hpp>
#include <serdepp/adaptor/nlohmann_json.hpp>


nlohmann::json json_v = R"({
"str" : "hello",
"i": 10,
Expand All @@ -16,8 +14,6 @@ nlohmann::json json_v = R"({
using namespace serde;

TEST_CASE("2: nlohmann json struct (pass)", "[multi-file:2]") {
REQUIRE(json_v.dump() == serialize<nlohmann::json>(deserialize<test>(json_v)).dump());
REQUIRE(json_v.dump() ==
serialize<nlohmann::json>(deserialize<test>(json_v)).dump());
}



23 changes: 12 additions & 11 deletions tests/rapid_json.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
#include <catch2/catch.hpp>
#include "test_struct.hpp"
#include <catch2/catch_all.hpp>
#include <serdepp/adaptor/rapidjson.hpp>

std::string str(rapidjson::Document& doc) {
using namespace rapidjson;
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
doc.Accept(writer);
return buffer.GetString();
std::string str(rapidjson::Document &doc) {
using namespace rapidjson;
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
doc.Accept(writer);
return buffer.GetString();
};

using namespace serde;

TEST_CASE("5: toml11 struct (pass)", "[multi-file:5]") {
rapidjson::Document json_v;
json_v.Parse(R"({
rapidjson::Document json_v;
json_v.Parse(R"({
"str" : "hello",
"i": 10,
"vec": [ "one", "two", "three"],
"opt": "hello",
"sm": { "one" : "tone", "two" : "ttwo"},
"sub" : { "str": "hello" }
})");
rapidjson::Document json_c = serialize<rapidjson::Document>(deserialize<test>(json_v));
rapidjson::Document json_c =
serialize<rapidjson::Document>(deserialize<test>(json_v));

REQUIRE(str(json_v) == str(json_c));
REQUIRE(str(json_v) == str(json_c));
}
17 changes: 6 additions & 11 deletions tests/reflection.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#include <catch2/catch.hpp>
#include "test_struct.hpp"
#include <catch2/catch_all.hpp>
#include <serdepp/adaptor/reflection.hpp>

using namespace serde;

TEST_CASE("3: reflection struct (pass)", "[multi-file:3]") {
REQUIRE(std::is_same_v<to_tuple_t<test>,
std::tuple<std::string,
int,
std::vector<std::string>,
std::optional<std::string>,
std::optional<std::string>,
std::map<std::string, std::string>,
nested>>);
REQUIRE(std::is_same_v<
to_tuple_t<test>,
std::tuple<std::string, int, std::vector<std::string>,
std::optional<std::string>, std::optional<std::string>,
std::map<std::string, std::string>, nested>>);
}


26 changes: 13 additions & 13 deletions tests/test_struct.hpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#include <serdepp/serde.hpp>

#pragma once

#ifndef __CATCH_TEST_STRUCT_HPP__
#define __CATCH_TEST_STRUCT_HPP__

#include <serdepp/serde.hpp>

struct nested {
DERIVE_SERDE(nested, _SF_(str))
std::string str;
DERIVE_SERDE(nested, _SF_(str))
std::string str;
};

struct test {
DERIVE_SERDE(test, _SF_(str)_SF_(i)_SF_(vec)_SF_(opt)_SF_(none_opt)_SF_(sm)_SF_(sub))
std::string str;
int i;
std::vector<std::string> vec;
std::optional<std::string> none_opt;
std::optional<std::string> opt;
std::map<std::string, std::string> sm;
nested sub;
DERIVE_SERDE(test, _SF_(str) _SF_(i) _SF_(vec) _SF_(opt) _SF_(none_opt)
_SF_(sm) _SF_(sub))
std::string str;
int i;
std::vector<std::string> vec;
std::optional<std::string> none_opt;
std::optional<std::string> opt;
std::map<std::string, std::string> sm;
nested sub;
};

#endif

4 changes: 2 additions & 2 deletions tests/toml11.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <catch2/catch.hpp>
#include "test_struct.hpp"
#include <catch2/catch_all.hpp>
#include <serdepp/adaptor/toml11.hpp>

using namespace serde;
Expand All @@ -21,5 +21,5 @@ str = "hello"
)"_toml;

TEST_CASE("4: toml11 struct (pass)", "[multi-file:4]") {
REQUIRE(toml_vl == serialize<toml::value>(deserialize<test>(toml_vl)));
REQUIRE(toml_vl == serialize<toml::value>(deserialize<test>(toml_vl)));
}
13 changes: 6 additions & 7 deletions tests/yaml_cpp.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <catch2/catch.hpp>
#include "test_struct.hpp"
#include <catch2/catch_all.hpp>
#include <serdepp/adaptor/yaml-cpp.hpp>


YAML::Node yaml_v = YAML::Load(R"(
str: hello
i: 10
Expand All @@ -21,10 +20,10 @@ opt: hello
using namespace serde;

TEST_CASE("5: yaml-cpp struct (pass)", "[multi-file:5]") {
std::ostringstream origin;
origin << yaml_v;
std::ostringstream convert;
convert << serialize<YAML::Node>(deserialize<test>(yaml_v));
std::ostringstream origin;
origin << yaml_v;
std::ostringstream convert;
convert << serialize<YAML::Node>(deserialize<test>(yaml_v));

REQUIRE(origin.str() == convert.str());
REQUIRE(origin.str() == convert.str());
}

0 comments on commit df400d6

Please sign in to comment.