improve tests

change the default chunk name (and make it trail off if chunk name is too small)
minor changes to appease g++'s and clang++'s many warnings
This commit is contained in:
ThePhD 2017-08-07 07:54:43 -04:00
parent b86d90f0e5
commit f1ff3d6492
6 changed files with 19 additions and 10 deletions

View File

@ -1073,7 +1073,7 @@ namespace sol {
static int get(lua_State* L) {
T& self = get_src(L);
std::ptrdiff_t idx = stack::get<std::ptrdiff_t>(L, 2);
if (idx > std::extent<T>::value || idx < 1) {
if (idx > static_cast<std::ptrdiff_t>(std::extent<T>::value) || idx < 1) {
return stack::push(L, lua_nil);
}
--idx;
@ -1087,7 +1087,7 @@ namespace sol {
static int set(lua_State* L) {
T& self = get_src(L);
std::ptrdiff_t idx = stack::get<std::ptrdiff_t>(L, 2);
if (idx > std::extent<T>::value) {
if (idx > static_cast<std::ptrdiff_t>(std::extent<T>::value)) {
return luaL_error(L, "sol: index out of bounds (too big) for set on '%s'", detail::demangle<T>().c_str());
}
if (idx < 1) {

View File

@ -47,10 +47,15 @@ namespace sol {
auto it = code.cbegin();
auto e = code.cend();
std::size_t i = 0;
static const std::size_t n = N - 1;
static const std::size_t n = N - 4;
for (i = 0; i < n && it != e; ++i, ++it) {
basechunkname[i] = *it;
}
if (it != e) {
for (std::size_t c = 0; c < 3; ++i, ++c) {
basechunkname[i] = ".";
}
}
basechunkname[i] = '\0';
return &basechunkname[0];
}

View File

@ -458,7 +458,11 @@ namespace sol {
load_result load(lua_Reader reader, void* data, const std::string& chunkname = detail::default_chunk_name(), load_mode mode = load_mode::any) {
char basechunkname[17] = {};
const char* chunknametarget = detail::make_chunk_name("lua_reader", chunkname, basechunkname);
#if SOL_LUA_VERSION > 501
load_status x = static_cast<load_status>(lua_load(L, reader, data, chunknametarget, to_string(mode).c_str()));
#else
load_status x = static_cast<load_status>(lua_load(L, reader, data, chunknametarget));
#endif
return load_result(L, absolute_index(L, -1), 1, 1, x);
}

View File

@ -681,7 +681,7 @@ TEST_CASE("containers/fixed containers", "check immutable container types") {
sol::state lua;
lua.open_libraries(sol::lib::base);
std::array<int, 5> items{ 11, 12, 13, 14, 15 };
std::array<int, 5> items{ { 11, 12, 13, 14, 15 } };
lua["c"] = &items;
fixed_container_check(lua, items);
}
@ -689,7 +689,7 @@ TEST_CASE("containers/fixed containers", "check immutable container types") {
sol::state lua;
lua.open_libraries(sol::lib::base);
std::array<int, 5> items{ 11, 12, 13, 14, 15 };
std::array<int, 5> items{ { 11, 12, 13, 14, 15 } };
lua["c"] = std::ref(items);
fixed_container_check(lua, items);
}

View File

@ -99,7 +99,7 @@ TEST_CASE("containers/deque roundtrip", "make sure deques can be round-tripped")
TEST_CASE("containers/array roundtrip", "make sure arrays can be round-tripped") {
sol::state lua;
std::array<int, 3> v{ 1, 2, 3 };
std::array<int, 3> v{ { 1, 2, 3 } };
lua.set_function("f", [&]() -> std::array<int, 3>& {
return v;
});
@ -207,7 +207,7 @@ TEST_CASE("containers/deque table roundtrip", "make sure deques can be round-tri
TEST_CASE("containers/array table roundtrip", "make sure arrays can be round-tripped") {
sol::state lua;
std::array<int, 3> v{ 1, 2, 3 };
std::array<int, 3> v{ { 1, 2, 3 } };
lua.set_function("f", [&]() {
return sol::as_table(v);
});

View File

@ -182,15 +182,15 @@ TEST_CASE("variadics/variadic_results", "returning a variable amount of argument
}
TEST_CASE("variadics/fallback_constructor", "ensure constructor matching behaves properly in the presence of variadic fallbacks") {
struct vec2 { float x, y; };
struct vec2 { float x = 0, y = 0; };
sol::state lua;
lua.new_simple_usertype<vec2>("vec2",
sol::call_constructor, sol::factories([]() {
return vec2{};
}, [](vec2 const& v) {
return vec2{ v };
}, [](vec2 const& v) -> vec2 {
return v;
}, [](sol::variadic_args va) {
vec2 res{};
if (va.size() == 1) {