| 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 | // Test basic time arithmetic |
| 17 | func TestTimesConstructorsSuite(t *testing.T) { |
| 18 | suite.Run(t, new(TimesConstructorsSuite)) |
| 19 | } |
| 20 | |
| 21 | type TimesConstructorsSuite struct { |
| 22 | suite.Suite |
| 23 | |
| 24 | session *r.Session |
| 25 | } |
| 26 | |
| 27 | func (suite *TimesConstructorsSuite) SetupTest() { |
| 28 | suite.T().Log("Setting up TimesConstructorsSuite") |
| 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_timesctor").Exec(suite.session) |
| 40 | err = r.DBCreate("db_timesctor").Exec(suite.session) |
| 41 | suite.Require().NoError(err) |
| 42 | err = r.DB("db_timesctor").Wait().Exec(suite.session) |
| 43 | suite.Require().NoError(err) |
| 44 | |
| 45 | } |
| 46 | |
| 47 | func (suite *TimesConstructorsSuite) TearDownSuite() { |
| 48 | suite.T().Log("Tearing down TimesConstructorsSuite") |
| 49 | |
| 50 | if suite.session != nil { |
| 51 | r.DB("rethinkdb").Table("_debug_scratch").Delete().Exec(suite.session) |
| 52 | r.DBDrop("db_timesctor").Exec(suite.session) |
| 53 | |
| 54 | suite.session.Close() |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func (suite *TimesConstructorsSuite) TestCases() { |
| 59 | suite.T().Log("Running TimesConstructorsSuite: Test basic time arithmetic") |
| 60 | |
| 61 | { |
| 62 | // times/constructors.yaml line #5 |
| 63 | /* datetime.fromtimestamp(896571240, r.ast.RqlTzinfo('00:00')) */ |
| 64 | var expected_ time.Time = Ast.Fromtimestamp(896571240, Ast.RqlTzinfo("00:00")) |
| 65 | /* r.expr(r.epoch_time(896571240)) */ |
| 66 | |
| 67 | suite.T().Log("About to run line #5: r.Expr(r.EpochTime(896571240))") |
| 68 | |
| 69 | runAndAssert(suite.Suite, expected_, r.Expr(r.EpochTime(896571240)), suite.session, r.RunOpts{ |
| 70 | GeometryFormat: "raw", |
| 71 | GroupFormat: "map", |
| 72 | }) |
| 73 | suite.T().Log("Finished running line #5") |
| 74 | } |
| 75 | |
| 76 | { |
| 77 | // times/constructors.yaml line #11 |
| 78 | /* {'stuff':datetime.fromtimestamp(896571240, r.ast.RqlTzinfo('00:00')), 'more':[datetime.fromtimestamp(996571240, r.ast.RqlTzinfo('00:00'))]} */ |
| 79 | var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"stuff": Ast.Fromtimestamp(896571240, Ast.RqlTzinfo("00:00")), "more": []interface{}{Ast.Fromtimestamp(996571240, Ast.RqlTzinfo("00:00"))}} |
| 80 | /* r.expr({'stuff':r.epoch_time(896571240), 'more':[r.epoch_time(996571240)]}) */ |
| 81 | |
| 82 | suite.T().Log("About to run line #11: r.Expr(map[interface{}]interface{}{'stuff': r.EpochTime(896571240), 'more': []interface{}{r.EpochTime(996571240)}, })") |
| 83 | |
| 84 | runAndAssert(suite.Suite, expected_, r.Expr(map[interface{}]interface{}{"stuff": r.EpochTime(896571240), "more": []interface{}{r.EpochTime(996571240)}}), suite.session, r.RunOpts{ |
| 85 | GeometryFormat: "raw", |
| 86 | GroupFormat: "map", |
| 87 | }) |
| 88 | suite.T().Log("Finished running line #11") |
| 89 | } |
| 90 | |
| 91 | { |
| 92 | // times/constructors.yaml line #17 |
| 93 | /* [datetime.fromtimestamp(796571240, r.ast.RqlTzinfo('00:00')), datetime.fromtimestamp(896571240, r.ast.RqlTzinfo('00:00')), {'stuff':datetime.fromtimestamp(996571240, r.ast.RqlTzinfo('00:00'))}] */ |
| 94 | var expected_ []interface{} = []interface{}{Ast.Fromtimestamp(796571240, Ast.RqlTzinfo("00:00")), Ast.Fromtimestamp(896571240, Ast.RqlTzinfo("00:00")), map[interface{}]interface{}{"stuff": Ast.Fromtimestamp(996571240, Ast.RqlTzinfo("00:00"))}} |
| 95 | /* r.expr([r.epoch_time(796571240), r.epoch_time(896571240), {'stuff':r.epoch_time(996571240)}]) */ |
| 96 | |
| 97 | suite.T().Log("About to run line #17: r.Expr([]interface{}{r.EpochTime(796571240), r.EpochTime(896571240), map[interface{}]interface{}{'stuff': r.EpochTime(996571240), }})") |
| 98 | |
| 99 | runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{r.EpochTime(796571240), r.EpochTime(896571240), map[interface{}]interface{}{"stuff": r.EpochTime(996571240)}}), suite.session, r.RunOpts{ |
| 100 | GeometryFormat: "raw", |
| 101 | GroupFormat: "map", |
| 102 | }) |
| 103 | suite.T().Log("Finished running line #17") |
| 104 | } |
| 105 | |
| 106 | { |
| 107 | // times/constructors.yaml line #23 |
| 108 | /* {'nested':{'time':datetime.fromtimestamp(896571240, r.ast.RqlTzinfo('00:00'))}} */ |
| 109 | var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"nested": map[interface{}]interface{}{"time": Ast.Fromtimestamp(896571240, Ast.RqlTzinfo("00:00"))}} |
| 110 | /* r.expr({'nested':{'time':r.epoch_time(896571240)}}) */ |
| 111 | |
| 112 | suite.T().Log("About to run line #23: r.Expr(map[interface{}]interface{}{'nested': map[interface{}]interface{}{'time': r.EpochTime(896571240), }, })") |
| 113 | |
| 114 | runAndAssert(suite.Suite, expected_, r.Expr(map[interface{}]interface{}{"nested": map[interface{}]interface{}{"time": r.EpochTime(896571240)}}), suite.session, r.RunOpts{ |
| 115 | GeometryFormat: "raw", |
| 116 | GroupFormat: "map", |
| 117 | }) |
| 118 | suite.T().Log("Finished running line #23") |
| 119 | } |
| 120 | |
| 121 | { |
| 122 | // times/constructors.yaml line #29 |
| 123 | /* [1, "two", ["a", datetime.fromtimestamp(896571240, r.ast.RqlTzinfo('00:00')), 3]] */ |
| 124 | var expected_ []interface{} = []interface{}{1, "two", []interface{}{"a", Ast.Fromtimestamp(896571240, Ast.RqlTzinfo("00:00")), 3}} |
| 125 | /* r.expr([1, "two", ["a", r.epoch_time(896571240), 3]]) */ |
| 126 | |
| 127 | suite.T().Log("About to run line #29: r.Expr([]interface{}{1, 'two', []interface{}{'a', r.EpochTime(896571240), 3}})") |
| 128 | |
| 129 | runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{1, "two", []interface{}{"a", r.EpochTime(896571240), 3}}), suite.session, r.RunOpts{ |
| 130 | GeometryFormat: "raw", |
| 131 | GroupFormat: "map", |
| 132 | }) |
| 133 | suite.T().Log("Finished running line #29") |
| 134 | } |
| 135 | |
| 136 | { |
| 137 | // times/constructors.yaml line #35 |
| 138 | /* 1 */ |
| 139 | var expected_ int = 1 |
| 140 | /* r.epoch_time(1).to_epoch_time() */ |
| 141 | |
| 142 | suite.T().Log("About to run line #35: r.EpochTime(1).ToEpochTime()") |
| 143 | |
| 144 | runAndAssert(suite.Suite, expected_, r.EpochTime(1).ToEpochTime(), suite.session, r.RunOpts{ |
| 145 | GeometryFormat: "raw", |
| 146 | GroupFormat: "map", |
| 147 | }) |
| 148 | suite.T().Log("Finished running line #35") |
| 149 | } |
| 150 | |
| 151 | { |
| 152 | // times/constructors.yaml line #37 |
| 153 | /* -1 */ |
| 154 | var expected_ int = -1 |
| 155 | /* r.epoch_time(-1).to_epoch_time() */ |
| 156 | |
| 157 | suite.T().Log("About to run line #37: r.EpochTime(-1).ToEpochTime()") |
| 158 | |
| 159 | runAndAssert(suite.Suite, expected_, r.EpochTime(-1).ToEpochTime(), suite.session, r.RunOpts{ |
| 160 | GeometryFormat: "raw", |
| 161 | GroupFormat: "map", |
| 162 | }) |
| 163 | suite.T().Log("Finished running line #37") |
| 164 | } |
| 165 | |
| 166 | { |
| 167 | // times/constructors.yaml line #39 |
| 168 | /* 1.444 */ |
| 169 | var expected_ float64 = 1.444 |
| 170 | /* r.epoch_time(1.4444445).to_epoch_time() */ |
| 171 | |
| 172 | suite.T().Log("About to run line #39: r.EpochTime(1.4444445).ToEpochTime()") |
| 173 | |
| 174 | runAndAssert(suite.Suite, expected_, r.EpochTime(1.4444445).ToEpochTime(), suite.session, r.RunOpts{ |
| 175 | GeometryFormat: "raw", |
| 176 | GroupFormat: "map", |
| 177 | }) |
| 178 | suite.T().Log("Finished running line #39") |
| 179 | } |
| 180 | |
| 181 | { |
| 182 | // times/constructors.yaml line #42 |
| 183 | /* "1970-01-01T00:00:01.444+00:00" */ |
| 184 | var expected_ string = "1970-01-01T00:00:01.444+00:00" |
| 185 | /* r.epoch_time(1.4444445).to_iso8601() */ |
| 186 | |
| 187 | suite.T().Log("About to run line #42: r.EpochTime(1.4444445).ToISO8601()") |
| 188 | |
| 189 | runAndAssert(suite.Suite, expected_, r.EpochTime(1.4444445).ToISO8601(), suite.session, r.RunOpts{ |
| 190 | GeometryFormat: "raw", |
| 191 | GroupFormat: "map", |
| 192 | }) |
| 193 | suite.T().Log("Finished running line #42") |
| 194 | } |
| 195 | |
| 196 | { |
| 197 | // times/constructors.yaml line #45 |
| 198 | /* 1.444 */ |
| 199 | var expected_ float64 = 1.444 |
| 200 | /* r.epoch_time(1.4444445).seconds() */ |
| 201 | |
| 202 | suite.T().Log("About to run line #45: r.EpochTime(1.4444445).Seconds()") |
| 203 | |
| 204 | runAndAssert(suite.Suite, expected_, r.EpochTime(1.4444445).Seconds(), suite.session, r.RunOpts{ |
| 205 | GeometryFormat: "raw", |
| 206 | GroupFormat: "map", |
| 207 | }) |
| 208 | suite.T().Log("Finished running line #45") |
| 209 | } |
| 210 | |
| 211 | { |
| 212 | // times/constructors.yaml line #48 |
| 213 | /* 10000 */ |
| 214 | var expected_ int = 10000 |
| 215 | /* r.epoch_time(253430000000).year() */ |
| 216 | |
| 217 | suite.T().Log("About to run line #48: r.EpochTime(253430000000).Year()") |
| 218 | |
| 219 | runAndAssert(suite.Suite, expected_, r.EpochTime(253430000000).Year(), suite.session, r.RunOpts{ |
| 220 | GeometryFormat: "raw", |
| 221 | GroupFormat: "map", |
| 222 | }) |
| 223 | suite.T().Log("Finished running line #48") |
| 224 | } |
| 225 | |
| 226 | { |
| 227 | // times/constructors.yaml line #50 |
| 228 | /* err("ReqlQueryLogicError", "Year `10000` out of valid ISO 8601 range [0, 9999].", []) */ |
| 229 | var expected_ Err = err("ReqlQueryLogicError", "Year `10000` out of valid ISO 8601 range [0, 9999].") |
| 230 | /* r.epoch_time(253430000000).to_iso8601() */ |
| 231 | |
| 232 | suite.T().Log("About to run line #50: r.EpochTime(253430000000).ToISO8601()") |
| 233 | |
| 234 | runAndAssert(suite.Suite, expected_, r.EpochTime(253430000000).ToISO8601(), suite.session, r.RunOpts{ |
| 235 | GeometryFormat: "raw", |
| 236 | GroupFormat: "map", |
| 237 | }) |
| 238 | suite.T().Log("Finished running line #50") |
| 239 | } |
| 240 | |
| 241 | { |
| 242 | // times/constructors.yaml line #53 |
| 243 | /* err("ReqlQueryLogicError", "Error in time logic: Year is out of valid range: 1400..10000.", []) */ |
| 244 | var expected_ Err = err("ReqlQueryLogicError", "Error in time logic: Year is out of valid range: 1400..10000.") |
| 245 | /* r.epoch_time(253440000000).year() */ |
| 246 | |
| 247 | suite.T().Log("About to run line #53: r.EpochTime(253440000000).Year()") |
| 248 | |
| 249 | runAndAssert(suite.Suite, expected_, r.EpochTime(253440000000).Year(), suite.session, r.RunOpts{ |
| 250 | GeometryFormat: "raw", |
| 251 | GroupFormat: "map", |
| 252 | }) |
| 253 | suite.T().Log("Finished running line #53") |
| 254 | } |
| 255 | |
| 256 | { |
| 257 | // times/constructors.yaml line #55 |
| 258 | /* 253440000000 */ |
| 259 | var expected_ int = 253440000000 |
| 260 | /* r.epoch_time(253440000000).to_epoch_time() */ |
| 261 | |
| 262 | suite.T().Log("About to run line #55: r.EpochTime(253440000000).ToEpochTime()") |
| 263 | |
| 264 | runAndAssert(suite.Suite, expected_, r.EpochTime(253440000000).ToEpochTime(), suite.session, r.RunOpts{ |
| 265 | GeometryFormat: "raw", |
| 266 | GroupFormat: "map", |
| 267 | }) |
| 268 | suite.T().Log("Finished running line #55") |
| 269 | } |
| 270 | |
| 271 | { |
| 272 | // times/constructors.yaml line #57 |
| 273 | /* 1400 */ |
| 274 | var expected_ int = 1400 |
| 275 | /* r.epoch_time(-17980000000).year() */ |
| 276 | |
| 277 | suite.T().Log("About to run line #57: r.EpochTime(-17980000000).Year()") |
| 278 | |
| 279 | runAndAssert(suite.Suite, expected_, r.EpochTime(-17980000000).Year(), suite.session, r.RunOpts{ |
| 280 | GeometryFormat: "raw", |
| 281 | GroupFormat: "map", |
| 282 | }) |
| 283 | suite.T().Log("Finished running line #57") |
| 284 | } |
| 285 | |
| 286 | { |
| 287 | // times/constructors.yaml line #59 |
| 288 | /* err("ReqlQueryLogicError", "Error in time logic: Year is out of valid range: 1400..10000.", []) */ |
| 289 | var expected_ Err = err("ReqlQueryLogicError", "Error in time logic: Year is out of valid range: 1400..10000.") |
| 290 | /* r.epoch_time(-17990000000).year() */ |
| 291 | |
| 292 | suite.T().Log("About to run line #59: r.EpochTime(-17990000000).Year()") |
| 293 | |
| 294 | runAndAssert(suite.Suite, expected_, r.EpochTime(-17990000000).Year(), suite.session, r.RunOpts{ |
| 295 | GeometryFormat: "raw", |
| 296 | GroupFormat: "map", |
| 297 | }) |
| 298 | suite.T().Log("Finished running line #59") |
| 299 | } |
| 300 | |
| 301 | { |
| 302 | // times/constructors.yaml line #61 |
| 303 | /* -17990000000 */ |
| 304 | var expected_ int = -17990000000 |
| 305 | /* r.epoch_time(-17990000000).to_epoch_time() */ |
| 306 | |
| 307 | suite.T().Log("About to run line #61: r.EpochTime(-17990000000).ToEpochTime()") |
| 308 | |
| 309 | runAndAssert(suite.Suite, expected_, r.EpochTime(-17990000000).ToEpochTime(), suite.session, r.RunOpts{ |
| 310 | GeometryFormat: "raw", |
| 311 | GroupFormat: "map", |
| 312 | }) |
| 313 | suite.T().Log("Finished running line #61") |
| 314 | } |
| 315 | |
| 316 | // times/constructors.yaml line #65 |
| 317 | // cdate = "2013-01-01" |
| 318 | suite.T().Log("Possibly executing: var cdate string = '2013-01-01'") |
| 319 | |
| 320 | cdate := "2013-01-01" |
| 321 | _ = cdate // Prevent any noused variable errors |
| 322 | |
| 323 | // times/constructors.yaml line #66 |
| 324 | // dates = ["2013", "2013-01", "2013-01-01", "20130101", "2013-001", "2013001"] |
| 325 | suite.T().Log("Possibly executing: var dates []interface{} = []interface{}{'2013', '2013-01', '2013-01-01', '20130101', '2013-001', '2013001'}") |
| 326 | |
| 327 | dates := []interface{}{"2013", "2013-01", "2013-01-01", "20130101", "2013-001", "2013001"} |
| 328 | _ = dates // Prevent any noused variable errors |
| 329 | |
| 330 | // times/constructors.yaml line #67 |
| 331 | // ctime = "13:00:00" |
| 332 | suite.T().Log("Possibly executing: var ctime string = '13:00:00'") |
| 333 | |
| 334 | ctime := "13:00:00" |
| 335 | _ = ctime // Prevent any noused variable errors |
| 336 | |
| 337 | // times/constructors.yaml line #68 |
| 338 | // times = ["13", "13:00", "1300", "13:00:00", "13:00:00.000000", "130000.000000"] |
| 339 | suite.T().Log("Possibly executing: var times []interface{} = []interface{}{'13', '13:00', '1300', '13:00:00', '13:00:00.000000', '130000.000000'}") |
| 340 | |
| 341 | times := []interface{}{"13", "13:00", "1300", "13:00:00", "13:00:00.000000", "130000.000000"} |
| 342 | _ = times // Prevent any noused variable errors |
| 343 | |
| 344 | // times/constructors.yaml line #69 |
| 345 | // ctz = "+00:00" |
| 346 | suite.T().Log("Possibly executing: var ctz string = '+00:00'") |
| 347 | |
| 348 | ctz := "+00:00" |
| 349 | _ = ctz // Prevent any noused variable errors |
| 350 | |
| 351 | // times/constructors.yaml line #70 |
| 352 | // tzs = ["Z", "+00", "+0000", "+00:00"] |
| 353 | suite.T().Log("Possibly executing: var tzs []interface{} = []interface{}{'Z', '+00', '+0000', '+00:00'}") |
| 354 | |
| 355 | tzs := []interface{}{"Z", "+00", "+0000", "+00:00"} |
| 356 | _ = tzs // Prevent any noused variable errors |
| 357 | |
| 358 | // times/constructors.yaml line #71 |
| 359 | // cdt = [cdate+"T"+ctime+ctz] |
| 360 | suite.T().Log("Possibly executing: var cdt []interface{} = []interface{}{cdate + 'T' + ctime + ctz}") |
| 361 | |
| 362 | cdt := []interface{}{cdate + "T" + ctime + ctz} |
| 363 | _ = cdt // Prevent any noused variable errors |
| 364 | |
| 365 | // times/constructors.yaml line #81 |
| 366 | // bad_dates = ["201301", "2013-0101", "2a13", "2013+01", "2013-01-01.1"] |
| 367 | suite.T().Log("Possibly executing: var bad_dates []interface{} = []interface{}{'201301', '2013-0101', '2a13', '2013+01', '2013-01-01.1'}") |
| 368 | |
| 369 | bad_dates := []interface{}{"201301", "2013-0101", "2a13", "2013+01", "2013-01-01.1"} |
| 370 | _ = bad_dates // Prevent any noused variable errors |
| 371 | |
| 372 | // times/constructors.yaml line #82 |
| 373 | // bad_times = ["a3", "13:0000", "13:000", "13:00.00", "130000.00000000a"] |
| 374 | suite.T().Log("Possibly executing: var bad_times []interface{} = []interface{}{'a3', '13:0000', '13:000', '13:00.00', '130000.00000000a'}") |
| 375 | |
| 376 | bad_times := []interface{}{"a3", "13:0000", "13:000", "13:00.00", "130000.00000000a"} |
| 377 | _ = bad_times // Prevent any noused variable errors |
| 378 | |
| 379 | // times/constructors.yaml line #83 |
| 380 | // bad_tzs = ["X", "-7", "-07:-1", "+07+01", "PST", "UTC", "Z+00"] |
| 381 | suite.T().Log("Possibly executing: var bad_tzs []interface{} = []interface{}{'X', '-7', '-07:-1', '+07+01', 'PST', 'UTC', 'Z+00'}") |
| 382 | |
| 383 | bad_tzs := []interface{}{"X", "-7", "-07:-1", "+07+01", "PST", "UTC", "Z+00"} |
| 384 | _ = bad_tzs // Prevent any noused variable errors |
| 385 | |
| 386 | } |