diff --git a/cmd/cheatmd/compose.go b/cmd/cheatmd/compose.go index 1a579ae..2a65694 100644 --- a/cmd/cheatmd/compose.go +++ b/cmd/cheatmd/compose.go @@ -118,13 +118,11 @@ func buildComposeMarkdown(name, desc, command string) string { sb.WriteString(command) sb.WriteString("\n```\n") - if len(vars) > 0 { - sb.WriteString("\n") + sb.WriteString("\n") return sb.String() } diff --git a/cmd/cheatmd/compose_marker_test.go b/cmd/cheatmd/compose_marker_test.go new file mode 100644 index 0000000..f14f20a --- /dev/null +++ b/cmd/cheatmd/compose_marker_test.go @@ -0,0 +1,28 @@ +package main + +import ( + "os" + "path/filepath" + "testing" + + "github.com/cheatmd-dev/cheatmd/pkg/parser" +) + +func TestComposedCommandWithoutVariablesIsExecutable(t *testing.T) { + path := filepath.Join(t.TempDir(), "composed.md") + content := buildComposeMarkdown("Greeting", "", "echo hello") + if err := os.WriteFile(path, []byte(content), 0o600); err != nil { + t.Fatal(err) + } + index, err := parser.NewParser().ParseSingleFile(path) + if err != nil { + t.Fatal(err) + } + cheats := index.FilterByConfig(true) + if len(cheats) != 1 { + t.Fatalf("got %d executable cheats, want one", len(cheats)) + } + if cheats[0].Command != "echo hello" { + t.Fatalf("got command %q, want echo hello", cheats[0].Command) + } +}