"
EXECUTE: "context + '{"name3": "zalupa"}';
IF context->condition THEN
RAISE INFO 'some log';
RETURN 'some text';
END
RETURN 'some other text';"
TEXT: "
"$expected15$
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Complex example from documentation - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Complex example from documentation - FAILED', total_tests;
END IF;
-- Test 16: Multiple nested sections
total_tests := total_tests + 1;
result := test_template_parse(
'{{ for a in items }}
{{ for b in a.items }}
{{ for c in b.items }}
{{ c.name }}
{{ end }}
{{ end }}
{{ end }}',
'SECTION: iterator="a", collection="items"
TEXT: "
"
SECTION: iterator="b", collection="a.items"
TEXT: "
"
SECTION: iterator="c", collection="b.items"
TEXT: "
"
INTERPOLATE: "c.name"
TEXT: "
"'
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Multiple nested sections - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Multiple nested sections - FAILED', total_tests;
END IF;
-- Test 17: Interpolation with special characters
total_tests := total_tests + 1;
result := test_template_parse(
'{{ special@field }}',
'INTERPOLATE: "special@field"'
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Interpolation with special characters - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Interpolation with special characters - FAILED', total_tests;
END IF;
-- Test 18: Section with complex iterator and collection names
total_tests := total_tests + 1;
result := test_template_parse(
'{{ for complex_item.with.dots in complex_collection[0].items }}{{ end }}',
'SECTION: iterator="complex_item.with.dots", collection="complex_collection[0].items"'
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Section with complex iterator and collection names - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Section with complex iterator and collection names - FAILED', total_tests;
END IF;
-- Test 19: Include with complex path
total_tests := total_tests + 1;
result := test_template_parse(
'{{ include templates[0].nested.path }}',
'INCLUDE: "templates[0].nested.path"'
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Include with complex path - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Include with complex path - FAILED', total_tests;
END IF;
-- Test 20: Execute with complex SQL and quotes
total_tests := total_tests + 1;
result := test_template_parse(
$template20$
{{ exec SELECT 'text with "double" quotes' AS result; }}
$template20$,
$expected20$EXECUTE: "SELECT 'text with "double" quotes' AS result;"$expected20$
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Execute with complex SQL and quotes - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Execute with complex SQL and quotes - FAILED', total_tests;
END IF;
-- Test 21: Execute tag with braces inside SQL code
total_tests := total_tests + 1;
result := test_template_parse(
$template21${{ exec
-- SQL with curly braces in string literals and comments
/* Comment with {{ braces }} inside */
SELECT
'{{ This is inside a string literal }}' AS braced_text,
$str$String with {{ and }} inside$str$ AS dollar_quoted,
regexp_replace('test', 'e(.)t', 'a$1z') AS regex_with_curly;
}}$template21$,
$expected21$EXECUTE: "-- SQL with curly braces in string literals and comments
/* Comment with {{ braces }} inside */
SELECT
'{{ This is inside a string literal }}' AS braced_text,
$str$String with {{ and }} inside$str$ AS dollar_quoted,
regexp_replace('test', 'e(.)t', 'a$1z') AS regex_with_curly;"$expected21$
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Execute tag with braces inside SQL code - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Execute tag with braces inside SQL code - FAILED', total_tests;
END IF;
-- Test 22: Deeply nested sections with mixed content
total_tests := total_tests + 1;
result := test_template_parse(
$template22${{ for x in outer }}
Level 1: {{ x.name }}
{{ for y in x.items }}
Level 2: {{ y.title }}
{{ for z in y.subitems }}
Level 3: {{ z.label }} - {{ z.value }}
{{ for detail in z.details }}
Details: {{ detail }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}$template22$,
$expected22$Template parsed successfully. Structure:
SECTION: iterator="x", collection="outer"
TEXT: "
Level 1: "
INTERPOLATE: "x.name"
TEXT: "
"
SECTION: iterator="y", collection="x.items"
TEXT: "
Level 2: "
INTERPOLATE: "y.title"
TEXT: "
"
SECTION: iterator="z", collection="y.subitems"
TEXT: "
Level 3: "
INTERPOLATE: "z.label"
TEXT: " - "
INTERPOLATE: "z.value"
TEXT: "
"
SECTION: iterator="detail", collection="z.details"
TEXT: "
Details: "
INTERPOLATE: "detail"
TEXT: "
"
TEXT: "
"
TEXT: "
"
TEXT: "
"$expected22$
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Deeply nested sections with mixed content - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Deeply nested sections with mixed content - FAILED', total_tests;
END IF;
-- Test 23: Multiple tag types mixed with HTML
total_tests := total_tests + 1;
result := test_template_parse(
$template23$
{{ page_title }}
{{ include content_template }}
{{ exec SELECT get_footer_text() AS footer_text; }}
"$expected23$
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Multiple tag types mixed with HTML - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Multiple tag types mixed with HTML - FAILED', total_tests;
END IF;
-- Test 24: Section with complex iterator paths
total_tests := total_tests + 1;
result := test_template_parse(
$template24${{ for item.nested[0].value in collection[5].items[2].values }}
{{ item.nested[0].value }}
{{ end }}$template24$,
$expected24$SECTION: iterator="item.nested[0].value", collection="collection[5].items[2].values"$expected24$
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Section with complex iterator paths - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Section with complex iterator paths - FAILED', total_tests;
END IF;
-- Test 25: Interpolation with Unicode characters
total_tests := total_tests + 1;
result := test_template_parse(
$template25${{ unicode_var_ẞαж한글💻🌍 }}$template25$,
$expected25$INTERPOLATE: "unicode_var_ẞαж한글💻🌍"$expected25$
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Interpolation with Unicode characters - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Interpolation with Unicode characters - FAILED', total_tests;
END IF;
-- Test 26: Multiple consecutive sections
total_tests := total_tests + 1;
result := test_template_parse(
$template26${{ for a in list_a }}{{ a }}{{ end }}{{ for b in list_b }}{{ b }}{{ end }}{{ for c in list_c }}{{ c }}{{ end }}$template26$,
$expected26$SECTION: iterator="a", collection="list_a"
INTERPOLATE: "a"
SECTION: iterator="b", collection="list_b"
INTERPOLATE: "b"
SECTION: iterator="c", collection="list_c"
INTERPOLATE: "c"$expected26$
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Multiple consecutive sections - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Multiple consecutive sections - FAILED', total_tests;
END IF;
-- Test 27: Includes with variable paths
total_tests := total_tests + 1;
result := test_template_parse(
$template27${{ include user.preferences.theme_template }}
{{ include system.templates[user.template_index] }}$template27$,
$expected27$INCLUDE: "user.preferences.theme_template"
TEXT: "
"
INCLUDE: "system.templates[user.template_index]"$expected27$
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Includes with variable paths - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Includes with variable paths - FAILED', total_tests;
END IF;
-- Test 28: Extremely long interpolation key
total_tests := total_tests + 1;
result := test_template_parse(
$template28${{ very_long_variable_name_with_many_parts.that_continues_for_a_while.with_multiple_segments.and_keeps_going.for_quite_some_time.until_it_becomes_quite_verbose }}$template28$,
$expected28$INTERPOLATE: "very_long_variable_name_with_many_parts.that_continues_for_a_while.with_multiple_segments.and_keeps_going.for_quite_some_time.until_it_becomes_quite_verbose"$expected28$
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Extremely long interpolation key - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Extremely long interpolation key - FAILED', total_tests;
END IF;
-- Test 29: Tags with extra whitespace
total_tests := total_tests + 1;
result := test_template_parse(
$template29${{ for item in items }}
{{ item.name }}
{{ end }}$template29$,
$expected29$SECTION: iterator="item", collection="items"
TEXT: "
"
INTERPOLATE: "item.name"
TEXT: "
"$expected29$
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Tags with extra whitespace - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Tags with extra whitespace - FAILED', total_tests;
END IF;
-- Test 30: Execute with PL/pgSQL code blocks
total_tests := total_tests + 1;
result := test_template_parse(
$template30${{ exec
DECLARE
temp_var text;
counter int := 0;
BEGIN
FOR i IN 1..10 LOOP
counter := counter + i;
END LOOP;
IF counter > 50 THEN
temp_var := 'High';
ELSE
temp_var := 'Low';
END IF;
RETURN json_build_object('result', temp_var, 'count', counter);
END;
}}$template30$,
$expected30$EXECUTE: "DECLARE
temp_var text;
counter int := 0;
BEGIN
FOR i IN 1..10 LOOP
counter := counter + i;
END LOOP;
IF counter > 50 THEN
temp_var := 'High';
ELSE
temp_var := 'Low';
END IF;
RETURN json_build_object('result', temp_var, 'count', counter);
END;"$expected30$
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: Execute with PL/pgSQL code blocks - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Execute with PL/pgSQL code blocks - FAILED', total_tests;
END IF;
-- Test 31: Template with mixed indentation and newlines
total_tests := total_tests + 1;
result := test_template_parse(
$template31$