diff --git a/cmd/bd/dep_test.go b/cmd/bd/dep_test.go index 312e692c1..188e1309e 100644 --- a/cmd/bd/dep_test.go +++ b/cmd/bd/dep_test.go @@ -517,6 +517,29 @@ func TestDepTreeFormatFlag(t *testing.T) { } } +// TestDepTreeFormatMermaidCaseInsensitive pins that --format mermaid folds case +// the same way the json format check does. +func TestDepTreeFormatMermaidCaseInsensitive(t *testing.T) { + tests := []struct { + format string + want bool + }{ + {"mermaid", true}, + {"Mermaid", true}, + {"MERMAID", true}, + {"", false}, + {"json", false}, + {"dot", false}, + } + for _, tt := range tests { + t.Run(tt.format, func(t *testing.T) { + if got := isMermaidTreeFormat(tt.format); got != tt.want { + t.Errorf("isMermaidTreeFormat(%q) = %v, want %v", tt.format, got, tt.want) + } + }) + } +} + func TestGetStatusEmoji(t *testing.T) { tests := []struct { status types.Status diff --git a/cmd/bd/dep_tree.go b/cmd/bd/dep_tree.go index ffce21492..a8a4393ad 100644 --- a/cmd/bd/dep_tree.go +++ b/cmd/bd/dep_tree.go @@ -80,6 +80,11 @@ func proxiedTreeTarget(ctx context.Context, arg string) (treeTarget, error) { return treeTarget{rootID: rootID, walker: walker, cleanup: func() {}}, nil } +// isMermaidTreeFormat reports whether --format selects the mermaid renderer. +func isMermaidTreeFormat(formatStr string) bool { + return strings.EqualFold(formatStr, "mermaid") +} + // runDepTree is the whole of `bd dep tree` on both routes. func runDepTree(cmd *cobra.Command, ctx context.Context, args []string) error { maxDepth, _ := cmd.Flags().GetInt("max-depth") @@ -145,7 +150,7 @@ func runDepTree(cmd *cobra.Command, ctx context.Context, args []string) error { tree := result.Nodes // Handle format presets (json handled earlier, near the flag read). - if formatStr == "mermaid" { + if isMermaidTreeFormat(formatStr) { // The raw argument, not the resolved id: this is only read when the tree // is empty. outputMermaidTree(tree, args[0])