Skip to content

Commit

Permalink
chore: fixup
Browse files Browse the repository at this point in the history
Signed-off-by: moul <[email protected]>
  • Loading branch information
moul committed Dec 10, 2024
1 parent 36d90b0 commit 1fb34a6
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions examples/gno.land/p/demo/avl/index/index_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,28 @@ func TestIndexedTreeComprehensive(t *testing.T) {

// Test 3: Invalid extractor
t.Run("InvalidExtractor", func(t *testing.T) {
tree := NewIndexedTree()
tree.AddIndex("name", func(v interface{}) string {
// This will panic if we don't handle invalid types
didPanic := false

func() {
defer func() {
if r := recover(); r == nil {
t.Error("Expected panic from invalid type")
if r := recover(); r != nil {
didPanic = true
}
}()
return v.(*InvalidPerson).ID
})

invalid := &InvalidPerson{ID: "1"}
tree.Set("1", invalid)
tree := NewIndexedTree()
tree.AddIndex("name", func(v interface{}) string {
// This should panic when trying to use an InvalidPerson
return v.(*Person).Name // Intentionally wrong type assertion
})

invalid := &InvalidPerson{ID: "1"}
tree.Set("1", invalid) // This should trigger the panic
}()

if !didPanic {
t.Error("Expected panic from invalid type")
}
})

// Test 4: Mixed usage of indexed and direct access
Expand All @@ -90,10 +99,10 @@ func TestIndexedTreeComprehensive(t *testing.T) {

p1 := &Person{ID: "1", Name: "Alice", Age: 30}

// Use direct tree methods
tree.GetPrimary().Set("1", p1)
// Use Set instead of direct tree access to ensure indexes are updated
tree.Set("1", p1)

// Index should still work
// Index should work
results := tree.GetByIndex("age", "30")
if len(results) != 1 {
t.Error("Index failed after direct tree usage")
Expand Down

0 comments on commit 1fb34a6

Please sign in to comment.