package filepath import ( "bytes" "testing" "github.com/yuin/goldmark" ) func TestFilePathExtension(t *testing.T) { markdown := goldmark.New( goldmark.WithExtensions( New(), ), ) tests := []struct { name string input string expected string }{ { name: "basic file path reference", input: "{file}`/etc/passwd`", expected: "

/etc/passwd

\n", }, { name: "file path reference in sentence", input: "The configuration file {file}`/etc/fstab` contains file system information.", expected: "

The configuration file /etc/fstab" + " contains file system information.

\n", }, { name: "multiple file path references", input: "Both {file}`/etc/hosts` and {file}`/etc/resolv.conf` define DNS settings.", expected: "

Both /etc/hosts and " + "/etc/resolv.conf define DNS settings.

\n", }, { name: "incomplete file path reference - no closing backtick", input: "{file}`/missing/backtick", expected: "

{file}`/missing/backtick

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

{file}``

\n", }, { name: "file path reference with code block", input: "Edit {file}`~/.bashrc` using your favorite `text editor`.", expected: "

Edit ~/.bashrc " + "using your favorite text editor.

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