44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package views_test
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"task/internal/ui/views"
|
|
)
|
|
|
|
func TestRenderMarkdownFastWithoutAutoStyle(t *testing.T) {
|
|
src := "## Hello\n\nSome **bold** text\n\n- a\n- b\n"
|
|
start := time.Now()
|
|
out := views.RenderMarkdown(src, 80)
|
|
elapsed := time.Since(start)
|
|
if elapsed > 2*time.Second {
|
|
t.Fatalf("RenderMarkdown took %v — WithAutoStyle/OSC hang likely still present", elapsed)
|
|
}
|
|
if out == "" || out == src {
|
|
// glamour should style bold; at least produce non-empty output
|
|
if strings.TrimSpace(out) == "" {
|
|
t.Fatal("empty output")
|
|
}
|
|
}
|
|
// cached path should be near-instant
|
|
start = time.Now()
|
|
_ = views.RenderMarkdown(src, 80)
|
|
if time.Since(start) > 500*time.Millisecond {
|
|
t.Fatalf("cached render too slow: %v", time.Since(start))
|
|
}
|
|
t.Logf("first=%v cached=%v", elapsed, time.Since(start))
|
|
}
|
|
|
|
func TestRenderDescriptionHighlightsCheckbox(t *testing.T) {
|
|
src := "Intro\n\n- [ ] one\n- [x] two\n"
|
|
out := views.RenderDescription(src, 40, 0)
|
|
if !strings.Contains(out, "one") || !strings.Contains(out, "[ ]") {
|
|
t.Fatalf("expected unchecked item in output: %q", out)
|
|
}
|
|
if !strings.Contains(out, "two") || !strings.Contains(out, "[x]") {
|
|
t.Fatalf("expected checked item in output: %q", out)
|
|
}
|
|
}
|