From 88a089c4aec4d6e1bdad748cb72e9e358cd0a993 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Mon, 14 Jan 2019 07:27:55 -0500 Subject: [PATCH] proxy testing --- include/sol/optional_implementation.hpp | 14 +++++++------- include/sol/proxy.hpp | 2 +- tests/runtime_tests/source/proxies.cpp | 12 ++++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/sol/optional_implementation.hpp b/include/sol/optional_implementation.hpp index 6ca71930..d48af999 100644 --- a/include/sol/optional_implementation.hpp +++ b/include/sol/optional_implementation.hpp @@ -91,7 +91,7 @@ namespace sol { namespace detail { }} // namespace sol::detail #endif -#define SOL_TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) tl::detail::is_trivially_copy_constructible::value +#define SOL_TL_OPTIONAL_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) sol::detail::is_trivially_copy_constructible::value #define SOL_TL_OPTIONAL_IS_TRIVIALLY_COPY_ASSIGNABLE(T) std::is_trivially_copy_assignable::value #define SOL_TL_OPTIONAL_IS_TRIVIALLY_DESTRUCTIBLE(T) std::is_trivially_destructible::value #else @@ -220,7 +220,7 @@ namespace sol { template using void_t = typename voider::type; - // Trait for checking if a type is a tl::optional + // Trait for checking if a type is a sol::optional template struct is_optional_impl : std::false_type {}; template @@ -228,7 +228,7 @@ namespace sol { template using is_optional = is_optional_impl>; - // Change void to tl::monostate + // Change void to sol::monostate template using fixup_void = conditional_t::value, monostate, U>; @@ -644,9 +644,9 @@ namespace sol { /// /// *Examples*: /// ``` - /// tl::optional a = tl::nullopt; - /// void foo (tl::optional); - /// foo(tl::nullopt); //pass an empty optional + /// sol::optional a = sol::nullopt; + /// void foo (sol::optional); + /// foo(sol::nullopt); //pass an empty optional /// ``` static constexpr nullopt_t nullopt{ nullopt_t::do_not_use{}, nullopt_t::do_not_use{} }; @@ -1652,7 +1652,7 @@ namespace sol { /// /// ``` /// int i = 42; - /// tl::optional o = i; + /// sol::optional o = i; /// *o == 42; //true /// i = 12; /// *o = 12; //true diff --git a/include/sol/proxy.hpp b/include/sol/proxy.hpp index da48cb7e..3da63b2b 100644 --- a/include/sol/proxy.hpp +++ b/include/sol/proxy.hpp @@ -184,7 +184,7 @@ namespace sol { } proxy& force() { - if (this->valid()) { + if (!this->valid()) { this->set(new_table()); } return *this; diff --git a/tests/runtime_tests/source/proxies.cpp b/tests/runtime_tests/source/proxies.cpp index 00fcd342..4695248f 100644 --- a/tests/runtime_tests/source/proxies.cpp +++ b/tests/runtime_tests/source/proxies.cpp @@ -97,3 +97,15 @@ TEST_CASE("proxy/equality", "check to make sure equality tests work") { REQUIRE_FALSE((lua["a"] != 2)); #endif // clang screws up by trying to access int128 types that it doesn't support, even when we don't ask for them } + +TEST_CASE("proxy/force", "allow proxies to force creation of tables") { + sol::state lua; + lua.open_libraries(sol::lib::base, sol::lib::io); + + sol::optional not_there = lua["a"]["b"]["c"]; + REQUIRE_FALSE(static_cast(not_there)); + lua["a"].force()["b"].force()["c"] = 357; + sol::optional totally_there = lua["a"]["b"]["c"]; + REQUIRE(static_cast(totally_there)); + REQUIRE(*totally_there == 357); +}