AtlatestRepositoryapiary

apiary / tree / testtest-markdown-irc.sgl

1(import (sigil test)
2 (sigil string)
3 (apiary markdown-irc))
4
5;; mIRC formatting code constants (single-byte controls)
6(define BOLD (string (integer->char #x02)))
7(define ITALIC (string (integer->char #x1d)))
8(define UNDERLINE (string (integer->char #x1f)))
9(define MONO (string (integer->char #x11)))
10(define STRIKE (string (integer->char #x1e)))
11(define RESET (string (integer->char #x0f)))
13(test-group "markdown->irc inline forms"
14 (test "bold"
15 (assert-equal (string-append BOLD "hello" BOLD)
16 (markdown->irc "**hello**")))
18 (test "italic with *"
19 (assert-equal (string-append ITALIC "ok" ITALIC)
20 (markdown->irc "*ok*")))
22 (test "italic with _"
23 (assert-equal (string-append ITALIC "ok" ITALIC)
24 (markdown->irc "_ok_")))
26 (test "underline"
27 (assert-equal (string-append UNDERLINE "ok" UNDERLINE)
28 (markdown->irc "__ok__")))
30 (test "monospace"
31 (assert-equal (string-append MONO "code" MONO)
32 (markdown->irc "`code`")))
34 (test "strike"
35 (assert-equal (string-append STRIKE "old" STRIKE)
36 (markdown->irc "~~old~~")))
38 (test "bold with italic inside (toggle codes nest cleanly)"
39 (assert-equal (string-append BOLD "before "
40 ITALIC "mid" ITALIC
41 " after" BOLD)
42 (markdown->irc "**before *mid* after**")))
44 (test "literal *: plain text passes through"
45 (assert-equal "* is just an asterisk"
46 (markdown->irc "* is just an asterisk")))
48 (test "unmatched delimiter is preserved as literal"
49 (assert-equal "stray ** here"
50 (markdown->irc "stray ** here")))
52 (test "backslash escapes asterisks"
53 ;; "\\*not bold\\*" should produce "*not bold*" with no formatting
54 (assert-equal "*not bold*"
55 (markdown->irc "\\*not bold\\*"))))
57(test-group "markdown->irc line forms"
58 (test "single # heading wraps line in bold"
59 (assert-equal (string-append BOLD "Title" RESET)
60 (markdown->irc "# Title")))
62 (test "multi-# heading also bold"
63 (assert-equal (string-append BOLD "Sub" RESET)
64 (markdown->irc "### Sub")))
66 (test "heading with inline italic"
67 (assert-equal (string-append BOLD "Sec " ITALIC "α" ITALIC RESET)
68 (markdown->irc "## Sec *α*")))
70 (test "lone # at start without space is not a heading"
71 (assert-equal "#tag word"
72 (markdown->irc "#tag word")))
74 (test "bullets pass through verbatim"
75 (assert-equal "- item one"
76 (markdown->irc "- item one"))))
78(test-group "markdown->irc multi-line"
79 (test "newlines preserved"
80 (assert-equal (string-append BOLD "Title" RESET "\n"
81 "body " ITALIC "italic" ITALIC)
82 (markdown->irc "# Title\nbody *italic*"))))
84(test-group "markdown->irc edge cases"
85 (test "empty string"
86 (assert-equal "" (markdown->irc "")))
88 (test "non-string returns input"
89 (assert-false (markdown->irc #f)))
91 (test "single character"
92 (assert-equal "x" (markdown->irc "x")))
94 (test "code is literal — markers inside aren't parsed"
95 (assert-equal (string-append MONO "*not italic*" MONO)
96 (markdown->irc "`*not italic*`"))))
98;; Regression tests for the apply-arity bug fixed in v0.1.3
99;; (markdown-irc.sgl now uses `string-join` instead of `apply
100;; string-append` so multi-sentence prose with em-dashes,
101;; apostrophes, and other non-ASCII chars survives the inline
102;; parser without hitting the Sigil-VM apply-arity ceiling).
103;;
104;; The trigger text below is the exact string from the
105;; apiary-bug-fix-spike brief (Bug C). Each sweep case combines
106;; em-dashes with another non-trivial inline character.
107(test-group "markdown->irc apply-arity regression (multi-sentence prose)"
108 (define brief-trigger
109 "Got it via DM. The fix landed — does Goguma's conversations list now show this thread? That's the actual test — message delivery was always working...")
111 (test "exact trigger text from bug-fix-spike brief"
112 ;; No markdown markers in the prose, so the output is the
113 ;; input verbatim. The assertion here is that the call
114 ;; *returns* — not what it returns.
115 (assert-equal brief-trigger
116 (markdown->irc brief-trigger)))
118 (test "em-dash sweep"
119 (assert-equal "a — b — c — d — e — f"
120 (markdown->irc "a — b — c — d — e — f")))
122 (test "em-dash + ASCII apostrophe"
123 (assert-equal "It's working — that's the test — really."
124 (markdown->irc "It's working — that's the test — really.")))
126 (test "em-dash + curly single quote"
127 (assert-equal "It’s working — that’s the test."
128 (markdown->irc "It’s working — that’s the test.")))
130 (test "em-dash + curly double quote"
131 (assert-equal "She said “go” — and “stop” — repeatedly."
132 (markdown->irc "She said “go” — and “stop” — repeatedly.")))
134 (test "em-dash + ellipsis"
135 (assert-equal "Sometimes — when waiting — the loop hangs…"
136 (markdown->irc "Sometimes — when waiting — the loop hangs…")))
138 (test "em-dash + backtick (markdown active)"
139 (assert-equal (string-append "Run " MONO "build" MONO " — then " MONO "test" MONO " — then ship.")
140 (markdown->irc "Run `build` — then `test` — then ship.")))
142 (test "em-dash + bold (markdown active)"
143 (assert-equal (string-append "Note " BOLD "carefully" BOLD " — and " BOLD "twice" BOLD " — please.")
144 (markdown->irc "Note **carefully** — and **twice** — please.")))
146 (test "very long multi-sentence prose with non-ASCII"
147 ;; Build a string ~3000 chars long that's many sentences with
148 ;; em-dashes and apostrophes — the case that originally
149 ;; tripped the apply ceiling.
150 (let* ((sentence "It's a long sentence — with an em-dash — and apostrophes that test the inline parser's accumulator. ")
151 (long-text
152 (let loop ((acc "") (n 0))
153 (if (= n 30) acc
154 (loop (string-append acc sentence) (+ n 1))))))
155 (assert-equal long-text (markdown->irc long-text)))))