File: query_string_test.go

package info (click to toggle)
golang-gopkg-dancannon-gorethink.v1 1.4.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 764 kB
  • sloc: makefile: 3
file content (91 lines) | stat: -rw-r--r-- 2,032 bytes parent folder | download | duplicates (3)
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
package gorethink

import (
	test "gopkg.in/check.v1"
)

func (s *RethinkSuite) TestStringMatchSuccess(c *test.C) {
	query := Expr("id:0,name:mlucy,foo:bar").Match("name:(\\w+)").Field("groups").Nth(0).Field("str")

	var response string
	res, err := query.Run(session)
	c.Assert(err, test.IsNil)

	err = res.One(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.Equals, "mlucy")
}

func (s *RethinkSuite) TestStringMatchFail(c *test.C) {
	query := Expr("id:0,foo:bar").Match("name:(\\w+)")

	res, err := query.Run(session)
	c.Assert(err, test.IsNil)
	c.Assert(res.IsNil(), test.Equals, true)
}

func (s *RethinkSuite) TestStringSplit(c *test.C) {
	query := Expr("a,b,c").Split(",")

	var response []string
	res, err := query.Run(session)
	c.Assert(err, test.IsNil)

	err = res.All(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.DeepEquals, []string{"a", "b", "c"})
}

func (s *RethinkSuite) TestStringSplitMax(c *test.C) {
	query := Expr("a,b,c").Split(",", 1)

	var response []string
	res, err := query.Run(session)
	c.Assert(err, test.IsNil)

	err = res.All(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.DeepEquals, []string{"a", "b,c"})
}

func (s *RethinkSuite) TestStringSplitWhitespace(c *test.C) {
	query := Expr("a b c").Split()

	var response []string
	res, err := query.Run(session)
	c.Assert(err, test.IsNil)

	err = res.All(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.DeepEquals, []string{"a", "b", "c"})
}

func (s *RethinkSuite) TestStringMatchUpcase(c *test.C) {
	query := Expr("tESt").Upcase()

	var response string
	res, err := query.Run(session)
	c.Assert(err, test.IsNil)

	err = res.One(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.Equals, "TEST")
}

func (s *RethinkSuite) TestStringMatchDowncase(c *test.C) {
	query := Expr("tESt").Downcase()

	var response string
	res, err := query.Run(session)
	c.Assert(err, test.IsNil)

	err = res.One(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.Equals, "test")
}