github.com/artpar/rclone@v1.67.3/backend/dropbox/dropbox_internal_test.go (about)

     1  package dropbox
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestInternalCheckPathLength(t *testing.T) {
    10  	rep := func(n int, r rune) (out string) {
    11  		rs := make([]rune, n)
    12  		for i := range rs {
    13  			rs[i] = r
    14  		}
    15  		return string(rs)
    16  	}
    17  	for _, test := range []struct {
    18  		in string
    19  		ok bool
    20  	}{
    21  		{in: "", ok: true},
    22  		{in: rep(maxFileNameLength, 'a'), ok: true},
    23  		{in: rep(maxFileNameLength+1, 'a'), ok: false},
    24  		{in: rep(maxFileNameLength, '£'), ok: true},
    25  		{in: rep(maxFileNameLength+1, '£'), ok: false},
    26  		{in: rep(maxFileNameLength, '☺'), ok: true},
    27  		{in: rep(maxFileNameLength+1, '☺'), ok: false},
    28  		{in: rep(maxFileNameLength, '你'), ok: true},
    29  		{in: rep(maxFileNameLength+1, '你'), ok: false},
    30  		{in: "/ok/ok", ok: true},
    31  		{in: "/ok/" + rep(maxFileNameLength, 'a') + "/ok", ok: true},
    32  		{in: "/ok/" + rep(maxFileNameLength+1, 'a') + "/ok", ok: false},
    33  		{in: "/ok/" + rep(maxFileNameLength, '£') + "/ok", ok: true},
    34  		{in: "/ok/" + rep(maxFileNameLength+1, '£') + "/ok", ok: false},
    35  		{in: "/ok/" + rep(maxFileNameLength, '☺') + "/ok", ok: true},
    36  		{in: "/ok/" + rep(maxFileNameLength+1, '☺') + "/ok", ok: false},
    37  		{in: "/ok/" + rep(maxFileNameLength, '你') + "/ok", ok: true},
    38  		{in: "/ok/" + rep(maxFileNameLength+1, '你') + "/ok", ok: false},
    39  	} {
    40  
    41  		err := checkPathLength(test.in)
    42  		assert.Equal(t, test.ok, err == nil, test.in)
    43  	}
    44  }