github.com/xhebox/bstruct@v0.0.0-20221115052913-86d4d6d98866/field_test.go (about)

     1  package bstruct
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  //func TestMain(m *testing.M) {
    12  
    13  func TestMain(t *testing.T) {
    14  	enc := NewBuilder()
    15  
    16  	buf := new(strings.Builder)
    17  	struc := New(FieldStruct).
    18  		Reg(enc, "Struct1").
    19  		Add("A", New(FieldBool)).
    20  		Add("B", NewSlice(New(FieldBool))).
    21  		Add("C",
    22  			New(FieldStruct).
    23  				Reg(enc, "Struct2").
    24  				Add("A", New(FieldBool)),
    25  		).
    26  		Add("D", NewString()).
    27  		Add("G", NewSlice(NewString())).
    28  		Add("E",
    29  			NewSlice(New(FieldStruct).
    30  				Add("E", NewString())).
    31  				Reg(enc, "Slice1"),
    32  		).
    33  		Add("F", New(FieldBool))
    34  	require.NotNil(t, struc)
    35  	enc.Process()
    36  	require.NoError(t, enc.Print(buf))
    37  	fmt.Printf(buf.String())
    38  }