-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation_test.go
More file actions
102 lines (77 loc) · 2.23 KB
/
validation_test.go
File metadata and controls
102 lines (77 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package devtui
import (
"testing"
)
func TestValidateTabSection_Nil(t *testing.T) {
tui := NewTUI(&TuiConfig{})
defer func() {
if r := recover(); r == nil {
t.Error("Expected panic for nil tabSection")
}
}()
tui.AddHandler(&validationTestHandler{}, "", nil)
}
func TestValidateTabSection_WrongType(t *testing.T) {
tui := NewTUI(&TuiConfig{})
defer func() {
if r := recover(); r == nil {
t.Error("Expected panic for wrong type")
}
}()
tui.AddHandler(&validationTestHandler{}, "", "not a tabSection")
}
func TestValidateTabSection_WrongDevTUI(t *testing.T) {
tui1 := NewTUI(&TuiConfig{})
tui2 := NewTUI(&TuiConfig{})
tab := tui1.NewTabSection("TEST", "test")
defer func() {
if r := recover(); r == nil {
t.Error("Expected panic for tabSection from different DevTUI")
}
}()
tui2.AddHandler(&validationTestHandler{}, "", tab)
}
func (h *validationTestDisplayHandler) Content() string {
return "display value"
}
func TestValidateTabSection_Success(t *testing.T) {
tui := NewTUI(&TuiConfig{})
tab := tui.NewTabSection("TEST", "test")
// Should not panic
tui.AddHandler(&validationTestDisplayHandler{name: "test"}, "", tab)
// Loggable handlers are registered via AddHandler
h := &validationTestLoggableHandler{name: "logger"}
tui.AddHandler(h, "", tab)
if h.logFunc == nil {
t.Error("Expected logger function to be injected, got nil")
}
}
// validationTestLoggableHandler is a minimal loggable handler for testing purposes
type validationTestLoggableHandler struct {
name string
logFunc func(message ...any)
}
func (h *validationTestLoggableHandler) Name() string {
return h.name
}
func (h *validationTestLoggableHandler) SetLog(f func(message ...any)) {
h.logFunc = f
}
// validationTestHandler is a minimal handler for testing purposes
type validationTestHandler struct{}
func (h *validationTestHandler) Name() string {
return "test"
}
func (h *validationTestHandler) Value() string {
return "test value"
}
// validationTestDisplayHandler is a minimal display handler for testing purposes
type validationTestDisplayHandler struct {
name string
}
func (h *validationTestDisplayHandler) Name() string {
return h.name
}
func (h *validationTestDisplayHandler) Value() string {
return "display value"
}