Implement test for function ordering for dispatch. Catch bug for "const" characterization of function parameters. Add test for type characterizations.
This commit is contained in:
@@ -159,6 +159,14 @@ IF(BUILD_TESTING)
|
|||||||
target_link_libraries(object_lifetime_test ${LIBS})
|
target_link_libraries(object_lifetime_test ${LIBS})
|
||||||
add_test(NAME Object_Lifetime_Test COMMAND object_lifetime_test)
|
add_test(NAME Object_Lifetime_Test COMMAND object_lifetime_test)
|
||||||
|
|
||||||
|
add_executable(function_ordering_test unittests/function_ordering_test.cpp)
|
||||||
|
target_link_libraries(function_ordering_test ${LIBS})
|
||||||
|
add_test(NAME Function_Ordering_Test COMMAND function_ordering_test)
|
||||||
|
|
||||||
|
add_executable(type_info_test unittests/type_info_test.cpp)
|
||||||
|
target_link_libraries(type_info_test ${LIBS})
|
||||||
|
add_test(NAME Type_Info_Test COMMAND type_info_test)
|
||||||
|
|
||||||
add_executable(multifile_test unittests/multifile_test_main.cpp unittests/multifile_test_chai.cpp
|
add_executable(multifile_test unittests/multifile_test_main.cpp unittests/multifile_test_chai.cpp
|
||||||
unittests/multifile_test_module.cpp)
|
unittests/multifile_test_module.cpp)
|
||||||
target_link_libraries(multifile_test ${LIBS})
|
target_link_libraries(multifile_test ${LIBS})
|
||||||
|
@@ -814,6 +814,35 @@ namespace chaiscript
|
|||||||
const Type_Info boxed_type = user_type<Boxed_Value>();
|
const Type_Info boxed_type = user_type<Boxed_Value>();
|
||||||
const Type_Info boxed_pod_type = user_type<Boxed_POD_Value>();
|
const Type_Info boxed_pod_type = user_type<Boxed_POD_Value>();
|
||||||
|
|
||||||
|
boost::shared_ptr<const Dynamic_Proxy_Function> dynamic_lhs(boost::dynamic_pointer_cast<const Dynamic_Proxy_Function>(lhs));
|
||||||
|
boost::shared_ptr<const Dynamic_Proxy_Function> dynamic_rhs(boost::dynamic_pointer_cast<const Dynamic_Proxy_Function>(rhs));
|
||||||
|
|
||||||
|
if (dynamic_lhs && dynamic_rhs)
|
||||||
|
{
|
||||||
|
if (dynamic_lhs->get_guard())
|
||||||
|
{
|
||||||
|
if (dynamic_rhs->get_guard())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dynamic_lhs && !dynamic_rhs)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dynamic_lhs && dynamic_rhs)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 1; i < lhssize && i < rhssize; ++i)
|
for (int i = 1; i < lhssize && i < rhssize; ++i)
|
||||||
{
|
{
|
||||||
|
@@ -221,6 +221,11 @@ namespace chaiscript
|
|||||||
return m_arity;
|
return m_arity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Proxy_Function get_guard() const
|
||||||
|
{
|
||||||
|
return m_guard;
|
||||||
|
}
|
||||||
|
|
||||||
virtual std::string annotation() const
|
virtual std::string annotation() const
|
||||||
{
|
{
|
||||||
return m_description;
|
return m_description;
|
||||||
|
@@ -7,6 +7,9 @@
|
|||||||
#ifndef __type_info_hpp__
|
#ifndef __type_info_hpp__
|
||||||
#define __type_info_hpp__
|
#define __type_info_hpp__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <typeinfo>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/type_traits/is_const.hpp>
|
#include <boost/type_traits/is_const.hpp>
|
||||||
#include <boost/type_traits/is_void.hpp>
|
#include <boost/type_traits/is_void.hpp>
|
||||||
#include <boost/type_traits/is_reference.hpp>
|
#include <boost/type_traits/is_reference.hpp>
|
||||||
@@ -139,7 +142,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
static Type_Info get()
|
static Type_Info get()
|
||||||
{
|
{
|
||||||
return Type_Info(boost::is_const<T>::value, boost::is_reference<T>::value, boost::is_pointer<T>::value,
|
return Type_Info(boost::is_const<typename boost::remove_pointer<typename boost::remove_reference<T>::type>::type>::value, boost::is_reference<T>::value, boost::is_pointer<T>::value,
|
||||||
boost::is_void<T>::value,
|
boost::is_void<T>::value,
|
||||||
&typeid(T),
|
&typeid(T),
|
||||||
&typeid(typename Bare_Type<T>::type));
|
&typeid(typename Bare_Type<T>::type));
|
||||||
|
38
unittests/function_ordering_test.cpp
Normal file
38
unittests/function_ordering_test.cpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// Tests to make sure that the order in which function dispatches occur is correct
|
||||||
|
|
||||||
|
#include <chaiscript/utility/utility.hpp>
|
||||||
|
|
||||||
|
int test_one(const int &)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_two(int &)
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
chaiscript::ChaiScript chai;
|
||||||
|
chai.eval("def test_fun(x) { return 3; }");
|
||||||
|
chai.eval("def test_fun(x) : x == \"hi\" { return 4; }");
|
||||||
|
chai.eval("def test_fun(x) { return 5; }");
|
||||||
|
chai.add(chaiscript::fun(&test_one), "test_fun");
|
||||||
|
chai.add(chaiscript::fun(&test_two), "test_fun");
|
||||||
|
|
||||||
|
int res1 = chai.eval<int>("test_fun(1)");
|
||||||
|
int res2 = chai.eval<int>("var i = 1; test_fun(i)");
|
||||||
|
int res3 = chai.eval<int>("test_fun(\"bob\")");
|
||||||
|
int res4 = chai.eval<int>("test_fun(\"hi\")");
|
||||||
|
|
||||||
|
if (res1 == 1
|
||||||
|
&& res2 == 2
|
||||||
|
&& res3 == 3
|
||||||
|
&& res4 == 4 )
|
||||||
|
{
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
} else {
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
32
unittests/type_info_test.cpp
Normal file
32
unittests/type_info_test.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
// Tests to make sure that the order in which function dispatches occur is correct
|
||||||
|
|
||||||
|
#include <chaiscript/dispatchkit/type_info.hpp>
|
||||||
|
|
||||||
|
void test_type(const chaiscript::Type_Info &ti, bool t_is_const, bool t_is_pointer, bool t_is_reference, bool t_is_void,
|
||||||
|
bool t_is_undef)
|
||||||
|
{
|
||||||
|
if (ti.is_const() == t_is_const
|
||||||
|
&& ti.is_pointer() == t_is_pointer
|
||||||
|
&& ti.is_reference() == t_is_reference
|
||||||
|
&& ti.is_void() == t_is_void
|
||||||
|
&& ti.is_undef() == t_is_undef)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test_type(chaiscript::user_type<void>(), false, false, false, true, false);
|
||||||
|
test_type(chaiscript::user_type<const int>(), true, false, false, false, false);
|
||||||
|
test_type(chaiscript::user_type<const int &>(), true, false, true, false, false);
|
||||||
|
test_type(chaiscript::user_type<int>(), false, false, false, false, false);
|
||||||
|
test_type(chaiscript::user_type<int *>(), false, true, false, false, false);
|
||||||
|
test_type(chaiscript::user_type<const int *>(), true, true, false, false, false);
|
||||||
|
test_type(chaiscript::Type_Info(), false, false, false, false, true);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Reference in New Issue
Block a user