Skip to content

Commit c2d6a8f

Browse files
tests: align common coverage with postgres-specific subscription/reset rules
1 parent eec8df0 commit c2d6a8f

1 file changed

Lines changed: 38 additions & 21 deletions

File tree

tests/sqlparser_common.rs

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15377,35 +15377,40 @@ fn parse_comments() {
1537715377

1537815378
// https://www.postgresql.org/docs/current/sql-comment.html
1537915379
let object_types = [
15380-
("COLLATION", CommentObject::Collation),
15381-
("COLUMN", CommentObject::Column),
15382-
("DATABASE", CommentObject::Database),
15383-
("DOMAIN", CommentObject::Domain),
15384-
("EXTENSION", CommentObject::Extension),
15385-
("FUNCTION", CommentObject::Function),
15386-
("INDEX", CommentObject::Index),
15387-
("MATERIALIZED VIEW", CommentObject::MaterializedView),
15388-
("PROCEDURE", CommentObject::Procedure),
15389-
("ROLE", CommentObject::Role),
15390-
("SCHEMA", CommentObject::Schema),
15391-
("SEQUENCE", CommentObject::Sequence),
15392-
("TABLE", CommentObject::Table),
15393-
("TYPE", CommentObject::Type),
15394-
("USER", CommentObject::User),
15395-
("VIEW", CommentObject::View),
15380+
("COLLATION", CommentObject::Collation, "db.t0"),
15381+
("COLUMN", CommentObject::Column, "db.t0"),
15382+
("DATABASE", CommentObject::Database, "db.t0"),
15383+
("DOMAIN", CommentObject::Domain, "db.t0"),
15384+
("EXTENSION", CommentObject::Extension, "db.t0"),
15385+
("FUNCTION", CommentObject::Function, "db.t0"),
15386+
("INDEX", CommentObject::Index, "db.t0"),
15387+
(
15388+
"MATERIALIZED VIEW",
15389+
CommentObject::MaterializedView,
15390+
"db.t0",
15391+
),
15392+
("PROCEDURE", CommentObject::Procedure, "db.t0"),
15393+
("ROLE", CommentObject::Role, "db.t0"),
15394+
("SCHEMA", CommentObject::Schema, "db.t0"),
15395+
("SEQUENCE", CommentObject::Sequence, "db.t0"),
15396+
("SUBSCRIPTION", CommentObject::Subscription, "t0"),
15397+
("TABLE", CommentObject::Table, "db.t0"),
15398+
("TYPE", CommentObject::Type, "db.t0"),
15399+
("USER", CommentObject::User, "db.t0"),
15400+
("VIEW", CommentObject::View, "db.t0"),
1539615401
];
15397-
for (keyword, expected_object_type) in object_types.iter() {
15398-
match all_dialects_where(|d| d.supports_comment_on())
15399-
.verified_stmt(format!("COMMENT IF EXISTS ON {keyword} db.t0 IS 'comment'").as_str())
15400-
{
15402+
for (keyword, expected_object_type, object_name_sql) in object_types.iter() {
15403+
match all_dialects_where(|d| d.supports_comment_on()).verified_stmt(
15404+
format!("COMMENT IF EXISTS ON {keyword} {object_name_sql} IS 'comment'").as_str(),
15405+
) {
1540115406
Statement::Comment {
1540215407
object_type,
1540315408
object_name,
1540415409
comment: Some(comment),
1540515410
if_exists,
1540615411
} => {
1540715412
assert_eq!("comment", comment);
15408-
assert_eq!("db.t0", object_name.to_string());
15413+
assert_eq!(*object_name_sql, object_name.to_string());
1540915414
assert_eq!(*expected_object_type, object_type);
1541015415
assert!(if_exists);
1541115416
}
@@ -18631,6 +18636,18 @@ fn parse_reset_statement() {
1863118636
Statement::Reset(ResetStatement { reset }) => assert_eq!(reset, Reset::ALL),
1863218637
_ => unreachable!(),
1863318638
}
18639+
let postgres = TestedDialects::new(vec![Box::new(PostgreSqlDialect {})]);
18640+
match postgres.verified_stmt("RESET SESSION AUTHORIZATION") {
18641+
Statement::Reset(ResetStatement { reset }) => {
18642+
assert_eq!(reset, Reset::SessionAuthorization)
18643+
}
18644+
_ => unreachable!(),
18645+
}
18646+
18647+
let non_pg = all_dialects_where(|d| !d.is::<PostgreSqlDialect>());
18648+
assert!(non_pg
18649+
.parse_sql_statements("RESET SESSION AUTHORIZATION")
18650+
.is_err());
1863418651
}
1863518652

1863618653
#[test]

0 commit comments

Comments
 (0)