github.com/git-lfs/git-lfs@v2.5.2+incompatible/config/extension_test.go (about)

     1  package config
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestSortExtensions(t *testing.T) {
    10  	m := map[string]Extension{
    11  		"baz": Extension{
    12  			"baz",
    13  			"baz-clean %f",
    14  			"baz-smudge %f",
    15  			2,
    16  		},
    17  		"foo": Extension{
    18  			"foo",
    19  			"foo-clean %f",
    20  			"foo-smudge %f",
    21  			0,
    22  		},
    23  		"bar": Extension{
    24  			"bar",
    25  			"bar-clean %f",
    26  			"bar-smudge %f",
    27  			1,
    28  		},
    29  	}
    30  
    31  	names := []string{"foo", "bar", "baz"}
    32  
    33  	sorted, err := SortExtensions(m)
    34  
    35  	assert.Nil(t, err)
    36  
    37  	for i, ext := range sorted {
    38  		name := names[i]
    39  		assert.Equal(t, name, ext.Name)
    40  		assert.Equal(t, name+"-clean %f", ext.Clean)
    41  		assert.Equal(t, name+"-smudge %f", ext.Smudge)
    42  		assert.Equal(t, i, ext.Priority)
    43  	}
    44  }
    45  
    46  func TestSortExtensionsDuplicatePriority(t *testing.T) {
    47  	m := map[string]Extension{
    48  		"foo": Extension{
    49  			"foo",
    50  			"foo-clean %f",
    51  			"foo-smudge %f",
    52  			0,
    53  		},
    54  		"bar": Extension{
    55  			"bar",
    56  			"bar-clean %f",
    57  			"bar-smudge %f",
    58  			0,
    59  		},
    60  	}
    61  
    62  	sorted, err := SortExtensions(m)
    63  
    64  	assert.NotNil(t, err)
    65  	assert.Empty(t, sorted)
    66  }