github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/cli/flags/fixed8_test.go (about) 1 package flags 2 3 import ( 4 "flag" 5 "io" 6 "testing" 7 8 "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestFixed8_String(t *testing.T) { 13 value := fixedn.Fixed8(123) 14 f := Fixed8{ 15 Value: value, 16 } 17 18 require.Equal(t, "0.00000123", f.String()) 19 } 20 21 func TestFixed8_Set(t *testing.T) { 22 value := fixedn.Fixed8(123) 23 f := Fixed8{} 24 25 require.Error(t, f.Set("not-a-fixed8")) 26 27 require.NoError(t, f.Set("0.00000123")) 28 require.Equal(t, value, f.Value) 29 } 30 31 func TestFixed8_Fixed8(t *testing.T) { 32 f := Fixed8{ 33 Value: fixedn.Fixed8(123), 34 } 35 36 require.Equal(t, fixedn.Fixed8(123), f.Fixed8()) 37 } 38 39 func TestFixed8Flag_String(t *testing.T) { 40 flag := Fixed8Flag{ 41 Name: "myFlag", 42 Usage: "Gas amount", 43 } 44 45 require.Equal(t, "--myFlag value\tGas amount", flag.String()) 46 } 47 48 func TestFixed8Flag_GetName(t *testing.T) { 49 flag := Fixed8Flag{ 50 Name: "myFlag", 51 } 52 53 require.Equal(t, "myFlag", flag.GetName()) 54 } 55 56 func TestFixed8(t *testing.T) { 57 f := flag.NewFlagSet("", flag.ContinueOnError) 58 f.SetOutput(io.Discard) // don't pollute test output 59 gas := Fixed8Flag{Name: "gas, g"} 60 gas.Apply(f) 61 require.NoError(t, f.Parse([]string{"--gas", "0.123"})) 62 require.Equal(t, "0.123", f.Lookup("g").Value.String()) 63 require.NoError(t, f.Parse([]string{"-g", "0.456"})) 64 require.Equal(t, "0.456", f.Lookup("g").Value.String()) 65 require.Error(t, f.Parse([]string{"--gas", "kek"})) 66 }