package main
import (
- "reflect"
"testing"
)
}
}
-func TestJoinAndSplitCommandArgs(t *testing.T) {
- tests := []struct {
- Query []string
- Wanted string
- }{
- {[]string{`test case`}, `"test case"`},
- {[]string{`quote "test"`}, `"quote \"test\""`},
- {[]string{`slash\\\ test`}, `"slash\\\\\\ test"`},
- {[]string{`path 1`, `path\" 2`}, `"path 1" "path\\\" 2"`},
- {[]string{`foo`}, `foo`},
- {[]string{`foo\"bar`}, `"foo\\\"bar"`},
- {[]string{``}, ``},
- {[]string{`"`}, `"\""`},
- {[]string{`a`, ``}, `a `},
- {[]string{``, ``, ``, ``}, ` `},
- {[]string{"\n"}, `"\n"`},
- {[]string{"foo\tbar"}, `"foo\tbar"`},
- }
-
- for i, test := range tests {
- if result := JoinCommandArgs(test.Query...); test.Wanted != result {
- t.Errorf("JoinCommandArgs failed at Test %d\nGot: %q", i, result)
- }
-
- if result := SplitCommandArgs(test.Wanted); !reflect.DeepEqual(test.Query, result) {
- t.Errorf("SplitCommandArgs failed at Test %d\nGot: `%q`", i, result)
- }
- }
-
- splitTests := []struct {
- Query string
- Wanted []string
- }{
- {`"hallo""Welt"`, []string{`halloWelt`}},
- {`"hallo" "Welt"`, []string{`hallo`, `Welt`}},
- {`\"`, []string{`\"`}},
- {`"foo`, []string{`"foo`}},
- {`"foo"`, []string{`foo`}},
- {`"\"`, []string{`"\"`}},
- {`"C:\\"foo.txt`, []string{`C:\foo.txt`}},
- {`"\n"new"\n"line`, []string{"\nnew\nline"}},
- }
-
- for i, test := range splitTests {
- if result := SplitCommandArgs(test.Query); !reflect.DeepEqual(test.Wanted, result) {
- t.Errorf("SplitCommandArgs failed at Split-Test %d\nGot: `%q`", i, result)
- }
- }
-}
-
func TestStringWidth(t *testing.T) {
tabsize := 4
if w := StringWidth("1\t2", tabsize); w != 5 {