github.com/psexton/git-lfs@v2.1.1-0.20170517224304-289a18b2bc53+incompatible/tools/str_tools_test.go (about) 1 package tools 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 type QuotedFieldsTestCase struct { 10 Given string 11 Expected []string 12 } 13 14 func (c *QuotedFieldsTestCase) Assert(t *testing.T) { 15 actual := QuotedFields(c.Given) 16 17 assert.Equal(t, c.Expected, actual, 18 "tools: expected QuotedFields(%q) to equal %#v (was %#v)", 19 c.Given, c.Expected, actual, 20 ) 21 } 22 23 func TestQuotedFields(t *testing.T) { 24 for desc, c := range map[string]QuotedFieldsTestCase{ 25 "simple": {`foo bar`, []string{"foo", "bar"}}, 26 "simple trailing": {`foo bar `, []string{"foo", "bar"}}, 27 "simple leading": {` foo bar`, []string{"foo", "bar"}}, 28 29 "single quotes": {`foo 'bar baz'`, []string{"foo", "bar baz"}}, 30 "single quotes trailing": {`foo 'bar baz' `, []string{"foo", "bar baz"}}, 31 "single quotes leading": {` foo 'bar baz'`, []string{"foo", "bar baz"}}, 32 33 "single quotes empty": {`foo ''`, []string{"foo", ""}}, 34 "single quotes trailing empty": {`foo '' `, []string{"foo", ""}}, 35 "single quotes leading empty": {` foo ''`, []string{"foo", ""}}, 36 37 "double quotes": {`foo "bar baz"`, []string{"foo", "bar baz"}}, 38 "double quotes trailing": {`foo "bar baz" `, []string{"foo", "bar baz"}}, 39 "double quotes leading": {` foo "bar baz"`, []string{"foo", "bar baz"}}, 40 41 "double quotes empty": {`foo ""`, []string{"foo", ""}}, 42 "double quotes trailing empty": {`foo "" `, []string{"foo", ""}}, 43 "double quotes leading empty": {` foo ""`, []string{"foo", ""}}, 44 45 "nested single quotes": {`foo 'bar 'baz''`, []string{"foo", "bar 'baz'"}}, 46 "nested single quotes trailing": {`foo 'bar 'baz'' `, []string{"foo", "bar 'baz'"}}, 47 "nested single quotes leading": {` foo 'bar 'baz''`, []string{"foo", "bar 'baz'"}}, 48 49 "nested single quotes empty": {`foo 'bar '''`, []string{"foo", "bar ''"}}, 50 "nested single quotes trailing empty": {`foo 'bar ''' `, []string{"foo", "bar ''"}}, 51 "nested single quotes leading empty": {` foo 'bar '''`, []string{"foo", "bar ''"}}, 52 53 "nested double quotes": {`foo "bar "baz""`, []string{"foo", `bar "baz"`}}, 54 "nested double quotes trailing": {`foo "bar "baz"" `, []string{"foo", `bar "baz"`}}, 55 "nested double quotes leading": {` foo "bar "baz""`, []string{"foo", `bar "baz"`}}, 56 57 "nested double quotes empty": {`foo "bar """`, []string{"foo", `bar ""`}}, 58 "nested double quotes trailing empty": {`foo "bar """ `, []string{"foo", `bar ""`}}, 59 "nested double quotes leading empty": {` foo "bar """`, []string{"foo", `bar ""`}}, 60 61 "mixed quotes": {`foo 'bar "baz"'`, []string{"foo", `bar "baz"`}}, 62 "mixed quotes trailing": {`foo 'bar "baz"' `, []string{"foo", `bar "baz"`}}, 63 "mixed quotes leading": {` foo 'bar "baz"'`, []string{"foo", `bar "baz"`}}, 64 65 "mixed quotes empty": {`foo 'bar ""'`, []string{"foo", `bar ""`}}, 66 "mixed quotes trailing empty": {`foo 'bar ""' `, []string{"foo", `bar ""`}}, 67 "mixed quotes leading empty": {` foo 'bar ""'`, []string{"foo", `bar ""`}}, 68 } { 69 t.Log(desc) 70 c.Assert(t) 71 } 72 }