1
0
mirror of https://github.com/rclone/rclone.git synced 2025-08-16 00:28:09 +02:00
Files
.github
backend
bin
cmd
cmdtest
contrib
docs
fs
accounting
asyncreader
cache
chunkedreader
chunksize
config
dirtree
driveletter
filter
fserrors
fshttp
fspath
hash
list
log
logger
march
object
operations
rc
sync
walk
backend_config.go
backend_config_test.go
bits.go
bits_test.go
bwtimetable.go
bwtimetable_test.go
config.go
config_list.go
config_list_test.go
config_test.go
configmap.go
countsuffix.go
countsuffix_test.go
cutoffmode.go
cutoffmode_test.go
daemon_other.go
daemon_unix.go
deletemode.go
dir.go
dir_wrapper.go
direntries.go
direntries_test.go
dump.go
dump_test.go
enum.go
enum_test.go
features.go
fingerprint.go
fingerprint_test.go
fs.go
fs_test.go
log.go
log_test.go
metadata.go
metadata_mapper_code.go
metadata_test.go
mimetype.go
mount_helper.go
mount_helper_test.go
newfs.go
newfs_test.go
open_options.go
open_options_test.go
override.go
override_dir.go
override_dir_test.go
override_test.go
pacer.go
parseduration.go
parseduration_test.go
parsetime.go
parsetime_test.go
registry.go
sizesuffix.go
sizesuffix_test.go
terminalcolormode.go
terminalcolormode_test.go
tristate.go
tristate_test.go
types.go
version.go
versioncheck.go
versionsuffix.go
versiontag.go
fstest
graphics
lib
librclone
vfs
.gitattributes
.gitignore
.golangci.yml
CONTRIBUTING.md
COPYING
Dockerfile
MAINTAINERS.md
MANUAL.html
MANUAL.md
MANUAL.txt
Makefile
README.md
RELEASE.md
VERSION
go.mod
go.sum
notes.txt
rclone.1
rclone.go
rclone/fs/config_list_test.go
2018-08-21 10:58:59 +01:00

88 lines
2.3 KiB
Go

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)
}
}