improved markdown table support for go port
This commit is contained in:
@@ -1519,6 +1519,67 @@ func TestRenderTableFormatting(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWrapCell(t *testing.T) {
|
||||
COL = true
|
||||
defer func() { COL = false }()
|
||||
|
||||
lines := wrapCell("Short text", 20)
|
||||
if len(lines) != 1 || lines[0] != "Short text" {
|
||||
t.Errorf("wrapCell short = %v", lines)
|
||||
}
|
||||
|
||||
lines = wrapCell("The quick brown fox jumps over the lazy dog", 15)
|
||||
if len(lines) < 3 {
|
||||
t.Errorf("wrapCell long = %v", lines)
|
||||
}
|
||||
for _, l := range lines {
|
||||
if visibleLen(l) > 15 {
|
||||
t.Errorf("line %q visible length = %d > 15", l, visibleLen(l))
|
||||
}
|
||||
}
|
||||
|
||||
// With ANSI escape codes
|
||||
styled := "\033[1;36mAlice In Wonderland\033[0m"
|
||||
lines = wrapCell(styled, 10)
|
||||
if len(lines) != 2 {
|
||||
t.Errorf("wrapCell styled count = %d, lines = %v", len(lines), lines)
|
||||
}
|
||||
for _, l := range lines {
|
||||
if visibleLen(l) > 10 {
|
||||
t.Errorf("styled line %q length = %d > 10", l, visibleLen(l))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderTableWidthConstraint(t *testing.T) {
|
||||
COL = true
|
||||
defer func() { COL = false }()
|
||||
|
||||
// Create an extra-wide table with long text
|
||||
raw := strings.Join([]string{
|
||||
"| Long Column Header One | Extremely Long Column Header Two That Would Definitely Overflow | Another Very Wide Column Header Three |",
|
||||
"|---|---|---|",
|
||||
"| Some detailed explanation that is very long and has lots of words in it | Another paragraph of text that continues on and on without stopping | Final column with even more long descriptions |",
|
||||
}, "\n")
|
||||
|
||||
rendered := renderMD(raw)
|
||||
lines := strings.Split(rendered, "\n")
|
||||
maxW := termWidth()
|
||||
if maxW < 20 { maxW = 80 }
|
||||
|
||||
for i, ln := range lines {
|
||||
vl := visibleLen(ln)
|
||||
if vl > maxW {
|
||||
t.Errorf("table line %d visible length = %d, exceeds max width %d:\n%s", i, vl, maxW, ln)
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure content was wrapped rather than dropped
|
||||
if !strings.Contains(rendered, "detailed") || !strings.Contains(rendered, "explanation") || !strings.Contains(rendered, "paragraph") {
|
||||
t.Errorf("rendered table should contain all words wrapped across lines:\n%s", rendered)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderMDNoColorFallback(t *testing.T) {
|
||||
COL = false
|
||||
raw := "# Heading\n**bold** and `code`\n- list item"
|
||||
|
||||
Reference in New Issue
Block a user