From 344023239b08720530105ef519fa10500393ed21 Mon Sep 17 00:00:00 2001 From: Thierry Treyer Date: Wed, 30 Aug 2023 14:19:29 -0700 Subject: [PATCH] Add OILv2 tests for std::optional --- oi/IntrospectionResult.cpp | 2 -- test/integration/std_optional.toml | 56 ++++++++++++++++++++++++++++++ types/optional_type.toml | 8 +++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/oi/IntrospectionResult.cpp b/oi/IntrospectionResult.cpp index f4fb323..cd09806 100644 --- a/oi/IntrospectionResult.cpp +++ b/oi/IntrospectionResult.cpp @@ -20,7 +20,6 @@ #include #include #include -#include // TODO: remove template inline constexpr bool always_false_v = false; @@ -49,7 +48,6 @@ IntrospectionResult::const_iterator::operator++() { using T = std::decay_t; if constexpr (std::is_same_v) { - std::cerr << "ty.name = " << ty.name << std::endl; type_path_.emplace_back(ty.name); stack_.emplace(exporters::inst::PopTypePath{}); next_ = result::Element{ diff --git a/test/integration/std_optional.toml b/test/integration/std_optional.toml index f88063d..7475e28 100644 --- a/test/integration/std_optional.toml +++ b/test/integration/std_optional.toml @@ -15,6 +15,17 @@ includes = ["optional", "cstdint", "vector"] } ] ''' + expect_json_v2 = ''' + [ + { + "staticSize": 16, + "exclusiveSize": 16, + "length": 0, + "capacity": 1, + "members": [] + } + ] + ''' [cases.uint64_present] param_types = ["std::optional&"] setup = "return 64;" @@ -30,6 +41,22 @@ includes = ["optional", "cstdint", "vector"] } ] ''' + expect_json_v2 = ''' + [ + { + "staticSize": 16, + "exclusiveSize": 8, + "length": 1, + "capacity": 1, + "members": [ + { + "staticSize": 8, + "exclusiveSize": 8 + } + ] + } + ] + ''' [cases.vector_empty] param_types = ["std::optional>&"] setup = "return std::nullopt;" @@ -45,6 +72,17 @@ includes = ["optional", "cstdint", "vector"] } ] ''' + expect_json_v2 = ''' + [ + { + "staticSize": 32, + "exclusiveSize": 32, + "length": 0, + "capacity": 1, + "members": [] + } + ] + ''' [cases.vector_present] param_types = ["std::optional>&"] setup = "return {{{1,2,3,4,5}}};" @@ -68,3 +106,21 @@ includes = ["optional", "cstdint", "vector"] } ] ''' + expect_json_v2 = ''' + [ + { + "staticSize": 32, + "exclusiveSize": 8, + "length": 1, + "capacity": 1, + "members": [ + { + "staticSize": 24, + "exclusiveSize": 24, + "length": 5, + "capacity": 5 + } + ] + } + ] + ''' diff --git a/types/optional_type.toml b/types/optional_type.toml index a8d3ebb..1e417d9 100644 --- a/types/optional_type.toml +++ b/types/optional_type.toml @@ -39,6 +39,14 @@ struct TypeHandler> { static types::st::Unit getSizeType( const %1%& container, typename TypeHandler>::type returnArg) { + if (container) { + return returnArg.template delegate<1>([&container](auto ret) { + return OIInternal::getSizeType(*container, ret); + }); + } else { + return returnArg.template delegate<0>(std::identity()); + } + } }; """