Skip to content

Commit b4d817b

Browse files
committed
Start working on tests
1 parent 75231ee commit b4d817b

3 files changed

Lines changed: 109 additions & 2 deletions

File tree

libraries/core/lib/morpheus/core/serialisation/toml_reader.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,26 @@ void TomlReader::beginComposite() {}
1414

1515
void TomlReader::endComposite() {}
1616

17-
void TomlReader::beginValue(std::string_view const key) {}
17+
void TomlReader::beginValue(std::string_view const key)
18+
{
19+
if (mCurrentKey)
20+
mKeyStack.push_back(*mCurrentKey);
21+
22+
mCurrentKey = std::string(key);
23+
}
1824

19-
void TomlReader::endValue() {}
25+
void TomlReader::endValue()
26+
{
27+
if (!mKeyStack.empty())
28+
{
29+
mCurrentKey = mKeyStack.back();
30+
mKeyStack.pop_back();
31+
}
32+
else
33+
{
34+
mCurrentKey.reset();
35+
}
36+
}
2037

2138
std::optional<std::size_t> TomlReader::beginSequence()
2239
{

libraries/core/lib/morpheus/core/serialisation/toml_reader.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class TomlReader
9797

9898
private:
9999
std::istream& mStream;
100+
std::optional<std::string> mCurrentKey;
101+
std::vector<std::string> mKeyStack;
100102
toml::table mTable;
101103
};
102104

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#include "morpheus/core/conformance/value_types.hpp"
2+
#include "morpheus/core/serialisation/adapters/aggregate.hpp"
3+
#include "morpheus/core/serialisation/adapters/boost/circular_buffer.hpp"
4+
#include "morpheus/core/serialisation/adapters/boost/dynamic_bitset.hpp"
5+
#include "morpheus/core/serialisation/adapters/std/bitset.hpp"
6+
#include "morpheus/core/serialisation/adapters/std/chrono.hpp"
7+
#include "morpheus/core/serialisation/adapters/std/indirect.hpp"
8+
#include "morpheus/core/serialisation/adapters/std/monostate.hpp"
9+
#include "morpheus/core/serialisation/adapters/std/optional.hpp"
10+
#include "morpheus/core/serialisation/adapters/std/pair.hpp"
11+
#include "morpheus/core/serialisation/adapters/std/tuple.hpp"
12+
#include "morpheus/core/serialisation/adapters/std/unique_ptr.hpp"
13+
#include "morpheus/core/serialisation/adapters/std/variant.hpp"
14+
#include "morpheus/core/serialisation/adapters/std/vector.hpp"
15+
#include "morpheus/core/serialisation/serialisers.hpp"
16+
#include "morpheus/core/serialisation/write_serialiser.hpp"
17+
18+
#include "morpheus/serialisation/helpers.hpp"
19+
20+
#include <catch2/catch_template_test_macros.hpp>
21+
#include <catch2/catch_test_macros.hpp>
22+
23+
#include <bitset>
24+
#include <chrono>
25+
#include <memory>
26+
#include <optional>
27+
#include <sstream>
28+
#include <string>
29+
#include <utility>
30+
#include <variant>
31+
#include <vector>
32+
33+
using namespace Catch;
34+
35+
namespace morpheus::serialisation
36+
{
37+
38+
namespace test
39+
{
40+
41+
template <class T>
42+
static std::string serialise(std::string_view key, T const& value)
43+
{
44+
std::ostringstream oss;
45+
TomlWriteSerialiser serialiser{std::in_place, oss};
46+
serialiser.serialise(key, value);
47+
return oss.str();
48+
}
49+
50+
} // namespace test
51+
52+
TEMPLATE_TEST_CASE("Toml Json writer can write single native types to underlying text representation",
53+
"[morpheus.serialisation.toml_reader.native]",
54+
bool,
55+
std::int8_t,
56+
std::uint8_t,
57+
std::int16_t,
58+
std::uint16_t,
59+
std::int32_t,
60+
std::uint32_t,
61+
std::int64_t,
62+
std::uint64_t,
63+
float,
64+
double)
65+
{
66+
if constexpr (std::is_integral_v<TestType>)
67+
{
68+
REQUIRE(test::serialise("value", std::numeric_limits<TestType>::min()) == conf::fmt::format("value = {}", std::numeric_limits<TestType>::min()));
69+
REQUIRE(test::serialise("value", std::numeric_limits<TestType>::lowest()) == conf::fmt::format("value = {}", std::numeric_limits<TestType>::lowest()));
70+
REQUIRE(test::serialise("value", std::numeric_limits<TestType>::max()) == conf::fmt::format("value = {}", std::numeric_limits<TestType>::max()));
71+
REQUIRE(test::serialise("value", std::numeric_limits<TestType>::radix) == conf::fmt::format("value = {}", std::numeric_limits<TestType>::radix));
72+
}
73+
else if constexpr (std::is_floating_point_v<TestType>)
74+
{
75+
REQUIRE(test::serialise("value", 0) == "value = 0");
76+
REQUIRE(test::serialise("value", -0) == "value = 0");
77+
REQUIRE(test::serialise("value", TestType(2.75)) == "value = 2.75");
78+
REQUIRE(test::serialise("value", TestType(-2.75)) == "value = -2.75");
79+
REQUIRE(test::serialise("value", std::numeric_limits<TestType>::infinity()) == "value = Infinity");
80+
REQUIRE(test::serialise("value", -std::numeric_limits<TestType>::infinity()) == "value = -Infinity");
81+
REQUIRE(test::serialise("value", std::numeric_limits<TestType>::quiet_NaN()) == "value = NaN");
82+
REQUIRE(test::serialise("value", -std::numeric_limits<TestType>::quiet_NaN()) == "value = NaN");
83+
REQUIRE(test::serialise("value", std::numeric_limits<TestType>::signaling_NaN()) == "value = NaN");
84+
REQUIRE(test::serialise("value", -std::numeric_limits<TestType>::signaling_NaN()) == "value = NaN");
85+
}
86+
}
87+
88+
} // namespace morpheus::serialisation

0 commit comments

Comments
 (0)