1
0
Fork 0
mirror of https://github.com/Luzifer/rconfig.git synced 2024-11-08 07:50:07 +00:00
rconfig/float_test.go
Knut Ahlers 37f53184c3
Port tests to pure-Go-tests
to remove dependencies to ginkgo and rconfig/v1

Signed-off-by: Knut Ahlers <knut@ahlers.me>
2021-09-06 18:43:24 +02:00

38 lines
796 B
Go

package rconfig
import (
"testing"
)
func TestFloatParsing(t *testing.T) {
var (
args = []string{
"--float32=5.5", "-3", "6.6",
"--float64=7.7", "-6", "8.8",
}
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"`
}
)
if err := parse(&cfg, args); err != nil {
t.Fatalf("Parsing options caused error: %s", err)
}
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)},
{cfg.TestDef, float32(66.256)},
} {
if test[0] != test[1] {
t.Errorf("Expected value does not match: %#v != %#v", test[0], test[1])
}
}
}