gopkg.in/rethinkdb/rethinkdb-go.v6@v6.2.2/internal/integration/reql_tests/reql_datum_bool_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 of conversion to and from the RQL bool type
    17  func TestDatumBoolSuite(t *testing.T) {
    18  	suite.Run(t, new(DatumBoolSuite))
    19  }
    20  
    21  type DatumBoolSuite struct {
    22  	suite.Suite
    23  
    24  	session *r.Session
    25  }
    26  
    27  func (suite *DatumBoolSuite) SetupTest() {
    28  	suite.T().Log("Setting up DatumBoolSuite")
    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 *DatumBoolSuite) TearDownSuite() {
    48  	suite.T().Log("Tearing down DatumBoolSuite")
    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 *DatumBoolSuite) TestCases() {
    59  	suite.T().Log("Running DatumBoolSuite: Tests of conversion to and from the RQL bool type")
    60  
    61  	{
    62  		// datum/bool.yaml line #3
    63  		/* true */
    64  		var expected_ bool = true
    65  		/* r.expr(True) */
    66  
    67  		suite.T().Log("About to run line #3: r.Expr(true)")
    68  
    69  		runAndAssert(suite.Suite, expected_, r.Expr(true), suite.session, r.RunOpts{
    70  			GeometryFormat: "raw",
    71  			GroupFormat:    "map",
    72  		})
    73  		suite.T().Log("Finished running line #3")
    74  	}
    75  
    76  	{
    77  		// datum/bool.yaml line #10
    78  		/* false */
    79  		var expected_ bool = false
    80  		/* r.expr(False) */
    81  
    82  		suite.T().Log("About to run line #10: r.Expr(false)")
    83  
    84  		runAndAssert(suite.Suite, expected_, r.Expr(false), suite.session, r.RunOpts{
    85  			GeometryFormat: "raw",
    86  			GroupFormat:    "map",
    87  		})
    88  		suite.T().Log("Finished running line #10")
    89  	}
    90  
    91  	{
    92  		// datum/bool.yaml line #17
    93  		/* 'BOOL' */
    94  		var expected_ string = "BOOL"
    95  		/* r.expr(False).type_of() */
    96  
    97  		suite.T().Log("About to run line #17: r.Expr(false).TypeOf()")
    98  
    99  		runAndAssert(suite.Suite, expected_, r.Expr(false).TypeOf(), suite.session, r.RunOpts{
   100  			GeometryFormat: "raw",
   101  			GroupFormat:    "map",
   102  		})
   103  		suite.T().Log("Finished running line #17")
   104  	}
   105  
   106  	{
   107  		// datum/bool.yaml line #21
   108  		/* 'true' */
   109  		var expected_ string = "true"
   110  		/* r.expr(True).coerce_to('string') */
   111  
   112  		suite.T().Log("About to run line #21: r.Expr(true).CoerceTo('string')")
   113  
   114  		runAndAssert(suite.Suite, expected_, r.Expr(true).CoerceTo("string"), suite.session, r.RunOpts{
   115  			GeometryFormat: "raw",
   116  			GroupFormat:    "map",
   117  		})
   118  		suite.T().Log("Finished running line #21")
   119  	}
   120  
   121  	{
   122  		// datum/bool.yaml line #24
   123  		/* True */
   124  		var expected_ bool = true
   125  		/* r.expr(True).coerce_to('bool') */
   126  
   127  		suite.T().Log("About to run line #24: r.Expr(true).CoerceTo('bool')")
   128  
   129  		runAndAssert(suite.Suite, expected_, r.Expr(true).CoerceTo("bool"), suite.session, r.RunOpts{
   130  			GeometryFormat: "raw",
   131  			GroupFormat:    "map",
   132  		})
   133  		suite.T().Log("Finished running line #24")
   134  	}
   135  
   136  	{
   137  		// datum/bool.yaml line #27
   138  		/* False */
   139  		var expected_ bool = false
   140  		/* r.expr(False).coerce_to('bool') */
   141  
   142  		suite.T().Log("About to run line #27: r.Expr(false).CoerceTo('bool')")
   143  
   144  		runAndAssert(suite.Suite, expected_, r.Expr(false).CoerceTo("bool"), suite.session, r.RunOpts{
   145  			GeometryFormat: "raw",
   146  			GroupFormat:    "map",
   147  		})
   148  		suite.T().Log("Finished running line #27")
   149  	}
   150  
   151  	{
   152  		// datum/bool.yaml line #30
   153  		/* False */
   154  		var expected_ bool = false
   155  		/* r.expr(null).coerce_to('bool') */
   156  
   157  		suite.T().Log("About to run line #30: r.Expr(nil).CoerceTo('bool')")
   158  
   159  		runAndAssert(suite.Suite, expected_, r.Expr(nil).CoerceTo("bool"), suite.session, r.RunOpts{
   160  			GeometryFormat: "raw",
   161  			GroupFormat:    "map",
   162  		})
   163  		suite.T().Log("Finished running line #30")
   164  	}
   165  
   166  	{
   167  		// datum/bool.yaml line #33
   168  		/* True */
   169  		var expected_ bool = true
   170  		/* r.expr(0).coerce_to('bool') */
   171  
   172  		suite.T().Log("About to run line #33: r.Expr(0).CoerceTo('bool')")
   173  
   174  		runAndAssert(suite.Suite, expected_, r.Expr(0).CoerceTo("bool"), suite.session, r.RunOpts{
   175  			GeometryFormat: "raw",
   176  			GroupFormat:    "map",
   177  		})
   178  		suite.T().Log("Finished running line #33")
   179  	}
   180  
   181  	{
   182  		// datum/bool.yaml line #36
   183  		/* True */
   184  		var expected_ bool = true
   185  		/* r.expr('false').coerce_to('bool') */
   186  
   187  		suite.T().Log("About to run line #36: r.Expr('false').CoerceTo('bool')")
   188  
   189  		runAndAssert(suite.Suite, expected_, r.Expr("false").CoerceTo("bool"), suite.session, r.RunOpts{
   190  			GeometryFormat: "raw",
   191  			GroupFormat:    "map",
   192  		})
   193  		suite.T().Log("Finished running line #36")
   194  	}
   195  
   196  	{
   197  		// datum/bool.yaml line #39
   198  		/* True */
   199  		var expected_ bool = true
   200  		/* r.expr('foo').coerce_to('bool') */
   201  
   202  		suite.T().Log("About to run line #39: r.Expr('foo').CoerceTo('bool')")
   203  
   204  		runAndAssert(suite.Suite, expected_, r.Expr("foo").CoerceTo("bool"), suite.session, r.RunOpts{
   205  			GeometryFormat: "raw",
   206  			GroupFormat:    "map",
   207  		})
   208  		suite.T().Log("Finished running line #39")
   209  	}
   210  
   211  	{
   212  		// datum/bool.yaml line #42
   213  		/* True */
   214  		var expected_ bool = true
   215  		/* r.expr([]).coerce_to('bool') */
   216  
   217  		suite.T().Log("About to run line #42: r.Expr([]interface{}{}).CoerceTo('bool')")
   218  
   219  		runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{}).CoerceTo("bool"), suite.session, r.RunOpts{
   220  			GeometryFormat: "raw",
   221  			GroupFormat:    "map",
   222  		})
   223  		suite.T().Log("Finished running line #42")
   224  	}
   225  
   226  	{
   227  		// datum/bool.yaml line #45
   228  		/* True */
   229  		var expected_ bool = true
   230  		/* r.expr({}).coerce_to('bool') */
   231  
   232  		suite.T().Log("About to run line #45: r.Expr(map[interface{}]interface{}{}).CoerceTo('bool')")
   233  
   234  		runAndAssert(suite.Suite, expected_, r.Expr(map[interface{}]interface{}{}).CoerceTo("bool"), suite.session, r.RunOpts{
   235  			GeometryFormat: "raw",
   236  			GroupFormat:    "map",
   237  		})
   238  		suite.T().Log("Finished running line #45")
   239  	}
   240  }