github.com/coveo/gotemplate@v2.7.7+incompatible/utils/list_test.go (about)

     1  package utils
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/coveo/gotemplate/collections"
     8  	"github.com/coveo/gotemplate/collections/implementation"
     9  )
    10  
    11  type iList = collections.IGenericList
    12  type list = implementation.ListTypeName
    13  
    14  func TestFormatList(t *testing.T) {
    15  	type args struct {
    16  		format string
    17  		v      interface{}
    18  	}
    19  	tests := []struct {
    20  		name string
    21  		args args
    22  		want iList
    23  	}{
    24  		{"quote", args{`"%v"`, []int{1, 2}}, list{`"1"`, `"2"`}},
    25  		{"greating", args{"Hello %v", []int{1, 2}}, list{"Hello 1", "Hello 2"}},
    26  	}
    27  	for _, tt := range tests {
    28  		t.Run(tt.name, func(t *testing.T) {
    29  			if got := FormatList(tt.args.format, tt.args.v); !reflect.DeepEqual(got, tt.want) {
    30  				t.Errorf("FormatList() = %v, want %v", got, tt.want)
    31  			}
    32  		})
    33  	}
    34  }
    35  
    36  func TestMergeLists(t *testing.T) {
    37  	tests := []struct {
    38  		name string
    39  		args []iList
    40  		want iList
    41  	}{
    42  		{"Empty list", nil, nil},
    43  		{"Simple list", []iList{list{1, 2, 3}}, list{1, 2, 3}},
    44  		{"Two lists", []iList{list{1, 2, 3}, list{4, 5, 6}}, list{1, 2, 3, 4, 5, 6}},
    45  		{"Three lists mixed", []iList{list{"One", 2, "3"}, list{4, 5, 6}, list{"7", "8", "9"}}, list{"One", 2, "3", 4, 5, 6, "7", "8", "9"}},
    46  	}
    47  	for _, tt := range tests {
    48  		t.Run(tt.name, func(t *testing.T) {
    49  			if got := MergeLists(tt.args...); !reflect.DeepEqual(got, tt.want) {
    50  				t.Errorf("MergeLists() = %v, want %v", got, tt.want)
    51  			}
    52  		})
    53  	}
    54  }