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

Function TestHandleStore_CustomStartID

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

Source from the content-addressed store, hash-verified

177}
178
179func TestHandleStore_CustomStartID(t *testing.T) {
180 t.Run("StartFromZero", func(t *testing.T) {
181 hs := newHandleStoreWithStartID(0)
182 id := hs.Store("test")
183 assert.Equal(t, int32(1), id)
184 assert.True(t, hs.Delete(id))
185 })
186
187 t.Run("StartFromCustom", func(t *testing.T) {
188 const startID = int32(1000)
189 hs := newHandleStoreWithStartID(startID)
190 id := hs.Store("test")
191 assert.Equal(t, startID+1, id)
192 assert.True(t, hs.Delete(id))
193 })
194
195 t.Run("BoundaryNearOverflow", func(t *testing.T) {
196 // Test behavior near MaxInt32
197 hs := newHandleStoreWithStartID(math.MaxInt32 - 3)
198
199 // Store 2 values successfully
200 id1 := hs.Store("value1")
201 id2 := hs.Store("value2")
202 assert.Equal(t, int32(math.MaxInt32-2), id1)
203 assert.Equal(t, int32(math.MaxInt32-1), id2)
204
205 // Third store should panic
206 assert.Panics(t, func() {
207 hs.Store("value3")
208 })
209
210 // Clean up
211 assert.True(t, hs.Delete(id1))
212 assert.True(t, hs.Delete(id2))
213 })
214}
215
216func TestHandleStore_Concurrency(t *testing.T) {
217 hs := newHandleStore()

Callers

nothing calls this directly

Calls 4

StoreMethod · 0.80
EqualMethod · 0.80
DeleteMethod · 0.45

Tested by

no test coverage detected