cli/command/help_test.go
2020-07-16 16:24:25 +02:00

90 lines
1.7 KiB
Go

package command
import (
"testing"
)
func TestDedent(t *testing.T) {
type c struct {
input string
expected string
}
cases := []c{
{
input: " --help Show help for command\n --version Show gh version\n",
expected: "--help Show help for command\n--version Show gh version\n",
},
{
input: " --help Show help for command\n -R, --repo OWNER/REPO Select another repository using the OWNER/REPO format\n",
expected: " --help Show help for command\n-R, --repo OWNER/REPO Select another repository using the OWNER/REPO format\n",
},
{
input: " line 1\n\n line 2\n line 3",
expected: " line 1\n\n line 2\nline 3",
},
{
input: " line 1\n line 2\n line 3\n\n",
expected: "line 1\nline 2\nline 3\n\n",
},
{
input: "\n\n\n\n\n\n",
expected: "\n\n\n\n\n\n",
},
{
input: "",
expected: "",
},
}
for _, tt := range cases {
got := dedent(tt.input)
if got != tt.expected {
t.Errorf("expected: %q, got: %q", tt.expected, got)
}
}
}
func Test_indent(t *testing.T) {
type args struct {
s string
indent string
}
tests := []struct {
name string
args args
want string
}{
{
name: "empty",
args: args{
s: "",
indent: "--",
},
want: "",
},
{
name: "blank",
args: args{
s: "\n",
indent: "--",
},
want: "\n",
},
{
name: "indent",
args: args{
s: "one\ntwo\nthree",
indent: "--",
},
want: "--one\n--two\n--three",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := indent(tt.args.s, tt.args.indent); got != tt.want {
t.Errorf("indent() = %q, want %q", got, tt.want)
}
})
}
}