@@ -69,3 +69,61 @@ func testParseCollation(t *testing.T, charset string, collation string, binaryAt
6969 }
7070 })
7171}
72+
73+ func TestConvertCollationID (t * testing.T ) {
74+ tests := []struct {
75+ input any
76+ expected string
77+ }{
78+ {uint64 (33 ), "utf8mb3_general_ci" },
79+ {int64 (33 ), "utf8mb3_general_ci" },
80+ {[]byte ("33" ), "utf8mb3_general_ci" },
81+ {uint64 (8 ), "latin1_swedish_ci" },
82+ {int32 (8 ), "latin1_swedish_ci" },
83+
84+ {45 , "utf8mb4_general_ci" },
85+ {uint64 (46 ), "utf8mb4_bin" },
86+ {255 , "utf8mb4_0900_ai_ci" },
87+ {uint64 (309 ), "utf8mb4_0900_bin" },
88+
89+ {83 , "utf8mb3_bin" },
90+ {uint64 (223 ), "utf8mb3_general_mysql500_ci" },
91+
92+ {uint64 (47 ), "latin1_bin" },
93+ {48 , "latin1_general_ci" },
94+ {49 , "latin1_general_cs" },
95+
96+ {uint64 (63 ), "binary" },
97+
98+ {uint64 (11 ), "ascii_general_ci" },
99+ {65 , "ascii_bin" },
100+
101+ {uint64 (15 ), "latin1_danish_ci" },
102+ {31 , "latin1_german2_ci" },
103+ {94 , "latin1_spanish_ci" },
104+
105+ {int8 (8 ), "latin1_swedish_ci" },
106+ {int16 (8 ), "latin1_swedish_ci" },
107+ {int (8 ), "latin1_swedish_ci" },
108+ {uint8 (8 ), "latin1_swedish_ci" },
109+ {uint16 (8 ), "latin1_swedish_ci" },
110+ {uint (8 ), "latin1_swedish_ci" },
111+ {uint32 (8 ), "latin1_swedish_ci" },
112+
113+ {"utf8mb4_0900_bin" , "utf8mb4_0900_bin" },
114+ {"utf8mb3_general_ci" , "utf8mb3_general_ci" },
115+ {"" , "" },
116+
117+ {uint64 (99999 ), "99999" },
118+ {uint64 (1000 ), "1000" },
119+ {int (500 ), "500" },
120+ }
121+
122+ for _ , tt := range tests {
123+ t .Run (fmt .Sprintf ("%T(%v)" , tt .input , tt .input ), func (t * testing.T ) {
124+ result , err := ConvertCollationID (tt .input )
125+ assert .NoError (t , err )
126+ assert .Equal (t , tt .expected , result )
127+ })
128+ }
129+ }
0 commit comments