mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-09 16:35:12 +00:00
65 lines
1.1 KiB
Go
65 lines
1.1 KiB
Go
package shellwords
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
type wordsTest struct {
|
|
line string
|
|
args []string
|
|
doErr bool
|
|
}
|
|
|
|
func TestParse(t *testing.T) {
|
|
var tests = []wordsTest{
|
|
{
|
|
`this is a "test"`,
|
|
[]string{"this", "is", "a", "test"},
|
|
false,
|
|
},
|
|
{
|
|
`hanging "quote`,
|
|
[]string{"hanging", "quote"},
|
|
true,
|
|
},
|
|
{
|
|
`Hello, 世界`,
|
|
[]string{"Hello,", "世界"},
|
|
false,
|
|
},
|
|
{
|
|
"this is `inline code`",
|
|
[]string{"this", "is", "inline code"},
|
|
false,
|
|
},
|
|
{
|
|
"how about a ```go\npackage main\n```\ngo code?",
|
|
[]string{"how", "about", "a", "go\npackage main\n", "go", "code?"},
|
|
false,
|
|
},
|
|
{
|
|
"this should not crash `",
|
|
[]string{"this", "should", "not", "crash"},
|
|
true,
|
|
},
|
|
{
|
|
"this should not crash '",
|
|
[]string{"this", "should", "not", "crash"},
|
|
true,
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
w, err := Parse(test.line)
|
|
if err != nil && !test.doErr {
|
|
t.Errorf("Error at %q: %v", test.line, err)
|
|
continue
|
|
}
|
|
|
|
if !reflect.DeepEqual(w, test.args) {
|
|
t.Errorf("Inequality:\n%#v !=\n%#v", w, test.args)
|
|
}
|
|
}
|
|
}
|