gopkg.in/rethinkdb/rethinkdb-go.v6@v6.2.2/internal/integration/reql_tests/reql_geo_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 geo constructors
    17  func TestGeoConstructorsSuite(t *testing.T) {
    18  	suite.Run(t, new(GeoConstructorsSuite))
    19  }
    20  
    21  type GeoConstructorsSuite struct {
    22  	suite.Suite
    23  
    24  	session *r.Session
    25  }
    26  
    27  func (suite *GeoConstructorsSuite) SetupTest() {
    28  	suite.T().Log("Setting up GeoConstructorsSuite")
    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 *GeoConstructorsSuite) TearDownSuite() {
    48  	suite.T().Log("Tearing down GeoConstructorsSuite")
    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 *GeoConstructorsSuite) TestCases() {
    59  	suite.T().Log("Running GeoConstructorsSuite: Test geo constructors")
    60  
    61  	{
    62  		// geo/constructors.yaml line #4
    63  		/* ({'$reql_type$':'GEOMETRY', 'coordinates':[0, 0], 'type':'Point'}) */
    64  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"$reql_type$": "GEOMETRY", "coordinates": []interface{}{0, 0}, "type": "Point"}
    65  		/* r.point(0, 0) */
    66  
    67  		suite.T().Log("About to run line #4: r.Point(0, 0)")
    68  
    69  		runAndAssert(suite.Suite, expected_, r.Point(0, 0), suite.session, r.RunOpts{
    70  			GeometryFormat: "raw",
    71  			GroupFormat:    "map",
    72  		})
    73  		suite.T().Log("Finished running line #4")
    74  	}
    75  
    76  	{
    77  		// geo/constructors.yaml line #6
    78  		/* ({'$reql_type$':'GEOMETRY', 'coordinates':[0, -90], 'type':'Point'}) */
    79  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"$reql_type$": "GEOMETRY", "coordinates": []interface{}{0, -90}, "type": "Point"}
    80  		/* r.point(0, -90) */
    81  
    82  		suite.T().Log("About to run line #6: r.Point(0, -90)")
    83  
    84  		runAndAssert(suite.Suite, expected_, r.Point(0, -90), suite.session, r.RunOpts{
    85  			GeometryFormat: "raw",
    86  			GroupFormat:    "map",
    87  		})
    88  		suite.T().Log("Finished running line #6")
    89  	}
    90  
    91  	{
    92  		// geo/constructors.yaml line #8
    93  		/* ({'$reql_type$':'GEOMETRY', 'coordinates':[0, 90], 'type':'Point'}) */
    94  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"$reql_type$": "GEOMETRY", "coordinates": []interface{}{0, 90}, "type": "Point"}
    95  		/* r.point(0, 90) */
    96  
    97  		suite.T().Log("About to run line #8: r.Point(0, 90)")
    98  
    99  		runAndAssert(suite.Suite, expected_, r.Point(0, 90), suite.session, r.RunOpts{
   100  			GeometryFormat: "raw",
   101  			GroupFormat:    "map",
   102  		})
   103  		suite.T().Log("Finished running line #8")
   104  	}
   105  
   106  	{
   107  		// geo/constructors.yaml line #10
   108  		/* ({'$reql_type$':'GEOMETRY', 'coordinates':[-180, 0], 'type':'Point'}) */
   109  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"$reql_type$": "GEOMETRY", "coordinates": []interface{}{-180, 0}, "type": "Point"}
   110  		/* r.point(-180, 0) */
   111  
   112  		suite.T().Log("About to run line #10: r.Point(-180, 0)")
   113  
   114  		runAndAssert(suite.Suite, expected_, r.Point(-180, 0), suite.session, r.RunOpts{
   115  			GeometryFormat: "raw",
   116  			GroupFormat:    "map",
   117  		})
   118  		suite.T().Log("Finished running line #10")
   119  	}
   120  
   121  	{
   122  		// geo/constructors.yaml line #12
   123  		/* ({'$reql_type$':'GEOMETRY', 'coordinates':[180, 0], 'type':'Point'}) */
   124  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"$reql_type$": "GEOMETRY", "coordinates": []interface{}{180, 0}, "type": "Point"}
   125  		/* r.point(180, 0) */
   126  
   127  		suite.T().Log("About to run line #12: r.Point(180, 0)")
   128  
   129  		runAndAssert(suite.Suite, expected_, r.Point(180, 0), suite.session, r.RunOpts{
   130  			GeometryFormat: "raw",
   131  			GroupFormat:    "map",
   132  		})
   133  		suite.T().Log("Finished running line #12")
   134  	}
   135  
   136  	{
   137  		// geo/constructors.yaml line #14
   138  		/* err('ReqlQueryLogicError', 'Latitude must be between -90 and 90.  Got -91.', [0]) */
   139  		var expected_ Err = err("ReqlQueryLogicError", "Latitude must be between -90 and 90.  Got -91.")
   140  		/* r.point(0, -91) */
   141  
   142  		suite.T().Log("About to run line #14: r.Point(0, -91)")
   143  
   144  		runAndAssert(suite.Suite, expected_, r.Point(0, -91), suite.session, r.RunOpts{
   145  			GeometryFormat: "raw",
   146  			GroupFormat:    "map",
   147  		})
   148  		suite.T().Log("Finished running line #14")
   149  	}
   150  
   151  	{
   152  		// geo/constructors.yaml line #16
   153  		/* err('ReqlQueryLogicError', 'Latitude must be between -90 and 90.  Got 91.', [0]) */
   154  		var expected_ Err = err("ReqlQueryLogicError", "Latitude must be between -90 and 90.  Got 91.")
   155  		/* r.point(0, 91) */
   156  
   157  		suite.T().Log("About to run line #16: r.Point(0, 91)")
   158  
   159  		runAndAssert(suite.Suite, expected_, r.Point(0, 91), suite.session, r.RunOpts{
   160  			GeometryFormat: "raw",
   161  			GroupFormat:    "map",
   162  		})
   163  		suite.T().Log("Finished running line #16")
   164  	}
   165  
   166  	{
   167  		// geo/constructors.yaml line #18
   168  		/* err('ReqlQueryLogicError', 'Longitude must be between -180 and 180.  Got -181.', [0]) */
   169  		var expected_ Err = err("ReqlQueryLogicError", "Longitude must be between -180 and 180.  Got -181.")
   170  		/* r.point(-181, 0) */
   171  
   172  		suite.T().Log("About to run line #18: r.Point(-181, 0)")
   173  
   174  		runAndAssert(suite.Suite, expected_, r.Point(-181, 0), suite.session, r.RunOpts{
   175  			GeometryFormat: "raw",
   176  			GroupFormat:    "map",
   177  		})
   178  		suite.T().Log("Finished running line #18")
   179  	}
   180  
   181  	{
   182  		// geo/constructors.yaml line #20
   183  		/* err('ReqlQueryLogicError', 'Longitude must be between -180 and 180.  Got 181.', [0]) */
   184  		var expected_ Err = err("ReqlQueryLogicError", "Longitude must be between -180 and 180.  Got 181.")
   185  		/* r.point(181, 0) */
   186  
   187  		suite.T().Log("About to run line #20: r.Point(181, 0)")
   188  
   189  		runAndAssert(suite.Suite, expected_, r.Point(181, 0), suite.session, r.RunOpts{
   190  			GeometryFormat: "raw",
   191  			GroupFormat:    "map",
   192  		})
   193  		suite.T().Log("Finished running line #20")
   194  	}
   195  
   196  	{
   197  		// geo/constructors.yaml line #28
   198  		/* err('ReqlQueryLogicError', 'Invalid LineString.  Are there antipodal or duplicate vertices?', [0]) */
   199  		var expected_ Err = err("ReqlQueryLogicError", "Invalid LineString.  Are there antipodal or duplicate vertices?")
   200  		/* r.line([0,0], [0,0]) */
   201  
   202  		suite.T().Log("About to run line #28: r.Line([]interface{}{0, 0}, []interface{}{0, 0})")
   203  
   204  		runAndAssert(suite.Suite, expected_, r.Line([]interface{}{0, 0}, []interface{}{0, 0}), suite.session, r.RunOpts{
   205  			GeometryFormat: "raw",
   206  			GroupFormat:    "map",
   207  		})
   208  		suite.T().Log("Finished running line #28")
   209  	}
   210  
   211  	{
   212  		// geo/constructors.yaml line #30
   213  		/* ({'$reql_type$':'GEOMETRY', 'coordinates':[[0,0], [0,1]], 'type':'LineString'}) */
   214  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"$reql_type$": "GEOMETRY", "coordinates": []interface{}{[]interface{}{0, 0}, []interface{}{0, 1}}, "type": "LineString"}
   215  		/* r.line([0,0], [0,1]) */
   216  
   217  		suite.T().Log("About to run line #30: r.Line([]interface{}{0, 0}, []interface{}{0, 1})")
   218  
   219  		runAndAssert(suite.Suite, expected_, r.Line([]interface{}{0, 0}, []interface{}{0, 1}), suite.session, r.RunOpts{
   220  			GeometryFormat: "raw",
   221  			GroupFormat:    "map",
   222  		})
   223  		suite.T().Log("Finished running line #30")
   224  	}
   225  
   226  	{
   227  		// geo/constructors.yaml line #32
   228  		/* err('ReqlQueryLogicError', 'Expected point coordinate pair.  Got 1 element array instead of a 2 element one.', [0]) */
   229  		var expected_ Err = err("ReqlQueryLogicError", "Expected point coordinate pair.  Got 1 element array instead of a 2 element one.")
   230  		/* r.line([0,0], [1]) */
   231  
   232  		suite.T().Log("About to run line #32: r.Line([]interface{}{0, 0}, []interface{}{1})")
   233  
   234  		runAndAssert(suite.Suite, expected_, r.Line([]interface{}{0, 0}, []interface{}{1}), suite.session, r.RunOpts{
   235  			GeometryFormat: "raw",
   236  			GroupFormat:    "map",
   237  		})
   238  		suite.T().Log("Finished running line #32")
   239  	}
   240  
   241  	{
   242  		// geo/constructors.yaml line #34
   243  		/* err('ReqlQueryLogicError', 'Expected point coordinate pair.  Got 3 element array instead of a 2 element one.', [0]) */
   244  		var expected_ Err = err("ReqlQueryLogicError", "Expected point coordinate pair.  Got 3 element array instead of a 2 element one.")
   245  		/* r.line([0,0], [1,0,0]) */
   246  
   247  		suite.T().Log("About to run line #34: r.Line([]interface{}{0, 0}, []interface{}{1, 0, 0})")
   248  
   249  		runAndAssert(suite.Suite, expected_, r.Line([]interface{}{0, 0}, []interface{}{1, 0, 0}), suite.session, r.RunOpts{
   250  			GeometryFormat: "raw",
   251  			GroupFormat:    "map",
   252  		})
   253  		suite.T().Log("Finished running line #34")
   254  	}
   255  
   256  	{
   257  		// geo/constructors.yaml line #36
   258  		/* ({'$reql_type$':'GEOMETRY', 'coordinates':[[0,0], [0,1], [0,0]], 'type':'LineString'}) */
   259  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"$reql_type$": "GEOMETRY", "coordinates": []interface{}{[]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{0, 0}}, "type": "LineString"}
   260  		/* r.line([0,0], [0,1], [0,0]) */
   261  
   262  		suite.T().Log("About to run line #36: r.Line([]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{0, 0})")
   263  
   264  		runAndAssert(suite.Suite, expected_, r.Line([]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{0, 0}), suite.session, r.RunOpts{
   265  			GeometryFormat: "raw",
   266  			GroupFormat:    "map",
   267  		})
   268  		suite.T().Log("Finished running line #36")
   269  	}
   270  
   271  	{
   272  		// geo/constructors.yaml line #38
   273  		/* ({'$reql_type$':'GEOMETRY', 'coordinates':[[0,0], [0,1], [0,0]], 'type':'LineString'}) */
   274  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"$reql_type$": "GEOMETRY", "coordinates": []interface{}{[]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{0, 0}}, "type": "LineString"}
   275  		/* r.line(r.point(0,0), r.point(0,1), r.point(0,0)) */
   276  
   277  		suite.T().Log("About to run line #38: r.Line(r.Point(0, 0), r.Point(0, 1), r.Point(0, 0))")
   278  
   279  		runAndAssert(suite.Suite, expected_, r.Line(r.Point(0, 0), r.Point(0, 1), r.Point(0, 0)), suite.session, r.RunOpts{
   280  			GeometryFormat: "raw",
   281  			GroupFormat:    "map",
   282  		})
   283  		suite.T().Log("Finished running line #38")
   284  	}
   285  
   286  	{
   287  		// geo/constructors.yaml line #40
   288  		/* err('ReqlQueryLogicError', 'Expected geometry of type `Point` but found `LineString`.', [0]) */
   289  		var expected_ Err = err("ReqlQueryLogicError", "Expected geometry of type `Point` but found `LineString`.")
   290  		/* r.line(r.point(0,0), r.point(1,0), r.line([0,0], [1,0])) */
   291  
   292  		suite.T().Log("About to run line #40: r.Line(r.Point(0, 0), r.Point(1, 0), r.Line([]interface{}{0, 0}, []interface{}{1, 0}))")
   293  
   294  		runAndAssert(suite.Suite, expected_, r.Line(r.Point(0, 0), r.Point(1, 0), r.Line([]interface{}{0, 0}, []interface{}{1, 0})), suite.session, r.RunOpts{
   295  			GeometryFormat: "raw",
   296  			GroupFormat:    "map",
   297  		})
   298  		suite.T().Log("Finished running line #40")
   299  	}
   300  
   301  	{
   302  		// geo/constructors.yaml line #50
   303  		/* err('ReqlQueryLogicError', 'Invalid LinearRing.  Are there antipodal or duplicate vertices? Is it self-intersecting?', [0]) */
   304  		var expected_ Err = err("ReqlQueryLogicError", "Invalid LinearRing.  Are there antipodal or duplicate vertices? Is it self-intersecting?")
   305  		/* r.polygon([0,0], [0,0], [0,0], [0,0]) */
   306  
   307  		suite.T().Log("About to run line #50: r.Polygon([]interface{}{0, 0}, []interface{}{0, 0}, []interface{}{0, 0}, []interface{}{0, 0})")
   308  
   309  		runAndAssert(suite.Suite, expected_, r.Polygon([]interface{}{0, 0}, []interface{}{0, 0}, []interface{}{0, 0}, []interface{}{0, 0}), suite.session, r.RunOpts{
   310  			GeometryFormat: "raw",
   311  			GroupFormat:    "map",
   312  		})
   313  		suite.T().Log("Finished running line #50")
   314  	}
   315  
   316  	{
   317  		// geo/constructors.yaml line #52
   318  		/* ({'$reql_type$':'GEOMETRY', 'coordinates':[[[0,0], [0,1], [1,0], [0,0]]], 'type':'Polygon'}) */
   319  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"$reql_type$": "GEOMETRY", "coordinates": []interface{}{[]interface{}{[]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{1, 0}, []interface{}{0, 0}}}, "type": "Polygon"}
   320  		/* r.polygon([0,0], [0,1], [1,0]) */
   321  
   322  		suite.T().Log("About to run line #52: r.Polygon([]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{1, 0})")
   323  
   324  		runAndAssert(suite.Suite, expected_, r.Polygon([]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{1, 0}), suite.session, r.RunOpts{
   325  			GeometryFormat: "raw",
   326  			GroupFormat:    "map",
   327  		})
   328  		suite.T().Log("Finished running line #52")
   329  	}
   330  
   331  	{
   332  		// geo/constructors.yaml line #54
   333  		/* ({'$reql_type$':'GEOMETRY', 'coordinates':[[[0,0], [0,1], [1,0], [0,0]]], 'type':'Polygon'}) */
   334  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"$reql_type$": "GEOMETRY", "coordinates": []interface{}{[]interface{}{[]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{1, 0}, []interface{}{0, 0}}}, "type": "Polygon"}
   335  		/* r.polygon([0,0], [0,1], [1,0], [0,0]) */
   336  
   337  		suite.T().Log("About to run line #54: r.Polygon([]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{1, 0}, []interface{}{0, 0})")
   338  
   339  		runAndAssert(suite.Suite, expected_, r.Polygon([]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{1, 0}, []interface{}{0, 0}), suite.session, r.RunOpts{
   340  			GeometryFormat: "raw",
   341  			GroupFormat:    "map",
   342  		})
   343  		suite.T().Log("Finished running line #54")
   344  	}
   345  
   346  	{
   347  		// geo/constructors.yaml line #56
   348  		/* err('ReqlQueryLogicError', 'Invalid LinearRing.  Are there antipodal or duplicate vertices? Is it self-intersecting?', [0]) */
   349  		var expected_ Err = err("ReqlQueryLogicError", "Invalid LinearRing.  Are there antipodal or duplicate vertices? Is it self-intersecting?")
   350  		/* r.polygon([0,0], [0,1], [1,0], [-1,0.5]) */
   351  
   352  		suite.T().Log("About to run line #56: r.Polygon([]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{1, 0}, []interface{}{-1, 0.5})")
   353  
   354  		runAndAssert(suite.Suite, expected_, r.Polygon([]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{1, 0}, []interface{}{-1, 0.5}), suite.session, r.RunOpts{
   355  			GeometryFormat: "raw",
   356  			GroupFormat:    "map",
   357  		})
   358  		suite.T().Log("Finished running line #56")
   359  	}
   360  
   361  	{
   362  		// geo/constructors.yaml line #58
   363  		/* err('ReqlQueryLogicError', 'Expected point coordinate pair.  Got 1 element array instead of a 2 element one.', [0]) */
   364  		var expected_ Err = err("ReqlQueryLogicError", "Expected point coordinate pair.  Got 1 element array instead of a 2 element one.")
   365  		/* r.polygon([0,0], [0,1], [0]) */
   366  
   367  		suite.T().Log("About to run line #58: r.Polygon([]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{0})")
   368  
   369  		runAndAssert(suite.Suite, expected_, r.Polygon([]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{0}), suite.session, r.RunOpts{
   370  			GeometryFormat: "raw",
   371  			GroupFormat:    "map",
   372  		})
   373  		suite.T().Log("Finished running line #58")
   374  	}
   375  
   376  	{
   377  		// geo/constructors.yaml line #60
   378  		/* err('ReqlQueryLogicError', 'Expected point coordinate pair.  Got 3 element array instead of a 2 element one.', [0]) */
   379  		var expected_ Err = err("ReqlQueryLogicError", "Expected point coordinate pair.  Got 3 element array instead of a 2 element one.")
   380  		/* r.polygon([0,0], [0,1], [0,1,0]) */
   381  
   382  		suite.T().Log("About to run line #60: r.Polygon([]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{0, 1, 0})")
   383  
   384  		runAndAssert(suite.Suite, expected_, r.Polygon([]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{0, 1, 0}), suite.session, r.RunOpts{
   385  			GeometryFormat: "raw",
   386  			GroupFormat:    "map",
   387  		})
   388  		suite.T().Log("Finished running line #60")
   389  	}
   390  
   391  	{
   392  		// geo/constructors.yaml line #62
   393  		/* err('ReqlQueryLogicError', 'Expected geometry of type `Point` but found `LineString`.', [0]) */
   394  		var expected_ Err = err("ReqlQueryLogicError", "Expected geometry of type `Point` but found `LineString`.")
   395  		/* r.polygon(r.point(0,0), r.point(0,1), r.line([0,0], [0,1])) */
   396  
   397  		suite.T().Log("About to run line #62: r.Polygon(r.Point(0, 0), r.Point(0, 1), r.Line([]interface{}{0, 0}, []interface{}{0, 1}))")
   398  
   399  		runAndAssert(suite.Suite, expected_, r.Polygon(r.Point(0, 0), r.Point(0, 1), r.Line([]interface{}{0, 0}, []interface{}{0, 1})), suite.session, r.RunOpts{
   400  			GeometryFormat: "raw",
   401  			GroupFormat:    "map",
   402  		})
   403  		suite.T().Log("Finished running line #62")
   404  	}
   405  }