MCPcopy Create free account
hub / github.com/buke/quickjs-go / TestHandleStore_MultipleValues

Function TestHandleStore_MultipleValues

handle_test.go:41–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func TestHandleStore_MultipleValues(t *testing.T) {
42 hs := newHandleStore()
43
44 // Store multiple different types
45 testValues := []interface{}{
46 "string",
47 42,
48 []int{1, 2, 3},
49 map[string]int{"key": 123},
50 nil,
51 }
52
53 ids := make([]int32, len(testValues))
54 for i, value := range testValues {
55 ids[i] = hs.Store(value)
56 assert.Greater(t, ids[i], int32(0))
57 }
58
59 assert.Equal(t, len(testValues), hs.Count())
60
61 // Verify IDs are sequential
62 for i := 1; i < len(ids); i++ {
63 assert.Greater(t, ids[i], ids[i-1])
64 }
65
66 // Verify all values can be loaded
67 for i, expectedValue := range testValues {
68 loadedValue, ok := hs.Load(ids[i])
69 assert.True(t, ok)
70 assert.Equal(t, expectedValue, loadedValue)
71 }
72
73 // Test function storage separately (can't use == comparison)
74 funcValue := func() int { return 42 }
75 funcID := hs.Store(funcValue)
76 loadedFunc, ok := hs.Load(funcID)
77 assert.True(t, ok)
78 assert.NotNil(t, loadedFunc)
79 // Verify it's actually a function by calling it
80 if fn, ok := loadedFunc.(func() int); ok {
81 assert.Equal(t, 42, fn())
82 }
83 assert.True(t, hs.Delete(funcID))
84
85 // Clear all
86 hs.Clear()
87 assert.Equal(t, 0, hs.Count())
88
89 // Verify all values are gone after clear
90 for _, id := range ids {
91 value, ok := hs.Load(id)
92 assert.False(t, ok)
93 assert.Nil(t, value)
94 }
95}
96
97func TestHandleStore_EdgeCases(t *testing.T) {
98 t.Run("IDOverflow", func(t *testing.T) {

Callers

nothing calls this directly

Calls 7

newHandleStoreFunction · 0.85
StoreMethod · 0.80
EqualMethod · 0.80
CountMethod · 0.80
LoadMethod · 0.80
ClearMethod · 0.80
DeleteMethod · 0.45

Tested by

no test coverage detected