@@ -811,6 +811,171 @@ fn parse_drop_extension() {
811811 ) ;
812812}
813813
814+ #[ test]
815+ fn parse_create_collation ( ) {
816+ assert_eq ! (
817+ pg_and_generic( )
818+ . verified_stmt( "CREATE COLLATION test3 (provider = icu, lc_collate = 'en_US.utf8')" , ) ,
819+ Statement :: CreateCollation ( CreateCollation {
820+ if_not_exists: false ,
821+ name: ObjectName :: from( vec![ Ident :: new( "test3" ) ] ) ,
822+ definition: CreateCollationDefinition :: Options ( vec![
823+ SqlOption :: KeyValue {
824+ key: Ident :: new( "provider" ) ,
825+ value: Expr :: Identifier ( Ident :: new( "icu" ) ) ,
826+ } ,
827+ SqlOption :: KeyValue {
828+ key: Ident :: new( "lc_collate" ) ,
829+ value: Expr :: Value (
830+ Value :: SingleQuotedString ( "en_US.utf8" . to_string( ) ) . with_empty_span( ) ,
831+ ) ,
832+ } ,
833+ ] ) ,
834+ } )
835+ ) ;
836+
837+ assert_eq ! (
838+ pg_and_generic( ) . verified_stmt( "CREATE COLLATION test4 FROM nonsense" ) ,
839+ Statement :: CreateCollation ( CreateCollation {
840+ if_not_exists: false ,
841+ name: ObjectName :: from( vec![ Ident :: new( "test4" ) ] ) ,
842+ definition: CreateCollationDefinition :: From ( ObjectName :: from( vec![ Ident :: new(
843+ "nonsense" ,
844+ ) ] ) ) ,
845+ } )
846+ ) ;
847+
848+ assert_eq ! (
849+ pg_and_generic( )
850+ . verified_stmt( "CREATE COLLATION testx (provider = icu, locale = 'nonsense-nowhere')" ) ,
851+ Statement :: CreateCollation ( CreateCollation {
852+ if_not_exists: false ,
853+ name: ObjectName :: from( vec![ Ident :: new( "testx" ) ] ) ,
854+ definition: CreateCollationDefinition :: Options ( vec![
855+ SqlOption :: KeyValue {
856+ key: Ident :: new( "provider" ) ,
857+ value: Expr :: Identifier ( Ident :: new( "icu" ) ) ,
858+ } ,
859+ SqlOption :: KeyValue {
860+ key: Ident :: new( "locale" ) ,
861+ value: Expr :: Value (
862+ Value :: SingleQuotedString ( "nonsense-nowhere" . to_string( ) ) . with_empty_span( ) ,
863+ ) ,
864+ } ,
865+ ] ) ,
866+ } )
867+ ) ;
868+ }
869+
870+ #[ test]
871+ fn parse_alter_collation ( ) {
872+ assert_eq ! (
873+ pg_and_generic( ) . verified_stmt( "ALTER COLLATION test1 RENAME TO test11" ) ,
874+ Statement :: AlterCollation ( AlterCollation {
875+ name: ObjectName :: from( vec![ Ident :: new( "test1" ) ] ) ,
876+ operation: AlterCollationOperation :: RenameTo {
877+ new_name: Ident :: new( "test11" ) ,
878+ } ,
879+ } )
880+ ) ;
881+
882+ assert_eq ! (
883+ pg_and_generic( ) . verified_stmt( "ALTER COLLATION test11 OWNER TO regress_test_role" ) ,
884+ Statement :: AlterCollation ( AlterCollation {
885+ name: ObjectName :: from( vec![ Ident :: new( "test11" ) ] ) ,
886+ operation: AlterCollationOperation :: OwnerTo ( Owner :: Ident ( Ident :: new(
887+ "regress_test_role" ,
888+ ) ) ) ,
889+ } )
890+ ) ;
891+
892+ assert_eq ! (
893+ pg_and_generic( ) . verified_stmt( "ALTER COLLATION test11 SET SCHEMA test_schema" ) ,
894+ Statement :: AlterCollation ( AlterCollation {
895+ name: ObjectName :: from( vec![ Ident :: new( "test11" ) ] ) ,
896+ operation: AlterCollationOperation :: SetSchema {
897+ schema_name: ObjectName :: from( vec![ Ident :: new( "test_schema" ) ] ) ,
898+ } ,
899+ } )
900+ ) ;
901+
902+ assert_eq ! (
903+ pg_and_generic( ) . verified_stmt( "ALTER COLLATION \" en-x-icu\" REFRESH VERSION" ) ,
904+ Statement :: AlterCollation ( AlterCollation {
905+ name: ObjectName :: from( vec![ Ident :: with_quote( '"' , "en-x-icu" ) ] ) ,
906+ operation: AlterCollationOperation :: RefreshVersion ,
907+ } )
908+ ) ;
909+ }
910+
911+ #[ test]
912+ fn parse_drop_and_comment_collation_ast ( ) {
913+ assert_eq ! (
914+ pg_and_generic( ) . verified_stmt( "DROP COLLATION test0" ) ,
915+ Statement :: Drop {
916+ object_type: ObjectType :: Collation ,
917+ if_exists: false ,
918+ names: vec![ ObjectName :: from( vec![ Ident :: new( "test0" ) ] ) ] ,
919+ cascade: false ,
920+ restrict: false ,
921+ purge: false ,
922+ temporary: false ,
923+ table: None ,
924+ }
925+ ) ;
926+
927+ assert_eq ! (
928+ pg_and_generic( ) . verified_stmt( "DROP COLLATION IF EXISTS test0" ) ,
929+ Statement :: Drop {
930+ object_type: ObjectType :: Collation ,
931+ if_exists: true ,
932+ names: vec![ ObjectName :: from( vec![ Ident :: new( "test0" ) ] ) ] ,
933+ cascade: false ,
934+ restrict: false ,
935+ purge: false ,
936+ temporary: false ,
937+ table: None ,
938+ }
939+ ) ;
940+
941+ assert_eq ! (
942+ pg_and_generic( ) . verified_stmt( "COMMENT ON COLLATION test0 IS 'US English'" ) ,
943+ Statement :: Comment {
944+ object_type: CommentObject :: Collation ,
945+ object_name: ObjectName :: from( vec![ Ident :: new( "test0" ) ] ) ,
946+ comment: Some ( "US English" . to_string( ) ) ,
947+ if_exists: false ,
948+ }
949+ ) ;
950+ }
951+
952+ #[ test]
953+ fn parse_collation_statements_roundtrip ( ) {
954+ let statements = [
955+ "CREATE COLLATION test3 (provider = icu, lc_collate = 'en_US.utf8')" ,
956+ "CREATE COLLATION testx (provider = icu, locale = 'nonsense-nowhere')" ,
957+ "CREATE COLLATION testx (provider = icu, locale = '@colStrength=primary;nonsense=yes')" ,
958+ "DROP COLLATION testx" ,
959+ "CREATE COLLATION test4 FROM nonsense" ,
960+ "CREATE COLLATION test5 FROM test0" ,
961+ "ALTER COLLATION test1 RENAME TO test11" ,
962+ "ALTER COLLATION test0 RENAME TO test11" ,
963+ "ALTER COLLATION test1 RENAME TO test22" ,
964+ "ALTER COLLATION test11 OWNER TO regress_test_role" ,
965+ "ALTER COLLATION test11 OWNER TO nonsense" ,
966+ "ALTER COLLATION test11 SET SCHEMA test_schema" ,
967+ "COMMENT ON COLLATION test0 IS 'US English'" ,
968+ "DROP COLLATION test0, test_schema.test11, test5" ,
969+ "DROP COLLATION test0" ,
970+ "DROP COLLATION IF EXISTS test0" ,
971+ "ALTER COLLATION \" en-x-icu\" REFRESH VERSION" ,
972+ ] ;
973+
974+ for sql in statements {
975+ pg_and_generic ( ) . verified_stmt ( sql) ;
976+ }
977+ }
978+
814979#[ test]
815980fn parse_alter_table_alter_column ( ) {
816981 pg ( ) . verified_stmt ( "ALTER TABLE tab ALTER COLUMN is_active TYPE TEXT USING 'text'" ) ;
0 commit comments