Пример #1
0
// Test that adding an empty array doesn't change the result of Err().
func TestListAddAllEmpty(t *testing.T) {
	examples := []*ErrorList{
		AsList(),
		AsList(New("")),
		AsList(New(""), New("1"), New("abcdef")),
	}
	for _, el := range examples {
		assert.Equal(t, el.Err(), el.copy().AddAll([]error{}).Err())
	}
}
Пример #2
0
// Test that AsList() is the same as List().AddAll().
func TestAsList(t *testing.T) {
	examples := [][]error{
		{nil},
		{New("")},
		{New(""), New("1"), New("abcdef")},
		{New(""), nil, New("1"), New("abcdef")},
	}
	for _, el := range examples {
		assert.Equal(t, List().AddAll(el), AsList(el...))
	}
}
Пример #3
0
// Test that AddAll() is the same as Add() in a loop.
func TestListAddAll(t *testing.T) {
	examples := [][]error{
		{nil},
		{New("")},
		{New(""), New("1"), New("abcdef")},
		{New(""), nil, New("1"), New("abcdef")},
	}
	for _, el := range examples {
		addLoop := List()
		for _, e := range el {
			addLoop.Add(e)
		}

		assert.Equal(t, addLoop, List().AddAll(el))
	}
}
Пример #4
0
// Test error message.
func TestListError(t *testing.T) {
	examples := []struct {
		List *ErrorList
		Msg  string
	}{
		{
			List: AsList(),
			Msg:  fmt.Sprintf("%v", nil),
		},
		{
			List: AsList(New("")),
			Msg:  fmt.Sprintf("%v", ""),
		},
		{
			List: AsList(New(""), New("1")),
			Msg:  fmt.Sprintf("%v", []error{New(""), New("1")}),
		},
	}
	for _, e := range examples {
		assert.Equal(t, e.Msg, e.List.Error())
	}
}
Пример #5
0
// Test that after adding several errors Err() returns an array of them.
func TestListAddErrs(t *testing.T) {
	examples := []struct {
		List *ErrorList
		Errs []error
	}{
		{
			List: AsList(),
			Errs: []error{New("1"), New("2"), New("3")},
		},
		{
			List: AsList(New("")),
			Errs: []error{New(""), New("1"), New("2"), New("3")},
		},
		{
			List: AsList(New(""), New("1"), New("abcdef")),
			Errs: []error{New(""), New("1"), New("abcdef"), New("1"), New("2"), New("3")},
		},
	}
	errs := []error{New("1"), New("2"), New("3")}
	for _, el := range examples {
		assert.Equal(t, AsList(el.Errs...), el.List.copy().AddAll(errs).Err())
	}
}
Пример #6
0
// Test that list with one element returns it as Err().
func TestListSingle(t *testing.T) {
	examples := []error{New("1"), New("2"), New("3")}
	for _, e := range examples {
		assert.Equal(t, e, AsList(e).Err())
	}
}
Пример #7
0
// Test that Ex(e).Reason() is the same as New(e).
func TestEx(t *testing.T) {
	examples := []string{"", "1", "abcdef"}
	for _, es := range examples {
		assert.Equal(t, New(es), Ex(es).Reason())
	}
}
Пример #8
0
// Test that New() is the same as errors.New().
func TestNew(t *testing.T) {
	examples := []string{"", "1", "abcdef"}
	for _, es := range examples {
		assert.Equal(t, errors.New(es), New(es))
	}
}