MCPcopy
hub / github.com/duke-git/lancet / TestIfNotNilOrElse

Function TestIfNotNilOrElse

datastructure/optional/optional_test.go:102–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

100}
101
102func TestIfNotNilOrElse(t *testing.T) {
103 assert := internal.NewAssert(t, "TestIfNotNilOrElse")
104
105 // Test when value is present
106 calledWithValue := false
107 valueAction := func(value int) { calledWithValue = true }
108 fallbackAction := func() { t.Errorf("Empty action should not be called when value is present") }
109
110 optWithValue := Of(42)
111 optWithValue.IfNotNilOrElse(valueAction, fallbackAction)
112
113 assert.ShouldBeTrue(calledWithValue)
114
115 // Test when value is not present
116 calledWithEmpty := false
117 valueAction = func(value int) { t.Errorf("Value action should not be called when value is not present") }
118 fallbackAction = func() { calledWithEmpty = true }
119
120 optDefault := Default[int]()
121 optDefault.IfNotNilOrElse(valueAction, fallbackAction)
122
123 assert.ShouldBeTrue(calledWithEmpty)
124}
125
126func TestGetWithPanicStandard(t *testing.T) {
127 assert := internal.NewAssert(t, "TestGetWithPanicStandard")

Callers

nothing calls this directly

Calls 4

ShouldBeTrueMethod · 0.95
NewAssertFunction · 0.92
IfNotNilOrElseMethod · 0.80
OfFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…