Skip to content

Commit

Permalink
Fix Lua test after renaming.
Browse files Browse the repository at this point in the history
  • Loading branch information
billyquith committed Nov 27, 2020
1 parent d1a11c2 commit 2cdadfa
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 64 deletions.
14 changes: 7 additions & 7 deletions include/ponder/uses/detail/lua.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct LuaValueReader<P, typename std::enable_if<std::is_enum<P>::value>::type>
template <typename P>
struct LuaValueReader<P,
typename std::enable_if<std::is_same<std::string,
typename detail::RawType<P>::Type>::value>::type>
typename detail::DataType<P>::Type>::value>::type>
{
typedef std::string ParamType;
static inline ParamType convert(lua_State* L, size_t index)
Expand All @@ -119,7 +119,7 @@ template <typename P>
struct LuaValueReader<P&, typename std::enable_if<detail::IsUserType<P>::value>::type>
{
typedef P& ParamType;
typedef typename detail::RawType<ParamType>::Type RawType;
typedef typename detail::DataType<ParamType>::Type DataType;

static inline ParamType convert(lua_State* L, size_t index)
{
Expand All @@ -129,15 +129,15 @@ struct LuaValueReader<P&, typename std::enable_if<detail::IsUserType<P>::value>:
}

UserObject *uobj = reinterpret_cast<UserObject*>(lua_touserdata(L, (int)index));
return uobj->ref<RawType>();
return uobj->ref<DataType>();
}
};

template <typename P>
struct LuaValueReader<P*, typename std::enable_if<ponder::detail::IsUserType<P>::value>::type>
{
typedef P* ParamType;
typedef typename ponder::detail::RawType<ParamType>::Type RawType;
typedef typename ponder::detail::DataType<ParamType>::Type DataType;

static inline ParamType convert(lua_State* L, size_t index)
{
Expand All @@ -147,7 +147,7 @@ struct LuaValueReader<P*, typename std::enable_if<ponder::detail::IsUserType<P>:
}

UserObject *uobj = reinterpret_cast<UserObject*>(lua_touserdata(L, (int)index));
return &uobj->ref<RawType>();
return &uobj->ref<DataType>();
}
};

Expand Down Expand Up @@ -304,7 +304,7 @@ template <typename R>
struct CallReturnInternalRef<R,
typename std::enable_if<
!ponder::detail::IsUserType<R>::value
&& !std::is_same<typename ponder::detail::RawType<R>::Type, UserObject>::value
&& !std::is_same<typename ponder::detail::DataType<R>::Type, UserObject>::value
>::type>
{
static inline int value(lua_State *L, R&& o) {return LuaValueWriter<R>::push(L, o);}
Expand All @@ -314,7 +314,7 @@ template <typename R>
struct CallReturnInternalRef<R,
typename std::enable_if<
ponder::detail::IsUserType<R>::value
|| std::is_same<typename ponder::detail::RawType<R>::Type, UserObject>::value
|| std::is_same<typename ponder::detail::DataType<R>::Type, UserObject>::value
>::type>
{
static inline int value(lua_State *L, R&& o)
Expand Down
99 changes: 42 additions & 57 deletions test/ponder/traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,57 +591,52 @@ TEST_CASE("Type testing")
{
using ponder::detail::DataType;

static_assert(std::is_same<int, DataType<int>::Type>::value, "RawType<> fail");
static_assert(std::is_same<int, DataType<int*>::Type>::value, "RawType<> fail");
static_assert(std::is_same<int, DataType<int**>::Type>::value, "RawType<> fail");
static_assert(std::is_same<int, DataType<int***>::Type>::value, "RawType<> fail");
static_assert(std::is_same<int, DataType<int&>::Type>::value, "RawType<> fail");

static_assert(std::is_same<char, DataType<char>::Type>::value, "RawType<> fail");
static_assert(std::is_same<float, DataType<float*>::Type>::value, "RawType<> fail");

static_assert(std::is_same<std::string, DataType<std::string>::Type>::value,
"RawType<> fail");
static_assert(std::is_same<std::string, DataType<std::string&>::Type>::value,
"RawType<> fail");
static_assert(std::is_same<std::string, DataType<const std::string&>::Type>::value,
"RawType<> fail");
static_assert(std::is_same<std::string, DataType<std::string*>::Type>::value,
"RawType<> fail");
static_assert(std::is_same<std::string, DataType<const std::string*>::Type>::value,
"RawType<> fail");

static_assert(std::is_same<Callable, DataType<Callable>::Type>::value, "RawType<> fail");
static_assert(std::is_same<Callable, DataType<Callable*>::Type>::value, "RawType<> fail");
static_assert(std::is_same<Callable, DataType<Callable&>::Type>::value, "RawType<> fail");
STATIC_ASSERT((std::is_same<int, DataType<int>::Type>::value));
STATIC_ASSERT((std::is_same<int, DataType<int*>::Type>::value));
STATIC_ASSERT((std::is_same<int, DataType<int**>::Type>::value));
STATIC_ASSERT((std::is_same<int, DataType<int***>::Type>::value));
STATIC_ASSERT((std::is_same<int, DataType<int&>::Type>::value));

STATIC_ASSERT((std::is_same<char, DataType<char>::Type>::value));
STATIC_ASSERT((std::is_same<float, DataType<float*>::Type>::value));

STATIC_ASSERT((std::is_same<std::string, DataType<std::string>::Type>::value));
STATIC_ASSERT((std::is_same<std::string, DataType<std::string&>::Type>::value));
STATIC_ASSERT((std::is_same<std::string, DataType<const std::string&>::Type>::value));
STATIC_ASSERT((std::is_same<std::string, DataType<std::string*>::Type>::value));
STATIC_ASSERT((std::is_same<std::string, DataType<const std::string*>::Type>::value));

STATIC_ASSERT((std::is_same<Callable, DataType<Callable>::Type>::value));
STATIC_ASSERT((std::is_same<Callable, DataType<Callable*>::Type>::value));
STATIC_ASSERT((std::is_same<Callable, DataType<Callable&>::Type>::value));
}

SECTION("which are user types")
{
using ponder::detail::IsUserType;

static_assert( ! IsUserType<int>::value, "IsUserType<> fail");
static_assert( ! IsUserType<char*>::value, "IsUserType<> fail");
static_assert( ! IsUserType<std::string>::value, "IsUserType<> fail");
static_assert( ! IsUserType<ponder::Value>::value, "IsUserType<> fail");
static_assert( ! IsUserType<Enum>::value, "IsUserType<> fail");
static_assert( ! IsUserType<EnumCls>::value, "IsUserType<> fail");
STATIC_ASSERT(( ! IsUserType<int>::value));
STATIC_ASSERT(( ! IsUserType<char*>::value));
STATIC_ASSERT(( ! IsUserType<std::string>::value));
STATIC_ASSERT(( ! IsUserType<ponder::Value>::value));
STATIC_ASSERT(( ! IsUserType<Enum>::value));
STATIC_ASSERT(( ! IsUserType<EnumCls>::value));

static_assert(IsUserType<Callable>::value, "IsUserType<> fail");
static_assert(IsUserType<NonCallable>::value, "IsUserType<> fail");
STATIC_ASSERT((IsUserType<Callable>::value));
STATIC_ASSERT((IsUserType<NonCallable>::value));
}

SECTION("which are user types")
{
using ponder::detail::IsUserObjRef;

static_assert( ! IsUserObjRef<int>::value, "IsUserObjRef<> fail");
static_assert( ! IsUserObjRef<Callable>::value, "IsUserObjRef<> fail");
static_assert( ! IsUserObjRef<NonCallable>::value, "IsUserObjRef<> fail");
STATIC_ASSERT(( ! IsUserObjRef<int>::value));
STATIC_ASSERT(( ! IsUserObjRef<Callable>::value));
STATIC_ASSERT(( ! IsUserObjRef<NonCallable>::value));

static_assert(IsUserObjRef<NonCallable*>::value, "IsUserObjRef<> fail");
static_assert(IsUserObjRef<NonCallable&>::value, "IsUserObjRef<> fail");
static_assert(IsUserObjRef<const NonCallable&>::value, "IsUserObjRef<> fail");
STATIC_ASSERT((IsUserObjRef<NonCallable*>::value));
STATIC_ASSERT((IsUserObjRef<NonCallable&>::value));
STATIC_ASSERT((IsUserObjRef<const NonCallable&>::value));
}
}

Expand All @@ -651,42 +646,32 @@ TEST_CASE("Types supporting array interface are supported")
{
SECTION("not arrays")
{
static_assert( ! ponder_ext::ArrayMapper<int>::isArray, "ponder_ext::ArrayMapper failed");
static_assert( ! ponder_ext::ArrayMapper<char*>::isArray, "ponder_ext::ArrayMapper failed");
STATIC_ASSERT(( ! ponder_ext::ArrayMapper<int>::isArray));
STATIC_ASSERT(( ! ponder_ext::ArrayMapper<char*>::isArray));
}

SECTION("C arrays")
{
static_assert(ponder_ext::ArrayMapper<int[10]>::isArray, "ponder_ext::ArrayMapper failed");
static_assert(std::is_same<int, ponder_ext::ArrayMapper<int[10]>::ElementType>::value,
"ponder_ext::ArrayMapper failed");
STATIC_ASSERT((ponder_ext::ArrayMapper<int[10]>::isArray));
STATIC_ASSERT((std::is_same<int, ponder_ext::ArrayMapper<int[10]>::ElementType>::value));
}

SECTION("std::array")
{
static_assert(ponder_ext::ArrayMapper<std::array<int, 10>>::isArray,
"ponder_ext::ArrayMapper failed");
static_assert(
std::is_same<int, ponder_ext::ArrayMapper<std::array<int, 10>>::ElementType>::value,
"ponder_ext::ArrayMapper failed");
STATIC_ASSERT((ponder_ext::ArrayMapper<std::array<int, 10>>::isArray));
STATIC_ASSERT((std::is_same<int, ponder_ext::ArrayMapper<std::array<int, 10>>::ElementType>::value));
}

SECTION("std::vector")
{
static_assert(ponder_ext::ArrayMapper<std::vector<int>>::isArray,
"ponder_ext::ArrayMapper failed");
static_assert(
std::is_same<int, ponder_ext::ArrayMapper<std::vector<int>>::ElementType>::value,
"ponder_ext::ArrayMapper failed");
STATIC_ASSERT((ponder_ext::ArrayMapper<std::vector<int>>::isArray));
static_assert(std::is_same<int, ponder_ext::ArrayMapper<std::vector<int>>::ElementType>::value);
}

SECTION("std::list")
{
static_assert(ponder_ext::ArrayMapper<std::list<int>>::isArray,
"ponder_ext::ArrayMapper failed");
static_assert(
std::is_same<int, ponder_ext::ArrayMapper<std::list<int>>::ElementType>::value,
"ponder_ext::ArrayMapper failed");
STATIC_ASSERT(ponder_ext::ArrayMapper<std::list<int>>::isArray);
STATIC_ASSERT((std::is_same<int, ponder_ext::ArrayMapper<std::list<int>>::ElementType>::value));
}
}

Expand Down

0 comments on commit 2cdadfa

Please sign in to comment.