feat(ltm): basic parsing of vars + some tests
This commit is contained in:
parent
0bc8fc8273
commit
af5e519663
2 changed files with 133 additions and 8 deletions
56
ltm/test/compile.c
Normal file
56
ltm/test/compile.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#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 }
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue