// SPDX-FileCopyrightText: (C) Copyright 2026 Pim van Pelt // SPDX-License-Identifier: Apache-2.0 package cli import ( "context" "strings" "testing" ) // TestValidateClean checks that a well-formed tree (the builder fixture, which // includes a circular slot) validates without error. func TestValidateClean(t *testing.T) { if err := Validate(buildFixtureB()); err != nil { t.Errorf("Validate(clean tree) = %v, want nil", err) } } // TestValidateFaults checks each fault class is reported. func TestValidateFaults(t *testing.T) { dyn := func(context.Context, fakeClient, []string) []string { return nil } root := &Node[fakeClient]{Children: []*Node[fakeClient]{ // two slot children under one node {Word: "twoslots", Help: "", Children: []*Node[fakeClient]{ {Word: "", Dynamic: dyn, Run: runNoop}, {Word: "", Dynamic: dyn, Run: runNoop}, }}, // duplicate fixed words {Word: "dup", Children: []*Node[fakeClient]{ {Word: "x", Run: runNoop}, {Word: "x", Run: runNoop}, }}, // dead end: neither runs nor has children {Word: "deadend"}, // empty word {Word: "", Run: runNoop}, }} err := Validate(root) if err == nil { t.Fatal("Validate(broken tree) = nil, want errors") } msg := err.Error() for _, want := range []string{ "only the first is reachable", `duplicate child word "x"`, "dead end", "empty Word", } { if !strings.Contains(msg, want) { t.Errorf("Validate missing %q in:\n%s", want, msg) } } }