45 lines
889 B
Go
45 lines
889 B
Go
package parsing
|
|
|
|
import (
|
|
"math/big"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestCliargs_Parse(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
args []string
|
|
want *big.Int
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "Test with valid integer",
|
|
args: []string{"", "10"}, // the first argument is the program name
|
|
want: big.NewInt(10),
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "Test with non-integer",
|
|
args: []string{"", "abc"}, // the first argument is the program name
|
|
want: nil,
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
os.Args = tt.args
|
|
parser := &Cliargs{}
|
|
got, err := parser.Parse()
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !tt.wantErr && got.Cmp(tt.want) != 0 {
|
|
t.Errorf("Parse() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|