package manpage import ( "bytes" "testing" "github.com/yuin/goldmark" ) func TestManPageExtension(t *testing.T) { markdown := goldmark.New( goldmark.WithExtensions( New(), ), ) tests := []struct { name string input string expected string }{ { name: "basic manpage reference", input: "{manpage}`nix.conf(5)`", expected: "

nix.conf(5)

\n", }, { name: "manpage reference in sentence", input: "See {manpage}`git(1)` for more information.", expected: "

See git(1) for more information.

\n", }, { name: "multiple manpage references", input: "Both {manpage}`ssh(1)` and {manpage}`sshd(8)` have configuration options.", expected: "

Both ssh(1) and " + "sshd(8) have configuration options.

\n", }, { name: "incomplete manpage reference - no closing backtick", input: "{manpage}`missing.backtick", expected: "

{manpage}`missing.backtick

\n", }, { name: "incomplete manpage reference - empty reference", input: "{manpage}``", expected: "

{manpage}``

\n", }, { name: "invalid manpage reference - no section", input: "{manpage}`nixos`", expected: "

nixos

\n", }, { name: "invalid manpage reference - invalid section format", input: "{manpage}`bash(x)`", expected: "

bash(x)

\n", }, { name: "manpage reference with code block", input: "Configure {manpage}`httpd.conf(5)` in your `apache` directory.", expected: "

Configure httpd.conf(5) " + "in your apache directory.

\n", }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { var buf bytes.Buffer if err := markdown.Convert([]byte(test.input), &buf); err != nil { t.Fatalf("Failed to convert markdown: %v", err) } if got := buf.String(); got != test.expected { t.Errorf("Expected:\n%q\nGot:\n%q", test.expected, got) } }) } } func TestManPageNodeKind(t *testing.T) { n := &Node{} if kind := n.Kind(); kind != KindManPage { t.Errorf("Expected node kind %v, got %v", KindManPage, kind) } if !n.Inline() { t.Error("Expected node to be inline") } }