github.com/Benchkram/bob@v0.0.0-20220321080157-7c8f3876e225/pkg/multilinecmd/multilinecmd_test.go (about) 1 package multilinecmd 2 3 import ( 4 "fmt" 5 "strings" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestMultilineCmd(t *testing.T) { 12 tests := []struct { 13 input string 14 expected []string 15 }{ 16 { 17 input: "", 18 expected: []string{}, 19 }, 20 { 21 input: "\n", 22 expected: []string{}, 23 }, 24 { 25 input: " ", 26 expected: []string{}, 27 }, 28 { 29 input: "echo Hello", 30 expected: []string{ 31 "echo Hello", 32 }, 33 }, 34 { 35 input: " leading and trailing spaces ", 36 expected: []string{ 37 "leading and trailing spaces", 38 }, 39 }, 40 { 41 input: strings.Join([]string{ 42 "echo Hello", 43 "some long\\\ncommand\\\nwith multiple line-breaks", 44 }, "\n"), 45 expected: []string{ 46 "echo Hello", 47 "some long command with multiple line-breaks", 48 }, 49 }, 50 } 51 52 for _, test := range tests { 53 result := Split(test.input) 54 55 assert.Equal(t, len(test.expected), len(result)) 56 for i := range result { 57 assert.Equal(t, test.expected[i], result[i], fmt.Sprintf("\nexpected: %s\ngot: %s\n", test.expected[i], result[i])) 58 } 59 } 60 }