Issues #11-13: WithAppName for variant binaries, NewPassthrough builder for flag.FlagSet commands, RegisterCommands test coverage with resetGlobals helper. Fix pre-existing daemon_test.go break. Issue #14: Rich Table with box-drawing borders (Normal, Rounded, Heavy, Double), per-column CellStyleFn, WithMaxWidth responsive truncation. Tree renderer with box-drawing connectors and styled nodes. Parallel TaskTracker with braille spinners, thread-safe concurrent updates, and non-TTY fallback. Streaming text renderer with word-wrap and channel pattern support. Issue #15: Frame live compositional AppShell using HLCRF regions with Model interface, Navigate/Back content swapping, alt-screen live mode, graceful non-TTY fallback. Built-in region components: StatusLine, KeyHints, Breadcrumb. Zero new dependencies — pure ANSI + x/term. 68 tests, all passing with -race. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
113 lines
2.4 KiB
Go
113 lines
2.4 KiB
Go
package cli
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTree_Good(t *testing.T) {
|
|
t.Run("single root", func(t *testing.T) {
|
|
tree := NewTree("root")
|
|
assert.Equal(t, "root\n", tree.String())
|
|
})
|
|
|
|
t.Run("flat children", func(t *testing.T) {
|
|
tree := NewTree("root")
|
|
tree.Add("alpha")
|
|
tree.Add("beta")
|
|
tree.Add("gamma")
|
|
|
|
expected := "root\n" +
|
|
"├── alpha\n" +
|
|
"├── beta\n" +
|
|
"└── gamma\n"
|
|
assert.Equal(t, expected, tree.String())
|
|
})
|
|
|
|
t.Run("nested children", func(t *testing.T) {
|
|
tree := NewTree("core-php")
|
|
tree.Add("core-tenant").Add("core-bio")
|
|
tree.Add("core-admin")
|
|
tree.Add("core-api")
|
|
|
|
expected := "core-php\n" +
|
|
"├── core-tenant\n" +
|
|
"│ └── core-bio\n" +
|
|
"├── core-admin\n" +
|
|
"└── core-api\n"
|
|
assert.Equal(t, expected, tree.String())
|
|
})
|
|
|
|
t.Run("deep nesting", func(t *testing.T) {
|
|
tree := NewTree("a")
|
|
tree.Add("b").Add("c").Add("d")
|
|
|
|
expected := "a\n" +
|
|
"└── b\n" +
|
|
" └── c\n" +
|
|
" └── d\n"
|
|
assert.Equal(t, expected, tree.String())
|
|
})
|
|
|
|
t.Run("mixed depth", func(t *testing.T) {
|
|
tree := NewTree("root")
|
|
a := tree.Add("a")
|
|
a.Add("a1")
|
|
a.Add("a2")
|
|
tree.Add("b")
|
|
|
|
expected := "root\n" +
|
|
"├── a\n" +
|
|
"│ ├── a1\n" +
|
|
"│ └── a2\n" +
|
|
"└── b\n"
|
|
assert.Equal(t, expected, tree.String())
|
|
})
|
|
|
|
t.Run("AddTree composes subtrees", func(t *testing.T) {
|
|
sub := NewTree("sub-root")
|
|
sub.Add("child")
|
|
|
|
tree := NewTree("main")
|
|
tree.AddTree(sub)
|
|
|
|
expected := "main\n" +
|
|
"└── sub-root\n" +
|
|
" └── child\n"
|
|
assert.Equal(t, expected, tree.String())
|
|
})
|
|
|
|
t.Run("styled nodes", func(t *testing.T) {
|
|
SetColorEnabled(false)
|
|
defer SetColorEnabled(true)
|
|
|
|
tree := NewTree("root")
|
|
tree.AddStyled("green", SuccessStyle)
|
|
tree.Add("plain")
|
|
|
|
expected := "root\n" +
|
|
"├── green\n" +
|
|
"└── plain\n"
|
|
assert.Equal(t, expected, tree.String())
|
|
})
|
|
|
|
t.Run("WithStyle on root", func(t *testing.T) {
|
|
SetColorEnabled(false)
|
|
defer SetColorEnabled(true)
|
|
|
|
tree := NewTree("root").WithStyle(ErrorStyle)
|
|
tree.Add("child")
|
|
|
|
expected := "root\n" +
|
|
"└── child\n"
|
|
assert.Equal(t, expected, tree.String())
|
|
})
|
|
}
|
|
|
|
func TestTree_Bad(t *testing.T) {
|
|
t.Run("empty label", func(t *testing.T) {
|
|
tree := NewTree("")
|
|
assert.Equal(t, "\n", tree.String())
|
|
})
|
|
}
|