forked from zenhack/go.notmuch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_test.go
121 lines (103 loc) · 2.52 KB
/
query_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package notmuch
// Copyright © 2015 The go.notmuch Authors. Authors can be found in the AUTHORS file.
// Licensed under the GPLv3 or later.
// See COPYING at the root of the repository for details.
import (
"runtime"
"testing"
)
func TestSearchThreads(t *testing.T) {
db, err := Open(dbPath, DBReadOnly)
if err != nil {
t.Fatal(err)
}
defer db.Close()
threads, err := db.NewQuery("").Threads()
if err != nil {
t.Fatalf("error getting the threads: %s", err)
}
var count int
thread := &Thread{}
for threads.Next(&thread) {
count++
// invoke the GC to make sure it's running smoothly.
if count%2 == 0 {
runtime.GC()
}
}
if want, got := 24, count; want != got {
t.Errorf("db.NewQuery(%q).Threads(): want %d got %d", "", want, got)
}
}
func TestGetNoResult(t *testing.T) {
db, err := Open(dbPath, DBReadOnly)
if err != nil {
t.Fatal(err)
}
defer db.Close()
threads, err := db.NewQuery("subject:notfoundnotfound").Threads()
if err != nil {
t.Fatalf("error getting the threads: %s", err)
}
var count int
thread := &Thread{}
for threads.Next(&thread) {
count++
// invoke the GC to make sure it's running smoothly.
if count%2 == 0 {
runtime.GC()
}
}
if want, got := 0, count; want != got {
t.Errorf("db.NewQuery(%q).Threads(): want %d got %d", "", want, got)
}
}
func TestQueryCountMessages(t *testing.T) {
db, err := Open(dbPath, DBReadOnly)
if err != nil {
t.Fatal(err)
}
defer db.Close()
q := db.NewQuery("subject:\"Introducing myself\"")
if want, got := 3, q.CountMessages(); want != got {
t.Errorf("q.Count(): want %d got %d", want, got)
}
}
func TestQueryCountThreads(t *testing.T) {
db, err := Open(dbPath, DBReadOnly)
if err != nil {
t.Fatal(err)
}
defer db.Close()
q := db.NewQuery("subject:\"Introducing myself\"")
if want, got := 1, q.CountThreads(); want != got {
t.Errorf("q.Count(): want %d got %d", want, got)
}
}
func TestString(t *testing.T) {
db, err := Open(dbPath, DBReadOnly)
if err != nil {
t.Fatal(err)
}
defer db.Close()
q := db.NewQuery("subject:\"Introducing myself\"")
if want, got := "subject:\"Introducing myself\"", q.String(); want != got {
t.Errorf("q.String(): want %s got %s", want, got)
}
}
func TestSetExcludeScheme(t *testing.T) {
db, err := Open(dbPath, DBReadOnly)
if err != nil {
t.Fatal(err)
}
defer db.Close()
q := db.NewQuery("subject:\"Introducing myself\"")
for _, mode := range []ExcludeMode{
QUERY_EXCLUDE_FLAG,
QUERY_EXCLUDE_ALL,
QUERY_EXCLUDE_TRUE,
QUERY_EXCLUDE_FALSE,
} {
q.SetExcludeScheme(mode)
}
}