-
Notifications
You must be signed in to change notification settings - Fork 0
/
gnquery_test.go
63 lines (58 loc) · 1.2 KB
/
gnquery_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package gnquery_test
import (
"fmt"
"testing"
"github.com/gnames/gnquery"
"github.com/gnames/gnquery/ent/search"
"github.com/stretchr/testify/assert"
)
func TestProcess(t *testing.T) {
inp := search.Input{
Genus: "P.",
Species: "saltator",
}
gnq := gnquery.New()
res := gnq.Process(inp)
val := search.Input{
Query: "g:P. sp:saltator",
Genus: "P.",
Species: "saltator",
}
assert.Equal(t, res, val)
inp = search.Input{
Query: "n:Puma concolor au:Linn. all:t",
Genus: "P.",
Species: "saltator",
}
res = gnq.Process(inp)
val = search.Input{
Query: "n:Puma concolor au:Linn. all:t",
Warnings: []string{},
NameString: "Puma concolor",
Genus: "Puma",
Species: "concolor",
Author: "Linn.",
WithAllMatches: true,
}
assert.Equal(t, res, val)
}
func Example() {
q := "ds:2 tx:Aves g:Bubo asp:bubo y:1758"
gnq := gnquery.New()
res := gnq.Parse(q)
fmt.Println(res.Query)
fmt.Println(res.DataSources)
fmt.Println(res.ParentTaxon)
fmt.Println(res.Genus)
fmt.Println(res.SpeciesAny)
fmt.Println(res.Year)
fmt.Println(res.Tail)
// Output:
// ds:2 tx:Aves g:Bubo asp:bubo y:1758
// [2]
// Aves
// Bubo
// bubo
// 1758
//
}