Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: migrate test-infra to testify for expression/collation_test.go (#28849) #28965

Merged
52 changes: 27 additions & 25 deletions expression/collation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,41 @@ package expression
import (
"testing"

. "github.com/pingcap/check"
"github.com/stretchr/testify/require"

"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/charset"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/mock"
"github.com/stretchr/testify/require"
)

var _ = SerialSuites(&testCollationSuites{})
func TestCompareString(t *testing.T) {
t.Parallel()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can not make it parallel, see #29125 (comment)


type testCollationSuites struct{}

func (s *testCollationSuites) TestCompareString(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)

c.Assert(types.CompareString("a", "A", "utf8_general_ci"), Equals, 0)
c.Assert(types.CompareString("À", "A", "utf8_general_ci"), Equals, 0)
c.Assert(types.CompareString("😜", "😃", "utf8_general_ci"), Equals, 0)
c.Assert(types.CompareString("a ", "a ", "utf8_general_ci"), Equals, 0)
c.Assert(types.CompareString("ß", "s", "utf8_general_ci"), Equals, 0)
c.Assert(types.CompareString("ß", "ss", "utf8_general_ci"), Not(Equals), 0)
require.Equal(t, 0, types.CompareString("a", "A", "utf8_general_ci"))
require.Equal(t, 0, types.CompareString("À", "A", "utf8_general_ci"))
require.Equal(t, 0, types.CompareString("😜", "😃", "utf8_general_ci"))
require.Equal(t, 0, types.CompareString("a ", "a ", "utf8_general_ci"))
require.Equal(t, 0, types.CompareString("ß", "s", "utf8_general_ci"))
require.NotEqual(t, 0, types.CompareString("ß", "ss", "utf8_general_ci"))

c.Assert(types.CompareString("a", "A", "utf8_unicode_ci"), Equals, 0)
c.Assert(types.CompareString("À", "A", "utf8_unicode_ci"), Equals, 0)
c.Assert(types.CompareString("😜", "😃", "utf8_unicode_ci"), Equals, 0)
c.Assert(types.CompareString("a ", "a ", "utf8_unicode_ci"), Equals, 0)
c.Assert(types.CompareString("ß", "s", "utf8_unicode_ci"), Not(Equals), 0)
c.Assert(types.CompareString("ß", "ss", "utf8_unicode_ci"), Equals, 0)
require.Equal(t, 0, types.CompareString("a", "A", "utf8_unicode_ci"))
require.Equal(t, 0, types.CompareString("À", "A", "utf8_unicode_ci"))
require.Equal(t, 0, types.CompareString("😜", "😃", "utf8_unicode_ci"))
require.Equal(t, 0, types.CompareString("a ", "a ", "utf8_unicode_ci"))
require.NotEqual(t, 0, types.CompareString("ß", "s", "utf8_unicode_ci"))
require.Equal(t, 0, types.CompareString("ß", "ss", "utf8_unicode_ci"))

c.Assert(types.CompareString("a", "A", "binary"), Not(Equals), 0)
c.Assert(types.CompareString("À", "A", "binary"), Not(Equals), 0)
c.Assert(types.CompareString("😜", "😃", "binary"), Not(Equals), 0)
c.Assert(types.CompareString("a ", "a ", "binary"), Not(Equals), 0)
require.NotEqual(t, 0, types.CompareString("a", "A", "binary"))
require.NotEqual(t, 0, types.CompareString("À", "A", "binary"))
require.NotEqual(t, 0, types.CompareString("😜", "😃", "binary"))
require.NotEqual(t, 0, types.CompareString("a ", "a ", "binary"))

ctx := mock.NewContext()
ft := types.NewFieldType(mysql.TypeVarString)
Expand All @@ -76,9 +74,9 @@ func (s *testCollationSuites) TestCompareString(c *C) {
chk.Column(1).AppendString("a ")
for i := 0; i < 4; i++ {
v, isNull, err := CompareStringWithCollationInfo(ctx, col1, col2, chk.GetRow(0), chk.GetRow(0), "utf8_general_ci")
c.Assert(err, IsNil)
c.Assert(isNull, IsFalse)
c.Assert(v, Equals, int64(0))
require.NoError(t, err)
require.False(t, isNull)
require.Equal(t, int64(0), v)
}
}

Expand All @@ -90,6 +88,8 @@ func newExpression(coercibility Coercibility, repertoire Repertoire, chs, coll s
}

func TestInferCollation(t *testing.T) {
t.Parallel()

tests := []struct {
exprs []Expression
err bool
Expand Down Expand Up @@ -322,6 +322,8 @@ func newColInt(coercibility Coercibility) *Column {
}

func TestDeriveCollation(t *testing.T) {
t.Parallel()

ctx := mock.NewContext()
tests := []struct {
fcs []string
Expand Down