diff options
Diffstat (limited to 'src/tests/hs_create_table_tests.c')
-rw-r--r-- | src/tests/hs_create_table_tests.c | 170 |
1 files changed, 169 insertions, 1 deletions
diff --git a/src/tests/hs_create_table_tests.c b/src/tests/hs_create_table_tests.c index 5205690..f529f57 100644 --- a/src/tests/hs_create_table_tests.c +++ b/src/tests/hs_create_table_tests.c @@ -260,6 +260,174 @@ TEST(create_table_bool_light) /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * + * integer keys + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +TEST(create_table_int_bool) +{ + int oldtop = lua_gettop(L); + int index = hs_create_table + (L, hs_int_bool(15, true), hs_int_bool(25, true)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + loadkey_int(index, 15); + checkval_bool(true); + loadkey_int(index, 25); + checkval_bool(true); + return 0; +} + +TEST(create_table_int_int) +{ + int oldtop = lua_gettop(L); + int index = hs_create_table + (L, hs_int_int(15, 15), hs_int_int(25, 25)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + loadkey_int(index, 15); + checkval_int(15); + loadkey_int(index, 25); + checkval_int(25); + return 0; +} + +TEST(create_table_int_num) +{ + int oldtop = lua_gettop(L); + int index = hs_create_table + (L, hs_int_num(15, 2.718), hs_int_num(25, 1.618)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + loadkey_int(index, 15); + checkval_num(2.718); + loadkey_int(index, 25); + checkval_num(1.618); + return 0; +} + +TEST(create_table_int_str) +{ + int oldtop = lua_gettop(L); + int index = hs_create_table + (L, hs_int_str(15, "hello"), hs_int_str(25, "world")); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + loadkey_int(index, 15); + checkval_str("hello"); + loadkey_int(index, 25); + checkval_str("world"); + return 0; +} + +TEST(create_table_int_tbl) +{ + int oldtop = lua_gettop(L); + + lua_newtable(L); + store(value1); + lua_newtable(L); + store(value2); + + int index = hs_create_table + (L, hs_int_tbl(15, value1), hs_int_tbl(25, value2)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + load(value1); + load(value2); + + loadkey_int(index, 15); + checkval_tbl(value1); + loadkey_int(index, 25); + checkval_tbl(value2); + return 0; +} + +TEST(create_table_int_func) +{ + int oldtop = lua_gettop(L); + + luaL_loadstring(L, "print('hello')"); + store(value1); + luaL_loadstring(L, "print('hello')"); + store(value2); + + int index = hs_create_table + (L, hs_int_func(15, value1), hs_int_func(25, value2)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + load(value1); + load(value2); + + loadkey_int(index, 15); + checkval_func(value1); + loadkey_int(index, 25); + checkval_func(value2); + return 0; +} + +TEST(create_table_int_cfunc) +{ + + int oldtop = lua_gettop(L); + int index = hs_create_table + (L, hs_int_cfunc(15, testfunc1), hs_int_cfunc(25, testfunc2)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + loadkey_int(index, 15); + checkval_cfunc(testfunc1); + loadkey_int(index, 25); + checkval_cfunc(testfunc2); + return 0; +} + + +TEST(create_table_int_user) +{ + int oldtop = lua_gettop(L); + + lua_newuserdata(L, sizeof(char)); + store(user1); + lua_newuserdata(L, sizeof(char)); + store(user2); + + int index = hs_create_table + (L, hs_int_user(15, user1), hs_int_user(25, user2)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + load(user1); + load(user2); + + loadkey_int(index, 15); + checkval_user(user1); + loadkey_int(index, 25); + checkval_user(user2); + return 0; +} + +TEST(create_table_int_light) +{ + int a1 = 5; + void *light1 = (void *) &a1; + int a2 = 6; + void *light2 = (void *) &a2; + + int oldtop = lua_gettop(L); + int index = hs_create_table + (L, hs_int_light(15, light1), hs_int_light(25, light2)); + mu_assert_equal(oldtop + 1, lua_gettop(L)); + + loadkey_int(index, 15); + checkval_light(light1); + loadkey_int(index, 25); + checkval_light(light2); + return 0; +} + + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * * test suite * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -291,7 +459,7 @@ void hs_create_table_tests() mu_run_test("create table with boolean keys and light userdata values", \ create_table_bool_light); - /* integer keys / + /* integer keys */ mu_run_test("create table with integer keys and boolean values", create_table_int_bool); mu_run_test("create table with integer keys and integer values", \ |