forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregex_query_test.go
73 lines (58 loc) · 1.68 KB
/
regex_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
package tests
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func regexQueryWueriesWithRegexFromDocumentQuery(t *testing.T, driver *RavenTestDriver) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
{
session := openSessionMust(t, store)
err = session.Store(NewRegexMe("I love dogs and cats"))
assert.NoError(t, err)
err = session.Store(NewRegexMe("I love cats"))
assert.NoError(t, err)
err = session.Store(NewRegexMe("I love dogs"))
assert.NoError(t, err)
err = session.Store(NewRegexMe("I love bats"))
assert.NoError(t, err)
err = session.Store(NewRegexMe("dogs love me"))
assert.NoError(t, err)
err = session.Store(NewRegexMe("cats love me"))
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
{
session := openSessionMust(t, store)
query := session.Advanced().QueryCollectionForType(reflect.TypeOf(&RegexMe{}))
query = query.WhereRegex("text", "^[a-z ]{2,4}love")
var result []*RegexMe
err = query.GetResults(&result)
assert.NoError(t, err)
assert.Equal(t, len(result), 4)
iq, err := query.GetIndexQuery()
assert.NoError(t, err)
assert.Equal(t, iq.GetQuery(), "from RegexMes where regex(text, $p0)")
assert.Equal(t, iq.GetQueryParameters()["p0"], "^[a-z ]{2,4}love")
session.Close()
}
}
type RegexMe struct {
Text string `json:"text"`
}
func NewRegexMe(text string) *RegexMe {
return &RegexMe{
Text: text,
}
}
func TestRegexQuery(t *testing.T) {
driver := createTestDriver(t)
destroy := func() { destroyDriver(t, driver) }
defer recoverTest(t, destroy)
// matches order of Java tests
regexQueryWueriesWithRegexFromDocumentQuery(t, driver)
}