gitlab.com/apertussolutions/u-root@v7.0.0+incompatible/pkg/shlex/shlex_test.go (about) 1 // Copyright 2017-2020 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package shlex 6 7 import ( 8 "fmt" 9 "reflect" 10 "testing" 11 ) 12 13 func TestArgv(t *testing.T) { 14 for i, tt := range []struct { 15 desc string 16 in string 17 want []string 18 }{ 19 { 20 desc: "nothing to do", 21 in: "stuff", 22 want: []string{"stuff"}, 23 }, 24 { 25 desc: "split", 26 in: "stuff more stuff", 27 want: []string{"stuff", "more", "stuff"}, 28 }, 29 { 30 desc: "escape", 31 in: "stuff\\ more stuff", 32 want: []string{"stuff more", "stuff"}, 33 }, 34 { 35 desc: "quote", 36 in: "stuff var='more stuff'", 37 want: []string{"stuff", "var=more stuff"}, 38 }, 39 { 40 desc: "double quote", 41 in: "stuff var=\"more stuff\"", 42 want: []string{"stuff", "var=more stuff"}, 43 }, 44 { 45 desc: "quote specials", 46 in: "stuff var='more stuff $ \\ \\$ \" '", 47 want: []string{"stuff", "var=more stuff $ \\ \\$ \" "}, 48 }, 49 { 50 desc: "double quote", 51 in: "stuff var=\"more stuff $ \\ \\$ \\\" \"", 52 want: []string{"stuff", "var=more stuff $ \\ $ \" "}, 53 }, 54 { 55 desc: "quote forgot close", 56 in: "stuff var='more stuff", 57 want: []string{"stuff", "var=more stuff"}, 58 }, 59 { 60 desc: "empty", 61 in: "", 62 want: nil, 63 }, 64 } { 65 t.Run(fmt.Sprintf("Test [%02d] %s", i, tt.desc), func(t *testing.T) { 66 got := Argv(tt.in) 67 if !reflect.DeepEqual(got, tt.want) { 68 t.Errorf("Argv = %#v, want %#v", got, tt.want) 69 } 70 71 }) 72 } 73 }