diff --git a/components/core/src/clp/ir/EncodedTextAst.hpp b/components/core/src/clp/ir/EncodedTextAst.hpp index 2bbf30b4d..945996ae1 100644 --- a/components/core/src/clp/ir/EncodedTextAst.hpp +++ b/components/core/src/clp/ir/EncodedTextAst.hpp @@ -37,6 +37,8 @@ class EncodedTextAst { ~EncodedTextAst() = default; // Methods + auto operator==(EncodedTextAst const&) const -> bool = default; + [[nodiscard]] auto get_logtype() const -> std::string const& { return m_logtype; } [[nodiscard]] auto get_dict_vars() const -> std::vector const& { diff --git a/components/core/tests/test-ffi_Value.cpp b/components/core/tests/test-ffi_Value.cpp index 51caeb982..33764c4ff 100644 --- a/components/core/tests/test-ffi_Value.cpp +++ b/components/core/tests/test-ffi_Value.cpp @@ -38,21 +38,23 @@ requires(std::is_same_v ) -> clp::ir::EncodedTextAst; /** - * Tests querying the underlying type of the given value against the given type. + * Tests that `Value::is` returns true for the given type and false for all others. * @tparam Type The type to query. * @param value The value to test against. */ template -auto test_type_probing(Value const& value) -> void; +auto test_value_is(Value const& value) -> void; /** - * Tests querying the typed value against the given type. + * Tests `Value::get_immutable_view` either: + * 1. returns the expected value with the expected type for the given type and value; + * 2. throws for any other type. * @tparam Type The type to query. * @param value The value to test against. * @param typed_value The typed value to compare with. */ template -auto test_typed_value_probing(Value const& value, Type const& typed_value) -> void; +auto test_value_get_immutable_view(Value const& value, Type const& typed_value) -> void; // Implementation @@ -78,7 +80,7 @@ auto get_encoded_text_ast(std::string_view text) -> clp::ir::EncodedTextAst // NOLINTNEXTLINE(readability-function-cognitive-complexity) -auto test_type_probing(Value const& value) -> void { +auto test_value_is(Value const& value) -> void { REQUIRE((std::is_same_v == value.is_null())); REQUIRE((std::is_same_v == value.is())); REQUIRE((std::is_same_v == value.is())); @@ -90,24 +92,24 @@ auto test_type_probing(Value const& value) -> void { template // NOLINTNEXTLINE(readability-function-cognitive-complexity) -auto test_typed_value_probing(Value const& value, Type const& typed_value) -> void { +auto test_value_get_immutable_view(Value const& value, Type const& typed_value) -> void { if constexpr (std::is_same_v) { REQUIRE((value.get_immutable_view() == typed_value)); - REQUIRE((std::is_same_v())>)); + REQUIRE((std::is_same_v())>)); } else { REQUIRE_THROWS(value.get_immutable_view()); } if constexpr (std::is_same_v) { REQUIRE((value.get_immutable_view() == typed_value)); - REQUIRE((std::is_same_v())>)); + REQUIRE((std::is_same_v())>)); } else { REQUIRE_THROWS(value.get_immutable_view()); } if constexpr (std::is_same_v) { REQUIRE((value.get_immutable_view() == typed_value)); - REQUIRE((std::is_same_v())>)); + REQUIRE((std::is_same_v())>)); } else { REQUIRE_THROWS(value.get_immutable_view()); } @@ -120,12 +122,7 @@ auto test_typed_value_probing(Value const& value, Type const& typed_value) -> vo } if constexpr (std::is_same_v) { - REQUIRE((value.get_immutable_view().get_logtype() == typed_value.get_logtype())); - REQUIRE((value.get_immutable_view().get_dict_vars() == typed_value.get_dict_vars())); - REQUIRE( - (value.get_immutable_view().get_encoded_vars() - == typed_value.get_encoded_vars()) - ); + REQUIRE((value.get_immutable_view() == typed_value)); REQUIRE((std::is_same_v< EightByteEncodedTextAst const&, decltype(value.get_immutable_view())>)); @@ -134,12 +131,7 @@ auto test_typed_value_probing(Value const& value, Type const& typed_value) -> vo } if constexpr (std::is_same_v) { - REQUIRE((value.get_immutable_view().get_logtype() == typed_value.get_logtype())); - REQUIRE((value.get_immutable_view().get_dict_vars() == typed_value.get_dict_vars())); - REQUIRE( - (value.get_immutable_view().get_encoded_vars() - == typed_value.get_encoded_vars()) - ); + REQUIRE((value.get_immutable_view() == typed_value)); REQUIRE((std::is_same_v< FourByteEncodedTextAst const&, decltype(value.get_immutable_view())>)); @@ -151,35 +143,35 @@ auto test_typed_value_probing(Value const& value, Type const& typed_value) -> vo TEST_CASE("ffi_Value_basic", "[ffi][Value]") { Value const null_value; - test_type_probing(null_value); - test_typed_value_probing(null_value, std::monostate{}); + test_value_is(null_value); + test_value_get_immutable_view(null_value, std::monostate{}); constexpr value_int_t cIntVal{1000}; Value const int_value{cIntVal}; - test_type_probing(int_value); - test_typed_value_probing(int_value, cIntVal); + test_value_is(int_value); + test_value_get_immutable_view(int_value, cIntVal); constexpr value_float_t cFloatValue{1000.0001}; Value const float_value{cFloatValue}; - test_type_probing(float_value); - test_typed_value_probing(float_value, cFloatValue); + test_value_is(float_value); + test_value_get_immutable_view(float_value, cFloatValue); constexpr value_bool_t cBoolVal{false}; Value const bool_value{cBoolVal}; - test_type_probing(bool_value); - test_typed_value_probing(bool_value, cBoolVal); + test_value_is(bool_value); + test_value_get_immutable_view(bool_value, cBoolVal); constexpr std::string_view cStringVal{"This is a test string message"}; Value const string_value{string{cStringVal}}; - test_type_probing(string_value); - test_typed_value_probing(string_value, string{cStringVal}); + test_value_is(string_value); + test_value_get_immutable_view(string_value, string{cStringVal}); constexpr std::string_view cStringToEncode{"uid=0, CPU usage: 99.99%, \"user_name\"=YScope"}; Value const eight_byte_encoded_text_ast_value{ get_encoded_text_ast(cStringToEncode) }; - test_type_probing(eight_byte_encoded_text_ast_value); - test_typed_value_probing( + test_value_is(eight_byte_encoded_text_ast_value); + test_value_get_immutable_view( eight_byte_encoded_text_ast_value, get_encoded_text_ast(cStringToEncode) ); @@ -187,8 +179,8 @@ TEST_CASE("ffi_Value_basic", "[ffi][Value]") { Value const four_byte_encoded_text_ast_value{ get_encoded_text_ast(cStringToEncode) }; - test_type_probing(four_byte_encoded_text_ast_value); - test_typed_value_probing( + test_value_is(four_byte_encoded_text_ast_value); + test_value_get_immutable_view( four_byte_encoded_text_ast_value, get_encoded_text_ast(cStringToEncode) );