package option
import (
"bytes"
"testing"
"github.com/yuin/goldmark"
)
func TestOptionExtension(t *testing.T) {
markdown := goldmark.New(
goldmark.WithExtensions(
New(),
),
)
tests := []struct {
name string
input string
expected string
}{
{
name: "basic option reference",
input: "{option}`initialHashedPassword`",
expected: "
" +
"initialHashedPassword
\n",
},
{
name: "option reference in sentence",
input: "You can set {option}`initialHashedPassword` to configure the initial password.",
expected: "You can set " +
"initialHashedPassword
to configure the initial password.
\n",
},
{
name: "multiple option references",
input: "Both {option}`initialHashedPassword` and {option}`passwordFile` can be used.",
expected: "Both " +
"initialHashedPassword
and " +
"passwordFile
can be used.
\n",
},
{
name: "incomplete option reference - no closing backtick",
input: "{option}`missingBacktick",
expected: "{option}`missingBacktick
\n",
},
{
name: "incomplete option reference - empty option name",
input: "{option}``",
expected: "{option}``
\n",
},
{
name: "option reference with code block",
input: "{option}`config` is set in `config.nix`",
expected: "config
" +
"is set in config.nix
\n",
},
{
name: "option reference with HTML-like content",
input: "{option}`users.users..hashedPassword`",
expected: "" +
"users.users.<name>.hashedPassword
\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 TestOptionNodeKind(t *testing.T) {
n := &Node{}
if kind := n.Kind(); kind != KindOption {
t.Errorf("Expected node kind %v, got %v", KindOption, kind)
}
if !n.Inline() {
t.Error("Expected node to be inline")
}
}