2023-12-16 20:42:07 +01:00
|
|
|
#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];
|
2023-12-16 22:15:21 +01:00
|
|
|
|
2023-12-16 20:42:07 +01:00
|
|
|
size_t written = 0;
|
2023-12-16 22:15:21 +01:00
|
|
|
TEST_CHECK(ltm_instance_write(&written, buf, 5, instance) == ltm_err_ok);
|
|
|
|
TEST_CHECK(written == 5);
|
|
|
|
|
|
|
|
written = 0;
|
|
|
|
TEST_CHECK(ltm_instance_write(&written, buf + 5, 5, instance) == ltm_err_ok);
|
|
|
|
TEST_CHECK(written == 5);
|
|
|
|
|
|
|
|
written = 0;
|
|
|
|
TEST_CHECK(ltm_instance_write(&written, buf + 10, 5, instance) == ltm_err_done);
|
|
|
|
TEST_CHECK(written == 3);
|
|
|
|
|
2023-12-16 20:42:07 +01:00
|
|
|
TEST_CHECK(strncmp(buf, "Hello, World!", 13) == 0);
|
2023-12-16 22:15:21 +01:00
|
|
|
TEST_DUMP("buf", buf, 13);
|
2023-12-16 20:42:07 +01:00
|
|
|
|
|
|
|
ltm_instance_free(instance);
|
|
|
|
ltm_template_free(template);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_LIST = {
|
|
|
|
{ "instance single placeholder", test_single_placeholder },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|