MCPcopy Create free account
hub / github.com/DoNewsCode/core / TestC_AddModule

Function TestC_AddModule

c_test.go:220–257  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

218}
219
220func TestC_AddModule(t *testing.T) {
221 type Module struct {
222 di.In
223 Int int
224 Float float64 `optional:"true"`
225 }
226 for _, c := range []struct {
227 name string
228 module interface{}
229 assertion func(t *testing.T, c *C)
230 }{
231 {
232 "di.In",
233 Module{Float: 2.0},
234 func(t *testing.T, c *C) {
235 assert.Equal(t, 1, c.Modules()[0].(Module).Int)
236 assert.Equal(t, 0.0, c.Modules()[0].(Module).Float)
237 },
238 },
239 {
240 "*di.In",
241 &Module{Float: 2.0},
242 func(t *testing.T, c *C) {
243 assert.Equal(t, 1, c.Modules()[0].(*Module).Int)
244 assert.Equal(t, 0.0, c.Modules()[0].(*Module).Float)
245 },
246 },
247 } {
248 t.Run(c.name, func(t *testing.T) {
249 cc := New()
250 cc.Provide(di.Deps{func() int {
251 return 1
252 }})
253 cc.AddModule(c.module)
254 c.assertion(t, cc)
255 })
256 }
257}

Callers

nothing calls this directly

Calls 5

ProvideMethod · 0.80
NewFunction · 0.70
ModulesMethod · 0.65
RunMethod · 0.45
AddModuleMethod · 0.45

Tested by

no test coverage detected