summaryrefslogtreecommitdiff
path: root/src/util/util.test.c
blob: b4029d2f0b9a09814c53b52c8a9fe332cb7f252b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <lua.h>
#include <lauxlib.h>
#include <honeysuckle.h>
#include "test/honey-test.h"


#include "util.c"


void test_append_table()
{
	lua_State *L = luaL_newstate();
	int a = hs_create_table(L,
		hs_str_int("one", 1),
		hs_str_int("two", 2),
	);
	int b = hs_create_table(L,
		hs_str_int("three", 3),
		hs_str_int("four", 4),
		hs_int_int(15, 2),
	);
	append_table(L, a, b);

	lua_getfield(L, a, "one");
	lily_assert_int_equal(lua_tointeger(L, -1), 1);
	
	lua_getfield(L, a, "two");
	lily_assert_int_equal(lua_tointeger(L, -1), 2);
	
	lua_getfield(L, a, "three");
	lily_assert_int_equal(lua_tointeger(L, -1), 3);

	lua_getfield(L, a, "four");
	lily_assert_int_equal(lua_tointeger(L, -1), 4);

	lua_pushinteger(L, 15);
	lua_gettable(L, a);
	lily_assert_int_equal(lua_tointeger(L, -1), 2);

	lua_close(L);
}


void suite_util()
{
	lily_run_test(test_append_table);
}