left_padded_test.go

 1package text
 2
 3import "testing"
 4
 5func TestLeftPadMaxLine(t *testing.T) {
 6	cases := []struct {
 7		input, output  string
 8		maxValueLength int
 9		leftPad        int
10	}{
11		{
12			"foo",
13			"foo ",
14			4,
15			0,
16		},
17		{
18			"foofoofoo",
19			"f...",
20			4,
21			0,
22		},
23		{
24			"foo",
25			"foo       ",
26			10,
27			0,
28		},
29		{
30			"foo",
31			"  ...",
32			4,
33			2,
34		},
35		{
36			"foofoofoo",
37			"  f...",
38			6,
39			2,
40		},
41		{
42			"foo",
43			"  foo     ",
44			10,
45			2,
46		},
47	}
48
49	for i, tc := range cases {
50		result := LeftPadMaxLine(tc.input, tc.maxValueLength, tc.leftPad)
51		if result != tc.output {
52			t.Fatalf("Case %d Input:\n\n`%s`\n\nExpected Output:\n\n`%s`\n\nActual Output:\n\n`%s`",
53				i, tc.input, tc.output, result)
54		}
55	}
56}