github.com/blend/go-sdk@v1.20220411.3/stringutil/split_space_quoted_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package stringutil 9 10 import ( 11 "fmt" 12 "testing" 13 14 "github.com/blend/go-sdk/assert" 15 ) 16 17 func TestSplitSpaceQuoted(t *testing.T) { 18 assert := assert.New(t) 19 20 values := SplitSpaceQuoted("") 21 assert.Len(values, 0) 22 23 values = SplitSpaceQuoted("foo") 24 assert.Len(values, 1) 25 assert.Equal("foo", values[0]) 26 27 values = SplitSpaceQuoted("foo bar") 28 assert.Len(values, 2) 29 assert.Equal("foo", values[0]) 30 assert.Equal("bar", values[1]) 31 32 values = SplitSpaceQuoted("foo bar") 33 assert.Len(values, 2) 34 assert.Equal("foo", values[0]) 35 assert.Equal("bar", values[1]) 36 37 values = SplitSpaceQuoted("foo\tbar") 38 assert.Len(values, 2) 39 assert.Equal("foo", values[0]) 40 assert.Equal("bar", values[1]) 41 42 values = SplitSpaceQuoted("foo \tbar") 43 assert.Len(values, 2) 44 assert.Equal("foo", values[0]) 45 assert.Equal("bar", values[1]) 46 47 values = SplitSpaceQuoted("foo bar ") 48 assert.Len(values, 2) 49 assert.Equal("foo", values[0]) 50 assert.Equal("bar", values[1]) 51 52 values = SplitSpaceQuoted("foo bar baz") 53 assert.Len(values, 3) 54 assert.Equal("foo", values[0]) 55 assert.Equal("bar", values[1]) 56 assert.Equal("baz", values[2]) 57 58 values = SplitSpaceQuoted(`foo "bar baz"`) 59 assert.Len(values, 2, fmt.Sprintf("%#v", values)) 60 assert.Equal("foo", values[0]) 61 assert.Equal(`bar baz`, values[1]) 62 63 values = SplitSpaceQuoted(`foo --config="bar baz"`) 64 assert.Len(values, 2) 65 assert.Equal("foo", values[0]) 66 assert.Equal(`--config="bar baz"`, values[1]) 67 68 values = SplitSpaceQuoted(`foo --config='bar baz="hi"'`) 69 assert.Len(values, 2) 70 assert.Equal("foo", values[0]) 71 assert.Equal(`--config='bar baz="hi"'`, values[1]) 72 73 values = SplitSpaceQuoted(`foo --config="bar baz='hi'"`) 74 assert.Len(values, 2) 75 assert.Equal("foo", values[0]) 76 assert.Equal(`--config="bar baz='hi'"`, values[1]) 77 78 values = SplitSpaceQuoted(`“what is xyz’s best kept secret?” “1st floor bathrooms” “xyz street side exit” “other (please explain)”`) 79 assert.Len(values, 4) 80 assert.Equal(`what is xyz’s best kept secret?`, values[0]) 81 assert.Equal(`1st floor bathrooms`, values[1]) 82 assert.Equal(`xyz street side exit`, values[2]) 83 assert.Equal(`other (please explain)`, values[3]) 84 85 values = SplitSpaceQuoted(`‘how about now’ ‘or now’`) 86 assert.Len(values, 2) 87 assert.Equal(`how about now`, values[0]) 88 assert.Equal(`or now`, values[1]) 89 }