github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/util/charset/charset_test.go (about) 1 // Copyright 2015 PingCAP, 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package charset 15 16 import ( 17 "testing" 18 19 . "github.com/insionng/yougam/libraries/pingcap/check" 20 "github.com/insionng/yougam/libraries/pingcap/tidb/util/testleak" 21 ) 22 23 func TestT(t *testing.T) { 24 TestingT(t) 25 } 26 27 var _ = Suite(&testCharsetSuite{}) 28 29 type testCharsetSuite struct { 30 } 31 32 func testValidCharset(c *C, charset string, collation string, expect bool) { 33 b := ValidCharsetAndCollation(charset, collation) 34 c.Assert(b, Equals, expect) 35 } 36 37 func (s *testCharsetSuite) TestValidCharset(c *C) { 38 defer testleak.AfterTest(c)() 39 tbl := []struct { 40 cs string 41 co string 42 succ bool 43 }{ 44 {"utf8", "utf8_general_ci", true}, 45 {"", "utf8_general_ci", true}, 46 {"latin1", "", true}, 47 {"utf8", "utf8_invalid_ci", false}, 48 {"gb2312", "gb2312_chinese_ci", false}, 49 } 50 for _, t := range tbl { 51 testValidCharset(c, t.cs, t.co, t.succ) 52 } 53 } 54 55 func (s *testCharsetSuite) TestGetAllCharsets(c *C) { 56 defer testleak.AfterTest(c)() 57 charset := &Charset{"test", nil, nil, "Test", 5} 58 charsetInfos = append(charsetInfos, charset) 59 descs := GetAllCharsets() 60 c.Assert(len(descs), Equals, len(charsetInfos)-1) 61 } 62 63 func testGetDefaultCollation(c *C, charset string, expectCollation string, succ bool) { 64 b, err := GetDefaultCollation(charset) 65 if !succ { 66 c.Assert(err, NotNil) 67 return 68 } 69 c.Assert(b, Equals, expectCollation) 70 } 71 72 func (s *testCharsetSuite) TestGetDefaultCollation(c *C) { 73 defer testleak.AfterTest(c)() 74 tbl := []struct { 75 cs string 76 co string 77 succ bool 78 }{ 79 {"utf8", "utf8_general_ci", true}, 80 {"latin1", "latin1_swedish_ci", true}, 81 {"invalid_cs", "", false}, 82 {"", "utf8_general_ci", false}, 83 } 84 for _, t := range tbl { 85 testGetDefaultCollation(c, t.cs, t.co, t.succ) 86 } 87 }