-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: border size getters when implicit borders are present (#411)
* fix: border size getters when implicit borders are present When a border style is set and no borders have been explicitly enabled or disabled, a border is implicitly applied to all sides of the block. Prior to this fix border size getters would incorrectly return 0 when an implicit border is set. This revision corrects that behavior. * refactor: remove redundant conditional check * Update get.go * test: add border tests Co-authored-by: @qualidafial --------- Co-authored-by: bashbunni <[email protected]> Co-authored-by: Ayman Bagabas <[email protected]> Co-authored-by: bashbunni <[email protected]>
- Loading branch information
1 parent
f34b553
commit 9b8304f
Showing
3 changed files
with
115 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,96 @@ | ||
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, | ||
}, | ||
{ | ||
name: "Custom BorderStyle", | ||
style: NewStyle().BorderStyle(Border{Left: "123456789"}), | ||
wantX: 1, // left and right borders are laid out vertically, one rune per row | ||
wantY: 0, | ||
}, | ||
} | ||
|
||
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