From 6dab0b778c8083b53b06ca25e35f9900f474075b Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sun, 7 Jan 2018 16:10:25 -0500 Subject: Fixed a bug with TMPL_IF not working as variable check Fixed a bug where the tag was not correctly checking if a variable exists if it does not have a "testval" attribute. --- t/test_1.c | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) (limited to 't') diff --git a/t/test_1.c b/t/test_1.c index 038f7bb..aa72213 100644 --- a/t/test_1.c +++ b/t/test_1.c @@ -39,6 +39,14 @@ char t_9[] = "Test if for existance: Exists!"; char c_9_1[] = "Test if for existance: Exists!"; char c_9_2[] = "Test if for existance:"; +char t_10[] = "Test else: One Two"; +char c_10_1[] = "Test else: One"; +char c_10_2[] = "Test else: Two"; + +char t_11[] = "Test else2: One Two"; +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; -- cgit v1.2.3-70-g09d2