urfave-cli/context_test.go

47 lines
1.1 KiB
Go
Raw Normal View History

package cli
import (
2013-07-19 00:39:42 +00:00
"flag"
"testing"
)
func Test_New(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Int("myflag", 12, "doc")
globalSet := flag.NewFlagSet("test", 0)
globalSet.Int("myflag", 42, "doc")
c := NewContext(nil, set, globalSet)
expect(t, c.Int("myflag"), 12)
expect(t, c.GlobalInt("myflag"), 42)
}
func Test_Int(t *testing.T) {
2013-07-19 00:39:42 +00:00
set := flag.NewFlagSet("test", 0)
set.Int("myflag", 12, "doc")
c := NewContext(nil, set, set)
2013-07-19 00:39:42 +00:00
expect(t, c.Int("myflag"), 12)
}
func Test_String(t *testing.T) {
2013-07-19 00:39:42 +00:00
set := flag.NewFlagSet("test", 0)
set.String("myflag", "hello world", "doc")
c := NewContext(nil, set, set)
2013-07-19 00:39:42 +00:00
expect(t, c.String("myflag"), "hello world")
}
func Test_Bool(t *testing.T) {
2013-07-19 00:39:42 +00:00
set := flag.NewFlagSet("test", 0)
set.Bool("myflag", false, "doc")
c := NewContext(nil, set, set)
2013-07-19 00:39:42 +00:00
expect(t, c.Bool("myflag"), false)
}
func Test_Args(t *testing.T) {
2013-07-19 00:39:42 +00:00
set := flag.NewFlagSet("test", 0)
set.Bool("myflag", false, "doc")
c := NewContext(nil, set, set)
2013-07-19 00:39:42 +00:00
set.Parse([]string{"--myflag", "bat", "baz"})
expect(t, len(c.Args()), 2)
expect(t, c.Bool("myflag"), true)
}