From f05ca49b390b1ce09b03b7923a66dda22b497dcb Mon Sep 17 00:00:00 2001 From: Ryan Plant Date: Mon, 22 Nov 2021 23:17:10 +1100 Subject: [PATCH] Fix JoinVertical behavior for non-edge non-center alignments --- join.go | 4 ++-- join_test.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 join_test.go diff --git a/join.go b/join.go index b96b7f0d..69ffdc9d 100644 --- a/join.go +++ b/join.go @@ -157,8 +157,8 @@ func JoinVertical(pos Position, strs ...string) string { } split := int(math.Round(float64(w) * pos.value())) - left := w - split - right := w - left + right := w - split + left := w - right b.WriteString(strings.Repeat(" ", left)) b.WriteString(line) diff --git a/join_test.go b/join_test.go new file mode 100644 index 00000000..813280de --- /dev/null +++ b/join_test.go @@ -0,0 +1,21 @@ +package lipgloss + +import "testing" + +func TestJoinVertical(t *testing.T) { + type test struct { + result string + expected string + } + tests := []test{ + {JoinVertical(0, "A", "BBBB"), "A \nBBBB"}, + {JoinVertical(1, "A", "BBBB"), " A\nBBBB"}, + {JoinVertical(0.25, "A", "BBBB"), " A \nBBBB"}, + } + + for _, test := range tests { + if test.result != test.expected { + t.Errorf("Got \n%s\n, expected \n%s\n", test.result, test.expected) + } + } +}