checkpoint

This commit is contained in:
2025-05-21 19:50:47 +00:00
parent d1b0d7154d
commit 3b7c4d71e7
5 changed files with 206 additions and 59 deletions

View File

@@ -29,7 +29,7 @@ BEGIN;
$$ LANGUAGE plpgsql;
\ir test_jsonb_path.sql
\ir test_template_parser.sql
--\ir test_template_parser.sql
\ir test_render_exec.sql
\ir test_render_interpolate.sql
\ir test_render_section.sql

View File

@@ -137,25 +137,25 @@ BEGIN
<header>{{ include header }}</header>
<main>
{{ for section in page.sections }}
<section id="{{ section.id }}">
<h2>{{ section.title }}</h2>
{{ for item in section.items }}
<div class="item {{ item.status }}">
{{ include item.template }}
{{ exec
DECLARE
v_status TEXT;
BEGIN
v_status := context->'item'->>'status';
RETURN CASE
WHEN v_status = 'active' THEN ' (Active Item)'
ELSE ' (Inactive Item)'
END;
END;
}}
</div>
{{ end }}
</section>
<section id="{{ section.id }}">
<h2>{{ section.title }}</h2>
{{ for item in section.items }}
<div class="item {{ item.status }}">
{{ include item.template }}
{{ exec
DECLARE
v_status TEXT;
BEGIN
v_status := context->'item'->>'status';
RETURN CASE
WHEN v_status = 'active' THEN ' (Active Item)'
ELSE ' (Inactive Item)'
END;
END;
}}
</div>
{{ end }}
</section>
{{ end }}
</main>
<footer>{{ include footer }}</footer>
@@ -172,15 +172,15 @@ BEGIN
<body>
<header>Welcome to My Page!</header>
<main>
<section id="section1">
<h2>Section 1</h2>
<div class="item active">
Status: active, Content: Item 1 Content (Active Item)
</div>
<div class="item inactive">
Status: inactive, Content: Item 2 Content (Inactive Item)
</div>
</section>
<section id="section1">
<h2>Section 1</h2>
<div class="item active">
Status: active, Content: Item 1 Content (Active Item)
</div>
<div class="item inactive">
Status: inactive, Content: Item 2 Content (Inactive Item)
</div>
</section>
</main>
<footer><footer>Copyright 2024</footer></footer>
</body>
@@ -192,7 +192,7 @@ BEGIN
RAISE NOTICE 'Test %: Complex template with all tag types: PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: Complex template with all tag types: FAILED. Expected "%", got "%"',
total_tests, expected, test_result;
total_tests, pg_temp.test_regexp_replace(expected), pg_temp.test_regexp_replace(test_result);
END IF;
EXCEPTION WHEN OTHERS THEN
RAISE WARNING 'Test % failed: Error: %', total_tests, SQLERRM;

View File

@@ -217,8 +217,7 @@ BEGIN
);
expected := ' item
item
item
';
item';
IF test_result = expected THEN
RAISE NOTICE 'Test %: Section whitespaces 2: PASSED', total_tests;
passed_tests := passed_tests + 1;
@@ -239,8 +238,7 @@ BEGIN
);
expected := ' item
item
item
';
item';
IF test_result = expected THEN
RAISE NOTICE 'Test %: Section whitespaces 3: PASSED', total_tests;
passed_tests := passed_tests + 1;
@@ -283,7 +281,6 @@ BEGIN
expected := ' item
item
item
';
IF test_result = expected THEN
RAISE NOTICE 'Test %: Section whitespaces 5: PASSED', total_tests;
@@ -295,6 +292,68 @@ BEGIN
RAISE WARNING 'Test %: Section whitespaces 5: FAILED with error: %', total_tests, SQLERRM;
END;
-- Test 16: Tabs
total_tests := total_tests + 1;
BEGIN
test_result := hemar.render(
'{"array": [1, 2, 3]}'::jsonb,
'
identation1
{{for item in array}}
identation2
{{end}}
identation1
'
);
expected := '
identation1
identation2
identation2
identation2
identation1
';
IF test_result = expected THEN
RAISE NOTICE 'Test %: Tabs: PASSED', total_tests;
passed_tests := passed_tests + 1;
ELSE
RAISE WARNING 'Test %: Tabs: FAILED. Expected "%", got "%"', total_tests, pg_temp.test_regexp_replace(expected), pg_temp.test_regexp_replace(test_result);
END IF;
EXCEPTION WHEN OTHERS THEN
RAISE WARNING 'Test %: Tabs: FAILED with error: %', total_tests, SQLERRM;
END;
-- Test 17: Tabs 2
total_tests := total_tests + 1;
BEGIN
test_result := hemar.render(
'{"array": [1, 2, 3]}'::jsonb,
'
identation1
{{for item in array}}
identation2
{{end}}
identation1
'
);
expected := '
identation1
identation2
identation2
identation2
identation1
';
IF test_result = expected THEN
RAISE NOTICE 'Test %: Tabs: PASSED', total_tests;
passed_tests := passed_tests + 1;
ELSE
RAISE WARNING 'Test %: Tabs: FAILED. Expected "%", got "%"', total_tests, pg_temp.test_regexp_replace(expected), pg_temp.test_regexp_replace(test_result);
END IF;
EXCEPTION WHEN OTHERS THEN
RAISE WARNING 'Test %: Tabs: FAILED with error: %', total_tests, SQLERRM;
END;
-- Print summary
IF passed_tests = total_tests THEN
RAISE NOTICE '------------------------------------';

View File

@@ -49,6 +49,38 @@ DECLARE
BEGIN
PERFORM pg_sleep(2);
RAISE NOTICE 'Starting template parser tests...';
-- Test 0: bruh
total_tests := total_tests + 1;
result := test_template_parse(
$hemar1$
text
{{ for i in a }}
item
item
item
{{ end }}
text
$hemar1$,
$expected1$Template parsed successfully. Structure:
TEXT: "
text"
SECTION: iterator="i", collection="a"
TEXT: " item
item
item
"
TEXT: "
text
"
$expected1$
);
IF result THEN
passed_tests := passed_tests + 1;
RAISE NOTICE 'Test %: bruh - PASSED', total_tests;
ELSE
RAISE WARNING 'Test %: bruh - FAILED', total_tests;
END IF;
-- Test 1: Simple interpolation
total_tests := total_tests + 1;