gopkg.in/rethinkdb/rethinkdb-go.v6@v6.2.2/internal/integration/reql_tests/reql_times_constructors_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 // 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("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 *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("test").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 #49 213 /* "1970-01-01T00:00:01.444+00:00" */ 214 var expected_ string = "1970-01-01T00:00:01.444+00:00" 215 /* r.epoch_time(1.444).to_iso8601() */ 216 217 suite.T().Log("About to run line #49: r.EpochTime(1.444).ToISO8601()") 218 219 runAndAssert(suite.Suite, expected_, r.EpochTime(1.444).ToISO8601(), suite.session, r.RunOpts{ 220 GeometryFormat: "raw", 221 GroupFormat: "map", 222 }) 223 suite.T().Log("Finished running line #49") 224 } 225 226 { 227 // times/constructors.yaml line #52 228 /* "1970-01-01T00:00:01.001+00:00" */ 229 var expected_ string = "1970-01-01T00:00:01.001+00:00" 230 /* r.epoch_time(1.001).to_iso8601() */ 231 232 suite.T().Log("About to run line #52: r.EpochTime(1.001).ToISO8601()") 233 234 runAndAssert(suite.Suite, expected_, r.EpochTime(1.001).ToISO8601(), suite.session, r.RunOpts{ 235 GeometryFormat: "raw", 236 GroupFormat: "map", 237 }) 238 suite.T().Log("Finished running line #52") 239 } 240 241 { 242 // times/constructors.yaml line #55 243 /* "1970-01-01T00:00:02.058+00:00" */ 244 var expected_ string = "1970-01-01T00:00:02.058+00:00" 245 /* r.epoch_time(2.058).to_iso8601() */ 246 247 suite.T().Log("About to run line #55: r.EpochTime(2.058).ToISO8601()") 248 249 runAndAssert(suite.Suite, expected_, r.EpochTime(2.058).ToISO8601(), suite.session, r.RunOpts{ 250 GeometryFormat: "raw", 251 GroupFormat: "map", 252 }) 253 suite.T().Log("Finished running line #55") 254 } 255 256 { 257 // times/constructors.yaml line #66 258 /* 253440000000 */ 259 var expected_ int = 253440000000 260 /* r.epoch_time(253440000000).to_epoch_time() */ 261 262 suite.T().Log("About to run line #66: 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 #66") 269 } 270 271 { 272 // times/constructors.yaml line #68 273 /* 1400 */ 274 var expected_ int = 1400 275 /* r.epoch_time(-17980000000).year() */ 276 277 suite.T().Log("About to run line #68: 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 #68") 284 } 285 286 { 287 // times/constructors.yaml line #72 288 /* -17990000000 */ 289 var expected_ int = -17990000000 290 /* r.epoch_time(-17990000000).to_epoch_time() */ 291 292 suite.T().Log("About to run line #72: r.EpochTime(-17990000000).ToEpochTime()") 293 294 runAndAssert(suite.Suite, expected_, r.EpochTime(-17990000000).ToEpochTime(), suite.session, r.RunOpts{ 295 GeometryFormat: "raw", 296 GroupFormat: "map", 297 }) 298 suite.T().Log("Finished running line #72") 299 } 300 301 // times/constructors.yaml line #76 302 // cdate = "2013-01-01" 303 suite.T().Log("Possibly executing: var cdate string = '2013-01-01'") 304 305 cdate := "2013-01-01" 306 _ = cdate // Prevent any noused variable errors 307 308 // times/constructors.yaml line #77 309 // dates = ["2013", "2013-01", "2013-01-01", "20130101", "2013-001", "2013001"] 310 suite.T().Log("Possibly executing: var dates []interface{} = []interface{}{'2013', '2013-01', '2013-01-01', '20130101', '2013-001', '2013001'}") 311 312 dates := []interface{}{"2013", "2013-01", "2013-01-01", "20130101", "2013-001", "2013001"} 313 _ = dates // Prevent any noused variable errors 314 315 // times/constructors.yaml line #78 316 // ctime = "13:00:00" 317 suite.T().Log("Possibly executing: var ctime string = '13:00:00'") 318 319 ctime := "13:00:00" 320 _ = ctime // Prevent any noused variable errors 321 322 // times/constructors.yaml line #79 323 // times = ["13", "13:00", "1300", "13:00:00", "13:00:00.000000", "130000.000000"] 324 suite.T().Log("Possibly executing: var times []interface{} = []interface{}{'13', '13:00', '1300', '13:00:00', '13:00:00.000000', '130000.000000'}") 325 326 times := []interface{}{"13", "13:00", "1300", "13:00:00", "13:00:00.000000", "130000.000000"} 327 _ = times // Prevent any noused variable errors 328 329 // times/constructors.yaml line #80 330 // ctz = "+00:00" 331 suite.T().Log("Possibly executing: var ctz string = '+00:00'") 332 333 ctz := "+00:00" 334 _ = ctz // Prevent any noused variable errors 335 336 // times/constructors.yaml line #81 337 // tzs = ["Z", "+00", "+0000", "+00:00"] 338 suite.T().Log("Possibly executing: var tzs []interface{} = []interface{}{'Z', '+00', '+0000', '+00:00'}") 339 340 tzs := []interface{}{"Z", "+00", "+0000", "+00:00"} 341 _ = tzs // Prevent any noused variable errors 342 343 // times/constructors.yaml line #82 344 // cdt = [cdate+"T"+ctime+ctz] 345 suite.T().Log("Possibly executing: var cdt []interface{} = []interface{}{cdate + 'T' + ctime + ctz}") 346 347 cdt := []interface{}{cdate + "T" + ctime + ctz} 348 _ = cdt // Prevent any noused variable errors 349 350 // times/constructors.yaml line #92 351 // bad_dates = ["201301", "2013-0101", "2a13", "2013+01", "2013-01-01.1"] 352 suite.T().Log("Possibly executing: var bad_dates []interface{} = []interface{}{'201301', '2013-0101', '2a13', '2013+01', '2013-01-01.1'}") 353 354 bad_dates := []interface{}{"201301", "2013-0101", "2a13", "2013+01", "2013-01-01.1"} 355 _ = bad_dates // Prevent any noused variable errors 356 357 // times/constructors.yaml line #93 358 // bad_times = ["a3", "13:0000", "13:000", "13:00.00", "130000.00000000a"] 359 suite.T().Log("Possibly executing: var bad_times []interface{} = []interface{}{'a3', '13:0000', '13:000', '13:00.00', '130000.00000000a'}") 360 361 bad_times := []interface{}{"a3", "13:0000", "13:000", "13:00.00", "130000.00000000a"} 362 _ = bad_times // Prevent any noused variable errors 363 364 // times/constructors.yaml line #94 365 // bad_tzs = ["X", "-7", "-07:-1", "+07+01", "PST", "UTC", "Z+00"] 366 suite.T().Log("Possibly executing: var bad_tzs []interface{} = []interface{}{'X', '-7', '-07:-1', '+07+01', 'PST', 'UTC', 'Z+00'}") 367 368 bad_tzs := []interface{}{"X", "-7", "-07:-1", "+07+01", "PST", "UTC", "Z+00"} 369 _ = bad_tzs // Prevent any noused variable errors 370 371 }