MCPcopy
hub / github.com/jesseduffield/lazygit / TestThreadSafeMap

Function TestThreadSafeMap

pkg/utils/thread_safe_map_test.go:7–45  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

5)
6
7func TestThreadSafeMap(t *testing.T) {
8 m := NewThreadSafeMap[int, int]()
9
10 m.Set(1, 1)
11 m.Set(2, 2)
12 m.Set(3, 3)
13
14 if m.Len() != 3 {
15 t.Errorf("Expected length to be 3, got %d", m.Len())
16 }
17
18 if !m.Has(1) {
19 t.Errorf("Expected to have key 1")
20 }
21
22 if m.Has(4) {
23 t.Errorf("Expected to not have key 4")
24 }
25
26 if _, ok := m.Get(1); !ok {
27 t.Errorf("Expected to have key 1")
28 }
29
30 if _, ok := m.Get(4); ok {
31 t.Errorf("Expected to not have key 4")
32 }
33
34 m.Delete(1)
35
36 if m.Has(1) {
37 t.Errorf("Expected to not have key 1")
38 }
39
40 m.Clear()
41
42 if m.Len() != 0 {
43 t.Errorf("Expected length to be 0, got %d", m.Len())
44 }
45}
46
47func TestThreadSafeMapConcurrentReadWrite(t *testing.T) {
48 m := NewThreadSafeMap[int, int]()

Callers

nothing calls this directly

Calls 8

NewThreadSafeMapFunction · 0.85
SetMethod · 0.80
ErrorfMethod · 0.80
HasMethod · 0.80
LenMethod · 0.65
GetMethod · 0.65
DeleteMethod · 0.45
ClearMethod · 0.45

Tested by

no test coverage detected