diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-02-14 13:23:51 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-02-14 13:23:51 +0100 |
commit | 758ff64c69e34965f8af5b2d6ffd65e8d7ab2150 (patch) | |
tree | 6d6b34f8c678862fe9b56c945a7b63f68502c245 /src/pkg/flag | |
parent | 3e45412327a2654a77944249962b3652e6142299 (diff) | |
download | golang-upstream/2011-02-01.1.tar.gz |
Imported Upstream version 2011-02-01.1upstream/2011-02-01.1
Diffstat (limited to 'src/pkg/flag')
-rw-r--r-- | src/pkg/flag/flag.go | 30 | ||||
-rw-r--r-- | src/pkg/flag/flag_test.go | 15 |
2 files changed, 4 insertions, 41 deletions
diff --git a/src/pkg/flag/flag.go b/src/pkg/flag/flag.go index 04fe2fa05..143a10611 100644 --- a/src/pkg/flag/flag.go +++ b/src/pkg/flag/flag.go @@ -166,22 +166,6 @@ func (s *stringValue) Set(val string) bool { func (s *stringValue) String() string { return fmt.Sprintf("%s", *s) } -// -- Float Value -type floatValue float - -func newFloatValue(val float, p *float) *floatValue { - *p = val - return (*floatValue)(p) -} - -func (f *floatValue) Set(s string) bool { - v, err := strconv.Atof(s) - *f = floatValue(v) - return err == nil -} - -func (f *floatValue) String() string { return fmt.Sprintf("%v", *f) } - // -- Float64 Value type float64Value float64 @@ -385,20 +369,6 @@ func String(name, value string, usage string) *string { return p } -// FloatVar defines a float flag with specified name, default value, and usage string. -// The argument p points to a float variable in which to store the value of the flag. -func FloatVar(p *float, name string, value float, usage string) { - Var(newFloatValue(value, p), name, usage) -} - -// Float defines a float flag with specified name, default value, and usage string. -// The return value is the address of a float variable that stores the value of the flag. -func Float(name string, value float, usage string) *float { - p := new(float) - FloatVar(p, name, value, usage) - return p -} - // Float64Var defines a float64 flag with specified name, default value, and usage string. // The argument p points to a float64 variable in which to store the value of the flag. func Float64Var(p *float64, name string, value float64, usage string) { diff --git a/src/pkg/flag/flag_test.go b/src/pkg/flag/flag_test.go index 4ebb73805..b91a8b567 100644 --- a/src/pkg/flag/flag_test.go +++ b/src/pkg/flag/flag_test.go @@ -18,8 +18,7 @@ var ( test_uint = Uint("test_uint", 0, "uint value") test_uint64 = Uint64("test_uint64", 0, "uint64 value") test_string = String("test_string", "0", "string value") - test_float = Float("test_float", 0, "float value") - test_float64 = Float("test_float64", 0, "float64 value") + test_float64 = Float64("test_float64", 0, "float64 value") ) func boolString(s string) string { @@ -48,7 +47,7 @@ func TestEverything(t *testing.T) { } } VisitAll(visitor) - if len(m) != 8 { + if len(m) != 7 { t.Error("VisitAll misses some flags") for k, v := range m { t.Log(k, *v) @@ -69,11 +68,10 @@ func TestEverything(t *testing.T) { Set("test_uint", "1") Set("test_uint64", "1") Set("test_string", "1") - Set("test_float", "1") Set("test_float64", "1") desired = "1" Visit(visitor) - if len(m) != 8 { + if len(m) != 7 { t.Error("Visit fails after set") for k, v := range m { t.Log(k, *v) @@ -101,8 +99,7 @@ func TestParse(t *testing.T) { uintFlag := Uint("uint", 0, "uint value") uint64Flag := Uint64("uint64", 0, "uint64 value") stringFlag := String("string", "0", "string value") - floatFlag := Float("float", 0, "float value") - float64Flag := Float("float64", 0, "float64 value") + float64Flag := Float64("float64", 0, "float64 value") extra := "one-extra-argument" args := []string{ "a.out", @@ -113,7 +110,6 @@ func TestParse(t *testing.T) { "-uint", "24", "--uint64", "25", "-string", "hello", - "--float", "3141.5", "-float64", "2718e28", extra, } @@ -141,9 +137,6 @@ func TestParse(t *testing.T) { if *stringFlag != "hello" { t.Error("string flag should be `hello`, is ", *stringFlag) } - if *floatFlag != 3141.5 { - t.Error("float flag should be 3141.5, is ", *floatFlag) - } if *float64Flag != 2718e28 { t.Error("float64 flag should be 2718e28, is ", *float64Flag) } |