github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/sqlx/builder/obj_column_test.go (about)

     1  package builder
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestColumns(t *testing.T) {
    10  	tt := assert.New(t)
    11  
    12  	columns := Columns{}
    13  
    14  	tt.Equal(0, columns.Len())
    15  
    16  	{
    17  		col := columns.AutoIncrement()
    18  		tt.Nil(col)
    19  	}
    20  
    21  	{
    22  		columns.Add(Col(nil, "F_id").Field("ID").Type("bigint(64) unsigned NOT NULL AUTO_INCREMENT"))
    23  
    24  		col := columns.AutoIncrement()
    25  		tt.NotNil(col)
    26  		tt.Equal("F_id", col.Name)
    27  	}
    28  
    29  	tt.Nil(columns.F("ID2"))
    30  	tt.Equal(0, columns.Fields("ID2").Len())
    31  	tt.Equal(1, columns.Fields().Len())
    32  	tt.Len(columns.Fields("ID2").List(), 0)
    33  	tt.Equal(1, columns.Cols("F_id").Len())
    34  	tt.Equal(1, columns.Cols().Len())
    35  	tt.Len(columns.Cols("F_id").List(), 1)
    36  	tt.Equal([]string{"ID"}, columns.Cols("F_id").FieldNames())
    37  }