added markdown support for go port

This commit is contained in:
Luxferre
2026-08-15 08:50:39 +03:00
parent c8d1836614
commit 99aa96ce0e
2 changed files with 254 additions and 4 deletions
+119
View File
@@ -1373,3 +1373,122 @@ func TestLLMForwardsRelevantParameters(t *testing.T) {
}
}
// ---------- Markdown rendering tests ----------
func TestRenderInline(t *testing.T) {
COL = true
defer func() { COL = false }()
// Code
out := renderInline("Use `go test -v` command")
if !strings.Contains(out, "\033[33mgo test -v\033[0m") {
t.Errorf("renderInline code = %q", out)
}
// Bold
out = renderInline("This is **bold** text")
if !strings.Contains(out, "\033[1mbold\033[0m") {
t.Errorf("renderInline bold = %q", out)
}
// Italic
out = renderInline("This is *italic* text")
if !strings.Contains(out, "\033[3mitalic\033[0m") {
t.Errorf("renderInline italic = %q", out)
}
// Bold + Italic
out = renderInline("This is ***important*** text")
if !strings.Contains(out, "\033[1;3mimportant\033[0m") {
t.Errorf("renderInline bold+italic = %q", out)
}
// Strikethrough
out = renderInline("This is ~~deleted~~ text")
if !strings.Contains(out, "\033[9mdeleted\033[0m") {
t.Errorf("renderInline strikethrough = %q", out)
}
// Link
out = renderInline("Visit [Go](https://go.dev) site")
if !strings.Contains(out, "\033[4;36mGo\033[0m") || !strings.Contains(out, "https://go.dev") {
t.Errorf("renderInline link = %q", out)
}
// Code shielding (asterisks inside code should not become italic)
out = renderInline("Run `foo * bar` now")
if !strings.Contains(out, "\033[33mfoo * bar\033[0m") {
t.Errorf("renderInline code shield = %q", out)
}
}
func TestRenderMDBlocks(t *testing.T) {
COL = true
defer func() { COL = false }()
// Headings
h1 := renderMD("# Title One")
if !strings.Contains(h1, "Title One") || !strings.Contains(h1, "\033[35m■ \033[0m") {
t.Errorf("renderMD H1 = %q", h1)
}
h2 := renderMD("## Subtitle")
if !strings.Contains(h2, "Subtitle") || !strings.Contains(h2, "\033[34m▲ \033[0m") {
t.Errorf("renderMD H2 = %q", h2)
}
h3 := renderMD("### Section")
if !strings.Contains(h3, "Section") || !strings.Contains(h3, "\033[32m● \033[0m") {
t.Errorf("renderMD H3 = %q", h3)
}
// Code block
codeMD := "```go\nfunc main() {\n println(1)\n}\n```"
renderedCode := renderMD(codeMD)
if !strings.Contains(renderedCode, "[ go ]") || !strings.Contains(renderedCode, "println(1)") {
t.Errorf("renderMD code block = %q", renderedCode)
}
// Lists
ul := renderMD("- Item A\n- Item B")
if !strings.Contains(ul, "• ") || !strings.Contains(ul, "Item A") {
t.Errorf("renderMD unordered list = %q", ul)
}
ol := renderMD("1. Step 1\n2. Step 2")
if !strings.Contains(ol, "1. ") || !strings.Contains(ol, "Step 1") {
t.Errorf("renderMD ordered list = %q", ol)
}
tasks := renderMD("- [ ] Pending\n- [x] Finished")
if !strings.Contains(tasks, "☐ ") || !strings.Contains(tasks, "☑ ") {
t.Errorf("renderMD task list = %q", tasks)
}
// Blockquote
bq := renderMD("> Important quote")
if !strings.Contains(bq, "▎ ") || !strings.Contains(bq, "Important quote") {
t.Errorf("renderMD blockquote = %q", bq)
}
// Horizontal rule
hr := renderMD("---")
if !strings.Contains(hr, "────") {
t.Errorf("renderMD hr = %q", hr)
}
// Table
tbl := renderMD("| Col A | Col B |\n|---|---|\n| Val 1 | Val 2 |")
if !strings.Contains(tbl, "Col A") || !strings.Contains(tbl, "Val 1") {
t.Errorf("renderMD table = %q", tbl)
}
}
func TestRenderMDNoColorFallback(t *testing.T) {
COL = false
raw := "# Heading\n**bold** and `code`\n- list item"
out := renderMD(raw)
if out != raw {
t.Errorf("renderMD with COL=false should return raw text, got %q", out)
}
}