hub/commands/args_test.go

45 строки
1.1 KiB
Go

package commands
import (
"github.com/bmizerany/assert"
"testing"
)
func TestNewArgs(t *testing.T) {
args := NewArgs([]string{})
assert.Equal(t, "", args.Command)
assert.Equal(t, 0, args.ParamsSize())
args = NewArgs([]string{"command"})
assert.Equal(t, "command", args.Command)
assert.Equal(t, 0, args.ParamsSize())
args = NewArgs([]string{"command", "args"})
assert.Equal(t, "command", args.Command)
assert.Equal(t, 1, args.ParamsSize())
}
func TestInsert(t *testing.T) {
args := NewArgs([]string{"command", "1", "2", "3", "4"})
args.InsertParam(0, "foo")
assert.Equal(t, 5, args.ParamsSize())
assert.Equal(t, "foo", args.FirstParam())
args = NewArgs([]string{"command", "1", "2", "3", "4"})
args.InsertParam(3, "foo")
assert.Equal(t, 5, args.ParamsSize())
assert.Equal(t, "foo", args.Params[3])
}
func TestRemove(t *testing.T) {
args := NewArgs([]string{"1", "2", "3", "4"})
item := args.RemoveParam(1)
assert.Equal(t, "3", item)
assert.Equal(t, 2, args.ParamsSize())
assert.Equal(t, "2", args.FirstParam())
assert.Equal(t, "4", args.GetParam(1))
}