aboutsummaryrefslogtreecommitdiffstats
path: root/util/text/left_padded_test.go
blob: a8ea12fe5ece055e63dcf730bc1b9989cd259c6a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package text

import "testing"

func TestLeftPadMaxLine(t *testing.T) {
	cases := []struct {
		input, output  string
		maxValueLength int
		leftPad        int
	}{
		{
			"foo",
			"foo ",
			4,
			0,
		},
		{
			"foofoofoo",
			"f...",
			4,
			0,
		},
		{
			"foo",
			"foo       ",
			10,
			0,
		},
		{
			"foo",
			"  ...",
			4,
			2,
		},
		{
			"foofoofoo",
			"  f...",
			6,
			2,
		},
		{
			"foo",
			"  foo     ",
			10,
			2,
		},
	}

	for i, tc := range cases {
		result := LeftPadMaxLine(tc.input, tc.maxValueLength, tc.leftPad)
		if result != tc.output {
			t.Fatalf("Case %d Input:\n\n`%s`\n\nExpected Output:\n\n`%s`\n\nActual Output:\n\n`%s`",
				i, tc.input, tc.output, result)
		}
	}
}