2015-09-08 20:07:40 +00:00
|
|
|
package rconfig
|
|
|
|
|
|
|
|
import (
|
2021-09-06 16:43:24 +00:00
|
|
|
"testing"
|
2015-09-08 20:07:40 +00:00
|
|
|
)
|
|
|
|
|
2021-09-06 16:43:24 +00:00
|
|
|
func TestFloatParsing(t *testing.T) {
|
2015-09-08 20:07:40 +00:00
|
|
|
var (
|
|
|
|
args = []string{
|
|
|
|
"--float32=5.5", "-3", "6.6",
|
|
|
|
"--float64=7.7", "-6", "8.8",
|
|
|
|
}
|
2021-09-06 16:43:24 +00:00
|
|
|
cfg struct {
|
|
|
|
Test32 float32 `flag:"float32"`
|
|
|
|
Test32P float32 `flag:"float32p,3"`
|
|
|
|
Test64 float64 `flag:"float64"`
|
|
|
|
Test64P float64 `flag:"float64p,6"`
|
|
|
|
TestDef float32 `default:"66.256"`
|
|
|
|
}
|
|
|
|
)
|
2015-09-08 20:07:40 +00:00
|
|
|
|
2021-09-06 16:43:24 +00:00
|
|
|
if err := parse(&cfg, args); err != nil {
|
|
|
|
t.Fatalf("Parsing options caused error: %s", err)
|
|
|
|
}
|
2015-09-08 20:07:40 +00:00
|
|
|
|
2021-09-06 16:43:24 +00:00
|
|
|
for _, test := range [][2]interface{}{
|
|
|
|
{cfg.Test32, float32(5.5)},
|
|
|
|
{cfg.Test32P, float32(6.6)},
|
|
|
|
{cfg.Test64, float64(7.7)},
|
|
|
|
{cfg.Test64P, float64(8.8)},
|
2015-09-08 20:07:40 +00:00
|
|
|
|
2021-09-06 16:43:24 +00:00
|
|
|
{cfg.TestDef, float32(66.256)},
|
|
|
|
} {
|
|
|
|
if test[0] != test[1] {
|
|
|
|
t.Errorf("Expected value does not match: %#v != %#v", test[0], test[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|