...

Source file src/github.com/doug-martin/goqu/v9/dialect/sqlserver/sqlserver_dialect_test.go

Documentation: github.com/doug-martin/goqu/v9/dialect/sqlserver

     1  package sqlserver_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/doug-martin/goqu/v9"
     7  	"github.com/doug-martin/goqu/v9/exp"
     8  	"github.com/stretchr/testify/suite"
     9  )
    10  
    11  type (
    12  	sqlserverDialectSuite struct {
    13  		suite.Suite
    14  	}
    15  	sqlTestCase struct {
    16  		ds         exp.SQLExpression
    17  		sql        string
    18  		err        string
    19  		isPrepared bool
    20  		args       []interface{}
    21  	}
    22  )
    23  
    24  func (sds *sqlserverDialectSuite) GetDs(table string) *goqu.SelectDataset {
    25  	return goqu.Dialect("sqlserver").From(table)
    26  }
    27  
    28  func (sds *sqlserverDialectSuite) assertSQL(cases ...sqlTestCase) {
    29  	for i, c := range cases {
    30  		actualSQL, actualArgs, err := c.ds.ToSQL()
    31  		if c.err == "" {
    32  			sds.NoError(err, "test case %d failed", i)
    33  		} else {
    34  			sds.EqualError(err, c.err, "test case %d failed", i)
    35  		}
    36  		sds.Equal(c.sql, actualSQL, "test case %d failed", i)
    37  		if c.isPrepared && c.args != nil || len(c.args) > 0 {
    38  			sds.Equal(c.args, actualArgs, "test case %d failed", i)
    39  		} else {
    40  			sds.Empty(actualArgs, "test case %d failed", i)
    41  		}
    42  	}
    43  }
    44  
    45  func (sds *sqlserverDialectSuite) TestBitwiseOperations() {
    46  	col := goqu.C("a")
    47  	ds := sds.GetDs("test")
    48  	sds.assertSQL(
    49  		sqlTestCase{ds: ds.Where(col.BitwiseInversion()), sql: "SELECT * FROM \"test\" WHERE (~ \"a\")"},
    50  		sqlTestCase{ds: ds.Where(col.BitwiseAnd(1)), sql: "SELECT * FROM \"test\" WHERE (\"a\" & 1)"},
    51  		sqlTestCase{ds: ds.Where(col.BitwiseOr(1)), sql: "SELECT * FROM \"test\" WHERE (\"a\" | 1)"},
    52  		sqlTestCase{ds: ds.Where(col.BitwiseXor(1)), sql: "SELECT * FROM \"test\" WHERE (\"a\" ^ 1)"},
    53  		sqlTestCase{ds: ds.Where(col.BitwiseLeftShift(1)), err: "goqu: bitwise operator 'Left Shift' not supported"},
    54  		sqlTestCase{ds: ds.Where(col.BitwiseRightShift(1)), err: "goqu: bitwise operator 'Right Shift' not supported"},
    55  	)
    56  }
    57  
    58  func TestDatasetAdapterSuite(t *testing.T) {
    59  	suite.Run(t, new(sqlserverDialectSuite))
    60  }
    61  

View as plain text