...

Source file src/dario.cat/mergo/issue66_test.go

Documentation: dario.cat/mergo

     1  package mergo_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"dario.cat/mergo"
     7  )
     8  
     9  type PrivateSliceTest66 struct {
    10  	PublicStrings  []string
    11  	privateStrings []string
    12  }
    13  
    14  func TestPrivateSlice(t *testing.T) {
    15  	p1 := PrivateSliceTest66{
    16  		PublicStrings:  []string{"one", "two", "three"},
    17  		privateStrings: []string{"four", "five"},
    18  	}
    19  	p2 := PrivateSliceTest66{
    20  		PublicStrings: []string{"six", "seven"},
    21  	}
    22  
    23  	if err := mergo.Merge(&p1, p2); err != nil {
    24  		t.Errorf("Error during the merge: %v", err)
    25  	}
    26  
    27  	if len(p1.PublicStrings) != 3 {
    28  		t.Error("3 elements should be in 'PublicStrings' field, when no append")
    29  	}
    30  
    31  	if len(p1.privateStrings) != 2 {
    32  		t.Error("2 elements should be in 'privateStrings' field")
    33  	}
    34  }
    35  
    36  func TestPrivateSliceWithAppendSlice(t *testing.T) {
    37  	p1 := PrivateSliceTest66{
    38  		PublicStrings:  []string{"one", "two", "three"},
    39  		privateStrings: []string{"four", "five"},
    40  	}
    41  	p2 := PrivateSliceTest66{
    42  		PublicStrings: []string{"six", "seven"},
    43  	}
    44  
    45  	if err := mergo.Merge(&p1, p2, mergo.WithAppendSlice); err != nil {
    46  		t.Errorf("Error during the merge: %v", err)
    47  	}
    48  
    49  	if len(p1.PublicStrings) != 5 {
    50  		t.Error("5 elements should be in 'PublicStrings' field")
    51  	}
    52  
    53  	if len(p1.privateStrings) != 2 {
    54  		t.Error("2 elements should be in 'privateStrings' field")
    55  	}
    56  }
    57  

View as plain text