@@ -30,4 +30,83 @@ describe.concurrent('collations', () => {
3030 test ( 'fromIndex good index' , ( ) => {
3131 assert . equal ( Collations . fromIndex ( 33 ) . name , 'UTF8MB3_GENERAL_CI' ) ;
3232 } ) ;
33+
34+ test ( 'fromName utf8mb4 default value' , ( ) => {
35+ const collation = Collations . fromName ( 'UCA1400_AI_CI' ) ;
36+ assert . isDefined ( collation ) ;
37+ assert . equal ( collation . name , 'UCA1400_AI_CI' ) ;
38+ assert . equal ( collation . maxLength , 4 ) ;
39+ } ) ;
40+
41+
42+ test ( 'fromCharsetAndName utf8mb4 with UCA1400_AI_CI' , ( ) => {
43+ const collation = Collations . fromCharsetAndName ( 'utf8mb4' , 'UCA1400_AI_CI' ) ;
44+ assert . isDefined ( collation ) ;
45+ assert . equal ( collation . name , 'UCA1400_AI_CI' ) ;
46+ assert . equal ( collation . maxLength , 4 ) ;
47+ } ) ;
48+
49+ test ( 'fromCharsetAndName utf8mb3 with UCA1400_AI_CI' , ( ) => {
50+ const collation = Collations . fromCharsetAndName ( 'utf8mb3' , 'UCA1400_AI_CI' ) ;
51+ assert . isDefined ( collation ) ;
52+ assert . equal ( collation . name , 'UCA1400_AI_CI' ) ;
53+ assert . equal ( collation . maxLength , 3 ) ;
54+ } ) ;
55+
56+ test ( 'fromCharsetAndName utf8 defaults to utf8mb4' , ( ) => {
57+ const collation = Collations . fromCharsetAndName ( 'utf8' , 'UCA1400_AI_CI' ) ;
58+ assert . isDefined ( collation ) ;
59+ assert . equal ( collation . name , 'UCA1400_AI_CI' ) ;
60+ assert . equal ( collation . maxLength , 4 ) ;
61+ } ) ;
62+
63+ test ( 'fromCharsetAndName non-utf8 charset' , ( ) => {
64+ const collation = Collations . fromCharsetAndName ( 'latin1' , 'LATIN1_SWEDISH_CI' ) ;
65+ assert . isDefined ( collation ) ;
66+ assert . equal ( collation . name , 'LATIN1_SWEDISH_CI' ) ;
67+ assert . equal ( collation . charset , 'latin1' ) ;
68+ } ) ;
69+
70+ test ( 'fromCharsetAndName unknown collation' , ( ) => {
71+ assert . isUndefined ( Collations . fromCharsetAndName ( 'utf8mb4' , 'UNKNOWN_COLLATION' ) ) ;
72+ } ) ;
73+
74+ test ( 'fromCharsetAndName both charset and collation unknown' , ( ) => {
75+ assert . isUndefined ( Collations . fromCharsetAndName ( 'unknown' , 'UNKNOWN_COLLATION' ) ) ;
76+ } ) ;
77+
78+ test ( 'fromCharsetAndName UTF8_ compatibility fallback to UTF8MB4_' , ( ) => {
79+ const collation = Collations . fromCharsetAndName ( 'utf8mb4' , 'UTF8_GENERAL_CI' ) ;
80+ assert . isDefined ( collation ) ;
81+ assert . equal ( collation . name , 'UTF8MB4_GENERAL_CI' ) ;
82+ assert . equal ( collation . maxLength , 4 ) ;
83+ } ) ;
84+
85+ test ( 'fromCharsetAndName ucs2 with UCA1400_AI_CI' , ( ) => {
86+ const collation = Collations . fromCharsetAndName ( 'ucs2' , 'UCA1400_AI_CI' ) ;
87+ assert . isDefined ( collation ) ;
88+ assert . equal ( collation . name , 'UCA1400_AI_CI' ) ;
89+ assert . equal ( collation . charset , 'ucs2' ) ;
90+ } ) ;
91+
92+ test ( 'fromCharsetAndName utf16 with UCA1400_AI_CI' , ( ) => {
93+ const collation = Collations . fromCharsetAndName ( 'utf16' , 'UCA1400_AI_CI' ) ;
94+ assert . isDefined ( collation ) ;
95+ assert . equal ( collation . name , 'UCA1400_AI_CI' ) ;
96+ assert . equal ( collation . charset , 'utf16' ) ;
97+ } ) ;
98+
99+ test ( 'fromCharsetAndName utf8mb4 with UTF8MB4_UNICODE_CI' , ( ) => {
100+ const collation = Collations . fromCharsetAndName ( 'utf8mb4' , 'UTF8MB4_UNICODE_CI' ) ;
101+ assert . isDefined ( collation ) ;
102+ assert . equal ( collation . name , 'UTF8MB4_UNICODE_CI' ) ;
103+ assert . equal ( collation . maxLength , 4 ) ;
104+ } ) ;
105+
106+ test ( 'fromCharsetAndName utf8mb3 with UTF8MB3_GENERAL_CI' , ( ) => {
107+ const collation = Collations . fromCharsetAndName ( 'utf8mb3' , 'UTF8MB3_GENERAL_CI' ) ;
108+ assert . isDefined ( collation ) ;
109+ assert . equal ( collation . name , 'UTF8MB3_GENERAL_CI' ) ;
110+ assert . equal ( collation . maxLength , 3 ) ;
111+ } ) ;
33112} ) ;
0 commit comments