lander/ltm/test/compile.c

57 lines
1.7 KiB
C
Raw Normal View History

#include "test.h"
#include "ltm/template.h"
#include "ltm/template_internal.h"
void test_single_placeholder() {
const char *s = "Hello, {{ world }}";
ltm_template *template;
TEST_CHECK(ltm_template_compile(&template, s) == ltm_err_ok);
TEST_CHECK(template->blocks.len == 2);
TEST_CHECK(template->blocks.arr[0].type == ltm_template_block_type_literal);
TEST_CHECK(template->blocks.arr[0].data.s == s);
TEST_CHECK(template->blocks.arr[0].len == 7);
TEST_CHECK(template->blocks.arr[1].type == ltm_template_block_type_var);
TEST_CHECK(template->names.len == 1);
TEST_CHECK(template->names.arr[0].name.s == s + 10);
TEST_CHECK(template->names.arr[0].name.len == 5);
TEST_CHECK(template->names.arr[0].index == 1);
}
void test_single_placeholder_trailing() {
const char *s = "Hello, {{ world }}!";
ltm_template *template;
TEST_CHECK(ltm_template_compile(&template, s) == ltm_err_ok);
TEST_CHECK(template->blocks.len == 3);
TEST_CHECK(template->blocks.arr[0].type == ltm_template_block_type_literal);
TEST_CHECK(template->blocks.arr[0].data.s == s);
TEST_CHECK(template->blocks.arr[0].len == 7);
TEST_CHECK(template->blocks.arr[1].type == ltm_template_block_type_var);
TEST_CHECK(template->blocks.arr[2].type == ltm_template_block_type_literal);
TEST_CHECK(template->blocks.arr[2].data.s == s + 18);
TEST_CHECK(template->blocks.arr[2].len == 1);
TEST_CHECK(template->names.len == 1);
TEST_CHECK(template->names.arr[0].name.s == s + 10);
TEST_CHECK(template->names.arr[0].name.len == 5);
TEST_CHECK(template->names.arr[0].index == 1);
}
TEST_LIST = {
{ "template single placeholder", test_single_placeholder },
{ "template single placeholder trailing", test_single_placeholder_trailing },
{ NULL, NULL }
};