Skip to content

Commit

Permalink
Fix JoinVertical behavior for non-edge non-center alignments
Browse files Browse the repository at this point in the history
  • Loading branch information
trytriangles authored and meowgorithm committed Feb 8, 2022
1 parent 526700f commit f05ca49
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions join.go
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions 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)
}
}
}

0 comments on commit f05ca49

Please sign in to comment.