github.com/abdfnx/gh-api@v0.0.0-20210414084727-f5432eec23b8/pkg/cmd/root/help_test.go (about)

     1  package root
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestDedent(t *testing.T) {
     8  	type c struct {
     9  		input    string
    10  		expected string
    11  	}
    12  
    13  	cases := []c{
    14  		{
    15  			input:    "      --help      Show help for command\n      --version   Show gh version\n",
    16  			expected: "--help      Show help for command\n--version   Show gh version\n",
    17  		},
    18  		{
    19  			input:    "      --help              Show help for command\n  -R, --repo OWNER/REPO   Select another repository using the OWNER/REPO format\n",
    20  			expected: "    --help              Show help for command\n-R, --repo OWNER/REPO   Select another repository using the OWNER/REPO format\n",
    21  		},
    22  		{
    23  			input:    "  line 1\n\n  line 2\n line 3",
    24  			expected: " line 1\n\n line 2\nline 3",
    25  		},
    26  		{
    27  			input:    "  line 1\n  line 2\n  line 3\n\n",
    28  			expected: "line 1\nline 2\nline 3\n\n",
    29  		},
    30  		{
    31  			input:    "\n\n\n\n\n\n",
    32  			expected: "\n\n\n\n\n\n",
    33  		},
    34  		{
    35  			input:    "",
    36  			expected: "",
    37  		},
    38  	}
    39  
    40  	for _, tt := range cases {
    41  		got := dedent(tt.input)
    42  		if got != tt.expected {
    43  			t.Errorf("expected: %q, got: %q", tt.expected, got)
    44  		}
    45  	}
    46  }