| 1 | // Code generated by gen_tests.py and process_polyglot.py. |
| 2 | // Do not edit this file directly. |
| 3 | // The template for this file is located at: |
| 4 | // ../template.go.tpl |
| 5 | package reql_tests |
| 6 | |
| 7 | import ( |
| 8 | "testing" |
| 9 | "time" |
| 10 | |
| 11 | "github.com/stretchr/testify/suite" |
| 12 | r "gopkg.in/rethinkdb/rethinkdb-go.v6" |
| 13 | "gopkg.in/rethinkdb/rethinkdb-go.v6/internal/compare" |
| 14 | ) |
| 15 | |
| 16 | // Tests for match |
| 17 | func TestMatchSuite(t *testing.T) { |
| 18 | suite.Run(t, new(MatchSuite)) |
| 19 | } |
| 20 | |
| 21 | type MatchSuite struct { |
| 22 | suite.Suite |
| 23 | |
| 24 | session *r.Session |
| 25 | } |
| 26 | |
| 27 | func (suite *MatchSuite) SetupTest() { |
| 28 | suite.T().Log("Setting up MatchSuite") |
| 29 | // Use imports to prevent errors |
| 30 | _ = time.Time{} |
| 31 | _ = compare.AnythingIsFine |
| 32 | |
| 33 | session, err := r.Connect(r.ConnectOpts{ |
| 34 | Address: url, |
| 35 | }) |
| 36 | suite.Require().NoError(err, "Error returned when connecting to server") |
| 37 | suite.session = session |
| 38 | |
| 39 | r.DBDrop("db_match").Exec(suite.session) |
| 40 | err = r.DBCreate("db_match").Exec(suite.session) |
| 41 | suite.Require().NoError(err) |
| 42 | err = r.DB("db_match").Wait().Exec(suite.session) |
| 43 | suite.Require().NoError(err) |
| 44 | |
| 45 | r.DB("db_match").TableDrop("table_test_match").Exec(suite.session) |
| 46 | err = r.DB("db_match").TableCreate("table_test_match").Exec(suite.session) |
| 47 | suite.Require().NoError(err) |
| 48 | err = r.DB("db_match").Table("table_test_match").Wait().Exec(suite.session) |
| 49 | suite.Require().NoError(err) |
| 50 | } |
| 51 | |
| 52 | func (suite *MatchSuite) TearDownSuite() { |
| 53 | suite.T().Log("Tearing down MatchSuite") |
| 54 | |
| 55 | if suite.session != nil { |
| 56 | r.DB("rethinkdb").Table("_debug_scratch").Delete().Exec(suite.session) |
| 57 | r.DB("db_match").TableDrop("table_test_match").Exec(suite.session) |
| 58 | r.DBDrop("db_match").Exec(suite.session) |
| 59 | |
| 60 | suite.session.Close() |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | func (suite *MatchSuite) TestCases() { |
| 65 | suite.T().Log("Running MatchSuite: Tests for match") |
| 66 | |
| 67 | table_test_match := r.DB("db_match").Table("table_test_match") |
| 68 | _ = table_test_match // Prevent any noused variable errors |
| 69 | |
| 70 | { |
| 71 | // match.yaml line #4 |
| 72 | /* ({'str':'bcde','groups':[null,{'start':2,'str':'cde','end':5}],'start':1,'end':5}) */ |
| 73 | var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"str": "bcde", "groups": []interface{}{nil, map[interface{}]interface{}{"start": 2, "str": "cde", "end": 5}}, "start": 1, "end": 5} |
| 74 | /* r.expr("abcdefg").match("a(b.e)|b(c.e)") */ |
| 75 | |
| 76 | suite.T().Log("About to run line #4: r.Expr('abcdefg').Match('a(b.e)|b(c.e)')") |
| 77 | |
| 78 | runAndAssert(suite.Suite, expected_, r.Expr("abcdefg").Match("a(b.e)|b(c.e)"), suite.session, r.RunOpts{ |
| 79 | GeometryFormat: "raw", |
| 80 | GroupFormat: "map", |
| 81 | }) |
| 82 | suite.T().Log("Finished running line #4") |
| 83 | } |
| 84 | |
| 85 | { |
| 86 | // match.yaml line #6 |
| 87 | /* (null) */ |
| 88 | var expected_ interface{} = nil |
| 89 | /* r.expr("abcdefg").match("a(b.e)|B(c.e)") */ |
| 90 | |
| 91 | suite.T().Log("About to run line #6: r.Expr('abcdefg').Match('a(b.e)|B(c.e)')") |
| 92 | |
| 93 | runAndAssert(suite.Suite, expected_, r.Expr("abcdefg").Match("a(b.e)|B(c.e)"), suite.session, r.RunOpts{ |
| 94 | GeometryFormat: "raw", |
| 95 | GroupFormat: "map", |
| 96 | }) |
| 97 | suite.T().Log("Finished running line #6") |
| 98 | } |
| 99 | |
| 100 | { |
| 101 | // match.yaml line #8 |
| 102 | /* ({'str':'bcde','groups':[null,{'start':2,'str':'cde','end':5}],'start':1,'end':5}) */ |
| 103 | var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"str": "bcde", "groups": []interface{}{nil, map[interface{}]interface{}{"start": 2, "str": "cde", "end": 5}}, "start": 1, "end": 5} |
| 104 | /* r.expr("abcdefg").match("(?i)a(b.e)|B(c.e)") */ |
| 105 | |
| 106 | suite.T().Log("About to run line #8: r.Expr('abcdefg').Match('(?i)a(b.e)|B(c.e)')") |
| 107 | |
| 108 | runAndAssert(suite.Suite, expected_, r.Expr("abcdefg").Match("(?i)a(b.e)|B(c.e)"), suite.session, r.RunOpts{ |
| 109 | GeometryFormat: "raw", |
| 110 | GroupFormat: "map", |
| 111 | }) |
| 112 | suite.T().Log("Finished running line #8") |
| 113 | } |
| 114 | |
| 115 | { |
| 116 | // match.yaml line #12 |
| 117 | /* (["aca", "ada"]) */ |
| 118 | var expected_ []interface{} = []interface{}{"aca", "ada"} |
| 119 | /* r.expr(["aba", "aca", "ada", "aea"]).filter(lambda row:row.match("a(.)a")['groups'][0]['str'].match("[cd]")) */ |
| 120 | |
| 121 | suite.T().Log("About to run line #12: r.Expr([]interface{}{'aba', 'aca', 'ada', 'aea'}).Filter(func(row r.Term) interface{} { return row.Match('a(.)a').AtIndex('groups').AtIndex(0).AtIndex('str').Match('[cd]')})") |
| 122 | |
| 123 | runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{"aba", "aca", "ada", "aea"}).Filter(func(row r.Term) interface{} { |
| 124 | return row.Match("a(.)a").AtIndex("groups").AtIndex(0).AtIndex("str").Match("[cd]") |
| 125 | }), suite.session, r.RunOpts{ |
| 126 | GeometryFormat: "raw", |
| 127 | GroupFormat: "map", |
| 128 | }) |
| 129 | suite.T().Log("Finished running line #12") |
| 130 | } |
| 131 | |
| 132 | { |
| 133 | // match.yaml line #16 |
| 134 | /* ({'deleted':0,'replaced':0,'unchanged':0,'errors':0,'skipped':0,'inserted':3}) */ |
| 135 | var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"deleted": 0, "replaced": 0, "unchanged": 0, "errors": 0, "skipped": 0, "inserted": 3} |
| 136 | /* table_test_match.insert([{'id':0,'a':'abc'},{'id':1,'a':'ab'},{'id':2,'a':'bc'}]) */ |
| 137 | |
| 138 | suite.T().Log("About to run line #16: table_test_match.Insert([]interface{}{map[interface{}]interface{}{'id': 0, 'a': 'abc', }, map[interface{}]interface{}{'id': 1, 'a': 'ab', }, map[interface{}]interface{}{'id': 2, 'a': 'bc', }})") |
| 139 | |
| 140 | runAndAssert(suite.Suite, expected_, table_test_match.Insert([]interface{}{map[interface{}]interface{}{"id": 0, "a": "abc"}, map[interface{}]interface{}{"id": 1, "a": "ab"}, map[interface{}]interface{}{"id": 2, "a": "bc"}}), suite.session, r.RunOpts{ |
| 141 | GeometryFormat: "raw", |
| 142 | GroupFormat: "map", |
| 143 | }) |
| 144 | suite.T().Log("Finished running line #16") |
| 145 | } |
| 146 | |
| 147 | { |
| 148 | // match.yaml line #20 |
| 149 | /* ([{'id':0,'a':'abc'},{'id':1,'a':'ab'},{'id':2,'a':'bc'}]) */ |
| 150 | var expected_ []interface{} = []interface{}{map[interface{}]interface{}{"id": 0, "a": "abc"}, map[interface{}]interface{}{"id": 1, "a": "ab"}, map[interface{}]interface{}{"id": 2, "a": "bc"}} |
| 151 | /* table_test_match.filter(lambda row:row['a'].match('b')).order_by('id') */ |
| 152 | |
| 153 | suite.T().Log("About to run line #20: table_test_match.Filter(func(row r.Term) interface{} { return row.AtIndex('a').Match('b')}).OrderBy('id')") |
| 154 | |
| 155 | runAndAssert(suite.Suite, expected_, table_test_match.Filter(func(row r.Term) interface{} { return row.AtIndex("a").Match("b") }).OrderBy("id"), suite.session, r.RunOpts{ |
| 156 | GeometryFormat: "raw", |
| 157 | GroupFormat: "map", |
| 158 | }) |
| 159 | suite.T().Log("Finished running line #20") |
| 160 | } |
| 161 | |
| 162 | { |
| 163 | // match.yaml line #24 |
| 164 | /* ([{'id':0,'a':'abc'},{'id':1,'a':'ab'}]) */ |
| 165 | var expected_ []interface{} = []interface{}{map[interface{}]interface{}{"id": 0, "a": "abc"}, map[interface{}]interface{}{"id": 1, "a": "ab"}} |
| 166 | /* table_test_match.filter(lambda row:row['a'].match('ab')).order_by('id') */ |
| 167 | |
| 168 | suite.T().Log("About to run line #24: table_test_match.Filter(func(row r.Term) interface{} { return row.AtIndex('a').Match('ab')}).OrderBy('id')") |
| 169 | |
| 170 | runAndAssert(suite.Suite, expected_, table_test_match.Filter(func(row r.Term) interface{} { return row.AtIndex("a").Match("ab") }).OrderBy("id"), suite.session, r.RunOpts{ |
| 171 | GeometryFormat: "raw", |
| 172 | GroupFormat: "map", |
| 173 | }) |
| 174 | suite.T().Log("Finished running line #24") |
| 175 | } |
| 176 | |
| 177 | { |
| 178 | // match.yaml line #28 |
| 179 | /* ([{'id':1,'a':'ab'}]) */ |
| 180 | var expected_ []interface{} = []interface{}{map[interface{}]interface{}{"id": 1, "a": "ab"}} |
| 181 | /* table_test_match.filter(lambda row:row['a'].match('ab$')).order_by('id') */ |
| 182 | |
| 183 | suite.T().Log("About to run line #28: table_test_match.Filter(func(row r.Term) interface{} { return row.AtIndex('a').Match('ab$')}).OrderBy('id')") |
| 184 | |
| 185 | runAndAssert(suite.Suite, expected_, table_test_match.Filter(func(row r.Term) interface{} { return row.AtIndex("a").Match("ab$") }).OrderBy("id"), suite.session, r.RunOpts{ |
| 186 | GeometryFormat: "raw", |
| 187 | GroupFormat: "map", |
| 188 | }) |
| 189 | suite.T().Log("Finished running line #28") |
| 190 | } |
| 191 | |
| 192 | { |
| 193 | // match.yaml line #32 |
| 194 | /* ([]) */ |
| 195 | var expected_ []interface{} = []interface{}{} |
| 196 | /* table_test_match.filter(lambda row:row['a'].match('^b$')).order_by('id') */ |
| 197 | |
| 198 | suite.T().Log("About to run line #32: table_test_match.Filter(func(row r.Term) interface{} { return row.AtIndex('a').Match('^b$')}).OrderBy('id')") |
| 199 | |
| 200 | runAndAssert(suite.Suite, expected_, table_test_match.Filter(func(row r.Term) interface{} { return row.AtIndex("a").Match("^b$") }).OrderBy("id"), suite.session, r.RunOpts{ |
| 201 | GeometryFormat: "raw", |
| 202 | GroupFormat: "map", |
| 203 | }) |
| 204 | suite.T().Log("Finished running line #32") |
| 205 | } |
| 206 | |
| 207 | { |
| 208 | // match.yaml line #36 |
| 209 | /* err("ReqlQueryLogicError", "Error in regexp `ab\\9` (portion `\\9`): invalid escape sequence: \\9", []) */ |
| 210 | var expected_ Err = err("ReqlQueryLogicError", "Error in regexp `ab\\9` (portion `\\9`): invalid escape sequence: \\9") |
| 211 | /* r.expr("").match("ab\\9") */ |
| 212 | |
| 213 | suite.T().Log("About to run line #36: r.Expr('').Match('ab\\\\9')") |
| 214 | |
| 215 | runAndAssert(suite.Suite, expected_, r.Expr("").Match("ab\\9"), suite.session, r.RunOpts{ |
| 216 | GeometryFormat: "raw", |
| 217 | GroupFormat: "map", |
| 218 | }) |
| 219 | suite.T().Log("Finished running line #36") |
| 220 | } |
| 221 | } |