fix: hemar: EBUCHIE WHITESPACЫ
This commit is contained in:
@@ -16,7 +16,7 @@ BEGIN;
|
||||
|
||||
CREATE OR REPLACE FUNCTION pg_temp.test_regexp_replace(string text) RETURNS text AS $$
|
||||
BEGIN
|
||||
RETURN regexp_replace(regexp_replace(
|
||||
RETURN regexp_replace(
|
||||
regexp_replace(
|
||||
regexp_replace(
|
||||
regexp_replace(
|
||||
@@ -24,8 +24,7 @@ BEGIN;
|
||||
E'\n', '\\n', 'g'),
|
||||
E'\r', '\\r', 'g'),
|
||||
' ', '[S]', 'g'),
|
||||
'\s', '\\s', 'g'), '\\n', '\\n
|
||||
');
|
||||
'\s', '\\s', 'g');
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
@@ -50,7 +50,8 @@ BEGIN
|
||||
{"id": 3, "value": 300}
|
||||
]
|
||||
}'::jsonb,
|
||||
$template$Items:{{ for item in items }}
|
||||
$template$Items:
|
||||
{{ for item in items }}
|
||||
Item {{ item.id }}: {{ exec RETURN (context->'item'->>'value')::int * 2; }}
|
||||
{{ end }}$template$
|
||||
);
|
||||
@@ -239,48 +240,6 @@ BEGIN
|
||||
RAISE WARNING 'Test % failed: Error: %', total_tests, SQLERRM;
|
||||
END;
|
||||
|
||||
-- Test 4: Template with execute tag using context from section
|
||||
total_tests := total_tests + 1;
|
||||
BEGIN
|
||||
test_result := hemar.render(
|
||||
'{
|
||||
"items": [
|
||||
{"id": 1, "value": 100},
|
||||
{"id": 2, "value": 200},
|
||||
{"id": 3, "value": 300}
|
||||
]
|
||||
}'::jsonb,
|
||||
$template$Items:
|
||||
{{ for item in items }}
|
||||
Item {{ item.id }}: {{ exec
|
||||
DECLARE
|
||||
v_value INT;
|
||||
BEGIN
|
||||
v_value := (context->>'value')::int;
|
||||
RETURN v_value * 2;
|
||||
END;
|
||||
}}
|
||||
{{ end }}$template$
|
||||
);
|
||||
|
||||
expected := 'Items:
|
||||
Item 1: 200
|
||||
Item 2: 400
|
||||
Item 3: 600
|
||||
';
|
||||
|
||||
passed := test_result = expected;
|
||||
passed_tests := passed_tests + (CASE WHEN passed THEN 1 ELSE 0 END);
|
||||
IF passed THEN
|
||||
RAISE NOTICE 'Test %: Template with execute tag using context from section: PASSED', total_tests;
|
||||
ELSE
|
||||
RAISE WARNING 'Test %: Template with execute tag using context from section: FAILED. Expected "%", got "%"',
|
||||
total_tests, expected, test_result;
|
||||
END IF;
|
||||
EXCEPTION WHEN OTHERS THEN
|
||||
RAISE WARNING 'Test % failed: Error: %', total_tests, SQLERRM;
|
||||
END;
|
||||
|
||||
-- Print summary
|
||||
IF passed_tests = total_tests THEN
|
||||
RAISE NOTICE '------------------------------------';
|
||||
|
||||
@@ -217,7 +217,8 @@ 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;
|
||||
@@ -238,7 +239,8 @@ 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;
|
||||
@@ -257,9 +259,7 @@ BEGIN
|
||||
'{{for item in array}}
|
||||
item {{end}}'
|
||||
);
|
||||
expected := ' item
|
||||
item
|
||||
item';
|
||||
expected := ' item item item ';
|
||||
IF test_result = expected THEN
|
||||
RAISE NOTICE 'Test %: Section whitespaces 4: PASSED', total_tests;
|
||||
passed_tests := passed_tests + 1;
|
||||
@@ -276,26 +276,25 @@ BEGIN
|
||||
test_result := hemar.render(
|
||||
'{"array": [1, 2, 3]}'::jsonb,
|
||||
'{{for item in array}}
|
||||
item
|
||||
item
|
||||
{{end}}
|
||||
'
|
||||
'
|
||||
);
|
||||
expected := ' item
|
||||
item
|
||||
item
|
||||
|
||||
';
|
||||
IF test_result = expected THEN
|
||||
RAISE NOTICE 'Test %: Section whitespaces 5: PASSED', total_tests;
|
||||
passed_tests := passed_tests + 1;
|
||||
ELSE
|
||||
RAISE WARNING 'Test %: Section whitespaces 5: FAILED. Expected "%", got "%"', total_tests, expected, test_result;
|
||||
RAISE WARNING 'Test %: Section whitespaces 5: 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 %: Section whitespaces 5: FAILED with error: %', total_tests, SQLERRM;
|
||||
END;
|
||||
|
||||
|
||||
|
||||
-- Print summary
|
||||
IF passed_tests = total_tests THEN
|
||||
RAISE NOTICE '------------------------------------';
|
||||
|
||||
Reference in New Issue
Block a user