Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/squawk_syntax/src/ast/generated/nodes.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/squawk_syntax/src/postgresql.ungram
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ CallExpr =
Expr ArgList

CastExpr =
Expr ColonColon Type
Expr (ColonColon? | 'as') Type

ArrayExpr =
'array' '[' (Expr (',' Expr)*) ']'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
---
source: crates/squawk_syntax/src/test.rs
input_file: crates/squawk_syntax/test_data/validation/alter_table_ok.sql
---
[email protected]
[email protected] "-- regression test fo ..."
[email protected] "\n"
[email protected]
[email protected] "alter"
[email protected] " "
[email protected] "table"
[email protected] " "
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected] "public"
[email protected] "."
[email protected]
[email protected]
[email protected] "widget"
[email protected] "\n "
[email protected]
[email protected] "add"
[email protected] " "
[email protected]
[email protected] "constraint"
[email protected] " "
[email protected]
[email protected] "widget_config_schema_ ..."
[email protected] " "
[email protected] "check"
[email protected] " "
[email protected] "("
[email protected] "\n "
[email protected]
[email protected]
[email protected]
[email protected] "checks"
[email protected] "."
[email protected]
[email protected] "is_widget_config_valid"
[email protected]
[email protected] "("
[email protected]
[email protected]
[email protected] "'widget'"
[email protected]
[email protected] ":"
[email protected] ":"
[email protected]
[email protected]
[email protected] "custom_types"
[email protected] "."
[email protected]
[email protected] "widget_schema_type"
[email protected] ","
[email protected] " "
[email protected]
[email protected] "config"
[email protected] ")"
[email protected] "\n "
[email protected] ")"
[email protected] " "
[email protected]
[email protected] "not"
[email protected] " "
[email protected] "valid"
[email protected] ";"
[email protected] "\n\n"
[email protected]
[email protected] "alter"
[email protected] " "
[email protected] "table"
[email protected] " "
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected] "public"
[email protected] "."
[email protected]
[email protected]
[email protected] "widget_instance"
[email protected] "\n "
[email protected]
[email protected] "add"
[email protected] " "
[email protected]
[email protected] "constraint"
[email protected] " "
[email protected]
[email protected] "widget_instance_confi ..."
[email protected] " "
[email protected] "check"
[email protected] " "
[email protected] "("
[email protected] "\n "
[email protected]
[email protected]
[email protected]
[email protected] "checks"
[email protected] "."
[email protected]
[email protected] "is_widget_config_valid"
[email protected]
[email protected] "("
[email protected]
[email protected]
[email protected] "'widget_instance'"
[email protected]
[email protected] ":"
[email protected] ":"
[email protected]
[email protected]
[email protected] "custom_types"
[email protected] "."
[email protected]
[email protected] "widget_schema_type"
[email protected] ","
[email protected] " "
[email protected]
[email protected] "config_overrides"
[email protected] ")"
[email protected] "\n "
[email protected] ")"
[email protected] " "
[email protected]
[email protected] "not"
[email protected] " "
[email protected] "valid"
[email protected] "\n"

This file was deleted.

18 changes: 13 additions & 5 deletions crates/squawk_syntax/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,17 @@ fn syntaxtest(fixture: Fixture<&str>) {
assert_snapshot!(format!("{}_{}", test_name, parent_dir), buffer);
});

assert_ne!(
errors.len(),
0,
"tests defined in the `syntax/test_data` must have errors."
);
if test_name.ends_with("_ok") {
assert_eq!(
errors.len(),
0,
"tests defined in the `syntax/test_data` ending with `_ok` can't have errors."
);
} else {
assert_ne!(
errors.len(),
0,
"tests defined in the `syntax/test_data` must have errors."
);
}
}
15 changes: 0 additions & 15 deletions crates/squawk_syntax/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub(crate) fn validate(root: &SyntaxNode, errors: &mut Vec<SyntaxError>) {
ast::PrefixExpr(it) => validate_prefix_expr(it, errors),
ast::ArrayExpr(it) => validate_array_expr(it, errors),
ast::DropAggregate(it) => validate_drop_aggregate(it, errors),
ast::CallExpr(it) => validate_call_expr(it, errors),
ast::JoinExpr(it) => validate_join_expr(it, errors),
ast::Literal(it) => validate_literal(it, errors),
ast::NonStandardParam(it) => validate_non_standard_param(it, errors),
Expand All @@ -28,20 +27,6 @@ pub(crate) fn validate(root: &SyntaxNode, errors: &mut Vec<SyntaxError>) {
}
}

fn validate_call_expr(it: ast::CallExpr, acc: &mut Vec<SyntaxError>) {
let Some(arg_list) = it.arg_list() else {
return;
};
for arg in arg_list.args() {
if let ast::Expr::CastExpr(cast_expr) = &arg {
acc.push(SyntaxError::new(
"Invalid cast. Use `cast`, `treat`, or `::` instead.",
cast_expr.syntax().text_range(),
));
}
}
}

fn validate_create_table(it: ast::CreateTable, acc: &mut Vec<SyntaxError>) {
let Some(arg_list) = it.table_arg_list() else {
return;
Expand Down
10 changes: 10 additions & 0 deletions crates/squawk_syntax/test_data/validation/alter_table_ok.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- regression test for https://github.com/sbdchd/squawk/issues/597
alter table public.widget
add constraint widget_config_schema_check check (
checks.is_widget_config_valid('widget'::custom_types.widget_schema_type, config)
) not valid;

alter table public.widget_instance
add constraint widget_instance_config_overrides_schema_check check (
checks.is_widget_config_valid('widget_instance'::custom_types.widget_schema_type, config_overrides)
) not valid
2 changes: 0 additions & 2 deletions crates/squawk_syntax/test_data/validation/call_expr.sql

This file was deleted.

Loading