package main import ( "strings" "testing" "github.com/charmbracelet/x/ansi" ) func TestCommentMarkdownDistinguishesQuoteAndReply(t *testing.T) { lines := renderCommentMarkdown("> This is the quoted review.\n\nThis is my reply.", 60) rendered := strings.Join(lines, "\n") plain := ansi.Strip(rendered) if !strings.Contains(plain, "This is the quoted review.") || !strings.Contains(plain, "This is my reply.") { t.Fatalf("comment content was lost:\n%q", rendered) } if !strings.Contains(plain, "│") && !strings.Contains(plain, "┃") && !strings.Contains(plain, ">") { t.Fatalf("quote has no visible marker:\n%q", rendered) } } func TestCommentMarkdownStylesInlineCode(t *testing.T) { rendered := strings.Join(renderCommentMarkdown( "Use `list_comparison` for this value.", 60, ), "\n") plain := ansi.Strip(rendered) if !strings.Contains(plain, "Use list_comparison for this value.") { t.Fatalf("inline code was lost: %q", rendered) } if strings.Contains(plain, "Use list_comparison for") { t.Fatalf("inline code added surrounding spaces: %q", plain) } if !strings.Contains(rendered, "48;5;236m") { t.Fatalf("inline code has no distinct background: %q", rendered) } } func TestWrappedQuoteKeepsRailOnEveryLine(t *testing.T) { const width = 28 lines := renderCommentMarkdown( "> This quoted reply is deliberately long enough to wrap across several terminal lines.", width, ) if len(lines) < 2 { t.Fatalf("quote did not wrap: %#v", lines) } for i, line := range lines { plain := ansi.Strip(line) if strings.TrimSpace(plain) != "" && !strings.HasPrefix(plain, "│ ") { t.Fatalf("wrapped quote line %d lost its rail: %q", i, plain) } if ansi.StringWidth(line) > width { t.Fatalf("wrapped quote line %d is too wide: %q", i, plain) } } } func TestCommentMarkdownRendersGFMStructures(t *testing.T) { body := "## Result\n\n- [x] done\n- [ ] pending\n\n~~old~~ **new** :+1:\n\n| Name | State |\n| --- | --- |\n| check | good |" plain := ansi.Strip(strings.Join(renderCommentMarkdown(body, 70), "\n")) for _, wanted := range []string{"Result", "done", "pending", "old", "new", "👍", "Name", "State", "check", "good"} { if !strings.Contains(plain, wanted) { t.Fatalf("rendered Markdown lost %q:\n%s", wanted, plain) } } } func TestCommentMarkdownRendersGitHubAlert(t *testing.T) { plain := ansi.Strip(strings.Join(renderCommentMarkdown( "> [!WARNING]\n> This can delete data.", 60, ), "\n")) if !strings.Contains(plain, "Warning") || !strings.Contains(plain, "This can delete data.") { t.Fatalf("GitHub alert was not rendered structurally:\n%s", plain) } } func TestCommentMarkdownStaysWithinRequestedWidth(t *testing.T) { const width = 34 body := "> A long quoted reply containing `inline_code` that needs wrapping.\n\n" + "- A similarly long list item that also needs wrapping." for i, line := range renderCommentMarkdown(body, width) { if got := ansi.StringWidth(line); got > width { t.Fatalf("line %d width = %d, want at most %d: %q", i, got, width, line) } } }