hub/commands/args_test.go

53 строки
1.2 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-12-10 13:04:36 +04:00
func TestArgs_Words(t *testing.T) {
args := NewArgs([]string{"--no-ff", "master"})
a := args.Words()
assert.Equal(t, 1, len(a))
assert.Equal(t, "master", a[0])
}
2013-12-11 01:29:09 +04:00
func TestArgs_Insert(t *testing.T) {
2013-07-11 03:29:26 +04:00
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-12-11 01:29:09 +04:00
func TestArgs_Remove(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
}