github.com/josephvusich/fdf@v0.0.0-20230522095411-9326dd32e33f/copyname_test.go (about)

     1  package main
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func TestIsCopyName(t *testing.T) {
    10  	assert := require.New(t)
    11  
    12  	positive := [][]string{
    13  		{
    14  			"foo.bar",
    15  			"Copy of foo.bar",
    16  			"foo copy.bar",
    17  			"foo (1).bar",
    18  			"foo(1).bar",
    19  			" foo .bar ",
    20  		},
    21  		{
    22  			"foo",
    23  			"Copy of foo",
    24  			"foo-01",
    25  		},
    26  	}
    27  
    28  	negative := []string{
    29  		"foo.bar",
    30  		"foo",
    31  		".bar",
    32  		"foo.",
    33  		"foo.abc",
    34  		"Copy of foo.xyz",
    35  		"bar.foo",
    36  		"f_o.bar",
    37  		"aa-1234.bar",
    38  		"aa-1234q.bar",
    39  		"aa-.bar",
    40  		"aa-foo-bar.bar",
    41  	}
    42  
    43  	for _, c := range positive {
    44  		for i, x := range c {
    45  			for j := i + 1; j < len(c); j++ {
    46  				assert.True(isCopyName(x, c[j]), "%s and %s should be copy names", x, c[j])
    47  				assert.True(isCopyName(c[j], x), "%s and %s should be copy names", c[j], x)
    48  			}
    49  		}
    50  	}
    51  
    52  	for i, x := range negative {
    53  		for j := i + 1; j < len(negative); j++ {
    54  			assert.False(isCopyName(x, negative[j]), "%s and %s should not be copy names", x, negative[j])
    55  			assert.False(isCopyName(negative[j], x), "%s and %s should not be copy names", negative[j], x)
    56  		}
    57  	}
    58  }