Skip to content

Commit

Permalink
test: add example test
Browse files Browse the repository at this point in the history
  • Loading branch information
zoncoen committed May 27, 2019
1 parent e4cd3c6 commit ccf6ca9
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions example_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package query_test

import (
"fmt"

"github.com/zoncoen/query-go"
)

type orderedMap struct {
elems []*elem
}

type elem struct {
k, v interface{}
}

func (m *orderedMap) ExtractByKey(key string) (interface{}, bool) {
for _, e := range m.elems {
if k, ok := e.k.(string); ok {
if k == key {
return e.v, true
}
}
}
return nil, false
}

func ExampleKeyExtractor() {
q := query.New().Key("key")
v, _ := q.Extract(&orderedMap{
elems: []*elem{{k: "key", v: "value"}},
})
fmt.Println(v)
// Output:
// value
}

0 comments on commit ccf6ca9

Please sign in to comment.