hub/commands/args_test.go

45 строки
1.1 KiB
Go
Исходник Обычный вид История

2013-06-26 19:58:15 +04:00
package commands
import (
"github.com/bmizerany/assert"
"testing"
)
2013-07-02 22:28:50 +04:00
func TestNewArgs(t *testing.T) {
args := NewArgs([]string{})
assert.Equal(t, "", args.Command)
2013-07-02 22:56:45 +04:00
assert.Equal(t, 0, args.ParamsSize())
2013-07-02 22:28:50 +04:00
args = NewArgs([]string{"command"})
assert.Equal(t, "command", args.Command)
2013-07-02 22:56:45 +04:00
assert.Equal(t, 0, args.ParamsSize())
2013-07-02 22:28:50 +04:00
args = NewArgs([]string{"command", "args"})
assert.Equal(t, "command", args.Command)
2013-07-02 22:56:45 +04:00
assert.Equal(t, 1, args.ParamsSize())
2013-07-02 22:28:50 +04:00
}
2013-07-11 03:29:26 +04:00
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])
}
2013-06-26 19:58:15 +04:00
func TestRemove(t *testing.T) {
2013-07-02 22:28:50 +04:00
args := NewArgs([]string{"1", "2", "3", "4"})
2013-06-26 19:58:15 +04:00
2013-07-02 22:56:45 +04:00
item := args.RemoveParam(1)
2013-07-02 22:28:50 +04:00
assert.Equal(t, "3", item)
2013-07-02 22:56:45 +04:00
assert.Equal(t, 2, args.ParamsSize())
assert.Equal(t, "2", args.FirstParam())
assert.Equal(t, "4", args.GetParam(1))
2013-06-26 19:58:15 +04:00
}