lander/ltm/test/instance.c

34 lines
903 B
C

#include "test.h"
#include "ltm/common.h"
#include "ltm/template.h"
#include "ltm/template_internal.h"
void test_single_placeholder() {
const char *s = "Hello, {{ world }}!";
ltm_template *template;
TEST_ASSERT(ltm_template_compile(&template, s) == ltm_err_ok);
ltm_instance *instance;
TEST_CHECK(ltm_template_instantiate(&instance, template) == ltm_err_ok);
TEST_CHECK(ltm_instance_block_add_var(instance, "world", ltm_instance_block_type_buf, "World", 5) == ltm_err_ok);
TEST_CHECK(ltm_instance_size(instance) == 13);
char buf[13];
size_t written = 0;
TEST_CHECK(ltm_instance_write(&written, buf, 13, instance) == ltm_err_done);
TEST_CHECK(written == 13);
TEST_CHECK(strncmp(buf, "Hello, World!", 13) == 0);
ltm_instance_free(instance);
ltm_template_free(template);
}
TEST_LIST = {
{ "instance single placeholder", test_single_placeholder },
{ NULL, NULL }
};