8 func TestNumOccurences(t *testing.T) {
15 {"\trfd\ta", '\t', 2},
16 {"∆ƒ\tø ® \t\t", '\t', 3},
18 for _, test := range tests {
19 if got := NumOccurrences(test.inputStr, test.inputChar); got != test.want {
20 t.Errorf("NumOccurences(%s, %c) = %d", test.inputStr, test.inputChar, got)
25 func TestSpaces(t *testing.T) {
26 var tests = []struct {
33 for _, test := range tests {
34 if got := Spaces(test.input); got != test.want {
35 t.Errorf("Spaces(%d) = \"%s\"", test.input, got)
40 func TestIsWordChar(t *testing.T) {
41 if IsWordChar("t") == false {
42 t.Errorf("IsWordChar(t) = false")
44 if IsWordChar("T") == false {
45 t.Errorf("IsWordChar(T) = false")
47 if IsWordChar("5") == false {
48 t.Errorf("IsWordChar(5) = false")
50 if IsWordChar("_") == false {
51 t.Errorf("IsWordChar(_) = false")
53 if IsWordChar("~") == true {
54 t.Errorf("IsWordChar(~) = true")
56 if IsWordChar(" ") == true {
57 t.Errorf("IsWordChar( ) = true")
59 if IsWordChar("ß") == true {
60 t.Errorf("IsWordChar(ß) = true")
62 if IsWordChar(")") == true {
63 t.Errorf("IsWordChar()) = true")
65 if IsWordChar("\n") == true {
66 t.Errorf("IsWordChar(\n)) = true")
70 func TestJoinAndSplitCommandArgs(t *testing.T) {
75 {[]string{`test case`}, `"test case"`},
76 {[]string{`quote "test"`}, `"quote \"test\""`},
77 {[]string{`slash\\\ test`}, `"slash\\\\\\ test"`},
78 {[]string{`path 1`, `path\" 2`}, `"path 1" "path\\\" 2"`},
79 {[]string{`foo`}, `foo`},
80 {[]string{`foo\"bar`}, `"foo\\\"bar"`},
82 {[]string{`"`}, `"\""`},
83 {[]string{`a`, ``}, `a `},
84 {[]string{``, ``, ``, ``}, ` `},
85 {[]string{"\n"}, `"\n"`},
86 {[]string{"foo\tbar"}, `"foo\tbar"`},
89 for i, test := range tests {
90 if result := JoinCommandArgs(test.Query...); test.Wanted != result {
91 t.Errorf("JoinCommandArgs failed at Test %d\nGot: %q", i, result)
94 if result := SplitCommandArgs(test.Wanted); !reflect.DeepEqual(test.Query, result) {
95 t.Errorf("SplitCommandArgs failed at Test %d\nGot: `%q`", i, result)
99 splitTests := []struct {
103 {`"hallo""Welt"`, []string{`"hallo""Welt"`}},
104 {`\"`, []string{`\"`}},
105 {`"\"`, []string{`"\"`}},
108 for i, test := range splitTests {
109 if result := SplitCommandArgs(test.Query); !reflect.DeepEqual(test.Wanted, result) {
110 t.Errorf("SplitCommandArgs failed at Split-Test %d\nGot: `%q`", i, result)