package optlink import ( "bytes" "testing" "github.com/yuin/goldmark" ) func TestOptLinkExtension(t *testing.T) { markdown := goldmark.New( goldmark.WithExtensions( New(), ), ) tests := []struct { name string input string expected string }{ { name: "basic option link", input: "[](#opt-systemd.sysusers.enable)", expected: "

" + "systemd.sysusers.enable

\n", }, { name: "option link in sentence", input: "You can enable this with [](#opt-systemd.sysusers.enable) in your configuration.", expected: "

You can enable this with " + "systemd.sysusers.enable in your configuration.

\n", }, { name: "multiple option links", input: "Both [](#opt-systemd.sysusers.enable) and [](#opt-networking.firewall.enable) can be used.", expected: "

Both " + "systemd.sysusers.enable and " + "networking.firewall.enable can be used.

\n", }, { name: "not an option link - normal link", input: "[regular link](https://example.com)", expected: "

regular link

\n", }, { name: "not an option link - empty link with different format", input: "[](#other-prefix)", expected: "

\n", }, { name: "option link with special characters", input: "[](#opt-users.users..hashedPassword)", expected: "

" + "users.users.<n>.hashedPassword

\n", }, { name: "option link with normal link in sentence", input: "Use [](#opt-networking.firewall.enable) and see [the docs](https://nixos.org) for more information.", expected: "

Use " + "networking.firewall.enable and see the docs for more information.

\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 TestOptLinkNodeKind(t *testing.T) { n := &Node{} if kind := n.Kind(); kind != KindOptLink { t.Errorf("Expected node kind %v, got %v", KindOptLink, kind) } if !n.Inline() { t.Error("Expected node to be inline") } }