github.com/coveo/gotemplate@v2.7.7+incompatible/xml/generated_test.go (about)

     1  // This file was automatically generated by genny.
     2  // Any changes will be lost if this file is regenerated.
     3  // see https://github.com/cheekybits/genny
     4  
     5  package xml
     6  
     7  import (
     8  	"fmt"
     9  	"reflect"
    10  	"strings"
    11  	"testing"
    12  
    13  	"github.com/coveo/gotemplate/errors"
    14  	"github.com/stretchr/testify/assert"
    15  )
    16  
    17  var strFixture = xmlList(xmlListHelper.NewStringList(strings.Split("Hello World, I'm Foo Bar!", " ")...).AsArray())
    18  
    19  func Test_list_Append(t *testing.T) {
    20  	t.Parallel()
    21  
    22  	tests := []struct {
    23  		name   string
    24  		l      xmlIList
    25  		values []interface{}
    26  		want   xmlIList
    27  	}{
    28  		{"Empty", xmlList{}, []interface{}{1, 2, 3}, xmlList{1, 2, 3}},
    29  		{"List of int", xmlList{1, 2, 3}, []interface{}{4, 5}, xmlList{1, 2, 3, 4, 5}},
    30  		{"List of string", strFixture, []interface{}{"That's all folks!"}, xmlList{"Hello", "World,", "I'm", "Foo", "Bar!", "That's all folks!"}},
    31  	}
    32  
    33  	for _, tt := range tests {
    34  		t.Run(tt.name, func(t *testing.T) {
    35  			if got := tt.l.Append(tt.values...); !reflect.DeepEqual(got, tt.want) {
    36  				t.Errorf("XmlList.Append():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
    37  			}
    38  		})
    39  	}
    40  }
    41  
    42  func Test_list_Prepend(t *testing.T) {
    43  	t.Parallel()
    44  
    45  	tests := []struct {
    46  		name   string
    47  		l      xmlIList
    48  		values []interface{}
    49  		want   xmlIList
    50  	}{
    51  		{"Empty", xmlList{}, []interface{}{1, 2, 3}, xmlList{1, 2, 3}},
    52  		{"List of int", xmlList{1, 2, 3}, []interface{}{4, 5}, xmlList{4, 5, 1, 2, 3}},
    53  		{"List of string", strFixture, []interface{}{"That's all folks!"}, xmlList{"That's all folks!", "Hello", "World,", "I'm", "Foo", "Bar!"}},
    54  	}
    55  
    56  	for _, tt := range tests {
    57  		t.Run(tt.name, func(t *testing.T) {
    58  			if got := tt.l.Prepend(tt.values...); !reflect.DeepEqual(got, tt.want) {
    59  				t.Errorf("XmlList.Prepend():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
    60  			}
    61  		})
    62  	}
    63  }
    64  
    65  func Test_list_AsArray(t *testing.T) {
    66  	t.Parallel()
    67  
    68  	tests := []struct {
    69  		name string
    70  		l    xmlList
    71  		want []interface{}
    72  	}{
    73  		{"Empty List", xmlList{}, []interface{}{}},
    74  		{"List of int", xmlList{1, 2, 3}, []interface{}{1, 2, 3}},
    75  		{"List of string", strFixture, []interface{}{"Hello", "World,", "I'm", "Foo", "Bar!"}},
    76  	}
    77  	for _, tt := range tests {
    78  		t.Run(tt.name, func(t *testing.T) {
    79  			if got := tt.l.AsArray(); !reflect.DeepEqual(got, tt.want) {
    80  				t.Errorf("XmlList.AsList():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
    81  			}
    82  		})
    83  	}
    84  }
    85  
    86  func Test_XmlList_Strings(t *testing.T) {
    87  	t.Parallel()
    88  
    89  	tests := []struct {
    90  		name string
    91  		l    xmlList
    92  		want []string
    93  	}{
    94  		{"Empty List", xmlList{}, []string{}},
    95  		{"List of int", xmlList{1, 2, 3}, []string{"1", "2", "3"}},
    96  		{"List of string", strFixture, []string{"Hello", "World,", "I'm", "Foo", "Bar!"}},
    97  	}
    98  	for _, tt := range tests {
    99  		t.Run(tt.name, func(t *testing.T) {
   100  			if got := tt.l.Strings(); !reflect.DeepEqual(got, tt.want) {
   101  				t.Errorf("XmlList.Strings() = %v, want %v", got, tt.want)
   102  			}
   103  		})
   104  	}
   105  }
   106  
   107  func Test_list_Capacity(t *testing.T) {
   108  	t.Parallel()
   109  
   110  	tests := []struct {
   111  		name string
   112  		l    xmlIList
   113  		want int
   114  	}{
   115  		{"Empty List with 100 spaces", xmlListHelper.CreateList(0, 100), 100},
   116  	}
   117  	for _, tt := range tests {
   118  		t.Run(tt.name, func(t *testing.T) {
   119  			if got := tt.l.Capacity(); got != tt.want {
   120  				t.Errorf("XmlList.Capacity() = %v, want %v", got, tt.want)
   121  			}
   122  			if tt.l.Capacity() != tt.l.Cap() {
   123  				t.Errorf("Cap and Capacity return different values")
   124  			}
   125  		})
   126  	}
   127  }
   128  
   129  func Test_list_Clone(t *testing.T) {
   130  	t.Parallel()
   131  
   132  	tests := []struct {
   133  		name string
   134  		l    xmlList
   135  		want xmlIList
   136  	}{
   137  		{"Empty List", xmlList{}, xmlList{}},
   138  		{"List of int", xmlList{1, 2, 3}, xmlList{1, 2, 3}},
   139  		{"List of string", strFixture, xmlList{"Hello", "World,", "I'm", "Foo", "Bar!"}},
   140  	}
   141  	for _, tt := range tests {
   142  		t.Run(tt.name, func(t *testing.T) {
   143  			if got := tt.l.Clone(); !reflect.DeepEqual(got, tt.want) {
   144  				t.Errorf("XmlList.Clone():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   145  			}
   146  		})
   147  	}
   148  }
   149  
   150  func Test_list_Get(t *testing.T) {
   151  	t.Parallel()
   152  
   153  	tests := []struct {
   154  		name    string
   155  		l       xmlList
   156  		indexes []int
   157  		want    interface{}
   158  	}{
   159  		{"Empty List", xmlList{}, []int{0}, nil},
   160  		{"Negative index", xmlList{}, []int{-1}, nil},
   161  		{"List of int", xmlList{1, 2, 3}, []int{0}, 1},
   162  		{"List of string", strFixture, []int{1}, "World,"},
   163  		{"Get last", strFixture, []int{-1}, "Bar!"},
   164  		{"Get before last", strFixture, []int{-2}, "Foo"},
   165  		{"A way to before last", strFixture, []int{-12}, nil},
   166  		{"Get nothing", strFixture, nil, nil},
   167  	}
   168  	for _, tt := range tests {
   169  		t.Run(tt.name, func(t *testing.T) {
   170  			if got := tt.l.Get(tt.indexes...); !reflect.DeepEqual(got, tt.want) {
   171  				t.Errorf("XmlList.Get() = %v, want %v", got, tt.want)
   172  			}
   173  		})
   174  	}
   175  }
   176  
   177  func Test_list_Len(t *testing.T) {
   178  	t.Parallel()
   179  
   180  	tests := []struct {
   181  		name string
   182  		l    xmlList
   183  		want int
   184  	}{
   185  		{"Empty List", xmlList{}, 0},
   186  		{"List of int", xmlList{1, 2, 3}, 3},
   187  		{"List of string", strFixture, 5},
   188  	}
   189  	for _, tt := range tests {
   190  		t.Run(tt.name, func(t *testing.T) {
   191  			if got := tt.l.Len(); got != tt.want {
   192  				t.Errorf("XmlList.Len() = %v, want %v", got, tt.want)
   193  			}
   194  			if tt.l.Len() != tt.l.Count() {
   195  				t.Errorf("Len and Count return different values")
   196  			}
   197  		})
   198  	}
   199  }
   200  
   201  func Test_CreateList(t *testing.T) {
   202  	t.Parallel()
   203  
   204  	tests := []struct {
   205  		name    string
   206  		args    []int
   207  		want    xmlIList
   208  		wantErr bool
   209  	}{
   210  		{"Empty", nil, xmlList{}, false},
   211  		{"With nil elements", []int{10}, make(xmlList, 10), false},
   212  		{"With capacity", []int{0, 10}, make(xmlList, 0, 10), false},
   213  		{"Too much args", []int{0, 10, 1}, nil, true},
   214  	}
   215  	for _, tt := range tests {
   216  		var err error
   217  		t.Run(tt.name, func(t *testing.T) {
   218  			defer func() { err = errors.Trap(err, recover()) }()
   219  			got := xmlListHelper.CreateList(tt.args...)
   220  			if !reflect.DeepEqual(got, tt.want) {
   221  				t.Errorf("CreateList():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   222  			}
   223  			if got.Capacity() != tt.want.Cap() {
   224  				t.Errorf("CreateList() capacity:\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got.Cap(), tt.want.Capacity())
   225  			}
   226  		})
   227  		if (err != nil) != tt.wantErr {
   228  			t.Errorf("CreateList() error = %v, wantErr %v", err, tt.wantErr)
   229  		}
   230  	}
   231  }
   232  
   233  func Test_list_Create(t *testing.T) {
   234  	t.Parallel()
   235  
   236  	tests := []struct {
   237  		name string
   238  		l    xmlList
   239  		args []int
   240  		want xmlIList
   241  	}{
   242  		{"Empty", nil, nil, xmlList{}},
   243  		{"Existing List", xmlList{1, 2}, nil, xmlList{}},
   244  		{"With Empty spaces", xmlList{1, 2}, []int{5}, xmlList{nil, nil, nil, nil, nil}},
   245  		{"With Capacity", xmlList{1, 2}, []int{0, 5}, xmlListHelper.CreateList(0, 5)},
   246  	}
   247  	for _, tt := range tests {
   248  		t.Run(tt.name, func(t *testing.T) {
   249  			got := tt.l.Create(tt.args...)
   250  			if !reflect.DeepEqual(got, tt.want) {
   251  				t.Errorf("XmlList.Create():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   252  			}
   253  			if got.Capacity() != tt.want.Capacity() {
   254  				t.Errorf("XmlList.Create() capacity:\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got.Capacity(), tt.want.Capacity())
   255  			}
   256  		})
   257  	}
   258  }
   259  
   260  func Test_list_New(t *testing.T) {
   261  	t.Parallel()
   262  
   263  	tests := []struct {
   264  		name string
   265  		l    xmlList
   266  		args []interface{}
   267  		want xmlIList
   268  	}{
   269  		{"Empty", nil, nil, xmlList{}},
   270  		{"Existing List", xmlList{1, 2}, nil, xmlList{}},
   271  		{"With elements", xmlList{1, 2}, []interface{}{3, 4, 5}, xmlList{3, 4, 5}},
   272  		{"With strings", xmlList{1, 2}, []interface{}{"Hello", "World"}, xmlList{"Hello", "World"}},
   273  		{"With nothing", xmlList{1, 2}, []interface{}{}, xmlList{}},
   274  		{"With nil", xmlList{1, 2}, nil, xmlList{}},
   275  		{"Adding array", xmlList{1, 2}, []interface{}{xmlList{3, 4}}, xmlList{3, 4}},
   276  	}
   277  	for _, tt := range tests {
   278  		t.Run(tt.name, func(t *testing.T) {
   279  			if got := tt.l.New(tt.args...); !reflect.DeepEqual(got, tt.want) {
   280  				t.Errorf("XmlList.Create():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   281  			}
   282  		})
   283  	}
   284  }
   285  
   286  func Test_list_CreateDict(t *testing.T) {
   287  	t.Parallel()
   288  
   289  	tests := []struct {
   290  		name    string
   291  		l       xmlList
   292  		args    []int
   293  		want    xmlIDict
   294  		wantErr bool
   295  	}{
   296  		{"Empty", nil, nil, xmlDict{}, false},
   297  		{"With capacity", nil, []int{10}, xmlDict{}, false},
   298  		{"With too much parameter", nil, []int{10, 1}, nil, true},
   299  	}
   300  	for _, tt := range tests {
   301  		var err error
   302  		t.Run(tt.name, func(t *testing.T) {
   303  			defer func() { err = errors.Trap(err, recover()) }()
   304  			got := tt.l.CreateDict(tt.args...)
   305  			if !reflect.DeepEqual(got, tt.want) {
   306  				t.Errorf("XmlList.CreateDict():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   307  			}
   308  		})
   309  		if (err != nil) != tt.wantErr {
   310  			t.Errorf("XmlList.CreateDict() error = %v, wantErr %v", err, tt.wantErr)
   311  			return
   312  		}
   313  	}
   314  }
   315  
   316  func Test_list_Contains(t *testing.T) {
   317  	t.Parallel()
   318  
   319  	tests := []struct {
   320  		name string
   321  		l    xmlList
   322  		args []interface{}
   323  		want bool
   324  	}{
   325  		{"Empty List", nil, []interface{}{}, false},
   326  		{"Search nothing", xmlList{1}, nil, true},
   327  		{"Search nothing 2", xmlList{1}, []interface{}{}, true},
   328  		{"Not there", xmlList{1}, []interface{}{2}, false},
   329  		{"Included", xmlList{1, 2}, []interface{}{2}, true},
   330  		{"Partially there", xmlList{1, 2}, []interface{}{2, 3}, false},
   331  	}
   332  	for _, tt := range tests {
   333  		t.Run(tt.name, func(t *testing.T) {
   334  			if got := tt.l.Contains(tt.args...); !reflect.DeepEqual(got, tt.want) {
   335  				t.Errorf("XmlList.Contains():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   336  			}
   337  			if got := tt.l.Has(tt.args...); !reflect.DeepEqual(got, tt.want) {
   338  				t.Errorf("XmlList.Has():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   339  			}
   340  		})
   341  	}
   342  }
   343  
   344  func Test_list_First_Last(t *testing.T) {
   345  	t.Parallel()
   346  
   347  	tests := []struct {
   348  		name      string
   349  		l         xmlList
   350  		wantFirst interface{}
   351  		wantLast  interface{}
   352  	}{
   353  		{"Nil", nil, nil, nil},
   354  		{"Empty", xmlList{}, nil, nil},
   355  		{"One element", xmlList{1}, 1, 1},
   356  		{"Many element ", xmlList{1, "two", 3.1415, "four"}, 1, "four"},
   357  	}
   358  	for _, tt := range tests {
   359  		t.Run(tt.name, func(t *testing.T) {
   360  			if got := tt.l.First(); !reflect.DeepEqual(got, tt.wantFirst) {
   361  				t.Errorf("XmlList.First():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.wantFirst)
   362  			}
   363  			if got := tt.l.Last(); !reflect.DeepEqual(got, tt.wantLast) {
   364  				t.Errorf("XmlList.Last():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.wantLast)
   365  			}
   366  		})
   367  	}
   368  }
   369  
   370  func Test_list_Pop(t *testing.T) {
   371  	t.Parallel()
   372  
   373  	tests := []struct {
   374  		name     string
   375  		l        xmlList
   376  		args     []int
   377  		want     interface{}
   378  		wantList xmlList
   379  	}{
   380  		{"Nil", nil, nil, nil, xmlList{}},
   381  		{"Empty", xmlList{}, nil, nil, xmlList{}},
   382  		{"Non existent", xmlList{}, []int{1}, nil, xmlList{}},
   383  		{"Empty with args", xmlList{}, []int{1, 3}, xmlList{nil, nil}, xmlList{}},
   384  		{"List with bad index", xmlList{0, 1, 2, 3, 4, 5}, []int{1, 3, 8}, xmlList{1, 3, nil}, xmlList{0, 2, 4, 5}},
   385  		{"Pop last element", xmlList{0, 1, 2, 3, 4, 5}, nil, 5, xmlList{0, 1, 2, 3, 4}},
   386  		{"Pop before last", xmlList{0, 1, 2, 3, 4, 5}, []int{-2}, 4, xmlList{0, 1, 2, 3, 5}},
   387  		{"Pop first element", xmlList{0, 1, 2, 3, 4, 5}, []int{0}, 0, xmlList{1, 2, 3, 4, 5}},
   388  		{"Pop all", xmlList{0, 1, 2, 3}, []int{0, 1, 2, 3}, xmlList{0, 1, 2, 3}, xmlList{}},
   389  		{"Pop same element many time", xmlList{0, 1, 2, 3}, []int{1, 1, 2, 2}, xmlList{1, 1, 2, 2}, xmlList{0, 3}},
   390  	}
   391  	for _, tt := range tests {
   392  		t.Run(tt.name, func(t *testing.T) {
   393  			got, gotL := tt.l.Pop(tt.args...)
   394  			if !reflect.DeepEqual(got, tt.want) {
   395  				t.Errorf("XmlList.Pop():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   396  			}
   397  			if !reflect.DeepEqual(gotL, tt.wantList) {
   398  				t.Errorf("XmlList.Pop():\ngotList %[1]v (%[1]T)\n   want %[2]v (%[2]T)", gotL, tt.wantList)
   399  			}
   400  		})
   401  	}
   402  }
   403  
   404  func Test_list_Intersect(t *testing.T) {
   405  	t.Parallel()
   406  
   407  	tests := []struct {
   408  		name string
   409  		l    xmlList
   410  		args []interface{}
   411  		want xmlList
   412  	}{
   413  		{"Empty List", nil, []interface{}{}, xmlList{}},
   414  		{"Intersect nothing", xmlList{1}, nil, xmlList{}},
   415  		{"Intersect nothing 2", xmlList{1}, []interface{}{}, xmlList{}},
   416  		{"Not there", xmlList{1}, []interface{}{2}, xmlList{}},
   417  		{"Included", xmlList{1, 2}, []interface{}{2}, xmlList{2}},
   418  		{"Partially there", xmlList{1, 2}, []interface{}{2, 3}, xmlList{2}},
   419  		{"With duplicates", xmlList{1, 2, 3, 4, 5, 4, 3, 2, 1}, []interface{}{3, 4, 5, 6, 7, 8, 7, 6, 5, 5, 4, 3}, xmlList{3, 4, 5}},
   420  	}
   421  	for _, tt := range tests {
   422  		t.Run(tt.name, func(t *testing.T) {
   423  			if got := tt.l.Intersect(tt.args...); !reflect.DeepEqual(got, tt.want) {
   424  				t.Errorf("XmlList.Intersect():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   425  			}
   426  		})
   427  	}
   428  }
   429  
   430  func Test_list_Union(t *testing.T) {
   431  	t.Parallel()
   432  
   433  	tests := []struct {
   434  		name string
   435  		l    xmlList
   436  		args []interface{}
   437  		want xmlList
   438  	}{
   439  		{"Empty List", nil, []interface{}{}, xmlList{}},
   440  		{"Intersect nothing", xmlList{1}, nil, xmlList{1}},
   441  		{"Intersect nothing 2", xmlList{1}, []interface{}{}, xmlList{1}},
   442  		{"Not there", xmlList{1}, []interface{}{2}, xmlList{1, 2}},
   443  		{"Included", xmlList{1, 2}, []interface{}{2}, xmlList{1, 2}},
   444  		{"Partially there", xmlList{1, 2}, []interface{}{2, 3}, xmlList{1, 2, 3}},
   445  		{"With duplicates", xmlList{1, 2, 3, 4, 5, 4, 3, 2, 1}, []interface{}{8, 7, 6, 5, 6, 7, 8}, xmlList{1, 2, 3, 4, 5, 8, 7, 6}},
   446  	}
   447  	for _, tt := range tests {
   448  		t.Run(tt.name, func(t *testing.T) {
   449  			if got := tt.l.Union(tt.args...); !reflect.DeepEqual(got, tt.want) {
   450  				t.Errorf("XmlList.Union():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   451  			}
   452  		})
   453  	}
   454  }
   455  
   456  func Test_list_Without(t *testing.T) {
   457  	t.Parallel()
   458  
   459  	tests := []struct {
   460  		name string
   461  		l    xmlList
   462  		args []interface{}
   463  		want xmlList
   464  	}{
   465  		{"Empty List", nil, []interface{}{}, xmlList{}},
   466  		{"Remove nothing", xmlList{1}, nil, xmlList{1}},
   467  		{"Remove nothing 2", xmlList{1}, []interface{}{}, xmlList{1}},
   468  		{"Not there", xmlList{1}, []interface{}{2}, xmlList{1}},
   469  		{"Included", xmlList{1, 2}, []interface{}{2}, xmlList{1}},
   470  		{"Partially there", xmlList{1, 2}, []interface{}{2, 3}, xmlList{1}},
   471  	}
   472  	for _, tt := range tests {
   473  		t.Run(tt.name, func(t *testing.T) {
   474  			if got := tt.l.Without(tt.args...); !reflect.DeepEqual(got, tt.want) {
   475  				t.Errorf("XmlList.Without():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   476  			}
   477  		})
   478  	}
   479  }
   480  
   481  func Test_list_Unique(t *testing.T) {
   482  	t.Parallel()
   483  
   484  	tests := []struct {
   485  		name string
   486  		l    xmlList
   487  		want xmlList
   488  	}{
   489  		{"Empty List", nil, xmlList{}},
   490  		{"Remove nothing", xmlList{1}, xmlList{1}},
   491  		{"Duplicates following", xmlList{1, 1, 2, 3}, xmlList{1, 2, 3}},
   492  		{"Duplicates not following", xmlList{1, 2, 3, 1, 2, 3, 4}, xmlList{1, 2, 3, 4}},
   493  	}
   494  	for _, tt := range tests {
   495  		t.Run(tt.name, func(t *testing.T) {
   496  			if got := tt.l.Unique(); !reflect.DeepEqual(got, tt.want) {
   497  				t.Errorf("XmlList.Unique():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   498  			}
   499  		})
   500  	}
   501  }
   502  func Test_list_Reverse(t *testing.T) {
   503  	t.Parallel()
   504  
   505  	tests := []struct {
   506  		name string
   507  		l    xmlList
   508  		want xmlIList
   509  	}{
   510  		{"Empty List", xmlList{}, xmlList{}},
   511  		{"List of int", xmlList{1, 2, 3}, xmlList{3, 2, 1}},
   512  		{"List of string", strFixture, xmlList{"Bar!", "Foo", "I'm", "World,", "Hello"}},
   513  	}
   514  	for _, tt := range tests {
   515  		t.Run(tt.name, func(t *testing.T) {
   516  			l := tt.l.Clone()
   517  			if got := l.Reverse(); !reflect.DeepEqual(got, tt.want) {
   518  				t.Errorf("XmlList.Reverse():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   519  			}
   520  		})
   521  	}
   522  }
   523  
   524  func Test_list_Set(t *testing.T) {
   525  	t.Parallel()
   526  
   527  	type args struct {
   528  		i int
   529  		v interface{}
   530  	}
   531  	tests := []struct {
   532  		name    string
   533  		l       xmlIList
   534  		args    args
   535  		want    xmlIList
   536  		wantErr bool
   537  	}{
   538  		{"Empty", xmlList{}, args{2, 1}, xmlList{nil, nil, 1}, false},
   539  		{"List of int", xmlList{1, 2, 3}, args{0, 10}, xmlList{10, 2, 3}, false},
   540  		{"List of string", strFixture, args{2, "You're"}, xmlList{"Hello", "World,", "You're", "Foo", "Bar!"}, false},
   541  		{"Negative", xmlList{}, args{-1, "negative value"}, nil, true},
   542  	}
   543  	for _, tt := range tests {
   544  		t.Run(tt.name, func(t *testing.T) {
   545  			got, err := tt.l.Clone().Set(tt.args.i, tt.args.v)
   546  			if (err != nil) != tt.wantErr {
   547  				t.Errorf("XmlList.Set() error = %v, wantErr %v", err, tt.wantErr)
   548  				return
   549  			}
   550  			if !reflect.DeepEqual(got, tt.want) {
   551  				t.Errorf("XmlList.Set():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   552  			}
   553  		})
   554  	}
   555  }
   556  
   557  var mapFixture = map[string]interface{}{
   558  	"int":     123,
   559  	"float":   1.23,
   560  	"string":  "Foo bar",
   561  	"list":    []interface{}{1, "two"},
   562  	"listInt": []int{1, 2, 3},
   563  	"map": map[string]interface{}{
   564  		"sub1": 1,
   565  		"sub2": "two",
   566  	},
   567  	"mapInt": map[int]interface{}{
   568  		1: 1,
   569  		2: "two",
   570  	},
   571  }
   572  
   573  var dictFixture = xmlDict(xmlDictHelper.AsDictionary(mapFixture).AsMap())
   574  
   575  func dumpKeys(t *testing.T, d1, d2 xmlIDict) {
   576  	t.Parallel()
   577  
   578  	for key := range d1.AsMap() {
   579  		v1, v2 := d1.Get(key), d2.Get(key)
   580  		if reflect.DeepEqual(v1, v2) {
   581  			continue
   582  		}
   583  		t.Logf("'%[1]v' = %[2]v (%[2]T) vs %[3]v (%[3]T)", key, v1, v2)
   584  	}
   585  }
   586  
   587  func Test_dict_AsMap(t *testing.T) {
   588  	t.Parallel()
   589  
   590  	tests := []struct {
   591  		name string
   592  		d    xmlDict
   593  		want map[string]interface{}
   594  	}{
   595  		{"Nil", nil, nil},
   596  		{"Empty", xmlDict{}, map[string]interface{}{}},
   597  		{"Map", dictFixture, map[string]interface{}(dictFixture)},
   598  	}
   599  	for _, tt := range tests {
   600  		t.Run(tt.name, func(t *testing.T) {
   601  			if got := tt.d.AsMap(); !reflect.DeepEqual(got, tt.want) {
   602  				t.Errorf("XmlDict.AsMap():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   603  			}
   604  		})
   605  	}
   606  }
   607  
   608  func Test_dict_Clone(t *testing.T) {
   609  	t.Parallel()
   610  
   611  	tests := []struct {
   612  		name string
   613  		d    xmlDict
   614  		keys []interface{}
   615  		want xmlIDict
   616  	}{
   617  		{"Nil", nil, nil, xmlDict{}},
   618  		{"Empty", xmlDict{}, nil, xmlDict{}},
   619  		{"Map", dictFixture, nil, dictFixture},
   620  		{"Map with Fields", dictFixture, []interface{}{"int", "list"}, xmlDict(dictFixture).Omit("float", "string", "listInt", "map", "mapInt")},
   621  	}
   622  	for _, tt := range tests {
   623  		t.Run(tt.name, func(t *testing.T) {
   624  			got := tt.d.Clone(tt.keys...)
   625  			if !reflect.DeepEqual(got, tt.want) {
   626  				t.Errorf("XmlDict.Clone():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   627  				dumpKeys(t, got, tt.want)
   628  			}
   629  
   630  			// Ensure that the copy is distinct from the original
   631  			got.Set("NewFields", "Test")
   632  			if reflect.DeepEqual(got, tt.want) {
   633  				t.Errorf("Should be different:\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   634  			}
   635  			if !got.Has("NewFields") || !reflect.DeepEqual(got.Get("NewFields"), "Test") {
   636  				t.Errorf("Element has not been added")
   637  			}
   638  			if got.Len() != tt.want.Count()+1 {
   639  				t.Errorf("Len and Count don't return the same value")
   640  			}
   641  		})
   642  	}
   643  }
   644  
   645  func Test_XmlDict_CreateList(t *testing.T) {
   646  	t.Parallel()
   647  
   648  	tests := []struct {
   649  		name         string
   650  		d            xmlDict
   651  		args         []int
   652  		want         xmlIList
   653  		wantLen      int
   654  		wantCapacity int
   655  	}{
   656  		{"Nil", nil, nil, xmlList{}, 0, 0},
   657  		{"Empty", xmlDict{}, nil, xmlList{}, 0, 0},
   658  		{"Map", dictFixture, nil, xmlList{}, 0, 0},
   659  		{"Map with size", dictFixture, []int{3}, xmlList{nil, nil, nil}, 3, 3},
   660  		{"Map with capacity", dictFixture, []int{0, 10}, xmlList{}, 0, 10},
   661  		{"Map with size&capacity", dictFixture, []int{3, 10}, xmlList{nil, nil, nil}, 3, 10},
   662  	}
   663  	for _, tt := range tests {
   664  		t.Run(tt.name, func(t *testing.T) {
   665  			got := tt.d.CreateList(tt.args...)
   666  			if !reflect.DeepEqual(got, tt.want) {
   667  				t.Errorf("XmlDict.CreateList() = %v, want %v", got, tt.want)
   668  			}
   669  			if got.Len() != tt.wantLen || got.Cap() != tt.wantCapacity {
   670  				t.Errorf("XmlDict.CreateList() size: %d, %d vs %d, %d", got.Len(), got.Cap(), tt.wantLen, tt.wantCapacity)
   671  			}
   672  		})
   673  	}
   674  }
   675  
   676  func Test_dict_Create(t *testing.T) {
   677  	t.Parallel()
   678  
   679  	tests := []struct {
   680  		name    string
   681  		d       xmlDict
   682  		args    []int
   683  		want    xmlIDict
   684  		wantErr bool
   685  	}{
   686  		{"Empty", nil, nil, xmlDict{}, false},
   687  		{"With capacity", nil, []int{10}, xmlDict{}, false},
   688  		{"With too much parameter", nil, []int{10, 1}, nil, true},
   689  	}
   690  	for _, tt := range tests {
   691  		var err error
   692  		t.Run(tt.name, func(t *testing.T) {
   693  			defer func() { err = errors.Trap(err, recover()) }()
   694  			got := tt.d.Create(tt.args...)
   695  			if !reflect.DeepEqual(got, tt.want) {
   696  				t.Errorf("XmlDict.Create():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   697  			}
   698  		})
   699  		if (err != nil) != tt.wantErr {
   700  			t.Errorf("XmlList.Create() error = %v, wantErr %v", err, tt.wantErr)
   701  			return
   702  		}
   703  	}
   704  }
   705  
   706  func Test_dict_Default(t *testing.T) {
   707  	t.Parallel()
   708  
   709  	type args struct {
   710  		key    interface{}
   711  		defVal interface{}
   712  	}
   713  	tests := []struct {
   714  		name string
   715  		d    xmlDict
   716  		args args
   717  		want interface{}
   718  	}{
   719  		{"Empty", nil, args{"Foo", "Bar"}, "Bar"},
   720  		{"Map int", dictFixture, args{"int", 1}, 123},
   721  		{"Map float", dictFixture, args{"float", 1}, 1.23},
   722  		{"Map Non existant", dictFixture, args{"Foo", "Bar"}, "Bar"},
   723  	}
   724  	for _, tt := range tests {
   725  		t.Run(tt.name, func(t *testing.T) {
   726  			if got := tt.d.Default(tt.args.key, tt.args.defVal); !reflect.DeepEqual(got, tt.want) {
   727  				t.Errorf("XmlDict.Default() = %v, want %v", got, tt.want)
   728  			}
   729  		})
   730  	}
   731  }
   732  
   733  func Test_dict_Delete(t *testing.T) {
   734  	t.Parallel()
   735  
   736  	type args struct {
   737  		key  interface{}
   738  		keys []interface{}
   739  	}
   740  	tests := []struct {
   741  		name    string
   742  		d       xmlDict
   743  		args    args
   744  		want    xmlIDict
   745  		wantErr bool
   746  	}{
   747  		{"Empty", nil, args{}, xmlDict{}, true},
   748  		{"Map", dictFixture, args{}, dictFixture, true},
   749  		{"Non existant key", dictFixture, args{"Test", nil}, dictFixture, true},
   750  		{"Map with keys", dictFixture, args{"int", []interface{}{"list"}}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt"), false},
   751  		{"Map with keys + non existant", dictFixture, args{"int", []interface{}{"list", "Test"}}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt"), true},
   752  	}
   753  	for _, tt := range tests {
   754  		t.Run(tt.name, func(t *testing.T) {
   755  			d := tt.d.Clone()
   756  			got, err := d.Delete(tt.args.key, tt.args.keys...)
   757  			if (err != nil) != tt.wantErr {
   758  				t.Errorf("XmlDict.Delete() error = %v, wantErr %v", err, tt.wantErr)
   759  				return
   760  			}
   761  			if !reflect.DeepEqual(got, tt.want) {
   762  				t.Errorf("XmlDict.Delete():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   763  				dumpKeys(t, got, tt.want)
   764  			}
   765  		})
   766  	}
   767  }
   768  
   769  func Test_dict_Flush(t *testing.T) {
   770  	t.Parallel()
   771  
   772  	tests := []struct {
   773  		name string
   774  		d    xmlDict
   775  		keys []interface{}
   776  		want xmlIDict
   777  	}{
   778  		{"Empty", nil, nil, xmlDict{}},
   779  		{"Map", dictFixture, nil, xmlDict{}},
   780  		{"Non existant key", dictFixture, []interface{}{"Test"}, dictFixture},
   781  		{"Map with keys", dictFixture, []interface{}{"int", "list"}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt")},
   782  		{"Map with keys + non existant", dictFixture, []interface{}{"int", "list", "Test"}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt")},
   783  	}
   784  	for _, tt := range tests {
   785  		t.Run(tt.name, func(t *testing.T) {
   786  			d := tt.d.Clone()
   787  			got := d.Flush(tt.keys...)
   788  			if !reflect.DeepEqual(got, tt.want) {
   789  				t.Errorf("XmlDict.Flush():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   790  				dumpKeys(t, got, tt.want)
   791  			}
   792  			if !reflect.DeepEqual(d, got) {
   793  				t.Errorf("Should be equal after: %v, want %v", d, got)
   794  				dumpKeys(t, d, got)
   795  			}
   796  		})
   797  	}
   798  }
   799  
   800  func Test_dict_Keys(t *testing.T) {
   801  	t.Parallel()
   802  
   803  	tests := []struct {
   804  		name string
   805  		d    xmlDict
   806  		want xmlIList
   807  	}{
   808  		{"Empty", nil, xmlList{}},
   809  		{"Map", dictFixture, xmlList{str("float"), str("int"), str("list"), str("listInt"), str("map"), str("mapInt"), str("string")}},
   810  	}
   811  	for _, tt := range tests {
   812  		t.Run(tt.name, func(t *testing.T) {
   813  			if got := tt.d.GetKeys(); !reflect.DeepEqual(got, tt.want) {
   814  				t.Errorf("XmlDict.GetKeys():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   815  			}
   816  		})
   817  	}
   818  }
   819  
   820  func Test_dict_KeysAsString(t *testing.T) {
   821  	t.Parallel()
   822  
   823  	tests := []struct {
   824  		name string
   825  		d    xmlDict
   826  		want strArray
   827  	}{
   828  		{"Empty", nil, strArray{}},
   829  		{"Map", dictFixture, strArray{"float", "int", "list", "listInt", "map", "mapInt", "string"}},
   830  	}
   831  	for _, tt := range tests {
   832  		t.Run(tt.name, func(t *testing.T) {
   833  			if got := tt.d.KeysAsString(); !reflect.DeepEqual(got, tt.want) {
   834  				t.Errorf("XmlDict.KeysAsString():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   835  			}
   836  		})
   837  	}
   838  }
   839  
   840  func Test_dict_Merge(t *testing.T) {
   841  	t.Parallel()
   842  
   843  	adding1 := xmlDict{
   844  		"int":        1000,
   845  		"Add1Int":    1,
   846  		"Add1String": "string",
   847  	}
   848  	adding2 := xmlDict{
   849  		"Add2Int":    1,
   850  		"Add2String": "string",
   851  		"map": map[string]interface{}{
   852  			"sub1":   2,
   853  			"newVal": "NewValue",
   854  		},
   855  	}
   856  	type args struct {
   857  		xmlDict xmlIDict
   858  		dicts   []xmlIDict
   859  	}
   860  	tests := []struct {
   861  		name string
   862  		d    xmlDict
   863  		args args
   864  		want xmlIDict
   865  	}{
   866  		{"Empty", nil, args{nil, []xmlIDict{}}, xmlDict{}},
   867  		{"Add map to empty", nil, args{dictFixture, []xmlIDict{}}, dictFixture},
   868  		{"Add map to same map", dictFixture, args{dictFixture, []xmlIDict{}}, dictFixture},
   869  		{"Add empty to map", dictFixture, args{nil, []xmlIDict{}}, dictFixture},
   870  		{"Add new1 to map", dictFixture, args{adding1, []xmlIDict{}}, dictFixture.Clone().Merge(adding1)},
   871  		{"Add new2 to map", dictFixture, args{adding2, []xmlIDict{}}, dictFixture.Clone().Merge(adding2)},
   872  		{"Add new1 & new2 to map", dictFixture, args{adding1, []xmlIDict{adding2}}, dictFixture.Clone().Merge(adding1, adding2)},
   873  		{"Add new1 & new2 to map", dictFixture, args{adding1, []xmlIDict{adding2}}, dictFixture.Clone().Merge(adding1).Merge(adding2)},
   874  	}
   875  	for _, tt := range tests {
   876  		go t.Run(tt.name, func(t *testing.T) {
   877  			d := tt.d.Clone()
   878  			got := d.Merge(tt.args.xmlDict, tt.args.dicts...)
   879  			if !reflect.DeepEqual(got, tt.want) {
   880  				t.Errorf("XmlDict.Merge():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   881  				dumpKeys(t, got, tt.want)
   882  			}
   883  		})
   884  	}
   885  }
   886  
   887  func Test_dict_Values(t *testing.T) {
   888  	t.Parallel()
   889  
   890  	tests := []struct {
   891  		name string
   892  		d    xmlDict
   893  		want xmlIList
   894  	}{
   895  		{"Empty", nil, xmlList{}},
   896  		{"Map", dictFixture, xmlList{1.23, 123, xmlList{1, "two"}, xmlList{1, 2, 3}, xmlDict{"sub1": 1, "sub2": "two"}, xmlDict{"1": 1, "2": "two"}, "Foo bar"}},
   897  	}
   898  	for _, tt := range tests {
   899  		t.Run(tt.name, func(t *testing.T) {
   900  			if got := tt.d.GetValues(); !reflect.DeepEqual(got, tt.want) {
   901  				t.Errorf("XmlDict.GetValues():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   902  			}
   903  		})
   904  	}
   905  }
   906  
   907  func Test_dict_Pop(t *testing.T) {
   908  	t.Parallel()
   909  
   910  	tests := []struct {
   911  		name       string
   912  		d          xmlDict
   913  		args       []interface{}
   914  		want       interface{}
   915  		wantObject xmlIDict
   916  	}{
   917  		{"Nil", dictFixture, nil, nil, dictFixture},
   918  		{"Pop one element", dictFixture, []interface{}{"float"}, 1.23, dictFixture.Omit("float")},
   919  		{"Pop missing element", dictFixture, []interface{}{"undefined"}, nil, dictFixture},
   920  		{"Pop element twice", dictFixture, []interface{}{"int", "int", "string"}, xmlList{123, 123, "Foo bar"}, dictFixture.Omit("int", "string")},
   921  	}
   922  	for _, tt := range tests {
   923  		t.Run(tt.name, func(t *testing.T) {
   924  			d := tt.d.Clone()
   925  			got := d.Pop(tt.args...)
   926  			if !reflect.DeepEqual(got, tt.want) {
   927  				t.Errorf("XmlDict.Pop():\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", got, tt.want)
   928  			}
   929  			if !reflect.DeepEqual(d, tt.wantObject) {
   930  				t.Errorf("XmlDict.Pop() object:\n got %[1]v (%[1]T)\nwant %[2]v (%[2]T)", d, tt.wantObject)
   931  			}
   932  		})
   933  	}
   934  }
   935  
   936  func Test_dict_Add(t *testing.T) {
   937  	t.Parallel()
   938  
   939  	type args struct {
   940  		key interface{}
   941  		v   interface{}
   942  	}
   943  	tests := []struct {
   944  		name string
   945  		d    xmlDict
   946  		args args
   947  		want xmlIDict
   948  	}{
   949  		{"Empty", nil, args{"A", 1}, xmlDict{"A": 1}},
   950  		{"With element", xmlDict{"A": 1}, args{"A", 2}, xmlDict{"A": xmlList{1, 2}}},
   951  		{"With element, another value", xmlDict{"A": 1}, args{"B", 2}, xmlDict{"A": 1, "B": 2}},
   952  		{"With list element", xmlDict{"A": xmlList{1, 2}}, args{"A", 3}, xmlDict{"A": xmlList{1, 2, 3}}},
   953  	}
   954  	for _, tt := range tests {
   955  		t.Run(tt.name, func(t *testing.T) {
   956  			if got := tt.d.Add(tt.args.key, tt.args.v); !reflect.DeepEqual(got, tt.want) {
   957  				t.Errorf("XmlDict.Add() = %v, want %v", got, tt.want)
   958  			}
   959  		})
   960  	}
   961  }
   962  
   963  func Test_dict_Set(t *testing.T) {
   964  	t.Parallel()
   965  
   966  	type args struct {
   967  		key interface{}
   968  		v   interface{}
   969  	}
   970  	tests := []struct {
   971  		name string
   972  		d    xmlDict
   973  		args args
   974  		want xmlIDict
   975  	}{
   976  		{"Empty", nil, args{"A", 1}, xmlDict{"A": 1}},
   977  		{"With element", xmlDict{"A": 1}, args{"A", 2}, xmlDict{"A": 2}},
   978  		{"With element, another value", xmlDict{"A": 1}, args{"B", 2}, xmlDict{"A": 1, "B": 2}},
   979  	}
   980  	for _, tt := range tests {
   981  		t.Run(tt.name, func(t *testing.T) {
   982  			if got := tt.d.Set(tt.args.key, tt.args.v); !reflect.DeepEqual(got, tt.want) {
   983  				t.Errorf("XmlDict.Set() = %v, want %v", got, tt.want)
   984  			}
   985  		})
   986  	}
   987  }
   988  
   989  func Test_dict_Transpose(t *testing.T) {
   990  	t.Parallel()
   991  
   992  	tests := []struct {
   993  		name string
   994  		d    xmlDict
   995  		want xmlIDict
   996  	}{
   997  		{"Empty", nil, xmlDict{}},
   998  		{"Base", xmlDict{"A": 1}, xmlDict{"1": str("A")}},
   999  		{"Multiple", xmlDict{"A": 1, "B": 2, "C": 1}, xmlDict{"1": xmlList{str("A"), str("C")}, "2": str("B")}},
  1000  		{"List", xmlDict{"A": []int{1, 2, 3}, "B": 2, "C": 3}, xmlDict{"1": str("A"), "2": xmlList{str("A"), str("B")}, "3": xmlList{str("A"), str("C")}}},
  1001  		{"Complex", xmlDict{"A": xmlDict{"1": 1, "2": 2}, "B": 2, "C": 3}, xmlDict{"2": str("B"), "3": str("C"), fmt.Sprint(xmlDict{"1": 1, "2": 2}): str("A")}},
  1002  	}
  1003  	for _, tt := range tests {
  1004  		t.Run(tt.name, func(t *testing.T) {
  1005  			if got := tt.d.Transpose(); !reflect.DeepEqual(got, tt.want) {
  1006  				t.Errorf("XmlDict.Transpose() = %v, want %v", got, tt.want)
  1007  			}
  1008  		})
  1009  	}
  1010  }
  1011  
  1012  func Test_XmlList_Get(t *testing.T) {
  1013  	type args struct {
  1014  		indexes []int
  1015  	}
  1016  	tests := []struct {
  1017  		name string
  1018  		l    xmlList
  1019  		args args
  1020  		want interface{}
  1021  	}{
  1022  		// TODO: Add test cases.
  1023  	}
  1024  	for _, tt := range tests {
  1025  		t.Run(tt.name, func(t *testing.T) {
  1026  			if got := tt.l.Get(tt.args.indexes...); !reflect.DeepEqual(got, tt.want) {
  1027  				t.Errorf("XmlList.Get() = %v, want %v", got, tt.want)
  1028  			}
  1029  		})
  1030  	}
  1031  }
  1032  
  1033  func Test_XmlList_TypeName(t *testing.T) {
  1034  	tests := []struct {
  1035  		name string
  1036  		l    xmlList
  1037  		want str
  1038  	}{
  1039  		// TODO: Add test cases.
  1040  	}
  1041  	for _, tt := range tests {
  1042  		t.Run(tt.name, func(t *testing.T) {
  1043  			if got := tt.l.TypeName(); !reflect.DeepEqual(got, tt.want) {
  1044  				t.Errorf("XmlList.TypeName() = %v, want %v", got, tt.want)
  1045  			}
  1046  		})
  1047  	}
  1048  }
  1049  
  1050  func Test_Xml_TypeName(t *testing.T) {
  1051  	t.Run("list", func(t *testing.T) { assert.Equal(t, xmlList{}.TypeName(), str("Xml")) })
  1052  	t.Run("dict", func(t *testing.T) { assert.Equal(t, xmlDict{}.TypeName(), str("Xml")) })
  1053  }
  1054  
  1055  func Test_Xml_GetHelper(t *testing.T) {
  1056  	t.Run("list", func(t *testing.T) {
  1057  		gotD, gotL := xmlList{}.GetHelpers()
  1058  		assert.Equal(t, gotD.CreateDictionary().TypeName(), xmlDictHelper.CreateDictionary().TypeName())
  1059  		assert.Equal(t, gotL.CreateList().TypeName(), xmlListHelper.CreateList().TypeName())
  1060  	})
  1061  	t.Run("dict", func(t *testing.T) {
  1062  		gotD, gotL := xmlDict{}.GetHelpers()
  1063  		assert.Equal(t, gotD.CreateDictionary().TypeName(), xmlDictHelper.CreateDictionary().TypeName())
  1064  		assert.Equal(t, gotL.CreateList().TypeName(), xmlListHelper.CreateList().TypeName())
  1065  	})
  1066  }