forked from TrueCloudLab/rclone
lib/encoder: move definitions here and remove uint casts
This commit is contained in:
parent
3c620d521d
commit
c555dc71c2
5 changed files with 172 additions and 200 deletions
|
@ -19,7 +19,7 @@ var (
|
|||
|
||||
func TestEncodeString(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
mask uint
|
||||
mask MultiEncoder
|
||||
want string
|
||||
}{
|
||||
{0, "None"},
|
||||
|
@ -31,7 +31,7 @@ func TestEncodeString(t *testing.T) {
|
|||
{EncodeSlash | EncodeDollar | EncodeColon, "Slash,Dollar,Colon"},
|
||||
{EncodeSlash | (1 << 31), "Slash,0x80000000"},
|
||||
} {
|
||||
got := MultiEncoder(test.mask).String()
|
||||
got := test.mask.String()
|
||||
assert.Equal(t, test.want, got)
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ func TestEncodeString(t *testing.T) {
|
|||
func TestEncodeSet(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
in string
|
||||
want uint
|
||||
want MultiEncoder
|
||||
wantErr bool
|
||||
}{
|
||||
{"", 0, true},
|
||||
|
@ -58,20 +58,20 @@ func TestEncodeSet(t *testing.T) {
|
|||
var got MultiEncoder
|
||||
err := got.Set(test.in)
|
||||
assert.Equal(t, test.wantErr, err != nil, err)
|
||||
assert.Equal(t, MultiEncoder(test.want), got, test.in)
|
||||
assert.Equal(t, test.want, got, test.in)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type testCase struct {
|
||||
mask uint
|
||||
mask MultiEncoder
|
||||
in string
|
||||
out string
|
||||
}
|
||||
|
||||
func TestEncodeSingleMask(t *testing.T) {
|
||||
for i, tc := range testCasesSingle {
|
||||
e := MultiEncoder(tc.mask)
|
||||
e := tc.mask
|
||||
t.Run(strconv.FormatInt(int64(i), 10), func(t *testing.T) {
|
||||
got := e.Encode(tc.in)
|
||||
if got != tc.out {
|
||||
|
@ -87,7 +87,7 @@ func TestEncodeSingleMask(t *testing.T) {
|
|||
|
||||
func TestEncodeSingleMaskEdge(t *testing.T) {
|
||||
for i, tc := range testCasesSingleEdge {
|
||||
e := MultiEncoder(tc.mask)
|
||||
e := tc.mask
|
||||
t.Run(strconv.FormatInt(int64(i), 10), func(t *testing.T) {
|
||||
got := e.Encode(tc.in)
|
||||
if got != tc.out {
|
||||
|
@ -103,7 +103,7 @@ func TestEncodeSingleMaskEdge(t *testing.T) {
|
|||
|
||||
func TestEncodeDoubleMaskEdge(t *testing.T) {
|
||||
for i, tc := range testCasesDoubleEdge {
|
||||
e := MultiEncoder(tc.mask)
|
||||
e := tc.mask
|
||||
t.Run(strconv.FormatInt(int64(i), 10), func(t *testing.T) {
|
||||
got := e.Encode(tc.in)
|
||||
if got != tc.out {
|
||||
|
@ -161,7 +161,7 @@ func TestEncodeInvalidUnicode(t *testing.T) {
|
|||
out: "a\xBF\\xFEb",
|
||||
},
|
||||
} {
|
||||
e := MultiEncoder(tc.mask)
|
||||
e := tc.mask
|
||||
t.Run(strconv.FormatInt(int64(i), 10), func(t *testing.T) {
|
||||
got := e.Encode(tc.in)
|
||||
if got != tc.out {
|
||||
|
@ -203,7 +203,7 @@ func TestEncodeDot(t *testing.T) {
|
|||
out: ". .",
|
||||
},
|
||||
} {
|
||||
e := MultiEncoder(tc.mask)
|
||||
e := tc.mask
|
||||
t.Run(strconv.FormatInt(int64(i), 10), func(t *testing.T) {
|
||||
got := e.Encode(tc.in)
|
||||
if got != tc.out {
|
||||
|
@ -245,7 +245,7 @@ func TestDecodeHalf(t *testing.T) {
|
|||
out: "a‛B\\‛Eg",
|
||||
},
|
||||
} {
|
||||
e := MultiEncoder(tc.mask)
|
||||
e := tc.mask
|
||||
t.Run(strconv.FormatInt(int64(i), 10), func(t *testing.T) {
|
||||
got := e.Decode(tc.in)
|
||||
if got != tc.out {
|
||||
|
@ -255,16 +255,15 @@ func TestDecodeHalf(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
const oneDrive = MultiEncoder(
|
||||
uint(Standard) |
|
||||
EncodeWin |
|
||||
EncodeBackSlash |
|
||||
EncodeHashPercent |
|
||||
EncodeDel |
|
||||
EncodeCtl |
|
||||
EncodeLeftTilde |
|
||||
EncodeRightSpace |
|
||||
EncodeRightPeriod)
|
||||
const oneDrive = (Standard |
|
||||
EncodeWin |
|
||||
EncodeBackSlash |
|
||||
EncodeHashPercent |
|
||||
EncodeDel |
|
||||
EncodeCtl |
|
||||
EncodeLeftTilde |
|
||||
EncodeRightSpace |
|
||||
EncodeRightPeriod)
|
||||
|
||||
var benchTests = []struct {
|
||||
in string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue