Debian Codegraph @

cmd/bpf2go/tools_test.go

raw symbols SCIP
1 //go:build !windows
2
3 package main
4
5 import (
6 "reflect"
7 "testing"
8 )
9
10 func TestSplitArguments(t *testing.T) {
11 testcases := []struct {
12 in string
13 out []string
14 }{
15 {`foo`, []string{"foo"}},
16 {`foo bar`, []string{"foo", "bar"}},
17 {`foo bar`, []string{"foo", "bar"}},
18 {`\\`, []string{`\`}},
19 {`\\\`, nil},
20 {`foo\ bar`, []string{"foo bar"}},
21 {`foo "" bar`, []string{"foo", "", "bar"}},
22 {`"bar baz"`, []string{"bar baz"}},
23 {`'bar baz'`, []string{"bar baz"}},
24 {`'bar " " baz'`, []string{`bar " " baz`}},
25 {`"bar \" baz"`, []string{`bar " baz`}},
26 {`"`, nil},
27 {`'`, nil},
28 }
29
30 for _, testcase := range testcases {
31 have, err := splitArguments(testcase.in)
32 if testcase.out == nil {
33 if err == nil {
34 t.Errorf("Test should fail for: %s", testcase.in)
35 }
36 } else if !reflect.DeepEqual(testcase.out, have) {
37 t.Logf("Have: %q\n", have)
38 t.Logf("Want: %q\n", testcase.out)
39 t.Errorf("Test fails for: %s", testcase.in)
40 }
41 }
42 }