github.com/dolthub/go-mysql-server@v0.18.0/sql/expression/function/concat_test.go (about)

     1  // Copyright 2020-2021 Dolthub, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package function
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/require"
    21  
    22  	"github.com/dolthub/go-mysql-server/sql"
    23  	"github.com/dolthub/go-mysql-server/sql/expression"
    24  	"github.com/dolthub/go-mysql-server/sql/types"
    25  )
    26  
    27  func TestConcat(t *testing.T) {
    28  	t.Run("concat multiple arguments", func(t *testing.T) {
    29  		require := require.New(t)
    30  		f, err := NewConcat(expression.NewLiteral("foo", types.LongText),
    31  			expression.NewLiteral(5, types.LongText),
    32  			expression.NewLiteral(true, types.Boolean),
    33  		)
    34  		require.NoError(err)
    35  
    36  		v, err := f.Eval(sql.NewEmptyContext(), nil)
    37  		require.NoError(err)
    38  		require.Equal("foo51", v)
    39  	})
    40  
    41  	t.Run("some argument is nil", func(t *testing.T) {
    42  		require := require.New(t)
    43  		f, err := NewConcat(expression.NewLiteral("foo", types.LongText),
    44  			expression.NewLiteral(nil, types.LongText),
    45  			expression.NewLiteral(true, types.Boolean),
    46  		)
    47  		require.NoError(err)
    48  
    49  		v, err := f.Eval(sql.NewEmptyContext(), nil)
    50  		require.NoError(err)
    51  		require.Equal(nil, v)
    52  	})
    53  }
    54  
    55  func TestNewConcat(t *testing.T) {
    56  	require := require.New(t)
    57  
    58  	_, err := NewConcat(expression.NewLiteral(nil, types.LongText))
    59  	require.NoError(err)
    60  
    61  	_, err = NewConcat(expression.NewLiteral(nil, types.LongText), expression.NewLiteral(nil, types.Int64))
    62  	require.NoError(err)
    63  
    64  	_, err = NewConcat(
    65  		expression.NewLiteral(nil, types.LongText),
    66  		expression.NewLiteral(nil, types.Boolean),
    67  		expression.NewLiteral(nil, types.Int64),
    68  		expression.NewLiteral(nil, types.LongText),
    69  	)
    70  	require.NoError(err)
    71  }