2013-07-18 00:00:02 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2013-07-19 00:39:42 +00:00
|
|
|
"flag"
|
|
|
|
"testing"
|
2013-07-18 00:00:02 +00:00
|
|
|
)
|
|
|
|
|
2013-07-19 01:00:52 +00:00
|
|
|
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")
|
2013-07-19 15:34:01 +00:00
|
|
|
c := NewContext(nil, set, globalSet)
|
2013-07-19 01:00:52 +00:00
|
|
|
expect(t, c.Int("myflag"), 12)
|
|
|
|
expect(t, c.GlobalInt("myflag"), 42)
|
|
|
|
}
|
|
|
|
|
2013-07-19 00:29:06 +00:00
|
|
|
func Test_Int(t *testing.T) {
|
2013-07-19 00:39:42 +00:00
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|
set.Int("myflag", 12, "doc")
|
2013-07-19 15:34:01 +00:00
|
|
|
c := NewContext(nil, set, set)
|
2013-07-19 00:39:42 +00:00
|
|
|
expect(t, c.Int("myflag"), 12)
|
2013-07-18 00:00:02 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 00:29:06 +00:00
|
|
|
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")
|
2013-07-19 15:34:01 +00:00
|
|
|
c := NewContext(nil, set, set)
|
2013-07-19 00:39:42 +00:00
|
|
|
expect(t, c.String("myflag"), "hello world")
|
2013-07-18 00:00:02 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 00:29:06 +00:00
|
|
|
func Test_Bool(t *testing.T) {
|
2013-07-19 00:39:42 +00:00
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|
set.Bool("myflag", false, "doc")
|
2013-07-19 15:34:01 +00:00
|
|
|
c := NewContext(nil, set, set)
|
2013-07-19 00:39:42 +00:00
|
|
|
expect(t, c.Bool("myflag"), false)
|
2013-07-18 00:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Test_Args(t *testing.T) {
|
2013-07-19 00:39:42 +00:00
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|
set.Bool("myflag", false, "doc")
|
2013-07-19 15:34:01 +00:00
|
|
|
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)
|
2013-07-18 00:00:02 +00:00
|
|
|
}
|