?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. // https://github.com/vinniefalco/LuaBridge
  2. // Copyright 2019, Dmitry Tarakanov
  3. // SPDX-License-Identifier: MIT
  4.  
  5. #include "TestBase.h"
  6. #include "TestTypes.h"
  7.  
  8. #include "LuaBridge/List.h"
  9.  
  10. #include <list>
  11.  
  12. namespace {
  13.  
  14. template<class T>
  15.  
  16. std::list<T> toList(const std::vector<T>& vector)
  17. {
  18.     return {vector.begin(), vector.end()};
  19. }
  20.  
  21. } // namespace
  22.  
  23. template<class T>
  24. struct ListTest : TestBase
  25. {
  26. };
  27.  
  28. TYPED_TEST_CASE_P(ListTest);
  29.  
  30. TYPED_TEST_P(ListTest, LuaRef)
  31. {
  32.     using Traits = TypeTraits<TypeParam>;
  33.  
  34.     this->runLua("result = {" + Traits::list() + "}");
  35.  
  36.     std::list<TypeParam> expected = toList(Traits::values());
  37.     std::list<TypeParam> actual = this->result();
  38.     ASSERT_EQ(expected, actual);
  39. }
  40.  
  41. REGISTER_TYPED_TEST_CASE_P(ListTest, LuaRef);
  42.  
  43. INSTANTIATE_TYPED_TEST_CASE_P(ListTest, ListTest, TestTypes);
  44.  
  45. struct ListTests : TestBase
  46. {
  47. };
  48.  
  49. TEST_F(ListTests, PassToFunction)
  50. {
  51.     runLua("function foo (list) "
  52.            "  result = list "
  53.            "end");
  54.  
  55.     auto foo = luabridge::getGlobal(L, "foo");
  56.  
  57.     resetResult();
  58.  
  59.     std::list<int> lvalue{10, 20, 30};
  60.     foo(lvalue);
  61.     ASSERT_TRUE(result().isTable());
  62.     ASSERT_EQ(lvalue, result<std::list<int>>());
  63.  
  64.     resetResult();
  65.  
  66.     const std::list<int> constLvalue = lvalue;
  67.     foo(constLvalue);
  68.     ASSERT_TRUE(result().isTable());
  69.     ASSERT_EQ(lvalue, result<std::list<int>>());
  70. }
  71.