gopkg.in/rethinkdb/rethinkdb-go.v6@v6.2.2/internal/integration/reql_tests/reql_json_test.go (about) 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 RQL json parsing 17 func TestJsonSuite(t *testing.T) { 18 suite.Run(t, new(JsonSuite)) 19 } 20 21 type JsonSuite struct { 22 suite.Suite 23 24 session *r.Session 25 } 26 27 func (suite *JsonSuite) SetupTest() { 28 suite.T().Log("Setting up JsonSuite") 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("test").Exec(suite.session) 40 err = r.DBCreate("test").Exec(suite.session) 41 suite.Require().NoError(err) 42 err = r.DB("test").Wait().Exec(suite.session) 43 suite.Require().NoError(err) 44 45 } 46 47 func (suite *JsonSuite) TearDownSuite() { 48 suite.T().Log("Tearing down JsonSuite") 49 50 if suite.session != nil { 51 r.DB("rethinkdb").Table("_debug_scratch").Delete().Exec(suite.session) 52 r.DBDrop("test").Exec(suite.session) 53 54 suite.session.Close() 55 } 56 } 57 58 func (suite *JsonSuite) TestCases() { 59 suite.T().Log("Running JsonSuite: Tests RQL json parsing") 60 61 { 62 // json.yaml line #4 63 /* [1,2,3] */ 64 var expected_ []interface{} = []interface{}{1, 2, 3} 65 /* r.json("[1,2,3]") */ 66 67 suite.T().Log("About to run line #4: r.JSON('[1,2,3]')") 68 69 runAndAssert(suite.Suite, expected_, r.JSON("[1,2,3]"), suite.session, r.RunOpts{ 70 GeometryFormat: "raw", 71 GroupFormat: "map", 72 }) 73 suite.T().Log("Finished running line #4") 74 } 75 76 { 77 // json.yaml line #7 78 /* 1 */ 79 var expected_ int = 1 80 /* r.json("1") */ 81 82 suite.T().Log("About to run line #7: r.JSON('1')") 83 84 runAndAssert(suite.Suite, expected_, r.JSON("1"), suite.session, r.RunOpts{ 85 GeometryFormat: "raw", 86 GroupFormat: "map", 87 }) 88 suite.T().Log("Finished running line #7") 89 } 90 91 { 92 // json.yaml line #10 93 /* {} */ 94 var expected_ map[interface{}]interface{} = map[interface{}]interface{}{} 95 /* r.json("{}") */ 96 97 suite.T().Log("About to run line #10: r.JSON('{}')") 98 99 runAndAssert(suite.Suite, expected_, r.JSON("{}"), suite.session, r.RunOpts{ 100 GeometryFormat: "raw", 101 GroupFormat: "map", 102 }) 103 suite.T().Log("Finished running line #10") 104 } 105 106 { 107 // json.yaml line #13 108 /* "foo" */ 109 var expected_ string = "foo" 110 /* r.json('"foo"') */ 111 112 suite.T().Log("About to run line #13: r.JSON('\\'foo\\'')") 113 114 runAndAssert(suite.Suite, expected_, r.JSON("\"foo\""), suite.session, r.RunOpts{ 115 GeometryFormat: "raw", 116 GroupFormat: "map", 117 }) 118 suite.T().Log("Finished running line #13") 119 } 120 121 { 122 // json.yaml line #16 123 /* err("ReqlQueryLogicError", 'Failed to parse "[1,2" as JSON:' + ' Missing a comma or \']\' after an array element.', [0]) */ 124 var expected_ Err = err("ReqlQueryLogicError", "Failed to parse \"[1,2\" as JSON:"+" Missing a comma or ']' after an array element.") 125 /* r.json("[1,2") */ 126 127 suite.T().Log("About to run line #16: r.JSON('[1,2')") 128 129 runAndAssert(suite.Suite, expected_, r.JSON("[1,2"), suite.session, r.RunOpts{ 130 GeometryFormat: "raw", 131 GroupFormat: "map", 132 }) 133 suite.T().Log("Finished running line #16") 134 } 135 136 { 137 // json.yaml line #19 138 /* '[1,2,3]' */ 139 var expected_ string = "[1,2,3]" 140 /* r.json("[1,2,3]").to_json_string() */ 141 142 suite.T().Log("About to run line #19: r.JSON('[1,2,3]').ToJSON()") 143 144 runAndAssert(suite.Suite, expected_, r.JSON("[1,2,3]").ToJSON(), suite.session, r.RunOpts{ 145 GeometryFormat: "raw", 146 GroupFormat: "map", 147 }) 148 suite.T().Log("Finished running line #19") 149 } 150 151 { 152 // json.yaml line #23 153 /* '[1,2,3]' */ 154 var expected_ string = "[1,2,3]" 155 /* r.json("[1,2,3]").to_json() */ 156 157 suite.T().Log("About to run line #23: r.JSON('[1,2,3]').ToJSON()") 158 159 runAndAssert(suite.Suite, expected_, r.JSON("[1,2,3]").ToJSON(), suite.session, r.RunOpts{ 160 GeometryFormat: "raw", 161 GroupFormat: "map", 162 }) 163 suite.T().Log("Finished running line #23") 164 } 165 166 { 167 // json.yaml line #26 168 /* '{"foo":4}' */ 169 var expected_ string = "{\"foo\":4}" 170 /* r.json("{\"foo\":4}").to_json_string() */ 171 172 suite.T().Log("About to run line #26: r.JSON('{\\'foo\\':4}').ToJSON()") 173 174 runAndAssert(suite.Suite, expected_, r.JSON("{\"foo\":4}").ToJSON(), suite.session, r.RunOpts{ 175 GeometryFormat: "raw", 176 GroupFormat: "map", 177 }) 178 suite.T().Log("Finished running line #26") 179 } 180 181 { 182 // json.yaml line #30 183 /* '{"foo":4}' */ 184 var expected_ string = "{\"foo\":4}" 185 /* r.json("{\"foo\":4}").to_json() */ 186 187 suite.T().Log("About to run line #30: r.JSON('{\\'foo\\':4}').ToJSON()") 188 189 runAndAssert(suite.Suite, expected_, r.JSON("{\"foo\":4}").ToJSON(), suite.session, r.RunOpts{ 190 GeometryFormat: "raw", 191 GroupFormat: "map", 192 }) 193 suite.T().Log("Finished running line #30") 194 } 195 196 // json.yaml line #34 197 // text = '[{"id":1,"first_name":"Harry","last_name":"Riley","email":"hriley0@usgs.gov","country":"Andorra","ip_address":"221.25.65.136"},{"id":2,"first_name":"Bonnie","last_name":"Anderson","email":"banderson1@list-manage.com","country":"Tuvalu","ip_address":"116.162.43.150"},{"id":3,"first_name":"Marie","last_name":"Schmidt","email":"mschmidt2@diigo.com","country":"Iraq","ip_address":"181.105.59.57"},{"id":4,"first_name":"Phillip","last_name":"Willis","email":"pwillis3@com.com","country":"Montenegro","ip_address":"24.223.139.156"}]' 198 suite.T().Log("Possibly executing: var text string = '[{\\'id\\':1,\\'first_name\\':\\'Harry\\',\\'last_name\\':\\'Riley\\',\\'email\\':\\'hriley0@usgs.gov\\',\\'country\\':\\'Andorra\\',\\'ip_address\\':\\'221.25.65.136\\'},{\\'id\\':2,\\'first_name\\':\\'Bonnie\\',\\'last_name\\':\\'Anderson\\',\\'email\\':\\'banderson1@list-manage.com\\',\\'country\\':\\'Tuvalu\\',\\'ip_address\\':\\'116.162.43.150\\'},{\\'id\\':3,\\'first_name\\':\\'Marie\\',\\'last_name\\':\\'Schmidt\\',\\'email\\':\\'mschmidt2@diigo.com\\',\\'country\\':\\'Iraq\\',\\'ip_address\\':\\'181.105.59.57\\'},{\\'id\\':4,\\'first_name\\':\\'Phillip\\',\\'last_name\\':\\'Willis\\',\\'email\\':\\'pwillis3@com.com\\',\\'country\\':\\'Montenegro\\',\\'ip_address\\':\\'24.223.139.156\\'}]'") 199 200 text := "[{\"id\":1,\"first_name\":\"Harry\",\"last_name\":\"Riley\",\"email\":\"hriley0@usgs.gov\",\"country\":\"Andorra\",\"ip_address\":\"221.25.65.136\"},{\"id\":2,\"first_name\":\"Bonnie\",\"last_name\":\"Anderson\",\"email\":\"banderson1@list-manage.com\",\"country\":\"Tuvalu\",\"ip_address\":\"116.162.43.150\"},{\"id\":3,\"first_name\":\"Marie\",\"last_name\":\"Schmidt\",\"email\":\"mschmidt2@diigo.com\",\"country\":\"Iraq\",\"ip_address\":\"181.105.59.57\"},{\"id\":4,\"first_name\":\"Phillip\",\"last_name\":\"Willis\",\"email\":\"pwillis3@com.com\",\"country\":\"Montenegro\",\"ip_address\":\"24.223.139.156\"}]" 201 _ = text // Prevent any noused variable errors 202 203 // json.yaml line #35 204 // sorted = '[{"country":"Andorra","email":"hriley0@usgs.gov","first_name":"Harry","id":1,"ip_address":"221.25.65.136","last_name":"Riley"},{"country":"Tuvalu","email":"banderson1@list-manage.com","first_name":"Bonnie","id":2,"ip_address":"116.162.43.150","last_name":"Anderson"},{"country":"Iraq","email":"mschmidt2@diigo.com","first_name":"Marie","id":3,"ip_address":"181.105.59.57","last_name":"Schmidt"},{"country":"Montenegro","email":"pwillis3@com.com","first_name":"Phillip","id":4,"ip_address":"24.223.139.156","last_name":"Willis"}]' 205 suite.T().Log("Possibly executing: var sorted string = '[{\\'country\\':\\'Andorra\\',\\'email\\':\\'hriley0@usgs.gov\\',\\'first_name\\':\\'Harry\\',\\'id\\':1,\\'ip_address\\':\\'221.25.65.136\\',\\'last_name\\':\\'Riley\\'},{\\'country\\':\\'Tuvalu\\',\\'email\\':\\'banderson1@list-manage.com\\',\\'first_name\\':\\'Bonnie\\',\\'id\\':2,\\'ip_address\\':\\'116.162.43.150\\',\\'last_name\\':\\'Anderson\\'},{\\'country\\':\\'Iraq\\',\\'email\\':\\'mschmidt2@diigo.com\\',\\'first_name\\':\\'Marie\\',\\'id\\':3,\\'ip_address\\':\\'181.105.59.57\\',\\'last_name\\':\\'Schmidt\\'},{\\'country\\':\\'Montenegro\\',\\'email\\':\\'pwillis3@com.com\\',\\'first_name\\':\\'Phillip\\',\\'id\\':4,\\'ip_address\\':\\'24.223.139.156\\',\\'last_name\\':\\'Willis\\'}]'") 206 207 sorted := "[{\"country\":\"Andorra\",\"email\":\"hriley0@usgs.gov\",\"first_name\":\"Harry\",\"id\":1,\"ip_address\":\"221.25.65.136\",\"last_name\":\"Riley\"},{\"country\":\"Tuvalu\",\"email\":\"banderson1@list-manage.com\",\"first_name\":\"Bonnie\",\"id\":2,\"ip_address\":\"116.162.43.150\",\"last_name\":\"Anderson\"},{\"country\":\"Iraq\",\"email\":\"mschmidt2@diigo.com\",\"first_name\":\"Marie\",\"id\":3,\"ip_address\":\"181.105.59.57\",\"last_name\":\"Schmidt\"},{\"country\":\"Montenegro\",\"email\":\"pwillis3@com.com\",\"first_name\":\"Phillip\",\"id\":4,\"ip_address\":\"24.223.139.156\",\"last_name\":\"Willis\"}]" 208 _ = sorted // Prevent any noused variable errors 209 210 { 211 // json.yaml line #37 212 /* sorted */ 213 var expected_ string = sorted 214 /* r.json(text).to_json_string() */ 215 216 suite.T().Log("About to run line #37: r.JSON(text).ToJSON()") 217 218 runAndAssert(suite.Suite, expected_, r.JSON(text).ToJSON(), suite.session, r.RunOpts{ 219 GeometryFormat: "raw", 220 GroupFormat: "map", 221 }) 222 suite.T().Log("Finished running line #37") 223 } 224 225 { 226 // json.yaml line #40 227 /* err('ReqlQueryLogicError', 'Cannot convert `r.minval` to JSON.') */ 228 var expected_ Err = err("ReqlQueryLogicError", "Cannot convert `r.minval` to JSON.") 229 /* r.expr(r.minval).to_json_string() */ 230 231 suite.T().Log("About to run line #40: r.Expr(r.MinVal).ToJSON()") 232 233 runAndAssert(suite.Suite, expected_, r.Expr(r.MinVal).ToJSON(), suite.session, r.RunOpts{ 234 GeometryFormat: "raw", 235 GroupFormat: "map", 236 }) 237 suite.T().Log("Finished running line #40") 238 } 239 240 { 241 // json.yaml line #43 242 /* err('ReqlQueryLogicError', 'Cannot convert `r.maxval` to JSON.') */ 243 var expected_ Err = err("ReqlQueryLogicError", "Cannot convert `r.maxval` to JSON.") 244 /* r.expr(r.maxval).to_json_string() */ 245 246 suite.T().Log("About to run line #43: r.Expr(r.MaxVal).ToJSON()") 247 248 runAndAssert(suite.Suite, expected_, r.Expr(r.MaxVal).ToJSON(), suite.session, r.RunOpts{ 249 GeometryFormat: "raw", 250 GroupFormat: "map", 251 }) 252 suite.T().Log("Finished running line #43") 253 } 254 255 { 256 // json.yaml line #46 257 /* err('ReqlQueryLogicError', 'Cannot convert `r.minval` to JSON.') */ 258 var expected_ Err = err("ReqlQueryLogicError", "Cannot convert `r.minval` to JSON.") 259 /* r.expr(r.minval).coerce_to('string') */ 260 261 suite.T().Log("About to run line #46: r.Expr(r.MinVal).CoerceTo('string')") 262 263 runAndAssert(suite.Suite, expected_, r.Expr(r.MinVal).CoerceTo("string"), suite.session, r.RunOpts{ 264 GeometryFormat: "raw", 265 GroupFormat: "map", 266 }) 267 suite.T().Log("Finished running line #46") 268 } 269 270 { 271 // json.yaml line #49 272 /* err('ReqlQueryLogicError', 'Cannot convert `r.maxval` to JSON.') */ 273 var expected_ Err = err("ReqlQueryLogicError", "Cannot convert `r.maxval` to JSON.") 274 /* r.expr(r.maxval).coerce_to('string') */ 275 276 suite.T().Log("About to run line #49: r.Expr(r.MaxVal).CoerceTo('string')") 277 278 runAndAssert(suite.Suite, expected_, r.Expr(r.MaxVal).CoerceTo("string"), suite.session, r.RunOpts{ 279 GeometryFormat: "raw", 280 GroupFormat: "map", 281 }) 282 suite.T().Log("Finished running line #49") 283 } 284 285 { 286 // json.yaml line #52 287 /* {'timezone':'+00:00','$reql_type$':'TIME','epoch_time':1410393600} */ 288 var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"timezone": "+00:00", "$reql_type$": "TIME", "epoch_time": 1410393600} 289 /* r.time(2014,9,11, 'Z') */ 290 291 suite.T().Log("About to run line #52: r.Time(2014, 9, 11, 'Z')") 292 293 runAndAssert(suite.Suite, expected_, r.Time(2014, 9, 11, "Z"), suite.session, r.RunOpts{ 294 GeometryFormat: "raw", 295 GroupFormat: "map", 296 TimeFormat: "raw", 297 }) 298 suite.T().Log("Finished running line #52") 299 } 300 301 { 302 // json.yaml line #57 303 /* '{"$reql_type$":"TIME","epoch_time":1410393600,"timezone":"+00:00"}' */ 304 var expected_ string = "{\"$reql_type$\":\"TIME\",\"epoch_time\":1410393600,\"timezone\":\"+00:00\"}" 305 /* r.time(2014,9,11, 'Z').to_json_string() */ 306 307 suite.T().Log("About to run line #57: r.Time(2014, 9, 11, 'Z').ToJSON()") 308 309 runAndAssert(suite.Suite, expected_, r.Time(2014, 9, 11, "Z").ToJSON(), suite.session, r.RunOpts{ 310 GeometryFormat: "raw", 311 GroupFormat: "map", 312 }) 313 suite.T().Log("Finished running line #57") 314 } 315 316 { 317 // json.yaml line #60 318 /* {'$reql_type$':'GEOMETRY','coordinates':[0,0],'type':'Point'} */ 319 var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"$reql_type$": "GEOMETRY", "coordinates": []interface{}{0, 0}, "type": "Point"} 320 /* r.point(0,0) */ 321 322 suite.T().Log("About to run line #60: r.Point(0, 0)") 323 324 runAndAssert(suite.Suite, expected_, r.Point(0, 0), suite.session, r.RunOpts{ 325 GeometryFormat: "raw", 326 GroupFormat: "map", 327 }) 328 suite.T().Log("Finished running line #60") 329 } 330 331 { 332 // json.yaml line #63 333 /* '{"$reql_type$":"GEOMETRY","coordinates":[0,0],"type":"Point"}' */ 334 var expected_ string = "{\"$reql_type$\":\"GEOMETRY\",\"coordinates\":[0,0],\"type\":\"Point\"}" 335 /* r.point(0,0).to_json_string() */ 336 337 suite.T().Log("About to run line #63: r.Point(0, 0).ToJSON()") 338 339 runAndAssert(suite.Suite, expected_, r.Point(0, 0).ToJSON(), suite.session, r.RunOpts{ 340 GeometryFormat: "raw", 341 GroupFormat: "map", 342 }) 343 suite.T().Log("Finished running line #63") 344 } 345 346 // json.yaml line #68 347 // s = b'\x66\x6f\x6f' 348 suite.T().Log("Possibly executing: var s []byte = []byte{102,111,111}") 349 350 s := []byte{102, 111, 111} 351 _ = s // Prevent any noused variable errors 352 353 { 354 // json.yaml line #70 355 /* s */ 356 var expected_ []byte = s 357 /* r.binary(s) */ 358 359 suite.T().Log("About to run line #70: r.Binary(s)") 360 361 runAndAssert(suite.Suite, expected_, r.Binary(s), suite.session, r.RunOpts{ 362 GeometryFormat: "raw", 363 GroupFormat: "map", 364 }) 365 suite.T().Log("Finished running line #70") 366 } 367 368 { 369 // json.yaml line #73 370 /* '{"$reql_type$":"BINARY","data":"Zm9v"}' */ 371 var expected_ string = "{\"$reql_type$\":\"BINARY\",\"data\":\"Zm9v\"}" 372 /* r.expr("foo").coerce_to("binary").to_json_string() */ 373 374 suite.T().Log("About to run line #73: r.Expr('foo').CoerceTo('binary').ToJSON()") 375 376 runAndAssert(suite.Suite, expected_, r.Expr("foo").CoerceTo("binary").ToJSON(), suite.session, r.RunOpts{ 377 GeometryFormat: "raw", 378 GroupFormat: "map", 379 }) 380 suite.T().Log("Finished running line #73") 381 } 382 }