aboutsummaryrefslogtreecommitdiff
path: root/t/test_1.c
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2018-04-06 13:18:05 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2018-04-06 13:18:05 -0400
commit864448e37769c96ba3db365de2680e2cff4fe023 (patch)
tree77258e5303c740d45efa834c521de003fb84ed64 /t/test_1.c
parent21b9f1bfe216450db5c1844d5f70d73de2bfe1d1 (diff)
downloadlibctemplates-864448e37769c96ba3db365de2680e2cff4fe023.tar.gz
libctemplates-864448e37769c96ba3db365de2680e2cff4fe023.tar.bz2
libctemplates-864448e37769c96ba3db365de2680e2cff4fe023.zip
Added more tests
Added a few more tests.
Diffstat (limited to 't/test_1.c')
-rw-r--r--t/test_1.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/t/test_1.c b/t/test_1.c
index fc1550f..67461cc 100644
--- a/t/test_1.c
+++ b/t/test_1.c
@@ -52,6 +52,17 @@ char c_12_1[] = "Test else3: One";
char c_12_2[] = "Test else3: Two";
char c_12_3[] = "Test else3:";
+char t_13[] = "Test else4:<TMPL_IF name=\"var\" value=\"one\"> One<TMPL_ELSEIF name=\"var2\" value=\"two\"> Two<TMPL_ELSE> Three<TMPL_END>";
+char c_13_1[] = "Test else4: One";
+char c_13_2[] = "Test else4: Two";
+char c_13_3[] = "Test else4: Three";
+
+char t_14[] = "Test if with empty value:<TMPL_IF name=\"var\" value=\"\"> Correct!<TMPL_END>";
+char c_14_1[] = "Test if with empty value: Correct!";
+
+char t_15[] = "Test elseif with empty value:<TMPL_IF name=\"missing\"> Wrong<TMPL_ELSEIF name=\"var\" value=\"\"> Correct!<TMPL_END>";
+char c_15_1[] = "Test elseif with empty value: Correct!";
+
int main(){
struct TMPL_templates* t;
struct TMPL_varlist* vl;
@@ -308,6 +319,63 @@ int main(){
TMPL_free_varlist(vl);
TMPL_free_template(t);
+ /*Test 13: If with elseif, no else*/
+ t = TMPL_alloc_template(t_13);
+ vl = TMPL_alloc_varlist();
+ TMPL_add_var_to_varlist(vl,"var","one");
+ ret = TMPL_render(t,vl,&dummy);
+ if(strcmp(ret, c_13_1) != 0){
+ fprintf(stderr, "Error in test file 1, test 13\n");
+ printf("Result should have been '%s'\n was '%s'\n",c_13_1,ret);
+ return -1;
+ }
+ TMPL_free_varlist(vl);
+ vl = TMPL_alloc_varlist();
+ TMPL_add_var_to_varlist(vl,"var2","two");
+ ret = TMPL_render(t,vl,&dummy);
+ if(strcmp(ret, c_13_2) != 0){
+ fprintf(stderr, "Error in test file 1, test 13\n");
+ printf("Result should have been '%s'\n was '%s'\n",c_13_2,ret);
+ return -1;
+ }
+ TMPL_free_varlist(vl);
+ vl = TMPL_alloc_varlist();
+ ret = TMPL_render(t,vl,&dummy);
+ if(strcmp(ret, c_13_3) != 0){
+ fprintf(stderr, "Error in test file 1, test 13\n");
+ printf("Result should have been '%s'\n was '%s'\n",c_13_3,ret);
+ return -1;
+ }
+ TMPL_free_varlist(vl);
+ TMPL_free_template(t);
+
+ /*Test 14: If with with empty value*/
+ t = TMPL_alloc_template(t_14);
+ vl = TMPL_alloc_varlist();
+ TMPL_add_var_to_varlist(vl,"var","");
+ ret = TMPL_render(t,vl,&dummy);
+ if(strcmp(ret, c_14_1) != 0){
+ fprintf(stderr, "Error in test file 1, test 14\n");
+ printf("Result should have been '%s'\n was '%s'\n",c_14_1,ret);
+ return -1;
+ }
+ TMPL_free_varlist(vl);
+ TMPL_free_template(t);
+ /*Test 15: Elseif with with empty value*/
+ t = TMPL_alloc_template(t_15);
+ vl = TMPL_alloc_varlist();
+ TMPL_add_var_to_varlist(vl,"var","");
+ ret = TMPL_render(t,vl,&dummy);
+ if(strcmp(ret, c_15_1) != 0){
+ fprintf(stderr, "Error in test file 1, test 15\n");
+ printf("Result should have been '%s'\n was '%s'\n",c_15_1,ret);
+ return -1;
+ }
+ TMPL_free_varlist(vl);
+ TMPL_free_template(t);
+
+
+
return 0;
}