github.com/songzhibin97/gkit@v1.2.13/tools/vto/default_test.go (about)

     1  package vto
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestCompletionDefault(t *testing.T) {
    10  	type (
    11  		mock1 struct {
    12  			String     string   `default:"handsome"`
    13  			Int8       int8     `default:"8"`
    14  			Int16      int16    `default:"16"`
    15  			Int32      int32    `default:"32"`
    16  			Int64      int64    `default:"64"`
    17  			Int        int      `default:"644"`
    18  			Float32    float32  `default:"32.23"`
    19  			Float64    float64  `default:"64.46"`
    20  			Bool       bool     `default:"true"`
    21  			StringPre  *string  `default:"handsome"`
    22  			Int8Pre    *int8    `default:"8"`
    23  			Int16Pre   *int16   `default:"16"`
    24  			Int32Pre   *int32   `default:"32"`
    25  			Int64Pre   *int64   `default:"64"`
    26  			IntPre     *int     `default:"644"`
    27  			Float32Pre *float32 `default:"32.23"`
    28  			Float64Pre *float64 `default:"64.46"`
    29  			BoolPre    *bool    `default:"true"`
    30  		}
    31  
    32  		mock2 struct {
    33  			M1 mock1 `default:"{}"`
    34  		}
    35  
    36  		mock3 struct {
    37  			M1 *mock1 `default:"{}"`
    38  		}
    39  	)
    40  
    41  	var (
    42  		String  = "handsome"
    43  		Int8    = int8(8)
    44  		Int16   = int16(16)
    45  		Int32   = int32(32)
    46  		Int64   = int64(64)
    47  		Int     = 644
    48  		Float32 = float32(32.23)
    49  		Float64 = 64.46
    50  		Bool    = true
    51  	)
    52  
    53  	{
    54  		var m1 mock1
    55  		err := CompletionDefault(&m1)
    56  		assert.NoError(t, err)
    57  		assert.Equal(t, mock1{
    58  			String:     String,
    59  			Int8:       Int8,
    60  			Int16:      Int16,
    61  			Int32:      Int32,
    62  			Int64:      Int64,
    63  			Int:        Int,
    64  			Float32:    Float32,
    65  			Float64:    Float64,
    66  			Bool:       Bool,
    67  			StringPre:  &String,
    68  			Int8Pre:    &Int8,
    69  			Int16Pre:   &Int16,
    70  			Int32Pre:   &Int32,
    71  			Int64Pre:   &Int64,
    72  			IntPre:     &Int,
    73  			Float32Pre: &Float32,
    74  			Float64Pre: &Float64,
    75  			BoolPre:    &Bool,
    76  		}, m1)
    77  	}
    78  
    79  	{
    80  		var m2 mock2
    81  		err := CompletionDefault(&m2)
    82  		assert.NoError(t, err)
    83  		assert.Equal(t, mock2{
    84  			M1: mock1{
    85  				String:     String,
    86  				Int8:       Int8,
    87  				Int16:      Int16,
    88  				Int32:      Int32,
    89  				Int64:      Int64,
    90  				Int:        Int,
    91  				Float32:    Float32,
    92  				Float64:    Float64,
    93  				Bool:       Bool,
    94  				StringPre:  &String,
    95  				Int8Pre:    &Int8,
    96  				Int16Pre:   &Int16,
    97  				Int32Pre:   &Int32,
    98  				Int64Pre:   &Int64,
    99  				IntPre:     &Int,
   100  				Float32Pre: &Float32,
   101  				Float64Pre: &Float64,
   102  				BoolPre:    &Bool,
   103  			},
   104  		}, m2)
   105  	}
   106  
   107  	{
   108  		var m3 mock3
   109  		err := CompletionDefault(&m3)
   110  		assert.NoError(t, err)
   111  		assert.Equal(t, mock3{
   112  			M1: &mock1{},
   113  		}, m3)
   114  	}
   115  }