Some checks are pending
Docs Deploy / build_and_deploy (push) Waiting to run
Generate Docs / cli (push) Waiting to run
Generate Config Doc / cli (push) Waiting to run
Go formatting / go-formatting (push) Waiting to run
Check links / markdown-link-check (push) Waiting to run
Integration / pre-test (push) Waiting to run
Integration / test on (push) Blocked by required conditions
Integration / status (push) Blocked by required conditions
Lint / Lint Go code (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
89 lines
1.9 KiB
Go
89 lines
1.9 KiB
Go
package field
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/ignite/cli/v29/ignite/pkg/multiformatname"
|
|
"github.com/ignite/cli/v29/ignite/templates/field/datatype"
|
|
)
|
|
|
|
// TestField_IsSlice tests the IsSlice method of Field struct.
|
|
func TestField_IsSlice(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
field Field
|
|
expected bool
|
|
}{
|
|
{
|
|
name: "array type should be slice",
|
|
field: Field{
|
|
Name: multiformatname.Name{},
|
|
DatatypeName: datatype.IntSlice,
|
|
Datatype: string(datatype.IntSlice),
|
|
},
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "array type should be slice",
|
|
field: Field{
|
|
Name: multiformatname.Name{},
|
|
DatatypeName: datatype.Bytes,
|
|
Datatype: string(datatype.Bytes),
|
|
},
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "array type should be slice",
|
|
field: Field{
|
|
Name: multiformatname.Name{},
|
|
DatatypeName: datatype.CoinSliceAlias,
|
|
Datatype: string(datatype.CoinSliceAlias),
|
|
},
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "coin type should not be slice",
|
|
field: Field{
|
|
Name: multiformatname.Name{},
|
|
DatatypeName: datatype.Coin,
|
|
Datatype: string(datatype.Coin),
|
|
},
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "string type should not be slice",
|
|
field: Field{
|
|
Name: multiformatname.Name{},
|
|
DatatypeName: datatype.String,
|
|
Datatype: "",
|
|
},
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "int type should not be slice",
|
|
field: Field{
|
|
Name: multiformatname.Name{},
|
|
DatatypeName: datatype.Int,
|
|
Datatype: "",
|
|
},
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "custom array type should be slice",
|
|
field: Field{
|
|
Name: multiformatname.Name{},
|
|
DatatypeName: datatype.CustomSlice,
|
|
Datatype: "Bar",
|
|
},
|
|
expected: true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
require.Equal(t, tc.expected, tc.field.IsSlice())
|
|
})
|
|
}
|
|
}
|