MCPcopy
hub / github.com/nats-io/nats.go / TestMapLoadAndDelete

Function TestMapLoadAndDelete

internal/syncx/map_test.go:88–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

86}
87
88func TestMapLoadAndDelete(t *testing.T) {
89 var m Map[int, string]
90 m.Store(1, "one")
91
92 v, ok := m.LoadAndDelete(1)
93 if !ok || v != "one" {
94 t.Errorf("LoadAndDelete(1) = %v, %v; want 'one', true", v, ok)
95 }
96
97 v, ok = m.Load(1)
98 if ok || v != "" {
99 t.Errorf("Load(1) after LoadAndDelete(1) = %v, %v; want '', false", v, ok)
100 }
101
102 // Test that LoadAndDelete on a missing key returns the zero value.
103 v, ok = m.LoadAndDelete(2)
104 if ok || v != "" {
105 t.Errorf("LoadAndDelete(2) = %v, %v; want '', false", v, ok)
106 }
107}
108
109func TestMapCompareAndSwap(t *testing.T) {
110 var m Map[int, string]

Callers

nothing calls this directly

Calls 4

StoreMethod · 0.80
LoadAndDeleteMethod · 0.80
ErrorfMethod · 0.80
LoadMethod · 0.80

Tested by

no test coverage detected