Skip to content

Commit

Permalink
Better unit testing for join.
Browse files Browse the repository at this point in the history
  • Loading branch information
knz committed Sep 3, 2022
1 parent ae23be4 commit c1a4c6a
Showing 1 changed file with 72 additions and 16 deletions.
88 changes: 72 additions & 16 deletions join_test.go
@@ -1,21 +1,77 @@
package lipgloss

import "testing"
func Example_vertical() {
blockA := "AAA\nAA"
blockB := "BBB\nBBBBB\nBB"
blockC := "C"

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"},
}
out(JoinVertical(Left, blockA, blockB, blockC))
out(JoinVertical(Center, blockA, blockB, blockC))
out(JoinVertical(Right, blockA, blockB, blockC))
out(JoinVertical(0.25, blockA, blockB, blockC))

for _, test := range tests {
if test.result != test.expected {
t.Errorf("Got \n%s\n, expected \n%s\n", test.result, test.expected)
}
}
// Output:
// AAA__␤
// AA___␤
// BBB__␤
// BBBBB␤
// BB___␤
// C____🛇
//
// _AAA_␤
// __AA_␤
// _BBB_␤
// BBBBB␤
// __BB_␤
// __C__🛇
//
// __AAA␤
// ___AA␤
// __BBB␤
// BBBBB␤
// ___BB␤
// ____C🛇
//
// _AAA_␤
// _AA__␤
// _BBB_␤
// BBBBB␤
// _BB__␤
// _C___🛇
}

func Example_horizontal() {
blockA := "AAA\nAA\n\n\n"
blockB := "BBB\nBBBBB\nBB"
blockC := "C"

out(JoinHorizontal(Top, blockA, blockB, blockC))
out(JoinHorizontal(Center, blockA, blockB, blockC))
out(JoinHorizontal(Bottom, blockA, blockB, blockC))
out(JoinHorizontal(0.25, blockA, blockB, blockC))

// Output:
// AAABBB__C␤
// AA_BBBBB_␤
// ___BB____␤
// _________␤
// _________🛇
//
// AAA______␤
// AA_BBB___␤
// ___BBBBBC␤
// ___BB____␤
// _________🛇
//
// AAA______␤
// AA_______␤
// ___BBB___␤
// ___BBBBB_␤
// ___BB___C🛇
//
// AAA______␤
// AA_BBB__C␤
// ___BBBBB_␤
// ___BB____␤
// _________🛇
}

0 comments on commit c1a4c6a

Please sign in to comment.