diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2018-01-07 16:10:25 -0500 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2018-01-07 16:10:25 -0500 |
| commit | 6dab0b778c8083b53b06ca25e35f9900f474075b (patch) | |
| tree | 63002d4f3a7c456270e7f5dc6ee026da4d124e77 /t | |
| parent | 59c84b0460418983b0e655fd9fbba34e19b10291 (diff) | |
| download | libctemplates-6dab0b778c8083b53b06ca25e35f9900f474075b.tar.gz libctemplates-6dab0b778c8083b53b06ca25e35f9900f474075b.tar.bz2 libctemplates-6dab0b778c8083b53b06ca25e35f9900f474075b.zip | |
Fixed a bug with TMPL_IF not working as variable check
Fixed a bug where the <TMPL_IF> tag was not correctly checking if a
variable exists if it does not have a "testval" attribute.
Diffstat (limited to 't')
| -rw-r--r-- | t/test_1.c | 48 |
1 files changed, 39 insertions, 9 deletions
@@ -39,6 +39,14 @@ char t_9[] = "Test if for existance:<TMPL_IF name=\"var\"> Exists!<TMPL_END>"; char c_9_1[] = "Test if for existance: Exists!"; char c_9_2[] = "Test if for existance:"; +char t_10[] = "Test else:<TMPL_IF name=\"var\"> One<TMPL_ELSE> Two<TMPL_END>"; +char c_10_1[] = "Test else: One"; +char c_10_2[] = "Test else: Two"; + +char t_11[] = "Test else2:<TMPL_IF name=\"var\" value=\"thing\"> One<TMPL_ELSE> Two<TMPL_END>"; +char c_11_1[] = "Test else2: One"; +char c_11_2[] = "Test else2: Two"; + int main(){ struct TMPL_templates* t; struct TMPL_varlist* vl; @@ -113,7 +121,7 @@ int main(){ vl = TMPL_alloc_varlist(); ret = TMPL_render(t,vl,&dummy); if(strcmp(ret,c_6_1) != 0){ - fprintf(stderr, "Error in test file 1, test 5\n"); + fprintf(stderr, "Error in test file 1, test 6\n"); printf("Result should have been '%s'\n was '%s'\n",c_6_1,ret); return -1; } @@ -129,7 +137,7 @@ int main(){ } ret = TMPL_render(t,vl,&dummy); if(strcmp(ret,c_7_1) != 0){ - fprintf(stderr, "Error in test file 1, test 5\n"); + fprintf(stderr, "Error in test file 1, test 7\n"); printf("Result should have been '%s'\n was '%s'\n",c_7_1,ret); return -1; } @@ -144,7 +152,7 @@ int main(){ } ret = TMPL_render(t,vl,&dummy); if(strcmp(ret,c_7_2) != 0){ - fprintf(stderr, "Error in test file 1, test 5\n"); + fprintf(stderr, "Error in test file 1, test 7\n"); printf("Result should have been '%s'\n was '%s'\n",c_7_1,ret); return -1; } @@ -165,7 +173,7 @@ int main(){ } ret = TMPL_render(t,vl,&dummy); if(strcmp(ret,c_7_3) != 0){ - fprintf(stderr, "Error in test file 1, test 5\n"); + fprintf(stderr, "Error in test file 1, test 7\n"); printf("Result should have been '%s'\n was '%s'\n",c_7_1,ret); return -1; } @@ -178,7 +186,7 @@ int main(){ TMPL_add_var_to_varlist(vl,"var","correct"); ret = TMPL_render(t,vl,&dummy); if(strcmp(ret,c_8_1) != 0){ - fprintf(stderr, "Error in test file 1, test 5\n"); + fprintf(stderr, "Error in test file 1, test 8\n"); printf("Result should have been '%s'\n was '%s'\n",c_8_1,ret); return -1; } @@ -187,7 +195,7 @@ int main(){ TMPL_add_var_to_varlist(vl,"var","incorrect"); ret = TMPL_render(t,vl,&dummy); if(strcmp(ret,c_8_2) != 0){ - fprintf(stderr, "Error in test file 1, test 5\n"); + fprintf(stderr, "Error in test file 1, test 8\n"); printf("Result should have been '%s'\n was '%s'\n",c_8_2,ret); return -1; } @@ -195,19 +203,20 @@ int main(){ vl = TMPL_alloc_varlist(); ret = TMPL_render(t,vl,&dummy); if(strcmp(ret,c_8_3) != 0){ - fprintf(stderr, "Error in test file 1, test 5\n"); + fprintf(stderr, "Error in test file 1, test 8\n"); printf("Result should have been '%s'\n was '%s'\n",c_8_3,ret); return -1; } TMPL_free_template(t); TMPL_free_varlist(vl); + /*Test 9*/ t = TMPL_alloc_template(t_9); vl = TMPL_alloc_varlist(); TMPL_add_var_to_varlist(vl,"var","thing"); ret = TMPL_render(t,vl,&dummy); if(strcmp(ret,c_9_1) != 0){ - fprintf(stderr, "Error in test file 1, test 5\n"); + fprintf(stderr, "Error in test file 1, test 9\n"); printf("Result should have been '%s'\n was '%s'\n",c_9_1,ret); return -1; } @@ -215,13 +224,34 @@ int main(){ vl = TMPL_alloc_varlist(); ret = TMPL_render(t,vl,&dummy); if(strcmp(ret,c_9_2) != 0){ - fprintf(stderr, "Error in test file 1, test 5\n"); + fprintf(stderr, "Error in test file 1, test 9\n"); printf("Result should have been '%s'\n was '%s'\n",c_9_1,ret); return -1; } TMPL_free_varlist(vl); TMPL_free_template(t); + /*Test 10*/ + t = TMPL_alloc_template(t_10); + vl = TMPL_alloc_varlist(); + TMPL_add_var_to_varlist(vl,"var","True"); + ret = TMPL_render(t,vl,&dummy); + if(strcmp(ret, c_10_1) != 0){ + fprintf(stderr, "Error in test file 1, test 10\n"); + printf("Result should have been '%s'\n was '%s'\n",c_10_1,ret); + return -1; + } + TMPL_free_varlist(vl); + vl = TMPL_alloc_varlist(); + ret = TMPL_render(t,vl,&dummy); + if(strcmp(ret, c_10_2) != 0){ + fprintf(stderr, "Error in test file 1, test 10\n"); + printf("Result should have been '%s'\n was '%s'\n",c_10_2,ret); + return -1; + } + TMPL_free_varlist(vl); + TMPL_free_template(t); + return 0; |
