Skip to content

Commit c6de6b3

Browse files
committed
Simplify; increase coverage.
1 parent 5fa5021 commit c6de6b3

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

style_test.go

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,40 +90,45 @@ type S = lipgloss.Style
9090

9191
// TestStyle validates most of the Get, Set and Unset methods.
9292
func TestStyle(t *testing.T) {
93+
g := lipgloss.Color("#0f0")
94+
r := lipgloss.Color("#f00")
95+
b := lipgloss.Color("#00f")
96+
w := lipgloss.Color("#fff")
97+
9398
td := []struct {
9499
changeStyle func(S) S
95100
repr string
96101
}{
97102
{func(s S) S { return s.Align(0.5) }, `align: 0.5;`},
98-
{func(s S) S { return s.Background(lipgloss.Color("#0f0")) }, `background: #0f0;`},
103+
{func(s S) S { return s.Background(g) }, `background: #0f0;`},
99104
{func(s S) S { return s.Blink(true) }, `blink: true;`},
100105
{func(s S) S { return s.Bold(true) }, `bold: true;`},
101106
{func(s S) S { return s.BorderBottom(true) }, `border-bottom: true;`},
102-
{func(s S) S { return s.BorderBottomBackground(lipgloss.Color("#0f0")) }, `border-bottom-background: #0f0;`},
103-
{func(s S) S { return s.BorderBottomForeground(lipgloss.Color("#0f0")) }, `border-bottom-foreground: #0f0;`},
107+
{func(s S) S { return s.BorderBottomBackground(g) }, `border-bottom-background: #0f0;`},
108+
{func(s S) S { return s.BorderBottomForeground(g) }, `border-bottom-foreground: #0f0;`},
104109
{func(s S) S { return s.BorderLeft(true) }, `border-left: true;`},
105-
{func(s S) S { return s.BorderLeftBackground(lipgloss.Color("#0f0")) }, `border-left-background: #0f0;`},
106-
{func(s S) S { return s.BorderLeftForeground(lipgloss.Color("#0f0")) }, `border-left-foreground: #0f0;`},
110+
{func(s S) S { return s.BorderLeftBackground(g) }, `border-left-background: #0f0;`},
111+
{func(s S) S { return s.BorderLeftForeground(g) }, `border-left-foreground: #0f0;`},
107112
{func(s S) S { return s.BorderRight(true) }, `border-right: true;`},
108-
{func(s S) S { return s.BorderRightBackground(lipgloss.Color("#0f0")) }, `border-right-background: #0f0;`},
109-
{func(s S) S { return s.BorderRightForeground(lipgloss.Color("#0f0")) }, `border-right-foreground: #0f0;`},
113+
{func(s S) S { return s.BorderRightBackground(g) }, `border-right-background: #0f0;`},
114+
{func(s S) S { return s.BorderRightForeground(g) }, `border-right-foreground: #0f0;`},
110115
{func(s S) S {
111116
return s.BorderStyle(lipgloss.Border{"a", "b", "c", "d", "e", "f", "g", "h"})
112117
}, `border-style: border("a","b","c","d","e","f","g","h");`},
113118
{func(s S) S { return s.BorderTop(true) }, `border-top: true;`},
114-
{func(s S) S { return s.BorderTopBackground(lipgloss.Color("#0f0")) }, `border-top-background: #0f0;`},
115-
{func(s S) S { return s.BorderTopForeground(lipgloss.Color("#0f0")) }, `border-top-foreground: #0f0;`},
119+
{func(s S) S { return s.BorderTopBackground(g) }, `border-top-background: #0f0;`},
120+
{func(s S) S { return s.BorderTopForeground(g) }, `border-top-foreground: #0f0;`},
116121
{func(s S) S {
117122
return s.Border(lipgloss.Border{"a", "b", "c", "d", "e", "f", "g", "h"}, true)
118123
}, `border-bottom: true; border-left: true; border-right: true; ` +
119124
`border-style: border("a","b","c","d","e","f","g","h"); ` +
120125
`border-top: true;`},
121-
{func(s S) S { return s.BorderBackground(lipgloss.Color("#0f0")) }, `border-bottom-background: #0f0; border-left-background: #0f0; border-right-background: #0f0; border-top-background: #0f0;`},
122-
{func(s S) S { return s.BorderForeground(lipgloss.Color("#0f0")) }, `border-bottom-foreground: #0f0; border-left-foreground: #0f0; border-right-foreground: #0f0; border-top-foreground: #0f0;`},
126+
{func(s S) S { return s.BorderBackground(g) }, `border-bottom-background: #0f0; border-left-background: #0f0; border-right-background: #0f0; border-top-background: #0f0;`},
127+
{func(s S) S { return s.BorderForeground(g) }, `border-bottom-foreground: #0f0; border-left-foreground: #0f0; border-right-foreground: #0f0; border-top-foreground: #0f0;`},
123128

124129
{func(s S) S { return s.ColorWhitespace(true) }, `color-whitespace: true;`},
125130
{func(s S) S { return s.Faint(true) }, `faint: true;`},
126-
{func(s S) S { return s.Foreground(lipgloss.Color("#0f0")) }, `foreground: #0f0;`},
131+
{func(s S) S { return s.Foreground(g) }, `foreground: #0f0;`},
127132
{func(s S) S { return s.Height(3) }, `height: 3;`},
128133
{func(s S) S { return s.Inline(true) }, `inline: true;`},
129134
{func(s S) S { return s.Italic(true) }, `italic: true;`},
@@ -132,7 +137,7 @@ func TestStyle(t *testing.T) {
132137
{func(s S) S { return s.MarginLeft(3) }, `margin-left: 3;`},
133138
{func(s S) S { return s.MarginRight(3) }, `margin-right: 3;`},
134139
{func(s S) S { return s.MarginTop(3) }, `margin-top: 3;`},
135-
{func(s S) S { return s.MarginBackground(lipgloss.Color("#0f0")) }, `margin-background: #0f0;`},
140+
{func(s S) S { return s.MarginBackground(g) }, `margin-background: #0f0;`},
136141
{func(s S) S { return s.MaxHeight(3) }, `max-height: 3;`},
137142
{func(s S) S { return s.MaxWidth(3) }, `max-width: 3;`},
138143
{func(s S) S { return s.PaddingBottom(3) }, `padding-bottom: 3;`},
@@ -149,13 +154,40 @@ func TestStyle(t *testing.T) {
149154
{func(s S) S { return s.Padding(1, 2, 3, 4) }, `padding-bottom: 3; padding-left: 4; padding-right: 2; padding-top: 1;`},
150155
{func(s S) S { return s.Padding(1, 2, 3) }, `padding-bottom: 3; padding-left: 2; padding-right: 2; padding-top: 1;`},
151156
{func(s S) S { return s.Padding(1, 2) }, `padding-bottom: 1; padding-left: 2; padding-right: 2; padding-top: 1;`},
157+
{func(s S) S { return s.Padding(1) }, `padding-bottom: 1; padding-left: 1; padding-right: 1; padding-top: 1;`},
152158
{func(s S) S { return s.Padding() }, ``},
153159
{func(s S) S { return s.Padding(1, 2, 3, 4, 5) }, ``},
154160
{func(s S) S { return s.Margin(1, 2, 3, 4) }, `margin-bottom: 3; margin-left: 4; margin-right: 2; margin-top: 1;`},
155161
{func(s S) S { return s.Margin(1, 2, 3) }, `margin-bottom: 3; margin-left: 2; margin-right: 2; margin-top: 1;`},
156162
{func(s S) S { return s.Margin(1, 2) }, `margin-bottom: 1; margin-left: 2; margin-right: 2; margin-top: 1;`},
163+
{func(s S) S { return s.Margin(1) }, `margin-bottom: 1; margin-left: 1; margin-right: 1; margin-top: 1;`},
157164
{func(s S) S { return s.Margin() }, ``},
158165
{func(s S) S { return s.Margin(1, 2, 3, 4, 5) }, ``},
166+
{func(s S) S {
167+
return s.Border(lipgloss.Border{}, true, true, true, true)
168+
}, `border-bottom: true; border-left: true; border-right: true; ` +
169+
`border-top: true;`},
170+
{func(s S) S {
171+
return s.Border(lipgloss.Border{}, true, true, true)
172+
}, `border-bottom: true; border-left: true; border-right: true; ` +
173+
`border-top: true;`},
174+
{func(s S) S {
175+
return s.Border(lipgloss.Border{}, true, true)
176+
}, `border-bottom: true; border-left: true; border-right: true; ` +
177+
`border-top: true;`},
178+
{func(s S) S {
179+
return s.Border(lipgloss.Border{})
180+
}, `border-bottom: true; border-left: true; border-right: true; ` +
181+
`border-top: true;`},
182+
{func(s S) S {
183+
return s.Border(lipgloss.Border{}, true, true, true, true, true)
184+
}, `border-bottom: true; border-left: true; border-right: true; ` +
185+
`border-top: true;`},
186+
{func(s S) S { return s.BorderBackground(g, r, b, w) }, `border-bottom-background: #00f; border-left-background: #fff; border-right-background: #f00; border-top-background: #0f0;`},
187+
{func(s S) S { return s.BorderBackground(g, r, b) }, `border-bottom-background: #00f; border-left-background: #f00; border-right-background: #f00; border-top-background: #0f0;`},
188+
{func(s S) S { return s.BorderBackground(g, r) }, `border-bottom-background: #0f0; border-left-background: #f00; border-right-background: #f00; border-top-background: #0f0;`},
189+
{func(s S) S { return s.BorderBackground() }, ``},
190+
{func(s S) S { return s.BorderBackground(g, r, b, w, g) }, ``},
159191
}
160192

161193
for _, tc := range td {

0 commit comments

Comments
 (0)