aboutsummaryrefslogtreecommitdiffstats
path: root/util/text/left_padded_test.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-12-01 15:15:57 +0100
committerMichael Muré <batolettre@gmail.com>2018-12-01 15:17:16 +0100
commit5e7448912618b6199310f0974118633aadbc3ccb (patch)
tree1c52c5a8418430be69d80f00d01205669871a0c0 /util/text/left_padded_test.go
parent5653ae98e0a7ac4396ac4e840f88ccf7ccdf7d7f (diff)
downloadgit-bug-5e7448912618b6199310f0974118633aadbc3ccb.tar.gz
text: fix broken truncate with unicode and use the ellipsis character in LeftPadMaxLine
Diffstat (limited to 'util/text/left_padded_test.go')
-rw-r--r--util/text/left_padded_test.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/util/text/left_padded_test.go b/util/text/left_padded_test.go
new file mode 100644
index 00000000..0be79e32
--- /dev/null
+++ b/util/text/left_padded_test.go
@@ -0,0 +1,56 @@
+package text
+
+import "testing"
+
+func TestLeftPadMaxLine(t *testing.T) {
+ cases := []struct {
+ input, output string
+ maxValueLength int
+ leftPad int
+ }{
+ {
+ "foo",
+ "foo ",
+ 4,
+ 0,
+ },
+ {
+ "foofoofoo",
+ "foo…",
+ 4,
+ 0,
+ },
+ {
+ "foo",
+ "foo ",
+ 10,
+ 0,
+ },
+ {
+ "foo",
+ " f…",
+ 4,
+ 2,
+ },
+ {
+ "foofoofoo",
+ " foo…",
+ 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)
+ }
+ }
+}