github.com/yoheimuta/protolint@v0.49.8-0.20240515023657-4ecaebb7575d/internal/linter/config/importsSortedOption_test.go (about)

     1  package config_test
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"gopkg.in/yaml.v2"
     8  
     9  	"github.com/yoheimuta/protolint/internal/linter/config"
    10  )
    11  
    12  func TestImportsSortedOption_UnmarshalYAML(t *testing.T) {
    13  	for _, test := range []struct {
    14  		name                    string
    15  		inputConfig             []byte
    16  		wantImportsSortedOption config.ImportsSortedOption
    17  		wantExistErr            bool
    18  	}{
    19  		{
    20  			name: "not found supported newline",
    21  			inputConfig: []byte(`
    22  newline: linefeed
    23  `),
    24  			wantExistErr: true,
    25  		},
    26  		{
    27  			name: "newline: \n",
    28  			inputConfig: []byte(`
    29  newline: "\n"
    30  `),
    31  			wantImportsSortedOption: config.ImportsSortedOption{
    32  				Newline: "\n",
    33  			},
    34  		},
    35  		{
    36  			name: "newline: \r",
    37  			inputConfig: []byte(`
    38  newline: "\r"
    39  `),
    40  			wantImportsSortedOption: config.ImportsSortedOption{
    41  				Newline: "\r",
    42  			},
    43  		},
    44  		{
    45  			name: "newline: \r\n",
    46  			inputConfig: []byte(`
    47  newline: "\r\n"
    48  `),
    49  			wantImportsSortedOption: config.ImportsSortedOption{
    50  				Newline: "\r\n",
    51  			},
    52  		},
    53  	} {
    54  		test := test
    55  		t.Run(test.name, func(t *testing.T) {
    56  			var got config.ImportsSortedOption
    57  
    58  			err := yaml.UnmarshalStrict(test.inputConfig, &got)
    59  			if test.wantExistErr {
    60  				if err == nil {
    61  					t.Errorf("got err nil, but want err")
    62  				}
    63  				return
    64  			}
    65  			if err != nil {
    66  				t.Errorf("got err %v, but want nil", err)
    67  				return
    68  			}
    69  
    70  			if !reflect.DeepEqual(got, test.wantImportsSortedOption) {
    71  				t.Errorf("got %v, but want %v", got, test.wantImportsSortedOption)
    72  			}
    73  		})
    74  	}
    75  }