aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--t/test_2.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/t/test_2.c b/t/test_2.c
index 6599c27..e11fcdc 100644
--- a/t/test_2.c
+++ b/t/test_2.c
@@ -14,6 +14,12 @@ char c_2_3[] = "Check break condition before after before after before after !";
char c_2_4[] = "Check break condition before in !";
char c_2_5[] = "Check break condition before after before in !";
+char t_3[] = "Check variable scope after breaking loop <TMPL_LOOP name=\"loop1\">one <TMPL_IF name=\"test1\">two <TMPL_BREAK>three <TMPL_END>four <TMPL_LOOP name=\"loop2\">five <TMPL_BREAK level=2>six <TMPL_END>seven <TMPL_END>eight <TMPL_VAR name=\"after\" default=\"\">nine.";
+char c_3_1[] = "Check variable scope after breaking loop one two eight nine.";//loop1 has test1 as a var, after is not a variable
+char c_3_2[] = "Check variable scope after breaking loop one two eight and a half nine.";//loop1 has test1 as a var, after is "and a half "
+char c_3_3[] = "Check variable scope after breaking loop one four five eight nine.";//loop1 does not have test1, loop1 has loop2, after is not a variable
+char c_3_4[] = "Check variable scope after breaking loop one four five eight and a half nine.";//loop1 does not have test1, loop1 has loop2, after is "and a half "
+
#define log(x) printf(x)
#define check(n,n2,a,b) if(strcmp(a,b) != 0){fprintf(stderr, "Error in test 2.%d.%d\n",n,n2);printf("Result should have been '%s'\n was '%s'\n", b, a); if(t->error) printf(TMPL_err(t, NULL)); return -1;}
@@ -61,6 +67,7 @@ int main(){
check(2,1,ret,c_2_1);
log("Test 2 complete\n");
TMPL_free_template(t);
+ printf("Freed template...\n");
TMPL_free_varlist(vl);
t = TMPL_alloc_template(t_2);
@@ -111,8 +118,55 @@ int main(){
TMPL_add_var_to_varlist(vl2,"test","true");
TMPL_add_varlist_to_loop(l1,vl1);
TMPL_add_varlist_to_loop(l1,vl2);
- TMPL_add_loop_to_varlist(vl1,"loop1",l1);
+ TMPL_add_loop_to_varlist(vl,"loop1",l1);
+ ret = TMPL_render(t,vl,&dummy);
+ check(2,5,ret,c_2_5);
+ log("Test 6 complete\n");
+ TMPL_free_template(t);
+ TMPL_free_varlist(vl);
+
+ t = TMPL_alloc_template(t_3);
+ vl = TMPL_alloc_varlist();
+ l1 = TMPL_alloc_loop();
+ vl1 = TMPL_alloc_varlist();
+ TMPL_add_var_to_varlist(vl1,"test1","true");
+ TMPL_add_varlist_to_loop(l1,vl1);
+ TMPL_add_loop_to_varlist(vl,"loop1",l1);
+ ret = TMPL_render(t,vl,&dummy);
+ check(3,1,ret,c_3_1);
+ log("Test 7 complete\n");
+ TMPL_free_template(t);
+ TMPL_free_varlist(vl);
+ t = TMPL_alloc_template(t_3);
+ vl = TMPL_alloc_varlist();
+ l1 = TMPL_alloc_loop();
+ vl1 = TMPL_alloc_varlist();
+ TMPL_add_var_to_varlist(vl1,"test1","true");
+ TMPL_add_varlist_to_loop(l1,vl1);
+ TMPL_add_loop_to_varlist(vl,"loop1",l1);
+ TMPL_add_var_to_varlist(vl,"after","and a half ");
+ ret = TMPL_render(t,vl,&dummy);
+ check(3,2,ret,c_3_2);
+ log("Test 8 complete\n");
+ TMPL_free_template(t);
+ TMPL_free_varlist(vl);
+
+ t = TMPL_alloc_template(t_3);
+ vl = TMPL_alloc_varlist();
+ l1 = TMPL_alloc_loop();
+ vl1 = TMPL_alloc_varlist();
+ l2 = TMPL_alloc_loop();
+ vl2 = TMPL_alloc_varlist();
+ TMPL_add_varlist_to_loop(l2,vl2);
+ TMPL_add_loop_to_varlist(vl1,"loop2",l2);
+ TMPL_add_varlist_to_loop(l1,vl1);
+ TMPL_add_loop_to_varlist(vl,"loop1",l1);
+ ret = TMPL_render(t,vl,&dummy);
+ check(3,3,ret,c_3_3);
+ log("Test 9 complete\n");
+ TMPL_free_template(t);
+ TMPL_free_varlist(vl);
return 0;
}