diff --git a/test/code-tests.lua b/test/code-tests.lua index 4ba2c0d..88a2621 100644 --- a/test/code-tests.lua +++ b/test/code-tests.lua @@ -20,8 +20,8 @@ return { %s ret ]], - replacements = { - { 2, 3, 'sum', expected_stack_top = 5 }, + scenarios = { + { parameters = { 2, 3, 'sum' }, name = "Sum", expected_stack_top = 5 }, }, } } \ No newline at end of file diff --git a/test/tests.c b/test/tests.c index 79cda1b..a31cb00 100644 --- a/test/tests.c +++ b/test/tests.c @@ -407,4 +407,31 @@ static void run_assembly_test_code(lua_State* L) static void run_assembly_test_template(lua_State* L) { + lua_getfield(L, -1, "template"); + const char* template = strdup(lua_tostring(L, -1)); + lua_pop(L, 1); + + lua_getfield(L, -1, "scenarios"); + assert(!lua_isnil(L, -1)); + + long n_scenarios = luaL_len(L, -1); + for (long i = 0; i < n_scenarios; ++i) { + lua_geti(L, -1, (int)i + 1); + + lua_getfield(L, -1, "name"); + printf(" .. %s\n", lua_tostring(L, -1)); + lua_pop(L, 1); + + // format code + lua_dostring(L, "string.format"); + lua_pushstring(L, template); + + lua_pop(L, 1); + } + + uint8_t* bytecode; size_t bytecode_sz; + // assert(code_assemble(lua_tostring(L, -1), &bytecode, &bytecode_sz) == T_OK); + + lua_pop(L, 1); + free(template); } \ No newline at end of file