* test: Add test coverage for 16 files (40.3% -> 45.5%) Add comprehensive tests for previously untested packages: - internal/agent/state_test.go - internal/cmd/errors_test.go - internal/crew/types_test.go - internal/doctor/errors_test.go - internal/dog/types_test.go - internal/mail/bd_test.go - internal/opencode/plugin_test.go - internal/rig/overlay_test.go - internal/runtime/runtime_test.go - internal/session/town_test.go - internal/style/style_test.go - internal/ui/markdown_test.go - internal/ui/terminal_test.go - internal/wisp/io_test.go - internal/wisp/types_test.go - internal/witness/types_test.go style_test.go uses func(...string) to match lipgloss variadic Render signature. * fix(lint): remove unused error return from buildCVSummary buildCVSummary always returned nil for its error value, causing golangci-lint to fail with "result 1 (error) is always nil". The function handles errors internally by returning partial data, so the error return was misleading. Removed it and updated caller.
170 lines
3.5 KiB
Go
170 lines
3.5 KiB
Go
package style
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestStyleVariables(t *testing.T) {
|
|
// Test that all style variables render non-empty output
|
|
tests := []struct {
|
|
name string
|
|
render func(...string) string
|
|
}{
|
|
{"Success", Success.Render},
|
|
{"Warning", Warning.Render},
|
|
{"Error", Error.Render},
|
|
{"Info", Info.Render},
|
|
{"Dim", Dim.Render},
|
|
{"Bold", Bold.Render},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if tt.render == nil {
|
|
t.Errorf("Style variable %s should not be nil", tt.name)
|
|
}
|
|
// Test that Render works
|
|
result := tt.render("test")
|
|
if result == "" {
|
|
t.Errorf("Style %s.Render() should not return empty string", tt.name)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPrefixVariables(t *testing.T) {
|
|
// Test that all prefix variables are non-empty
|
|
tests := []struct {
|
|
name string
|
|
prefix string
|
|
}{
|
|
{"SuccessPrefix", SuccessPrefix},
|
|
{"WarningPrefix", WarningPrefix},
|
|
{"ErrorPrefix", ErrorPrefix},
|
|
{"ArrowPrefix", ArrowPrefix},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if tt.prefix == "" {
|
|
t.Errorf("Prefix variable %s should not be empty", tt.name)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPrintWarning(t *testing.T) {
|
|
// Capture stdout
|
|
oldStdout := os.Stdout
|
|
r, w, _ := os.Pipe()
|
|
os.Stdout = w
|
|
|
|
PrintWarning("test warning: %s", "value")
|
|
|
|
w.Close()
|
|
os.Stdout = oldStdout
|
|
|
|
// Read captured output
|
|
var buf bytes.Buffer
|
|
io.Copy(&buf, r)
|
|
output := buf.String()
|
|
|
|
if output == "" {
|
|
t.Error("PrintWarning() should produce output")
|
|
}
|
|
|
|
// Check that warning message is present
|
|
if !bytes.Contains(buf.Bytes(), []byte("test warning: value")) {
|
|
t.Error("PrintWarning() output should contain the warning message")
|
|
}
|
|
}
|
|
|
|
func TestPrintWarning_NoFormatArgs(t *testing.T) {
|
|
oldStdout := os.Stdout
|
|
r, w, _ := os.Pipe()
|
|
os.Stdout = w
|
|
|
|
PrintWarning("simple warning")
|
|
|
|
w.Close()
|
|
os.Stdout = oldStdout
|
|
|
|
var buf bytes.Buffer
|
|
io.Copy(&buf, r)
|
|
output := buf.String()
|
|
|
|
if output == "" {
|
|
t.Error("PrintWarning() should produce output")
|
|
}
|
|
|
|
if !bytes.Contains(buf.Bytes(), []byte("simple warning")) {
|
|
t.Error("PrintWarning() output should contain the message")
|
|
}
|
|
}
|
|
|
|
func TestStyles_RenderConsistently(t *testing.T) {
|
|
// Test that styles consistently render non-empty output
|
|
testText := "test message"
|
|
|
|
styles := map[string]func(...string) string{
|
|
"Success": Success.Render,
|
|
"Warning": Warning.Render,
|
|
"Error": Error.Render,
|
|
"Info": Info.Render,
|
|
"Dim": Dim.Render,
|
|
"Bold": Bold.Render,
|
|
}
|
|
|
|
for name, renderFunc := range styles {
|
|
t.Run(name, func(t *testing.T) {
|
|
result := renderFunc(testText)
|
|
if result == "" {
|
|
t.Errorf("Style %s.Render() should not return empty string", name)
|
|
}
|
|
// Result should be different from input (has styling codes)
|
|
// except possibly for some edge cases
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMultiplePrintWarning(t *testing.T) {
|
|
// Test that multiple warnings can be printed
|
|
oldStdout := os.Stdout
|
|
r, w, _ := os.Pipe()
|
|
os.Stdout = w
|
|
|
|
for i := 0; i < 3; i++ {
|
|
PrintWarning("warning %d", i)
|
|
}
|
|
|
|
w.Close()
|
|
os.Stdout = oldStdout
|
|
|
|
var buf bytes.Buffer
|
|
io.Copy(&buf, r)
|
|
_ = buf.String() // ensure buffer is read
|
|
|
|
// Should have 3 lines
|
|
lineCount := 0
|
|
for _, b := range buf.Bytes() {
|
|
if b == '\n' {
|
|
lineCount++
|
|
}
|
|
}
|
|
|
|
if lineCount != 3 {
|
|
t.Errorf("Expected 3 lines of output, got %d", lineCount)
|
|
}
|
|
}
|
|
|
|
func ExamplePrintWarning() {
|
|
// This example demonstrates PrintWarning usage
|
|
fmt.Print("Example output:\n")
|
|
PrintWarning("This is a warning message")
|
|
PrintWarning("Warning with value: %d", 42)
|
|
}
|