Skip to content

Commit

Permalink
Add test for context iter
Browse files Browse the repository at this point in the history
  • Loading branch information
rongyi committed Jan 5, 2018
1 parent 0d5cc64 commit 5f1aa1f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package colly

import (
"strconv"
"testing"
)

func TestContextIteration(t *testing.T) {
ctx := NewContext()
for i := 0; i < 10; i++ {
ctx.Put(strconv.Itoa(i), i)
}
values := ctx.ForEach(func(k string, v interface{}) interface{} {
return v.(int)
})
if len(values) != 10 {
t.Fatal("fail to iterate context")
}
for _, i := range values {
v := i.(int)
if v != ctx.GetAny(strconv.Itoa(v)).(int) {
t.Fatal("value not equal")
}
}
}

0 comments on commit 5f1aa1f

Please sign in to comment.