Add OILv2 tests for std::optional

This commit is contained in:
Thierry Treyer 2023-08-30 14:19:29 -07:00 committed by Thierry Treyer
parent a95d6f2187
commit 344023239b
3 changed files with 64 additions and 2 deletions

View File

@ -20,7 +20,6 @@
#include <cassert>
#include <iterator>
#include <stdexcept>
#include <iostream> // TODO: remove
template <typename T>
inline constexpr bool always_false_v = false;
@ -49,7 +48,6 @@ IntrospectionResult::const_iterator::operator++() {
using T = std::decay_t<decltype(ty)>;
if constexpr (std::is_same_v<T, exporters::inst::Field>) {
std::cerr << "ty.name = " << ty.name << std::endl;
type_path_.emplace_back(ty.name);
stack_.emplace(exporters::inst::PopTypePath{});
next_ = result::Element{

View File

@ -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<std::uint64_t>&"]
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<std::vector<std::uint64_t>>&"]
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<std::vector<std::uint64_t>>&"]
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
}
]
}
]
'''

View File

@ -39,6 +39,14 @@ struct TypeHandler<DB, %1%<T0>> {
static types::st::Unit<DB> getSizeType(
const %1%<T0>& container,
typename TypeHandler<DB, %1%<T0>>::type returnArg) {
if (container) {
return returnArg.template delegate<1>([&container](auto ret) {
return OIInternal::getSizeType<DB>(*container, ret);
});
} else {
return returnArg.template delegate<0>(std::identity());
}
}
};
"""