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