forked from charmbracelet/lipgloss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: return consistent border sizes when BorderStyle is used.
Return non-zero border sizes when border style is set, and no border sides have been specifically turned on or off. Fixes: charmbracelet#281
- Loading branch information
1 parent
d0be07e
commit 86319a6
Showing
3 changed files
with
108 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package lipgloss | ||
|
||
import "testing" | ||
|
||
func TestStyle_GetBorderSizes(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
style Style | ||
wantX int | ||
wantY int | ||
}{ | ||
{ | ||
name: "Default style", | ||
style: NewStyle(), | ||
wantX: 0, | ||
wantY: 0, | ||
}, | ||
{ | ||
name: "Border(NormalBorder())", | ||
style: NewStyle().Border(NormalBorder()), | ||
wantX: 2, | ||
wantY: 2, | ||
}, | ||
{ | ||
name: "Border(NormalBorder(), true)", | ||
style: NewStyle().Border(NormalBorder(), true), | ||
wantX: 2, | ||
wantY: 2, | ||
}, | ||
{ | ||
name: "Border(NormalBorder(), true, false)", | ||
style: NewStyle().Border(NormalBorder(), true, false), | ||
wantX: 0, | ||
wantY: 2, | ||
}, | ||
{ | ||
name: "Border(NormalBorder(), true, true, false)", | ||
style: NewStyle().Border(NormalBorder(), true, true, false), | ||
wantX: 2, | ||
wantY: 1, | ||
}, | ||
{ | ||
name: "Border(NormalBorder(), true, true, false, false)", | ||
style: NewStyle().Border(NormalBorder(), true, true, false, false), | ||
wantX: 1, | ||
wantY: 1, | ||
}, | ||
{ | ||
name: "BorderTop(true).BorderStyle(NormalBorder())", | ||
style: NewStyle().BorderTop(true).BorderStyle(NormalBorder()), | ||
wantX: 0, | ||
wantY: 1, | ||
}, | ||
{ | ||
name: "BorderStyle(NormalBorder())", | ||
style: NewStyle().BorderStyle(NormalBorder()), | ||
wantX: 2, | ||
wantY: 2, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotX := tt.style.GetHorizontalBorderSize() | ||
if gotX != tt.wantX { | ||
t.Errorf("Style.GetHorizontalBorderSize() got %d, want %d", gotX, tt.wantX) | ||
} | ||
|
||
gotY := tt.style.GetVerticalBorderSize() | ||
if gotY != tt.wantY { | ||
t.Errorf("Style.GetVerticalBorderSize() got %d, want %d", gotY, tt.wantY) | ||
} | ||
|
||
gotX = tt.style.GetHorizontalFrameSize() | ||
if gotX != tt.wantX { | ||
t.Errorf("Style.GetHorizontalFrameSize() got %d, want %d", gotX, tt.wantX) | ||
} | ||
|
||
gotY = tt.style.GetVerticalFrameSize() | ||
if gotY != tt.wantY { | ||
t.Errorf("Style.GetVerticalFrameSize() got %d, want %d", gotY, tt.wantY) | ||
} | ||
|
||
gotX, gotY = tt.style.GetFrameSize() | ||
if gotX != tt.wantX || gotY != tt.wantY { | ||
t.Errorf("Style.GetFrameSize() got (%d, %d), want (%d, %d)", gotX, gotY, tt.wantX, tt.wantY) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters