diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/skaldpress/content/article.md | 11 | ||||
-rw-r--r-- | tests/skaldpress/templates/article.html | 22 | ||||
-rw-r--r-- | tests/skaldpress/templates/base.html | 14 | ||||
-rw-r--r-- | tests/smp/array_each_1 (renamed from tests/input_files/array_each_1) | 0 | ||||
-rw-r--r-- | tests/smp/array_push_1 (renamed from tests/input_files/array_push_1) | 0 | ||||
-rw-r--r-- | tests/smp/array_push_2 (renamed from tests/input_files/array_push_2) | 0 | ||||
-rw-r--r-- | tests/smp/array_push_3 (renamed from tests/input_files/array_push_3) | 0 | ||||
-rw-r--r-- | tests/smp/define_1 (renamed from tests/input_files/define_1) | 0 | ||||
-rw-r--r-- | tests/smp/define_2 (renamed from tests/input_files/define_2) | 0 | ||||
-rw-r--r-- | tests/smp/dnl_1 (renamed from tests/input_files/dnl_1) | 0 | ||||
-rw-r--r-- | tests/smp/dnl_2 (renamed from tests/input_files/dnl_2) | 0 | ||||
-rw-r--r-- | tests/smp/dnl_3 (renamed from tests/input_files/dnl_3) | 0 | ||||
-rw-r--r-- | tests/smp/dnl_4 (renamed from tests/input_files/dnl_4) | 0 | ||||
-rw-r--r-- | tests/smp/explode_1 (renamed from tests/input_files/explode_1) | 0 | ||||
-rw-r--r-- | tests/smp/explode_2 (renamed from tests/input_files/explode_2) | 0 | ||||
-rw-r--r-- | tests/smp/format_time_1 (renamed from tests/input_files/format_time_1) | 0 | ||||
-rw-r--r-- | tests/smp/ifdef_1 (renamed from tests/input_files/ifdef_1) | 0 | ||||
-rw-r--r-- | tests/smp/ifdef_2 (renamed from tests/input_files/ifdef_2) | 0 | ||||
-rw-r--r-- | tests/smp/ifdef_3 (renamed from tests/input_files/ifdef_3) | 0 | ||||
-rw-r--r-- | tests/smp/ifeq_1 (renamed from tests/input_files/ifeq_1) | 0 | ||||
-rw-r--r-- | tests/smp/ifeq_2 (renamed from tests/input_files/ifeq_2) | 0 | ||||
-rw-r--r-- | tests/smp/ifeq_3 (renamed from tests/input_files/ifeq_3) | 0 | ||||
-rw-r--r-- | tests/smp/ifeq_4 (renamed from tests/input_files/ifeq_4) | 0 | ||||
-rw-r--r-- | tests/smp/ifndef_1 (renamed from tests/input_files/ifndef_1) | 0 | ||||
-rw-r--r-- | tests/smp/ifndef_2 (renamed from tests/input_files/ifndef_2) | 0 | ||||
-rw-r--r-- | tests/smp/ifndef_3 (renamed from tests/input_files/ifndef_3) | 0 | ||||
-rw-r--r-- | tests/smp/ifneq_1 (renamed from tests/input_files/ifneq_1) | 0 | ||||
-rw-r--r-- | tests/smp/ifneq_2 (renamed from tests/input_files/ifneq_2) | 0 | ||||
-rw-r--r-- | tests/smp/ifneq_3 (renamed from tests/input_files/ifneq_3) | 0 | ||||
-rw-r--r-- | tests/smp/ifneq_4 (renamed from tests/input_files/ifneq_4) | 0 | ||||
-rw-r--r-- | tests/smp/include_1 (renamed from tests/input_files/include_1) | 0 | ||||
-rw-r--r-- | tests/smp/include_2 (renamed from tests/input_files/include_2) | 0 | ||||
-rw-r--r-- | tests/smp/markdown_html_1 (renamed from tests/input_files/markdown_html_1) | 0 | ||||
-rw-r--r-- | tests/smp/markdown_html_2 (renamed from tests/input_files/markdown_html_2) | 0 | ||||
-rw-r--r-- | tests/smp/non_macro_html (renamed from tests/input_files/non_macro_html) | 0 | ||||
-rw-r--r-- | tests/smp/shell_1 (renamed from tests/input_files/shell_1) | 0 | ||||
-rw-r--r-- | tests/smp/snnl_1 (renamed from tests/input_files/snnl_1) | 0 | ||||
-rw-r--r-- | tests/smp/snnl_2 (renamed from tests/input_files/snnl_2) | 0 | ||||
-rw-r--r-- | tests/smp/snnl_3 (renamed from tests/input_files/snnl_3) | 0 | ||||
-rw-r--r-- | tests/smp/whitespace_deleting_1 (renamed from tests/input_files/whitespace_deleting_1) | 0 | ||||
-rw-r--r-- | tests/smp/whitespace_deleting_2 (renamed from tests/input_files/whitespace_deleting_2) | 0 | ||||
-rw-r--r-- | tests/smp/wodl_1 (renamed from tests/input_files/wodl_1) | 0 | ||||
-rw-r--r-- | tests/smp/wodl_2 (renamed from tests/input_files/wodl_2) | 0 | ||||
-rwxr-xr-x | tests/test_macro_processor.sh | 4 | ||||
-rwxr-xr-x | tests/test_skaldpress.sh | 7 | ||||
-rwxr-xr-x | tests/test_unittests.sh | 27 | ||||
-rw-r--r-- | tests/unit_tests/metadata_parser_1.py | 28 |
47 files changed, 111 insertions, 2 deletions
diff --git a/tests/skaldpress/content/article.md b/tests/skaldpress/content/article.md new file mode 100644 index 0000000..b20468c --- /dev/null +++ b/tests/skaldpress/content/article.md @@ -0,0 +1,11 @@ +--- +title: Example-article +target_filename: example-article +template: article.html +publish_date: 2025-01-01T00:00:00Z +summary: A short example article +tags: + - article +--- + +This is a example article diff --git a/tests/skaldpress/templates/article.html b/tests/skaldpress/templates/article.html new file mode 100644 index 0000000..cb3b58b --- /dev/null +++ b/tests/skaldpress/templates/article.html @@ -0,0 +1,22 @@ +--- +template: base.html +table_of_contents: true +keep_states: + - TOC_ITEMS +--- +DNL include(templates/common_macros.smp)DNL +<header> + <h1>METADATA_title</h1> +</header> + +<main> + <div class="article-meta"> + <span>Published <time datetime="METADATA_publish_date">format_time(%d %B %Y,METADATA_publish_date)</time></span> + ifneq(METADATA_change_date, METADATA_publish_date,DNL + (<span>Changed <time datetime="METADATA_change_date">format_time(%d %B %Y,METADATA_change_date)</time></span>) DNL + ) + </div> + + CONTENT +</main> + diff --git a/tests/skaldpress/templates/base.html b/tests/skaldpress/templates/base.html new file mode 100644 index 0000000..aa73ffc --- /dev/null +++ b/tests/skaldpress/templates/base.html @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<html lang="en"> + <body> + <nav> + <a href="/">Home</a> + </nav> + + CONTENT + + <footer> + </footer> + </body> +</html> + diff --git a/tests/input_files/array_each_1 b/tests/smp/array_each_1 index 5844d71..5844d71 100644 --- a/tests/input_files/array_each_1 +++ b/tests/smp/array_each_1 diff --git a/tests/input_files/array_push_1 b/tests/smp/array_push_1 index fb59320..fb59320 100644 --- a/tests/input_files/array_push_1 +++ b/tests/smp/array_push_1 diff --git a/tests/input_files/array_push_2 b/tests/smp/array_push_2 index 3b4d652..3b4d652 100644 --- a/tests/input_files/array_push_2 +++ b/tests/smp/array_push_2 diff --git a/tests/input_files/array_push_3 b/tests/smp/array_push_3 index 60417b4..60417b4 100644 --- a/tests/input_files/array_push_3 +++ b/tests/smp/array_push_3 diff --git a/tests/input_files/define_1 b/tests/smp/define_1 index 68002ea..68002ea 100644 --- a/tests/input_files/define_1 +++ b/tests/smp/define_1 diff --git a/tests/input_files/define_2 b/tests/smp/define_2 index 016294a..016294a 100644 --- a/tests/input_files/define_2 +++ b/tests/smp/define_2 diff --git a/tests/input_files/dnl_1 b/tests/smp/dnl_1 index c12bc01..c12bc01 100644 --- a/tests/input_files/dnl_1 +++ b/tests/smp/dnl_1 diff --git a/tests/input_files/dnl_2 b/tests/smp/dnl_2 index 356aee9..356aee9 100644 --- a/tests/input_files/dnl_2 +++ b/tests/smp/dnl_2 diff --git a/tests/input_files/dnl_3 b/tests/smp/dnl_3 index 356aee9..356aee9 100644 --- a/tests/input_files/dnl_3 +++ b/tests/smp/dnl_3 diff --git a/tests/input_files/dnl_4 b/tests/smp/dnl_4 index 67c1c0e..67c1c0e 100644 --- a/tests/input_files/dnl_4 +++ b/tests/smp/dnl_4 diff --git a/tests/input_files/explode_1 b/tests/smp/explode_1 index 79b70ba..79b70ba 100644 --- a/tests/input_files/explode_1 +++ b/tests/smp/explode_1 diff --git a/tests/input_files/explode_2 b/tests/smp/explode_2 index 7ef0c08..7ef0c08 100644 --- a/tests/input_files/explode_2 +++ b/tests/smp/explode_2 diff --git a/tests/input_files/format_time_1 b/tests/smp/format_time_1 index bd9a097..bd9a097 100644 --- a/tests/input_files/format_time_1 +++ b/tests/smp/format_time_1 diff --git a/tests/input_files/ifdef_1 b/tests/smp/ifdef_1 index a308141..a308141 100644 --- a/tests/input_files/ifdef_1 +++ b/tests/smp/ifdef_1 diff --git a/tests/input_files/ifdef_2 b/tests/smp/ifdef_2 index ecef66c..ecef66c 100644 --- a/tests/input_files/ifdef_2 +++ b/tests/smp/ifdef_2 diff --git a/tests/input_files/ifdef_3 b/tests/smp/ifdef_3 index 4867034..4867034 100644 --- a/tests/input_files/ifdef_3 +++ b/tests/smp/ifdef_3 diff --git a/tests/input_files/ifeq_1 b/tests/smp/ifeq_1 index 3e49f68..3e49f68 100644 --- a/tests/input_files/ifeq_1 +++ b/tests/smp/ifeq_1 diff --git a/tests/input_files/ifeq_2 b/tests/smp/ifeq_2 index fe7c0ac..fe7c0ac 100644 --- a/tests/input_files/ifeq_2 +++ b/tests/smp/ifeq_2 diff --git a/tests/input_files/ifeq_3 b/tests/smp/ifeq_3 index 42646b8..42646b8 100644 --- a/tests/input_files/ifeq_3 +++ b/tests/smp/ifeq_3 diff --git a/tests/input_files/ifeq_4 b/tests/smp/ifeq_4 index d069530..d069530 100644 --- a/tests/input_files/ifeq_4 +++ b/tests/smp/ifeq_4 diff --git a/tests/input_files/ifndef_1 b/tests/smp/ifndef_1 index 857204b..857204b 100644 --- a/tests/input_files/ifndef_1 +++ b/tests/smp/ifndef_1 diff --git a/tests/input_files/ifndef_2 b/tests/smp/ifndef_2 index fbe0ba3..fbe0ba3 100644 --- a/tests/input_files/ifndef_2 +++ b/tests/smp/ifndef_2 diff --git a/tests/input_files/ifndef_3 b/tests/smp/ifndef_3 index 82a180d..82a180d 100644 --- a/tests/input_files/ifndef_3 +++ b/tests/smp/ifndef_3 diff --git a/tests/input_files/ifneq_1 b/tests/smp/ifneq_1 index 5b443c5..5b443c5 100644 --- a/tests/input_files/ifneq_1 +++ b/tests/smp/ifneq_1 diff --git a/tests/input_files/ifneq_2 b/tests/smp/ifneq_2 index 8145e9f..8145e9f 100644 --- a/tests/input_files/ifneq_2 +++ b/tests/smp/ifneq_2 diff --git a/tests/input_files/ifneq_3 b/tests/smp/ifneq_3 index 163d871..163d871 100644 --- a/tests/input_files/ifneq_3 +++ b/tests/smp/ifneq_3 diff --git a/tests/input_files/ifneq_4 b/tests/smp/ifneq_4 index c93a572..c93a572 100644 --- a/tests/input_files/ifneq_4 +++ b/tests/smp/ifneq_4 diff --git a/tests/input_files/include_1 b/tests/smp/include_1 index 1621de2..1621de2 100644 --- a/tests/input_files/include_1 +++ b/tests/smp/include_1 diff --git a/tests/input_files/include_2 b/tests/smp/include_2 index 2714eff..2714eff 100644 --- a/tests/input_files/include_2 +++ b/tests/smp/include_2 diff --git a/tests/input_files/markdown_html_1 b/tests/smp/markdown_html_1 index 6a9f143..6a9f143 100644 --- a/tests/input_files/markdown_html_1 +++ b/tests/smp/markdown_html_1 diff --git a/tests/input_files/markdown_html_2 b/tests/smp/markdown_html_2 index 6a9f143..6a9f143 100644 --- a/tests/input_files/markdown_html_2 +++ b/tests/smp/markdown_html_2 diff --git a/tests/input_files/non_macro_html b/tests/smp/non_macro_html index 6f49b4a..6f49b4a 100644 --- a/tests/input_files/non_macro_html +++ b/tests/smp/non_macro_html diff --git a/tests/input_files/shell_1 b/tests/smp/shell_1 index 3eb1f14..3eb1f14 100644 --- a/tests/input_files/shell_1 +++ b/tests/smp/shell_1 diff --git a/tests/input_files/snnl_1 b/tests/smp/snnl_1 index 47a10b9..47a10b9 100644 --- a/tests/input_files/snnl_1 +++ b/tests/smp/snnl_1 diff --git a/tests/input_files/snnl_2 b/tests/smp/snnl_2 index 2fcd0ba..2fcd0ba 100644 --- a/tests/input_files/snnl_2 +++ b/tests/smp/snnl_2 diff --git a/tests/input_files/snnl_3 b/tests/smp/snnl_3 index 4a7dad7..4a7dad7 100644 --- a/tests/input_files/snnl_3 +++ b/tests/smp/snnl_3 diff --git a/tests/input_files/whitespace_deleting_1 b/tests/smp/whitespace_deleting_1 index ccda45f..ccda45f 100644 --- a/tests/input_files/whitespace_deleting_1 +++ b/tests/smp/whitespace_deleting_1 diff --git a/tests/input_files/whitespace_deleting_2 b/tests/smp/whitespace_deleting_2 index 8777c39..8777c39 100644 --- a/tests/input_files/whitespace_deleting_2 +++ b/tests/smp/whitespace_deleting_2 diff --git a/tests/input_files/wodl_1 b/tests/smp/wodl_1 index 6466022..6466022 100644 --- a/tests/input_files/wodl_1 +++ b/tests/smp/wodl_1 diff --git a/tests/input_files/wodl_2 b/tests/smp/wodl_2 index 51be3e1..51be3e1 100644 --- a/tests/input_files/wodl_2 +++ b/tests/smp/wodl_2 diff --git a/tests/test_macro_processor.sh b/tests/test_macro_processor.sh index 1a7accd..daee5d2 100755 --- a/tests/test_macro_processor.sh +++ b/tests/test_macro_processor.sh @@ -3,7 +3,7 @@ ALL_OUTPUT=0 test () { - file_content=$(<tests/input_files/$1) + file_content=$(<tests/smp/$1) readarray -t sections < <(awk -v RS="---" '{print}' <<< "$file_content") var1=$(echo "$file_content" | awk -v RS="\n---\n" 'NR==1') var2=$(echo "$file_content" | awk -v RS="\n---\n" 'NR==2') @@ -36,7 +36,7 @@ if [ "$#" -eq 1 ]; then ALL_OUTPUT=1 test $1 else - for file in tests/input_files/*; do + for file in tests/smp/*; do test "$(basename $file)" done fi diff --git a/tests/test_skaldpress.sh b/tests/test_skaldpress.sh new file mode 100755 index 0000000..4e57a44 --- /dev/null +++ b/tests/test_skaldpress.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +cd tests/skaldpress +rm -rf build +mkdir -p build + +skaldpress diff --git a/tests/test_unittests.sh b/tests/test_unittests.sh new file mode 100755 index 0000000..802cc49 --- /dev/null +++ b/tests/test_unittests.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +ALL_OUTPUT=0 + +test () { + python tests/unit_tests/$1 + if [ "$?" -eq "1" ]; then + tput setaf 1 + echo "$1 NOT OK:" + tput sgr0 + exit 1 + else + tput setaf 2 + echo "$1 OK" + tput sgr0 + fi +} + +if [ "$#" -eq 1 ]; then + ALL_OUTPUT=1 + test $1 +else + for file in tests/unit_tests/*; do + test "$(basename $file)" + done +fi + diff --git a/tests/unit_tests/metadata_parser_1.py b/tests/unit_tests/metadata_parser_1.py new file mode 100644 index 0000000..6465845 --- /dev/null +++ b/tests/unit_tests/metadata_parser_1.py @@ -0,0 +1,28 @@ +import datetime +from skaldpress.metadata_parser import extract_parse_yaml_metadata + +res = extract_parse_yaml_metadata("""--- +title: Example-article +target_filename: example-article +template: article.html +publish_date: 2025-01-01T00:00:00Z +summary: A short example article +num: 2 +tags: + - article +--- +Article content +""") + +meta = { + "title": "Example-article", + "target_filename": "example-article", + "template": "article.html", + "publish_date": datetime.datetime(2025, 1, 1, 0, 0, tzinfo=datetime.timezone.utc), + "change_date": datetime.datetime(2025, 1, 1, 0, 0, tzinfo=datetime.timezone.utc), + "summary": "A short example article", + "num": 2, + "tags": ["article"] +} +assert res[0] == meta +assert res[1] == "Article content\n" |