Skip to content

Commit 1812929

Browse files
Ensured coverage of more corner cases
1 parent 48f1cd0 commit 1812929

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/sqlparser_postgres.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6937,6 +6937,35 @@ fn parse_create_operator_class() {
69376937
_ => panic!("Expected CreateOperatorClass statement"),
69386938
}
69396939

6940+
// Test function with no arguments (empty parentheses normalizes to no parentheses)
6941+
pg().one_statement_parses_to(
6942+
"CREATE OPERATOR CLASS test_ops FOR TYPE INT4 USING btree AS FUNCTION 1 my_func()",
6943+
"CREATE OPERATOR CLASS test_ops FOR TYPE INT4 USING btree AS FUNCTION 1 my_func",
6944+
);
6945+
match pg().verified_stmt(
6946+
"CREATE OPERATOR CLASS test_ops FOR TYPE INT4 USING btree AS FUNCTION 1 my_func",
6947+
) {
6948+
Statement::CreateOperatorClass(CreateOperatorClass { ref items, .. }) => {
6949+
assert_eq!(items.len(), 1);
6950+
match &items[0] {
6951+
OperatorClassItem::Function {
6952+
support_number: 1,
6953+
op_types: None,
6954+
ref function_name,
6955+
ref argument_types,
6956+
} => {
6957+
assert_eq!(
6958+
function_name,
6959+
&ObjectName::from(vec![Ident::new("my_func")])
6960+
);
6961+
assert_eq!(argument_types.len(), 0);
6962+
}
6963+
_ => panic!("Expected Function item without op_types and no arguments"),
6964+
}
6965+
}
6966+
_ => panic!("Expected CreateOperatorClass statement"),
6967+
}
6968+
69406969
// Test multiple items including STORAGE
69416970
match pg().verified_stmt("CREATE OPERATOR CLASS gist_ops FOR TYPE geometry USING gist AS OPERATOR 1 <<, FUNCTION 1 gist_consistent(internal, geometry, INT4), STORAGE box") {
69426971
Statement::CreateOperatorClass(CreateOperatorClass {
@@ -6978,4 +7007,11 @@ fn parse_create_operator_class() {
69787007
}
69797008
_ => panic!("Expected CreateOperatorClass statement"),
69807009
}
7010+
7011+
// Test nested empty parentheses error in function arguments
7012+
assert!(pg()
7013+
.parse_sql_statements(
7014+
"CREATE OPERATOR CLASS test_ops FOR TYPE INT4 USING btree AS FUNCTION 1 cas_cmp(()"
7015+
)
7016+
.is_err());
69817017
}

0 commit comments

Comments
 (0)