// SPDX-FileCopyrightText: 2024 Nicolas Peugnet // SPDX-License-Identifier: GPL-2.0-or-later package goldmark_ext_test import ( "fmt" "testing" "github.com/yuin/goldmark" "github.com/yuin/goldmark/parser" "github.com/yuin/goldmark/renderer/html" "github.com/yuin/goldmark/testutil" "github.com/yuin/goldmark/util" "salsa.debian.org/lintian/lintian-ssg/markdown/goldmark_ext" ) func TestManpageLink(t *testing.T) { markdown := goldmark.New( goldmark.WithRendererOptions( html.WithUnsafe(), ), goldmark.WithParserOptions(parser.WithInlineParsers( util.Prioritized(goldmark_ext.NewManpageLinkParser(), 500), )), ) cases := []struct { src string expected string }{ { // basic case `see lintian(1).`, `

see lintian(1).

`, }, { // with special chars `update-rc.d(8)`, `

update-rc.d(8)

`, }, { // inside `see lintian(1).`, `

see lintian(1).

`, }, { // In link label `[lintian(1)](http://another.url)`, `

lintian(1)

`, }, { // In link label with leading space `[manual page lintian(1)](http://another.url)`, `

manual page lintian(1)

`, }, { // very long page name `see very-looooooooooooong-page-name(1).`, `

see very-looooooooooooong-page-name(1).

`, }, { // link to perl section `deb-systemd-invoke(1p)`, `

deb-systemd-invoke(1p)

`, }, { // link to freebsd section `intro(9freebsd)`, `

intro(9freebsd)

`, }, { // no number in section `intro(freebsd)`, `

intro(freebsd)

`, }, { // number to big to be a section `intro(42)`, `

intro(42)

`, }, } for i, c := range cases { t.Run(fmt.Sprintf("%d %s", i, c.src), func(t *testing.T) { testutil.DoTestCase( markdown, testutil.MarkdownTestCase{ No: i, Markdown: c.src, Expected: c.expected, }, t, ) }) } }