| 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 the RQL `map` function |
| 17 | func TestTransformMapSuite(t *testing.T) { |
| 18 | suite.Run(t, new(TransformMapSuite)) |
| 19 | } |
| 20 | |
| 21 | type TransformMapSuite struct { |
| 22 | suite.Suite |
| 23 | |
| 24 | session *r.Session |
| 25 | } |
| 26 | |
| 27 | func (suite *TransformMapSuite) SetupTest() { |
| 28 | suite.T().Log("Setting up TransformMapSuite") |
| 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_tfm_map").Exec(suite.session) |
| 40 | err = r.DBCreate("db_tfm_map").Exec(suite.session) |
| 41 | suite.Require().NoError(err) |
| 42 | err = r.DB("db_tfm_map").Wait().Exec(suite.session) |
| 43 | suite.Require().NoError(err) |
| 44 | |
| 45 | } |
| 46 | |
| 47 | func (suite *TransformMapSuite) TearDownSuite() { |
| 48 | suite.T().Log("Tearing down TransformMapSuite") |
| 49 | |
| 50 | if suite.session != nil { |
| 51 | r.DB("rethinkdb").Table("_debug_scratch").Delete().Exec(suite.session) |
| 52 | r.DBDrop("db_tfm_map").Exec(suite.session) |
| 53 | |
| 54 | suite.session.Close() |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func (suite *TransformMapSuite) TestCases() { |
| 59 | suite.T().Log("Running TransformMapSuite: Tests the RQL `map` function") |
| 60 | |
| 61 | { |
| 62 | // transform/map.yaml line #5 |
| 63 | /* 'STREAM' */ |
| 64 | var expected_ string = "STREAM" |
| 65 | /* r.range().map(r.range(), lambda x, y:(x, y)).type_of() */ |
| 66 | |
| 67 | suite.T().Log("About to run line #5: r.Range().Map(r.Range(), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y}}).TypeOf()") |
| 68 | |
| 69 | runAndAssert(suite.Suite, expected_, r.Range().Map(r.Range(), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y} }).TypeOf(), suite.session, r.RunOpts{ |
| 70 | GeometryFormat: "raw", |
| 71 | GroupFormat: "map", |
| 72 | }) |
| 73 | suite.T().Log("Finished running line #5") |
| 74 | } |
| 75 | |
| 76 | { |
| 77 | // transform/map.yaml line #10 |
| 78 | /* 'STREAM' */ |
| 79 | var expected_ string = "STREAM" |
| 80 | /* r.range().map(r.expr([]), lambda x, y:(x, y)).type_of() */ |
| 81 | |
| 82 | suite.T().Log("About to run line #10: r.Range().Map(r.Expr([]interface{}{}), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y}}).TypeOf()") |
| 83 | |
| 84 | runAndAssert(suite.Suite, expected_, r.Range().Map(r.Expr([]interface{}{}), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y} }).TypeOf(), suite.session, r.RunOpts{ |
| 85 | GeometryFormat: "raw", |
| 86 | GroupFormat: "map", |
| 87 | }) |
| 88 | suite.T().Log("Finished running line #10") |
| 89 | } |
| 90 | |
| 91 | { |
| 92 | // transform/map.yaml line #15 |
| 93 | /* 'ARRAY' */ |
| 94 | var expected_ string = "ARRAY" |
| 95 | /* r.expr([]).map(r.expr([]), lambda x, y:(x, y)).type_of() */ |
| 96 | |
| 97 | suite.T().Log("About to run line #15: r.Expr([]interface{}{}).Map(r.Expr([]interface{}{}), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y}}).TypeOf()") |
| 98 | |
| 99 | runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{}).Map(r.Expr([]interface{}{}), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y} }).TypeOf(), suite.session, r.RunOpts{ |
| 100 | GeometryFormat: "raw", |
| 101 | GroupFormat: "map", |
| 102 | }) |
| 103 | suite.T().Log("Finished running line #15") |
| 104 | } |
| 105 | |
| 106 | { |
| 107 | // transform/map.yaml line #21 |
| 108 | /* [0, 0, 0] */ |
| 109 | var expected_ []interface{} = []interface{}{0, 0, 0} |
| 110 | /* r.range(3).map(lambda:0) */ |
| 111 | |
| 112 | suite.T().Log("About to run line #21: r.Range(3).Map(func() interface{} { return 0})") |
| 113 | |
| 114 | runAndAssert(suite.Suite, expected_, r.Range(3).Map(func() interface{} { return 0 }), suite.session, r.RunOpts{ |
| 115 | GeometryFormat: "raw", |
| 116 | GroupFormat: "map", |
| 117 | }) |
| 118 | suite.T().Log("Finished running line #21") |
| 119 | } |
| 120 | |
| 121 | { |
| 122 | // transform/map.yaml line #26 |
| 123 | /* [0, 0, 0] */ |
| 124 | var expected_ []interface{} = []interface{}{0, 0, 0} |
| 125 | /* r.range(3).map(r.range(4), lambda x,y:0) */ |
| 126 | |
| 127 | suite.T().Log("About to run line #26: r.Range(3).Map(r.Range(4), func(x r.Term, y r.Term) interface{} { return 0})") |
| 128 | |
| 129 | runAndAssert(suite.Suite, expected_, r.Range(3).Map(r.Range(4), func(x r.Term, y r.Term) interface{} { return 0 }), suite.session, r.RunOpts{ |
| 130 | GeometryFormat: "raw", |
| 131 | GroupFormat: "map", |
| 132 | }) |
| 133 | suite.T().Log("Finished running line #26") |
| 134 | } |
| 135 | |
| 136 | { |
| 137 | // transform/map.yaml line #31 |
| 138 | /* [[1]] */ |
| 139 | var expected_ []interface{} = []interface{}{[]interface{}{1}} |
| 140 | /* r.expr([1]).map(lambda x:(x,)) */ |
| 141 | |
| 142 | suite.T().Log("About to run line #31: r.Expr([]interface{}{1}).Map(func(x r.Term) interface{} { return []interface{}{x}})") |
| 143 | |
| 144 | runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{1}).Map(func(x r.Term) interface{} { return []interface{}{x} }), suite.session, r.RunOpts{ |
| 145 | GeometryFormat: "raw", |
| 146 | GroupFormat: "map", |
| 147 | }) |
| 148 | suite.T().Log("Finished running line #31") |
| 149 | } |
| 150 | |
| 151 | { |
| 152 | // transform/map.yaml line #36 |
| 153 | /* [[1, 1]] */ |
| 154 | var expected_ []interface{} = []interface{}{[]interface{}{1, 1}} |
| 155 | /* r.expr([1]).map(r.expr([1]), lambda x, y:(x, y)) */ |
| 156 | |
| 157 | suite.T().Log("About to run line #36: r.Expr([]interface{}{1}).Map(r.Expr([]interface{}{1}), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y}})") |
| 158 | |
| 159 | runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{1}).Map(r.Expr([]interface{}{1}), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y} }), suite.session, r.RunOpts{ |
| 160 | GeometryFormat: "raw", |
| 161 | GroupFormat: "map", |
| 162 | }) |
| 163 | suite.T().Log("Finished running line #36") |
| 164 | } |
| 165 | |
| 166 | { |
| 167 | // transform/map.yaml line #41 |
| 168 | /* [[1, 1, 1]] */ |
| 169 | var expected_ []interface{} = []interface{}{[]interface{}{1, 1, 1}} |
| 170 | /* r.expr([1]).map(r.expr([1]), r.expr([1]), lambda x, y, z:(x, y, z)) */ |
| 171 | |
| 172 | suite.T().Log("About to run line #41: r.Expr([]interface{}{1}).Map(r.Expr([]interface{}{1}), r.Expr([]interface{}{1}), func(x r.Term, y r.Term, z r.Term) interface{} { return []interface{}{x, y, z}})") |
| 173 | |
| 174 | runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{1}).Map(r.Expr([]interface{}{1}), r.Expr([]interface{}{1}), func(x r.Term, y r.Term, z r.Term) interface{} { return []interface{}{x, y, z} }), suite.session, r.RunOpts{ |
| 175 | GeometryFormat: "raw", |
| 176 | GroupFormat: "map", |
| 177 | }) |
| 178 | suite.T().Log("Finished running line #41") |
| 179 | } |
| 180 | |
| 181 | { |
| 182 | // transform/map.yaml line #47 |
| 183 | /* err("ReqlQueryLogicError", "The function passed to `map` expects 2 arguments, but 1 sequence was found.", []) */ |
| 184 | var expected_ Err = err("ReqlQueryLogicError", "The function passed to `map` expects 2 arguments, but 1 sequence was found.") |
| 185 | /* r.expr([1]).map(lambda x, y:(x, y)) */ |
| 186 | |
| 187 | suite.T().Log("About to run line #47: r.Expr([]interface{}{1}).Map(func(x r.Term, y r.Term) interface{} { return []interface{}{x, y}})") |
| 188 | |
| 189 | runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{1}).Map(func(x r.Term, y r.Term) interface{} { return []interface{}{x, y} }), suite.session, r.RunOpts{ |
| 190 | GeometryFormat: "raw", |
| 191 | GroupFormat: "map", |
| 192 | }) |
| 193 | suite.T().Log("Finished running line #47") |
| 194 | } |
| 195 | |
| 196 | { |
| 197 | // transform/map.yaml line #52 |
| 198 | /* err("ReqlQueryLogicError", "The function passed to `map` expects 1 argument, but 2 sequences were found.", []) */ |
| 199 | var expected_ Err = err("ReqlQueryLogicError", "The function passed to `map` expects 1 argument, but 2 sequences were found.") |
| 200 | /* r.expr([1]).map(r.expr([1]), lambda x:(x,)) */ |
| 201 | |
| 202 | suite.T().Log("About to run line #52: r.Expr([]interface{}{1}).Map(r.Expr([]interface{}{1}), func(x r.Term) interface{} { return []interface{}{x}})") |
| 203 | |
| 204 | runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{1}).Map(r.Expr([]interface{}{1}), func(x r.Term) interface{} { return []interface{}{x} }), suite.session, r.RunOpts{ |
| 205 | GeometryFormat: "raw", |
| 206 | GroupFormat: "map", |
| 207 | }) |
| 208 | suite.T().Log("Finished running line #52") |
| 209 | } |
| 210 | |
| 211 | { |
| 212 | // transform/map.yaml line #58 |
| 213 | /* [] */ |
| 214 | var expected_ []interface{} = []interface{}{} |
| 215 | /* r.range().map(r.expr([]), lambda x, y:(x, y)) */ |
| 216 | |
| 217 | suite.T().Log("About to run line #58: r.Range().Map(r.Expr([]interface{}{}), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y}})") |
| 218 | |
| 219 | runAndAssert(suite.Suite, expected_, r.Range().Map(r.Expr([]interface{}{}), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y} }), suite.session, r.RunOpts{ |
| 220 | GeometryFormat: "raw", |
| 221 | GroupFormat: "map", |
| 222 | }) |
| 223 | suite.T().Log("Finished running line #58") |
| 224 | } |
| 225 | |
| 226 | { |
| 227 | // transform/map.yaml line #63 |
| 228 | /* [[1, 1], [2, 2]] */ |
| 229 | var expected_ []interface{} = []interface{}{[]interface{}{1, 1}, []interface{}{2, 2}} |
| 230 | /* r.expr([1, 2]).map(r.expr([1, 2, 3, 4]), lambda x, y:(x, y)) */ |
| 231 | |
| 232 | suite.T().Log("About to run line #63: r.Expr([]interface{}{1, 2}).Map(r.Expr([]interface{}{1, 2, 3, 4}), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y}})") |
| 233 | |
| 234 | runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{1, 2}).Map(r.Expr([]interface{}{1, 2, 3, 4}), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y} }), suite.session, r.RunOpts{ |
| 235 | GeometryFormat: "raw", |
| 236 | GroupFormat: "map", |
| 237 | }) |
| 238 | suite.T().Log("Finished running line #63") |
| 239 | } |
| 240 | |
| 241 | { |
| 242 | // transform/map.yaml line #68 |
| 243 | /* [[0, 0], [1, 1]] */ |
| 244 | var expected_ []interface{} = []interface{}{[]interface{}{0, 0}, []interface{}{1, 1}} |
| 245 | /* r.range(2).map(r.range(4), lambda x, y:(x, y)) */ |
| 246 | |
| 247 | suite.T().Log("About to run line #68: r.Range(2).Map(r.Range(4), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y}})") |
| 248 | |
| 249 | runAndAssert(suite.Suite, expected_, r.Range(2).Map(r.Range(4), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y} }), suite.session, r.RunOpts{ |
| 250 | GeometryFormat: "raw", |
| 251 | GroupFormat: "map", |
| 252 | }) |
| 253 | suite.T().Log("Finished running line #68") |
| 254 | } |
| 255 | |
| 256 | { |
| 257 | // transform/map.yaml line #73 |
| 258 | /* [[0, 1], [1, 2], [2, 3], [3, 4]] */ |
| 259 | var expected_ []interface{} = []interface{}{[]interface{}{0, 1}, []interface{}{1, 2}, []interface{}{2, 3}, []interface{}{3, 4}} |
| 260 | /* r.range().map(r.expr([1, 2, 3, 4]), lambda x, y:(x, y)) */ |
| 261 | |
| 262 | suite.T().Log("About to run line #73: r.Range().Map(r.Expr([]interface{}{1, 2, 3, 4}), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y}})") |
| 263 | |
| 264 | runAndAssert(suite.Suite, expected_, r.Range().Map(r.Expr([]interface{}{1, 2, 3, 4}), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y} }), suite.session, r.RunOpts{ |
| 265 | GeometryFormat: "raw", |
| 266 | GroupFormat: "map", |
| 267 | }) |
| 268 | suite.T().Log("Finished running line #73") |
| 269 | } |
| 270 | |
| 271 | { |
| 272 | // transform/map.yaml line #78 |
| 273 | /* [[0, 0], [1, 1], [2, 2]] */ |
| 274 | var expected_ []interface{} = []interface{}{[]interface{}{0, 0}, []interface{}{1, 1}, []interface{}{2, 2}} |
| 275 | /* r.range(3).map(r.range(5), r.js("(function(x, y){return [x, y];})")) */ |
| 276 | |
| 277 | suite.T().Log("About to run line #78: r.Range(3).Map(r.Range(5), r.JS('(function(x, y){return [x, y];})'))") |
| 278 | |
| 279 | runAndAssert(suite.Suite, expected_, r.Range(3).Map(r.Range(5), r.JS("(function(x, y){return [x, y];})")), suite.session, r.RunOpts{ |
| 280 | GeometryFormat: "raw", |
| 281 | GroupFormat: "map", |
| 282 | }) |
| 283 | suite.T().Log("Finished running line #78") |
| 284 | } |
| 285 | |
| 286 | { |
| 287 | // transform/map.yaml line #83 |
| 288 | /* err("ReqlQueryLogicError", "Cannot convert NUMBER to SEQUENCE", []) */ |
| 289 | var expected_ Err = err("ReqlQueryLogicError", "Cannot convert NUMBER to SEQUENCE") |
| 290 | /* r.range().map(r.expr(1), lambda x, y:(x, y)) */ |
| 291 | |
| 292 | suite.T().Log("About to run line #83: r.Range().Map(r.Expr(1), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y}})") |
| 293 | |
| 294 | runAndAssert(suite.Suite, expected_, r.Range().Map(r.Expr(1), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y} }), suite.session, r.RunOpts{ |
| 295 | GeometryFormat: "raw", |
| 296 | GroupFormat: "map", |
| 297 | }) |
| 298 | suite.T().Log("Finished running line #83") |
| 299 | } |
| 300 | |
| 301 | { |
| 302 | // transform/map.yaml line #89 |
| 303 | /* err("ReqlQueryLogicError", "Cannot use an infinite stream with an aggregation function (`reduce`, `count`, etc.) or coerce it to an array.", []) */ |
| 304 | var expected_ Err = err("ReqlQueryLogicError", "Cannot use an infinite stream with an aggregation function (`reduce`, `count`, etc.) or coerce it to an array.") |
| 305 | /* r.range().map(r.range(), lambda x, y:(x, y)).count() */ |
| 306 | |
| 307 | suite.T().Log("About to run line #89: r.Range().Map(r.Range(), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y}}).Count()") |
| 308 | |
| 309 | runAndAssert(suite.Suite, expected_, r.Range().Map(r.Range(), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y} }).Count(), suite.session, r.RunOpts{ |
| 310 | GeometryFormat: "raw", |
| 311 | GroupFormat: "map", |
| 312 | }) |
| 313 | suite.T().Log("Finished running line #89") |
| 314 | } |
| 315 | |
| 316 | { |
| 317 | // transform/map.yaml line #95 |
| 318 | /* [[0], [1], [2]] */ |
| 319 | var expected_ []interface{} = []interface{}{[]interface{}{0}, []interface{}{1}, []interface{}{2}} |
| 320 | /* r.map(r.range(3), lambda x:(x,)) */ |
| 321 | |
| 322 | suite.T().Log("About to run line #95: r.Map(r.Range(3), func(x r.Term) interface{} { return []interface{}{x}})") |
| 323 | |
| 324 | runAndAssert(suite.Suite, expected_, r.Map(r.Range(3), func(x r.Term) interface{} { return []interface{}{x} }), suite.session, r.RunOpts{ |
| 325 | GeometryFormat: "raw", |
| 326 | GroupFormat: "map", |
| 327 | }) |
| 328 | suite.T().Log("Finished running line #95") |
| 329 | } |
| 330 | |
| 331 | { |
| 332 | // transform/map.yaml line #100 |
| 333 | /* [1, 2, 3] */ |
| 334 | var expected_ []interface{} = []interface{}{1, 2, 3} |
| 335 | /* r.map(r.range(3), r.row + 1) */ |
| 336 | |
| 337 | suite.T().Log("About to run line #100: r.Map(r.Range(3), r.Row.Add(1))") |
| 338 | |
| 339 | runAndAssert(suite.Suite, expected_, r.Map(r.Range(3), r.Row.Add(1)), suite.session, r.RunOpts{ |
| 340 | GeometryFormat: "raw", |
| 341 | GroupFormat: "map", |
| 342 | }) |
| 343 | suite.T().Log("Finished running line #100") |
| 344 | } |
| 345 | |
| 346 | { |
| 347 | // transform/map.yaml line #104 |
| 348 | /* [[0, 0], [1, 1], [2, 2]] */ |
| 349 | var expected_ []interface{} = []interface{}{[]interface{}{0, 0}, []interface{}{1, 1}, []interface{}{2, 2}} |
| 350 | /* r.map(r.range(3), r.range(5), lambda x, y:(x, y)) */ |
| 351 | |
| 352 | suite.T().Log("About to run line #104: r.Map(r.Range(3), r.Range(5), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y}})") |
| 353 | |
| 354 | runAndAssert(suite.Suite, expected_, r.Map(r.Range(3), r.Range(5), func(x r.Term, y r.Term) interface{} { return []interface{}{x, y} }), suite.session, r.RunOpts{ |
| 355 | GeometryFormat: "raw", |
| 356 | GroupFormat: "map", |
| 357 | }) |
| 358 | suite.T().Log("Finished running line #104") |
| 359 | } |
| 360 | } |