// https://github.com/vinniefalco/LuaBridge // // Copyright 2019, Dmitry Tarakanov // SPDX-License-Identifier: MIT #include "TestBase.h" #include "TestTypes.h" #include "LuaBridge/Vector.h" #include template struct VectorTest : TestBase { }; TYPED_TEST_CASE_P (VectorTest); TYPED_TEST_P (VectorTest, LuaRef) { using Traits = TypeTraits ; this->runLua ("result = {" + Traits::list () + "}"); std::vector expected (Traits::values ()); std::vector actual = this->result (); ASSERT_EQ (expected, actual); } REGISTER_TYPED_TEST_CASE_P (VectorTest, LuaRef); INSTANTIATE_TYPED_TEST_CASE_P(VectorTest, VectorTest, TestTypes); namespace { struct Data { /* explicit */ Data (int i) : i (i) {} int i; }; bool operator== (const Data& lhs, const Data& rhs) { return lhs.i == rhs.i; } std::ostream& operator<< (std::ostream& lhs, const Data& rhs) { lhs << "{" << rhs.i << "}"; return lhs; } std::vector processValues(const std::vector & data) { return data; } std::vector processPointers(const std::vector & data) { std::vector result; for (const auto* item : data) { result.emplace_back (*item); } return result; } } // namespace struct VectorTests : TestBase { }; TEST_F (VectorTests, PassFromLua) { luabridge::getGlobalNamespace (L) .beginClass ("Data") .addConstructor () .endClass () .addFunction ("processValues", &processValues) .addFunction ("processPointers", &processPointers); resetResult (); runLua ("result = processValues ({Data (-1), Data (2)})"); ASSERT_EQ ( std::vector ({-1, 2}), result >()); resetResult (); runLua ("result = processValues ({Data (-3), Data (4)})"); ASSERT_EQ( std::vector ({-3, 4}), result > ()); }