From 9d2b2c4395f47c7d3cdbdebd7d0240080a610008 Mon Sep 17 00:00:00 2001 From: Spencer Brower <6729162+sbrow@users.noreply.github.com> Date: Fri, 17 Jul 2026 15:05:33 -0400 Subject: [PATCH] test: Added tests for sectionate extension. --- TODOS.md | 8 ++++-- markdown/emoji_test.odin | 13 ++++------ markdown/sectionate.odin | 6 +++-- markdown/sectionate_test.odin | 49 +++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 markdown/sectionate_test.odin diff --git a/TODOS.md b/TODOS.md index 2415c51..24e2325 100644 --- a/TODOS.md +++ b/TODOS.md @@ -45,6 +45,8 @@ - [ ] Use spall to find ways to reduce run time. - [ ] warn/error when unknown key used in mustache. - [ ] Import/export packages. Hugo, jekyll, WordPress, etc. +- [ ] Markdown + - [ ] Add overloads for every extension - accept ^strings.Builder. - [ ] Review every file in thor - [ ] Review assets.odin - [ ] Review content.odin @@ -55,12 +57,14 @@ - [ ] Review minify.odin - [ ] Review `markdown/` - [ ] Review alerts.odin - - [ ] Review emoji.odin + - [x] Review emoji.odin + - [x] Review emoji_test.odin - [ ] Review footnotes.odin - [ ] Review footnotes_test.odin - [ ] Review highlight.odin - [ ] Review markdown.odin - - [ ] Review sectionate.odin + - [x] Review sectionate.odin + - [x] Review sectionate_test.odin - [ ] Review render.odin - [x] Review site.odin - [ ] Review treesitter/treesitter.odin diff --git a/markdown/emoji_test.odin b/markdown/emoji_test.odin index 17ea701..ac8f7a2 100644 --- a/markdown/emoji_test.odin +++ b/markdown/emoji_test.odin @@ -4,17 +4,19 @@ package markdown import "core:testing" @(test) -test_basic_expansion :: proc(t: ^testing.T) { +test_basic_emoji_expansion_works :: proc(t: ^testing.T) { testing.expect_value(t, expand_emoji(":smile:"), "😄") testing.expect_value(t, expand_emoji(":smile: :heart:"), "😄 ❤️") testing.expect_value(t, expand_emoji(":smile::heart:"), "😄❤️") testing.expect_value(t, expand_emoji("Hello :wave:!"), "Hello 👋!") testing.expect_value(t, expand_emoji(":smile: rest"), "😄 rest") testing.expect_value(t, expand_emoji("rest :smile:"), "rest 😄") + testing.expect_value(t, expand_emoji(":100:"), "💯") + testing.expect_value(t, expand_emoji(":stuck_out_tongue:"), "😛") } @(test) -test_no_match :: proc(t: ^testing.T) { +test_emoji_skips_non_matches :: proc(t: ^testing.T) { testing.expect_value(t, expand_emoji("Hello world"), "Hello world") testing.expect_value(t, expand_emoji("Hello:"), "Hello:") testing.expect_value(t, expand_emoji(":notreal:"), ":notreal:") @@ -23,14 +25,9 @@ test_no_match :: proc(t: ^testing.T) { } @(test) -test_invalid_shortcodes :: proc(t: ^testing.T) { +test_emoji_skips_invalid_shortcodes :: proc(t: ^testing.T) { testing.expect_value(t, expand_emoji("::"), "::") testing.expect_value(t, expand_emoji(":Smile:"), ":Smile:") testing.expect_value(t, expand_emoji(": not real :"), ": not real :") } -@(test) -test_valid_formats :: proc(t: ^testing.T) { - testing.expect_value(t, expand_emoji(":100:"), "💯") - testing.expect_value(t, expand_emoji(":stuck_out_tongue:"), "😛") -} diff --git a/markdown/sectionate.odin b/markdown/sectionate.odin index c69ea85..581ada7 100644 --- a/markdown/sectionate.odin +++ b/markdown/sectionate.odin @@ -37,8 +37,10 @@ wrap_sections :: proc(html: string) -> string { found = true } - if !found { + if found { + return strings.to_string(sb) + } else { return html } - return strings.to_string(sb) } + diff --git a/markdown/sectionate_test.odin b/markdown/sectionate_test.odin new file mode 100644 index 0000000..5e410f9 --- /dev/null +++ b/markdown/sectionate_test.odin @@ -0,0 +1,49 @@ +#+test +package markdown + +import "core:testing" + +@(test) +test_wrap_sections_works :: proc(t: ^testing.T) { + testing.expect_value( + t, + wrap_sections("
intro
body
"), + "intro
body
a
b
c
"), + "a
b
c
body
"), + "body
intro
intro
just text
"), + "just text