Beispiel #1
0
// TestComposeFilter_Empty_Nothing
func TestComposeFilter_Empty_Nothing(t *testing.T) {
	f := maybe.ComposeFilter()
	m := maybe.Nothing()
	b := f(m)
	assertFalse(t, b)
}
Beispiel #2
0
// TestComposeFilter_True_Nothing
func TestComposeFilter_True_Nothing(t *testing.T) {
	f := maybe.ComposeFilter(FilterTrue)
	m := maybe.Nothing()
	b := f(m)
	assertFalse(t, b)
}
Beispiel #3
0
// TestComposeMap_Empty_Nothing
func TestComposeMap_Empty_Nothing(t *testing.T) {
	f := maybe.ComposeMap()
	_m := maybe.Nothing()
	m := f(_m)
	assertNothing(t, m)
}
Beispiel #4
0
// TestComposeMap_Increment_Nothing
func TestComposeMap_Increment_Nothing(t *testing.T) {
	f := maybe.ComposeMap(increment)
	_m := maybe.Nothing()
	m := f(_m)
	assertNothing(t, m)
}
Beispiel #5
0
// TestCall_Nothing
func TestCall_Nothing(t *testing.T) {
	_m := maybe.Nothing()
	m := maybe.Call(MapAny_Echo, _m)
	assertNothing(t, m)
}
Beispiel #6
0
// TestCall_Multi_Nil
func TestCall_Multi_Nil(t *testing.T) {
	arg1 := maybe.New("one")
	arg2 := maybe.Nothing()
	m := maybe.Call(MultiArgs_Last, arg1, arg2)
	assertNothing(t, m)
}
Beispiel #7
0
// TestFilter_Nothing_Nil
func TestFilter_Nothing_Nil(t *testing.T) {
	_m := maybe.Nothing()
	m := _m.Filter(nil)
	assertNothing(t, m)
}
Beispiel #8
0
// TestFilter_Nothing_Panic
func TestFilter_Nothing_Panic(t *testing.T) {
	_m := maybe.Nothing()
	m := _m.Filter(FilterPanic)
	assertNothing(t, m)
}
Beispiel #9
0
// TestMap_Nothing_Nil
func TestMap_Nothing_Nil(t *testing.T) {
	_m := maybe.Nothing()
	m := _m.Map(nil)
	assertNothing(t, m)
}
Beispiel #10
0
// TestMap_Nothing_Panic
func TestMap_Nothing_Panic(t *testing.T) {
	_m := maybe.Nothing()
	m := _m.Map(MapPanic)
	assertNothing(t, m)
}
Beispiel #11
0
// TestGetOrElse_Nothing
func TestGetOrElse_Nothing(t *testing.T) {
	m := maybe.Nothing()
	assertGetOrElse(t, m, ELSE, ELSE)
}
Beispiel #12
0
// TestGetOrNil_Nothing
func TestGetOrNil_Nothing(t *testing.T) {
	m := maybe.Nothing()
	assertGetOrNil(t, m, nil)
}
Beispiel #13
0
// TestNothing
func TestNothing(t *testing.T) {
	m := maybe.Nothing()
	assertNothing(t, m)
}
Beispiel #14
0
// MapNothing
func MapNothing(m *maybe.T) *maybe.T {
	return maybe.Nothing()
}
Beispiel #15
0
 *********************************************************************/

const (
	ELSE             = "else"
	ERROR_MSG        = "error message"
	FILTER_PANIC     = "filter_panic"
	MAP_PANIC        = "map_panic"
	MAPPED           = "mapped"
	SOMETHING        = "something"
	FILTER_FUNC_ERR  = "maybe.T.Filter() expects func with single return value of type bool"
	MAP_FUNC_ERR     = "maybe.T.Map() expects func"
	MAP_FUNC_RET_ERR = "maybe.T.Map() expects return types to be one of: (any), (any, bool), (any, error)"
	CALL_FUNC_ERR    = "maybe.Call() expects func"
)

var nothing = maybe.Nothing()

/*********************************************************************
 ** Test Assert Functions
 *********************************************************************/

// assertNothing
func assertNothing(t *testing.T, m *maybe.T) {
	if m != nothing {
		t.Fatal("AssertNothing: m is not equal to maybe.Nothing()")
	}
	_, ok := m.Get()
	if ok {
		t.Fatal("assertNothing: m.Get() returned true")
	}
	err := m.Err()