github.com/diamondburned/arikawa@v1.3.14/bot/extras/shellwords/shellwords_test.go (about) 1 package shellwords 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 type wordsTest struct { 9 line string 10 args []string 11 doErr bool 12 } 13 14 func TestParse(t *testing.T) { 15 var tests = []wordsTest{ 16 { 17 `this is a "test"`, 18 []string{"this", "is", "a", "test"}, 19 false, 20 }, 21 { 22 `hanging "quote`, 23 []string{"hanging", "quote"}, 24 true, 25 }, 26 { 27 `Hello, 世界`, 28 []string{"Hello,", "世界"}, 29 false, 30 }, 31 { 32 "this is `inline code`", 33 []string{"this", "is", "inline code"}, 34 false, 35 }, 36 { 37 "how about a ```go\npackage main\n```\ngo code?", 38 []string{"how", "about", "a", "go\npackage main\n", "go", "code?"}, 39 false, 40 }, 41 { 42 "this should not crash `", 43 []string{"this", "should", "not", "crash"}, 44 true, 45 }, 46 { 47 "this should not crash '", 48 []string{"this", "should", "not", "crash"}, 49 true, 50 }, 51 } 52 53 for _, test := range tests { 54 w, err := Parse(test.line) 55 if err != nil && !test.doErr { 56 t.Errorf("Error at %q: %v", test.line, err) 57 continue 58 } 59 60 if !reflect.DeepEqual(w, test.args) { 61 t.Errorf("Inequality:\n%#v !=\n%#v", w, test.args) 62 } 63 } 64 }