...

Source file src/github.com/doug-martin/goqu/v9/exp/alias_test.go

Documentation: github.com/doug-martin/goqu/v9/exp

     1  package exp_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/doug-martin/goqu/v9/exp"
     7  	"github.com/stretchr/testify/suite"
     8  )
     9  
    10  type aliasExpressionSuite struct {
    11  	suite.Suite
    12  }
    13  
    14  func TestAliasExpressionSuite(t *testing.T) {
    15  	suite.Run(t, &aliasExpressionSuite{})
    16  }
    17  
    18  func (aes *aliasExpressionSuite) TestClone() {
    19  	ae := exp.NewAliasExpression(exp.NewIdentifierExpression("", "", "col"), "c")
    20  	aes.Equal(ae, ae.Clone())
    21  }
    22  
    23  func (aes *aliasExpressionSuite) TestExpression() {
    24  	ae := exp.NewAliasExpression(exp.NewIdentifierExpression("", "", "col"), "c")
    25  	aes.Equal(ae, ae.Expression())
    26  }
    27  
    28  func (aes *aliasExpressionSuite) TestAliased() {
    29  	ident := exp.NewIdentifierExpression("", "", "col")
    30  	ae := exp.NewAliasExpression(ident, "c")
    31  	aes.Equal(ident, ae.Aliased())
    32  }
    33  
    34  func (aes *aliasExpressionSuite) TestGetAs() {
    35  	ae := exp.NewAliasExpression(exp.NewIdentifierExpression("", "", "col"), "c")
    36  	aes.Equal(exp.NewIdentifierExpression("", "", "c"), ae.GetAs())
    37  }
    38  
    39  func (aes *aliasExpressionSuite) TestSchema() {
    40  	si := exp.NewAliasExpression(
    41  		exp.NewIdentifierExpression("", "t", nil),
    42  		exp.NewIdentifierExpression("", "t", nil),
    43  	).Schema("s")
    44  	aes.Equal(exp.NewIdentifierExpression("s", "t", nil), si)
    45  }
    46  
    47  func (aes *aliasExpressionSuite) TestTable() {
    48  	si := exp.NewAliasExpression(
    49  		exp.NewIdentifierExpression("schema", "", nil),
    50  		exp.NewIdentifierExpression("s", "", nil),
    51  	).Table("t")
    52  	aes.Equal(exp.NewIdentifierExpression("s", "t", nil), si)
    53  }
    54  
    55  func (aes *aliasExpressionSuite) TestCol() {
    56  	si := exp.NewAliasExpression(
    57  		exp.NewIdentifierExpression("", "table", nil),
    58  		exp.NewIdentifierExpression("", "t", nil),
    59  	).Col("c")
    60  	aes.Equal(exp.NewIdentifierExpression("", "t", "c"), si)
    61  }
    62  
    63  func (aes *aliasExpressionSuite) TestAll() {
    64  	si := exp.NewAliasExpression(
    65  		exp.NewIdentifierExpression("", "table", nil),
    66  		exp.NewIdentifierExpression("", "t", nil),
    67  	).All()
    68  	aes.Equal(exp.NewIdentifierExpression("", "t", exp.Star()), si)
    69  }
    70  

View as plain text