mirror of https://github.com/shunfei/cronsun
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.8 KiB
79 lines
1.8 KiB
package utils
|
|
|
|
import (
|
|
"testing"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
)
|
|
|
|
func TestCmdArgumentParser(t *testing.T) {
|
|
var args []string
|
|
var str string
|
|
|
|
Convey("Parse Cmd Arguments ["+str+"]", t, func() {
|
|
args = ParseCmdArguments(str)
|
|
So(len(args), ShouldEqual, 0)
|
|
})
|
|
|
|
str = " "
|
|
Convey("Parse Cmd Arguments ["+str+"]", t, func() {
|
|
args = ParseCmdArguments(str)
|
|
So(len(args), ShouldEqual, 0)
|
|
})
|
|
|
|
str = "aa bbb ccc "
|
|
Convey("Parse Cmd Arguments ["+str+"]", t, func() {
|
|
args = ParseCmdArguments(str)
|
|
So(len(args), ShouldEqual, 3)
|
|
So(args[0], ShouldEqual, "aa")
|
|
So(args[1], ShouldEqual, "bbb")
|
|
So(args[2], ShouldEqual, "ccc")
|
|
})
|
|
|
|
str = "' \\\""
|
|
Convey("Parse Cmd Arguments ["+str+"]", t, func() {
|
|
args = ParseCmdArguments(str)
|
|
So(len(args), ShouldEqual, 1)
|
|
So(args[0], ShouldEqual, " \\\"")
|
|
})
|
|
|
|
str = `a "b c"` // a "b c"
|
|
Convey("Parse Cmd Arguments ["+str+"]", t, func() {
|
|
args = ParseCmdArguments(str)
|
|
So(len(args), ShouldEqual, 2)
|
|
So(args[0], ShouldEqual, "a")
|
|
So(args[1], ShouldEqual, "b c")
|
|
})
|
|
|
|
str = `a '\''"`
|
|
Convey("Parse Cmd Arguments ["+str+"]", t, func() {
|
|
args = ParseCmdArguments(str)
|
|
So(len(args), ShouldEqual, 2)
|
|
So(args[0], ShouldEqual, "a")
|
|
So(args[1], ShouldEqual, "'")
|
|
})
|
|
|
|
str = ` \\a 'b c' c\ d\ `
|
|
Convey("Parse Cmd Arguments ["+str+"]", t, func() {
|
|
args = ParseCmdArguments(str)
|
|
So(len(args), ShouldEqual, 3)
|
|
So(args[0], ShouldEqual, "\\a")
|
|
So(args[1], ShouldEqual, "b c")
|
|
So(args[2], ShouldEqual, "c d ")
|
|
})
|
|
|
|
str = `\`
|
|
Convey("Parse Cmd Arguments ["+str+"]", t, func() {
|
|
args = ParseCmdArguments(str)
|
|
So(len(args), ShouldEqual, 1)
|
|
So(args[0], ShouldEqual, "\\")
|
|
})
|
|
|
|
str = ` \ ` // \SPACE
|
|
Convey("Parse Cmd Arguments ["+str+"]", t, func() {
|
|
args = ParseCmdArguments(str)
|
|
So(len(args), ShouldEqual, 1)
|
|
So(args[0], ShouldEqual, " ")
|
|
})
|
|
}
|