File: config_list_test.go

package info (click to toggle)
rclone 1.45-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 24,300 kB
  • sloc: python: 364; sh: 255; makefile: 190; xml: 30
file content (87 lines) | stat: -rw-r--r-- 2,376 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package fs

import (
	"fmt"
	"testing"

	"github.com/stretchr/testify/require"
)

func must(err error) {
	if err != nil {
		panic(err)
	}
}

func ExampleSpaceSepList() {
	for _, s := range []string{
		`remotea:test/dir remoteb:`,
		`"remotea:test/space dir" remoteb:`,
		`"remotea:test/quote""dir" remoteb:`,
	} {
		var l SpaceSepList
		must(l.Set(s))
		fmt.Printf("%#v\n", l)
	}
	// Output:
	// fs.SpaceSepList{"remotea:test/dir", "remoteb:"}
	// fs.SpaceSepList{"remotea:test/space dir", "remoteb:"}
	// fs.SpaceSepList{"remotea:test/quote\"dir", "remoteb:"}
}

func ExampleCommaSepList() {
	for _, s := range []string{
		`remotea:test/dir,remoteb:`,
		`"remotea:test/space dir",remoteb:`,
		`"remotea:test/quote""dir",remoteb:`,
	} {
		var l CommaSepList
		must(l.Set(s))
		fmt.Printf("%#v\n", l)
	}
	// Output:
	// fs.CommaSepList{"remotea:test/dir", "remoteb:"}
	// fs.CommaSepList{"remotea:test/space dir", "remoteb:"}
	// fs.CommaSepList{"remotea:test/quote\"dir", "remoteb:"}
}

func TestSpaceSepListSet(t *testing.T) {
	type tc struct {
		in  string
		out SpaceSepList
		err string
	}
	tests := []tc{
		{``, nil, ""},
		{`\`, SpaceSepList{`\`}, ""},
		{`\\`, SpaceSepList{`\\`}, ""},
		{`potato`, SpaceSepList{`potato`}, ""},
		{`po\tato`, SpaceSepList{`po\tato`}, ""},
		{`potato\`, SpaceSepList{`potato\`}, ""},
		{`'potato`, SpaceSepList{`'potato`}, ""},
		{`pot'ato`, SpaceSepList{`pot'ato`}, ""},
		{`potato'`, SpaceSepList{`potato'`}, ""},
		{`"potato"`, SpaceSepList{`potato`}, ""},
		{`'potato'`, SpaceSepList{`'potato'`}, ""},
		{`potato apple`, SpaceSepList{`potato`, `apple`}, ""},
		{`potato\ apple`, SpaceSepList{`potato\`, `apple`}, ""},
		{`"potato  apple"`, SpaceSepList{`potato  apple`}, ""},
		{`"potato'apple"`, SpaceSepList{`potato'apple`}, ""},
		{`"potato''apple"`, SpaceSepList{`potato''apple`}, ""},
		{`"potato' 'apple"`, SpaceSepList{`potato' 'apple`}, ""},
		{`potato="apple"`, nil, `bare " in non-quoted-field`},
		{`apple "potato`, nil, "extraneous"},
		{`apple pot"ato`, nil, "bare \" in non-quoted-field"},
		{`potato"`, nil, "bare \" in non-quoted-field"},
	}
	for _, tc := range tests {
		var l SpaceSepList
		err := l.Set(tc.in)
		if tc.err == "" {
			require.NoErrorf(t, err, "input: %q", tc.in)
		} else {
			require.Containsf(t, err.Error(), tc.err, "input: %q", tc.in)
		}
		require.Equalf(t, tc.out, l, "input: %q", tc.in)
	}
}