#define SOL_CHECK_ARGUMENTS #include #include #ifdef SOL_CXX17_FEATURES #include #include #endif TEST_CASE("utility/variant", "test that variant can be round-tripped") { #ifdef SOL_CXX17_FEATURES SECTION("okay") { sol::state lua; lua.open_libraries(sol::lib::base); lua.set_function("f", [](int v) { return v == 2; }); lua.set_function("g", [](std::variant vv) { int v = std::get(vv); return v == 2; }); lua["v"] = std::variant(2); REQUIRE_NOTHROW([&]() { lua.script("assert(f(v))"); lua.script("assert(g(v))"); }()); } SECTION("throws") { sol::state lua; lua.open_libraries(sol::lib::base); lua.set_function("f", [](int v) { return v == 2; }); lua.set_function("g", [](std::variant vv) { int v = std::get(vv); return v == 2; }); lua["v"] = std::variant(std::string("bark")); REQUIRE_THROWS([&]() { lua.script("assert(f(v))"); lua.script("assert(g(v))"); }()); } #else REQUIRE(true); #endif // C++17 } TEST_CASE("utility/string_view", "test that string_view can be taken as an argument") { #ifdef SOL_CXX17_FEATURES sol::state lua; lua.open_libraries(sol::lib::base); lua.set_function("f", [](std::string_view v) { return v == "bark!"; }); lua["v"] = "bark!"; REQUIRE_NOTHROW([&]() { lua.script("assert(f(v))"); }()); #else REQUIRE(true); #endif // C++17 }