diff options
Diffstat (limited to 't/test_1.c')
| -rw-r--r-- | t/test_1.c | 75 |
1 files changed, 65 insertions, 10 deletions
@@ -47,13 +47,18 @@ char t_11[] = "Test else2:<TMPL_IF name=\"var\" value=\"thing\"> One<TMPL_ELSE> char c_11_1[] = "Test else2: One"; char c_11_2[] = "Test else2: Two"; +char t_12[] = "Test else3:<TMPL_IF name=\"var\"> One<TMPL_ELSEIF name=\"var2\"> Two<TMPL_END>"; +char c_12_1[] = "Test else3: One"; +char c_12_2[] = "Test else3: Two"; +char c_12_3[] = "Test else3:"; + int main(){ struct TMPL_templates* t; struct TMPL_varlist* vl; char* ret; size_t dummy; - /*Test 1*/ + /*Test 1: Variable*/ t = TMPL_alloc_template(t_1); vl = TMPL_alloc_varlist(); TMPL_add_var_to_varlist(vl,"what","template"); @@ -66,7 +71,7 @@ int main(){ TMPL_free_template(t); TMPL_free_varlist(vl); - /*Test 2*/ + /*Test 2: Variable with default parameter*/ t = TMPL_alloc_template(t_2); vl = TMPL_alloc_varlist(); ret = TMPL_render(t,vl,&dummy); @@ -78,7 +83,7 @@ int main(){ TMPL_free_template(t); TMPL_free_varlist(vl); - /*Test 3*/ + /*Test 3: Template that starts with a tag*/ t = TMPL_alloc_template(t_3); vl = TMPL_alloc_varlist(); TMPL_add_var_to_varlist(vl,"what","This"); @@ -91,7 +96,7 @@ int main(){ TMPL_free_template(t); TMPL_free_varlist(vl); - /*Test 4*/ + /*Test 4: Starts with a tag with a default value*/ t = TMPL_alloc_template(t_4); vl = TMPL_alloc_varlist(); ret = TMPL_render(t,vl,&dummy); @@ -103,7 +108,7 @@ int main(){ TMPL_free_template(t); TMPL_free_varlist(vl); - /*Test 5*/ + /*Test 5: Ends with a tag*/ t = TMPL_alloc_template(t_5); vl = TMPL_alloc_varlist(); TMPL_add_var_to_varlist(vl,"what","tag"); @@ -116,7 +121,7 @@ int main(){ TMPL_free_template(t); TMPL_free_varlist(vl); - /*Test 6*/ + /*Test 6: Ends with a tag with a default value*/ t = TMPL_alloc_template(t_6); vl = TMPL_alloc_varlist(); ret = TMPL_render(t,vl,&dummy); @@ -128,7 +133,7 @@ int main(){ TMPL_free_template(t); TMPL_free_varlist(vl); - /*Test 7*/ + /*Test 7: Simple loop*/ t = TMPL_alloc_template(t_7); vl = TMPL_alloc_varlist(); { @@ -180,7 +185,7 @@ int main(){ TMPL_free_varlist(vl); TMPL_free_template(t); - /*Test 8*/ + /*Test 8: Simple if*/ t = TMPL_alloc_template(t_8); vl = TMPL_alloc_varlist(); TMPL_add_var_to_varlist(vl,"var","correct"); @@ -210,7 +215,7 @@ int main(){ TMPL_free_template(t); TMPL_free_varlist(vl); - /*Test 9*/ + /*Test 9: Use if to check for variable existance*/ t = TMPL_alloc_template(t_9); vl = TMPL_alloc_varlist(); TMPL_add_var_to_varlist(vl,"var","thing"); @@ -231,7 +236,7 @@ int main(){ TMPL_free_varlist(vl); TMPL_free_template(t); - /*Test 10*/ + /*Test 10: If with else section, if used to check for existance*/ t = TMPL_alloc_template(t_10); vl = TMPL_alloc_varlist(); TMPL_add_var_to_varlist(vl,"var","True"); @@ -252,7 +257,57 @@ int main(){ TMPL_free_varlist(vl); TMPL_free_template(t); + /*Test 11: If with else section, if used for equivalence*/ + t = TMPL_alloc_template(t_11); + vl = TMPL_alloc_varlist(); + TMPL_add_var_to_varlist(vl,"var","thing"); + ret = TMPL_render(t,vl,&dummy); + if(strcmp(ret, c_11_1) != 0){ + fprintf(stderr, "Error in test file 1, test 11\n"); + printf("Result should have been '%s'\n was '%s'\n",c_11_1,ret); + return -1; + } + TMPL_free_varlist(vl); + vl = TMPL_alloc_varlist(); + ret = TMPL_render(t,vl,&dummy); + if(strcmp(ret, c_11_2) != 0){ + fprintf(stderr, "Error in test file 1, test 11\n"); + printf("Result should have been '%s'\n was '%s'\n",c_11_2,ret); + return -1; + } + TMPL_free_varlist(vl); + TMPL_free_template(t); + /*Test 12: If with elseif, no else*/ + t = TMPL_alloc_template(t_12); + vl = TMPL_alloc_varlist(); + TMPL_add_var_to_varlist(vl,"var","thing"); + ret = TMPL_render(t,vl,&dummy); + if(strcmp(ret, c_12_1) != 0){ + fprintf(stderr, "Error in test file 1, test 12\n"); + printf("Result should have been '%s'\n was '%s'\n",c_12_1,ret); + return -1; + } + TMPL_free_varlist(vl); + vl = TMPL_alloc_varlist(); + TMPL_add_var_to_varlist(vl,"var2","thing"); + ret = TMPL_render(t,vl,&dummy); + if(strcmp(ret, c_12_2) != 0){ + fprintf(stderr, "Error in test file 1, test 12\n"); + printf("Result should have been '%s'\n was '%s'\n",c_12_2,ret); + return -1; + } + TMPL_free_varlist(vl); + vl = TMPL_alloc_varlist(); + ret = TMPL_render(t,vl,&dummy); + if(strcmp(ret, c_12_3) != 0){ + fprintf(stderr, "Error in test file 1, test 12\n"); + printf("Result should have been '%s'\n was '%s'\n",c_12_3,ret); + return -1; + } + TMPL_free_varlist(vl); + TMPL_free_template(t); + return 0; } |
