Skip to content

Commit

Permalink
tests: internal: lua: pass index to lua_arraylength
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 authored and edsiper committed Aug 29, 2023
1 parent b217fb6 commit 26e441a
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions tests/internal/lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,43 @@ static void test_lua_arraylength()
lua_settable(l, -3); /* points created table */
}

len = flb_lua_arraylength(l);
len = flb_lua_arraylength(l, -1);
if (!TEST_CHECK(len == size)) {
TEST_MSG("size error. got=%d expect=%d", len, size);
}
lua_pop(l, 1);

lua_close(l);
}

static void test_lua_arraylength_with_index()
{
lua_State *l;
int i;
int len;
int size = 10;

l = luaL_newstate();
if (!TEST_CHECK(l != NULL)) {
TEST_MSG("luaL_newstate faild");
return;
}
luaL_openlibs(l);

/* create array. */
lua_createtable(l, size, 0);

for (i=1; i<=size; i++) {
lua_pushinteger(l, i); /* set an index of array */
lua_pushinteger(l, 3+i); /* set a value */
lua_settable(l, -3); /* points created table */
}

/* push 2 values */
lua_pushinteger(l, 100);
lua_pushinteger(l, 101);

len = flb_lua_arraylength(l, -3); /* points array. -1 points 101, -2 points 100 */
if (!TEST_CHECK(len == size)) {
TEST_MSG("size error. got=%d expect=%d", len, size);
}
Expand Down Expand Up @@ -265,7 +301,7 @@ static void test_lua_arraylength_for_array_contains_nil()
lua_settable(l, -3); /* points created table */
}

len = flb_lua_arraylength(l);
len = flb_lua_arraylength(l, -1);
if (!TEST_CHECK(len == size)) {
TEST_MSG("size error. got=%d expect=%d", len, size);
}
Expand All @@ -283,6 +319,7 @@ TEST_LIST = {
{ "lua_tomsgpack" , test_tomsgpack },
{ "lua_tompack" , test_tompack },
{ "lua_arraylength" , test_lua_arraylength },
{ "lua_arraylength_with_index" , test_lua_arraylength_with_index },
{ "lua_arraylength_for_array_contains_nil", test_lua_arraylength_for_array_contains_nil},
{ 0 }
};

0 comments on commit 26e441a

Please sign in to comment.