mirror of
https://github.com/fumiama/ReiBot.git
synced 2026-06-08 20:10:30 +08:00
add more
This commit is contained in:
45
shell_test.go
Normal file
45
shell_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package rei
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_parse(t *testing.T) {
|
||||
shellTests := [...]struct {
|
||||
shell string
|
||||
expected []string
|
||||
}{
|
||||
{`rm -rf /*`, []string{"rm", "-rf", "/*"}},
|
||||
{`echo "cat cat" -n`, []string{"echo", "cat cat", "-n"}},
|
||||
{`shutdown halt init`, []string{"shutdown", "halt", "init"}},
|
||||
{`test test2`, []string{"test", "test2"}},
|
||||
}
|
||||
for i, v := range shellTests {
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
out := ParseShell(v.shell)
|
||||
assert.Equal(t, v.expected, out)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_registerFlag(t *testing.T) {
|
||||
type args struct {
|
||||
RF bool `flag:"rf"`
|
||||
File string `flag:"file"`
|
||||
Count int `flag:"count"`
|
||||
}
|
||||
got := args{}
|
||||
expected := args{
|
||||
RF: true,
|
||||
File: "123",
|
||||
Count: 10,
|
||||
}
|
||||
fs := registerFlag(reflect.TypeOf(args{}), reflect.ValueOf(&got))
|
||||
err := fs.Parse([]string{"-rf", "-file=123", "-count", "10"})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expected, got)
|
||||
}
|
||||
Reference in New Issue
Block a user