|
| 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