MCPcopy Create free account
hub / github.com/gavv/httpexpect / replace

Method replace

chain.go:336–367  ·  view source on GitHub ↗

Like enter(), but it replaces last element of the path instead appending to it. Must be called between enter() and leave().

(name string, args ...interface{})

Source from the content-addressed store, hash-verified

334// Like enter(), but it replaces last element of the path instead appending to it.
335// Must be called between enter() and leave().
336func (c *chain) replace(name string, args ...interface{}) *chain {
337 if chainValidation {
338 func() {
339 c.mu.Lock()
340 defer c.mu.Unlock()
341
342 if c.state != stateEntered {
343 panic("replace allowed only between enter/leave")
344 }
345 if len(c.context.Path) == 0 {
346 panic("replace allowed only if path is non-empty")
347 }
348 if len(c.context.AliasedPath) == 0 {
349 panic("replace allowed only if aliased path is non-empty")
350 }
351 }()
352 }
353
354 chainCopy := c.clone()
355
356 chainCopy.state = stateEntered
357 if len(chainCopy.context.Path) != 0 {
358 last := len(chainCopy.context.Path) - 1
359 chainCopy.context.Path[last] = fmt.Sprintf(name, args...)
360 }
361 if len(chainCopy.context.AliasedPath) != 0 {
362 last := len(chainCopy.context.AliasedPath) - 1
363 chainCopy.context.AliasedPath[last] = fmt.Sprintf(name, args...)
364 }
365
366 return chainCopy
367}
368
369// Finalize assertion.
370// Report success of failure to AssertionHandler.

Callers 15

TestChain_PanicsFunction · 0.80
TestChain_PathFunction · 0.80
IterMethod · 0.80
EveryMethod · 0.80
FilterMethod · 0.80
FindMethod · 0.80
FindAllMethod · 0.80
NotFindMethod · 0.80
IsOrderedMethod · 0.80
NotOrderedMethod · 0.80
IterMethod · 0.80
EveryMethod · 0.80

Calls 3

cloneMethod · 0.95
LockMethod · 0.80
UnlockMethod · 0.80

Tested by 2

TestChain_PanicsFunction · 0.64
TestChain_PathFunction · 0.64