package variable import ( "bytes" "testing" "github.com/yuin/goldmark" ) func TestVarExtension(t *testing.T) { markdown := goldmark.New( goldmark.WithExtensions( New(), ), ) tests := []struct { name string input string expected string }{ { name: "basic variable reference", input: "{var}`pkgs.virtualbox`", expected: "

pkgs.virtualbox

\n", }, { name: "variable reference in sentence", input: "Use {var}`nixpkgs.lib.attrsets` to manipulate attribute sets.", expected: "

Use nixpkgs.lib.attrsets to manipulate attribute sets.

\n", }, { name: "multiple variable references", input: "Both {var}`config.services.nginx` and {var}`config.services.postgresql` define service configurations.", expected: "

Both config.services.nginx and " + "config.services.postgresql define service configurations.

\n", }, { name: "incomplete variable reference - no closing backtick", input: "{var}`MISSING_BACKTICK", expected: "

{var}`MISSING_BACKTICK

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

{var}``

\n", }, { name: "variable reference with code block", input: "Set {var}`pkgs.hello` in your `configuration.nix` file.", expected: "

Set pkgs.hello " + "in your configuration.nix file.

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